Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge commit 'ade64d0' into integration

Conflicts:
	spec/sprinkle/package_spec.rb
  • Loading branch information...
commit cd0ed0229bd4a475de40dd8ca9e255bf56833e28 2 parents 3b5ee4e + ade64d0
@crafterm authored
View
15 lib/sprinkle/installers/group.rb
@@ -0,0 +1,15 @@
+module Sprinkle
+ module Installers
+ class Group < Installer
+ def initialize(package, groupname, options, &block)
+ super package, &block
+ @groupname = groupname
+ @options = options
+ end
+ protected
+ def install_commands
+ "addgroup #{@options[:flags]} #{@groupname}"
+ end
+ end
+ end
+end
View
4 lib/sprinkle/installers/user.rb
@@ -3,8 +3,8 @@ module Installers
class User < Installer
def initialize(package, username, options, &block)
super package, &block
- @username=username
- @options =options
+ @username = username
+ @options = options
end
protected
def install_commands
View
6 lib/sprinkle/package.rb
@@ -122,7 +122,11 @@ def initialize(name, metadata = {}, &block)
self.instance_eval &block
end
def add_user(username, options={}, &block)
- @installers<<Sprinkle::Installers::User.new(self, username, options, &block)
+ @installers << Sprinkle::Installers::User.new(self, username, options, &block)
+ end
+
+ def add_group(group, options={}, &block)
+ @installers << Sprinkle::Installers::Group.new(self, group, options, &block)
end
def freebsd_pkg(*names, &block)
View
2  lib/sprinkle/verifiers/file.rb
@@ -22,7 +22,7 @@ def file_contains(path, text)
@commands << "grep '#{text}' #{path}"
end
def user_present(username)
- @commands << %Q{grep -q -e \'^#{username}:x\' /etc/passwd && test -d ~#{username}}
+ has_user username
end
def matches_local(localfile, remotefile, mode=nil)
raise "Couldn't find local file #{localfile}" unless ::File.exists?(localfile)
View
15 lib/sprinkle/verifiers/user.rb
@@ -1,15 +0,0 @@
-module Sprinkle
- module Verifiers
- # = User Verifier
- # This was added so we dont have to verify a file to see if user was created
- # Defines a verify which can be used to test the existence of a user.
- module Users
- Sprinkle::Verify.register(Sprinkle::Verifiers::Users)
-
- # Tests that the user exists
- def has_user(user)
- @commands << "id #{user}"
- end
- end
- end
-end
View
33 lib/sprinkle/verifiers/users_groups.rb
@@ -0,0 +1,33 @@
+module Sprinkle
+ module Verifiers
+ # = Users and groups Verifier
+ #
+ # Tests for the existance of users and groups.
+ #
+ # == Example Usage
+ #
+ # verify do
+ # has_user 'ntp'
+ # has_user 'noone', :in_group => 'nobody'
+ # has_group 'nobody'
+ # end
+ #
+ module UsersGroups
+ Sprinkle::Verify.register(Sprinkle::Verifiers::UsersGroups)
+
+ # Tests that the user exists
+ def has_user(user, opts = {})
+ if opts[:in_group]
+ @commands << "id -G #{user} | xargs -n1 echo | grep #{opts[:in_group]}"
+ else
+ @commands << "id #{user}"
+ end
+ end
+
+ # Tests that the group exists
+ def has_group(group)
+ @commands << "id -g #{group}"
+ end
+ end
+ end
+end
View
78 spec/sprinkle/package_spec.rb
@@ -8,7 +8,7 @@
@empty = Proc.new { }
@opts = { }
end
-
+
# Kind of a messy way to do this but it works and DRYs out
# the specs. Checks to make sure an installer is receiving
# the block passed to it throught the package block.
@@ -21,12 +21,12 @@ def check_block_forwarding_on(installer)
pre :install, 'preOp'
end
end
-
+
pre_count = pkg.installers.first.instance_variable_get(:@pre)[:install].length
}.should change { pre_count }.by(1)
CODE
end
-
+
# More of Mitchell's meta-programming to dry up specs.
def create_package_with_blank_verify(n = 1)
eval(<<CODE)
@@ -141,7 +141,7 @@ def create_package_with_blank_verify(n = 1)
pkg.should respond_to(:gem)
pkg.installers.first.class.should == Sprinkle::Installers::Gem
end
-
+
it 'should optionally accept a noop installer' do
pkg = package @name do
noop do
@@ -154,6 +154,14 @@ def create_package_with_blank_verify(n = 1)
@install_commands.should == 'echo noop'
end
+ it 'should optionally accept an group installer' do
+ pkg = package @name do
+ add_group 'bob'
+ end
+ pkg.should respond_to(:add_group)
+ pkg.installers.first.class.should == Sprinkle::Installers::Group
+ end
+
it 'should optionally accept a source installer' do
pkg = package @name do
source 'archive'
@@ -162,6 +170,14 @@ def create_package_with_blank_verify(n = 1)
pkg.installers.first.class.should == Sprinkle::Installers::Source
end
+ it 'should optionally accept an user installer' do
+ pkg = package @name do
+ add_user 'bob'
+ end
+ pkg.should respond_to(:add_user)
+ pkg.installers.first.class.should == Sprinkle::Installers::User
+ end
+
it 'should allow multiple installer steps to be defined and respect order' do
pkg = package @name do
source 'archive'
@@ -191,7 +207,7 @@ def create_package_with_blank_verify(n = 1)
pkg.should respond_to(:source)
pkg.installers.first.class.should == Sprinkle::Installers::Source
end
-
+
it 'should forward block to installer superclass' do
check_block_forwarding_on(:source)
end
@@ -204,13 +220,13 @@ def create_package_with_blank_verify(n = 1)
end
end
-
+
describe 'with an apt installer' do
it 'should forward block to installer superclass' do
check_block_forwarding_on(:apt)
end
end
-
+
describe 'with an rpm installer' do
it 'should forward block to installer superclass' do
check_block_forwarding_on(:rpm)
@@ -225,7 +241,7 @@ def create_package_with_blank_verify(n = 1)
end
pkg.recommends.should include(:rubygems)
end
-
+
it 'should forward block to installer superclass' do
check_block_forwarding_on(:gem)
end
@@ -268,7 +284,7 @@ def create_package_with_blank_verify(n = 1)
end
end
-
+
describe 'with verifications' do
before do
@pkg = create_package_with_blank_verify(3)
@@ -276,47 +292,47 @@ def create_package_with_blank_verify(n = 1)
@installer.stub!(:defaults)
@installer.stub!(:process)
end
-
+
describe 'with forcing' do
before do
# Being explicit
Sprinkle::OPTIONS[:force] = true
end
-
+
it 'should process verifications only once' do
@pkg.should_receive(:process_verifications).once
@pkg.process(@deployment, @roles)
end
-
+
after do
# Being explicit
Sprinkle::OPTIONS[:force] = false
end
end
-
+
describe 'without forcing' do
before do
# Being explicit
Sprinkle::OPTIONS[:force] = false
end
-
+
it 'should process verifications twice' do
@pkg.should_receive(:process_verifications).once.with(@deployment, @roles, true).and_raise(Sprinkle::VerificationFailed.new(@pkg, ''))
@pkg.should_receive(:process_verifications).once.with(@deployment, @roles).and_raise(Sprinkle::VerificationFailed.new(@pkg, ''))
end
-
+
it 'should continue with installation if pre-verification fails' do
@pkg.should_receive(:process_verifications).twice.and_raise(Sprinkle::VerificationFailed.new(@pkg, ''))
@installer.should_receive(:defaults)
@installer.should_receive(:process)
end
-
+
it 'should only process verifications once and should not process installer if verifications succeed' do
@pkg.should_receive(:process_verifications).once.and_return(nil)
@installer.should_not_receive(:defaults)
@installer.should_not_receive(:process)
end
-
+
after do
begin
@pkg.process(@deployment, @roles)
@@ -326,7 +342,7 @@ def create_package_with_blank_verify(n = 1)
end
end
-
+
describe 'when processing verifications' do
before do
@deployment = mock(Sprinkle::Deployment)
@@ -339,7 +355,7 @@ def create_package_with_blank_verify(n = 1)
@logger = mock(ActiveSupport::BufferedLogger, :debug => true, :debug? => true)
@logger.stub!(:info)
end
-
+
it 'should request _each_ verification to configure itself against the deployment context' do
@pkg.verifications.each do |v|
v.should_receive(:defaults).with(@deployment).once
@@ -353,16 +369,16 @@ def create_package_with_blank_verify(n = 1)
v.should_receive(:process).with(@roles).once
end
end
-
+
it 'should enter a log info event to notify user whats happening' do
@pkg.verifications.each do |v|
v.stub!(:defaults)
v.stub!(:process)
end
-
+
@pkg.should_receive(:logger).once.and_return(@logger)
end
-
+
after do
@pkg.process_verifications(@deployment, @roles)
end
@@ -431,7 +447,7 @@ def create_package_with_blank_verify(n = 1)
@v1 = package :v1, :provides => :virtual do; end
@v2 = package :v2, :provides => :virtual do; end
end
-
+
it 'should select package for an array' do
@a.should_receive(:select_package).with(:virtual, [@v1,@v2]).and_return(@v1)
@a.tree do; end
@@ -452,31 +468,31 @@ def create_package_with_blank_verify(n = 1)
end
end
-
- describe 'with verifications' do
+
+ describe 'with verifications' do
it 'should create a Sprinkle::Verification object for the verify block' do
Sprinkle::Verify.should_receive(:new).once
-
+
create_package_with_blank_verify
end
-
+
it 'should create multiple Sprinkle::Verification objects for multiple verify blocks' do
Sprinkle::Verify.should_receive(:new).twice
-
+
create_package_with_blank_verify(2)
end
-
+
it 'should add each Sprinkle::Verificaton object to the @verifications array' do
@pkg = create_package_with_blank_verify(3)
@pkg.verifications.length.should eql(3)
end
-
+
it 'should initialize Sprinkle::Verification with the package name, description, and block' do
Sprinkle::Verify.should_receive(:new) do |pkg, desc|
pkg.name.should eql(@name)
desc.should eql('stuff happens')
end
-
+
# We do a should_not raise_error because if a block was NOT passed, an error
# is raised. This is specced in verification_spec.rb
lambda { create_package_with_blank_verify }.should_not raise_error
View
28 spec/sprinkle/verify_spec.rb
@@ -14,6 +14,18 @@
# Check a directory exists
has_directory 'mydir'
+
+ # Check for a user
+ has_user "bob"
+
+ # Check for user with old API
+ user_present "someuser"
+
+ # Check for user in a group
+ has_user "alf", :in_group => "alien"
+
+ # Check for a group
+ has_group "bobgroup"
# Check a symlink exists
has_symlink 'mypointer'
@@ -64,6 +76,22 @@
it 'should do a "test -d" on the has_directory check' do
@verification.commands.should include('test -d mydir')
end
+
+ it 'should use id to check for user in group' do
+ @verification.commands.should include("id -G alf | xargs -n1 echo | grep alien")
+ end
+
+ it 'should use id to check for user' do
+ @verification.commands.should include('id bob')
+ end
+
+ it 'should use id to check for user via user_present' do
+ @verification.commands.should include('id someuser')
+ end
+
+ it 'should use id to check for group' do
+ @verification.commands.should include('id -g bobgroup')
+ end
it 'should do a "test -L" to check something is a symbolic link' do
@verification.commands.should include('test -L mypointer')
Please sign in to comment.
Something went wrong with that request. Please try again.