sprinkle 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.4.0
@@ -0,0 +1,15 @@
1
+ module Sprinkle
2
+ module Installers
3
+ class Group < Installer
4
+ def initialize(package, groupname, options, &block)
5
+ super package, &block
6
+ @groupname = groupname
7
+ @options = options
8
+ end
9
+ protected
10
+ def install_commands
11
+ "addgroup #{@options[:flags]} #{@groupname}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -3,8 +3,8 @@ module Sprinkle
3
3
  class Runner < Installer
4
4
  attr_accessor :cmd #:nodoc:
5
5
 
6
- def initialize(parent, cmd) #:nodoc:
7
- super parent
6
+ def initialize(parent, cmd, &block) #:nodoc:
7
+ super parent, {}, &block
8
8
  @cmd = cmd
9
9
  end
10
10
 
@@ -3,8 +3,8 @@ module Sprinkle
3
3
  class User < Installer
4
4
  def initialize(package, username, options, &block)
5
5
  super package, &block
6
- @username=username
7
- @options =options
6
+ @username = username
7
+ @options = options
8
8
  end
9
9
  protected
10
10
  def install_commands
@@ -122,7 +122,11 @@ module Sprinkle
122
122
  self.instance_eval &block
123
123
  end
124
124
  def add_user(username, options={}, &block)
125
- @installers<<Sprinkle::Installers::User.new(self, username, options, &block)
125
+ @installers << Sprinkle::Installers::User.new(self, username, options, &block)
126
+ end
127
+
128
+ def add_group(group, options={}, &block)
129
+ @installers << Sprinkle::Installers::Group.new(self, group, options, &block)
126
130
  end
127
131
 
128
132
  def freebsd_pkg(*names, &block)
@@ -192,7 +196,7 @@ module Sprinkle
192
196
  end
193
197
 
194
198
  def noop(&block)
195
- @installers << Sprinkle::Installers::Noop.new(self, name, options, &block)
199
+ @installers << Sprinkle::Installers::Runner.new(self, "echo noop", &block)
196
200
  end
197
201
 
198
202
  def push_text(text, path, options = {}, &block)
@@ -207,8 +211,8 @@ module Sprinkle
207
211
  @installers << Sprinkle::Installers::Transfer.new(self, source, destination, options, &block)
208
212
  end
209
213
 
210
- def runner(cmd)
211
- @installers << Sprinkle::Installers::Runner.new(self, cmd)
214
+ def runner(cmd, &block)
215
+ @installers << Sprinkle::Installers::Runner.new(self, cmd, &block)
212
216
  end
213
217
 
214
218
  def verify(description = '', &block)
@@ -22,7 +22,7 @@ module Sprinkle
22
22
  @commands << "grep '#{text}' #{path}"
23
23
  end
24
24
  def user_present(username)
25
- @commands << %Q{grep -q -e \'^#{username}:x\' /etc/passwd && test -d ~#{username}}
25
+ has_user username
26
26
  end
27
27
  def matches_local(localfile, remotefile, mode=nil)
28
28
  raise "Couldn't find local file #{localfile}" unless ::File.exists?(localfile)
@@ -15,10 +15,10 @@ module Sprinkle
15
15
  @commands << "ruby -e \"#{files.join(';')}\""
16
16
  end
17
17
 
18
- # Checks if a gem exists by calling "sudo gem list" and grepping against it.
19
- def has_gem(name, version=nil)
20
- version = version.nil? ? '' : "--version '#{version}'"
21
- @commands << "sudo gem list '#{name}' --installed #{version} > /dev/null"
18
+ # Checks if a gem exists by calling "gem list" and grepping against it.
19
+ def has_gem(name, version = nil)
20
+ version = version ? "--version '#{version}'" : ''
21
+ @commands << "gem list '#{name}' --installed #{version} > /dev/null"
22
22
  end
23
23
  end
24
24
  end
@@ -0,0 +1,33 @@
1
+ module Sprinkle
2
+ module Verifiers
3
+ # = Users and groups Verifier
4
+ #
5
+ # Tests for the existance of users and groups.
6
+ #
7
+ # == Example Usage
8
+ #
9
+ # verify do
10
+ # has_user 'ntp'
11
+ # has_user 'noone', :in_group => 'nobody'
12
+ # has_group 'nobody'
13
+ # end
14
+ #
15
+ module UsersGroups
16
+ Sprinkle::Verify.register(Sprinkle::Verifiers::UsersGroups)
17
+
18
+ # Tests that the user exists
19
+ def has_user(user, opts = {})
20
+ if opts[:in_group]
21
+ @commands << "id -G #{user} | xargs -n1 echo | grep #{opts[:in_group]}"
22
+ else
23
+ @commands << "id #{user}"
24
+ end
25
+ end
26
+
27
+ # Tests that the group exists
28
+ def has_group(group)
29
+ @commands << "id -g #{group}"
30
+ end
31
+ end
32
+ end
33
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
2
  require 'sprinkle'
3
3
 
4
- module Kernel
4
+ class Object
5
5
  def logger
6
6
  @@__log_file__ ||= StringIO.new
7
- @@__log__ = ActiveSupport::BufferedLogger.new @@__log_file__
7
+ @@__log__ = ActiveSupport::BufferedLogger.new @@__log_file__, ActiveSupport::BufferedLogger::Severity::INFO
8
8
  end
9
9
  end
@@ -11,6 +11,7 @@ describe Sprinkle::Configurable do
11
11
  @configurable = MyPrefix::Configurable.new
12
12
  @default = Proc.new { }
13
13
  @defaults = { :configurable => @default }
14
+ @deployment = Object.new
14
15
  @deployment.stub!(:defaults).and_return(@defaults)
15
16
  @deployment.stub!(:style)
16
17
  end
@@ -8,7 +8,7 @@ describe Sprinkle::Package do
8
8
  @empty = Proc.new { }
9
9
  @opts = { }
10
10
  end
11
-
11
+
12
12
  # Kind of a messy way to do this but it works and DRYs out
13
13
  # the specs. Checks to make sure an installer is receiving
14
14
  # the block passed to it throught the package block.
@@ -21,12 +21,12 @@ describe Sprinkle::Package do
21
21
  pre :install, 'preOp'
22
22
  end
23
23
  end
24
-
24
+
25
25
  pre_count = pkg.installers.first.instance_variable_get(:@pre)[:install].length
26
26
  }.should change { pre_count }.by(1)
27
27
  CODE
28
28
  end
29
-
29
+
30
30
  # More of Mitchell's meta-programming to dry up specs.
31
31
  def create_package_with_blank_verify(n = 1)
32
32
  eval(<<CODE)
@@ -142,6 +142,26 @@ CODE
142
142
  pkg.installers.first.class.should == Sprinkle::Installers::Gem
143
143
  end
144
144
 
145
+ it 'should optionally accept a noop installer' do
146
+ pkg = package @name do
147
+ noop do
148
+ end
149
+ end
150
+ pkg.should respond_to(:noop)
151
+ pkg.installers.first.class.should == Sprinkle::Installers::Runner
152
+ @installer = pkg.installers.first
153
+ @install_commands = @installer.send :install_commands
154
+ @install_commands.should == 'echo noop'
155
+ end
156
+
157
+ it 'should optionally accept an group installer' do
158
+ pkg = package @name do
159
+ add_group 'bob'
160
+ end
161
+ pkg.should respond_to(:add_group)
162
+ pkg.installers.first.class.should == Sprinkle::Installers::Group
163
+ end
164
+
145
165
  it 'should optionally accept a source installer' do
146
166
  pkg = package @name do
147
167
  source 'archive'
@@ -150,6 +170,14 @@ CODE
150
170
  pkg.installers.first.class.should == Sprinkle::Installers::Source
151
171
  end
152
172
 
173
+ it 'should optionally accept an user installer' do
174
+ pkg = package @name do
175
+ add_user 'bob'
176
+ end
177
+ pkg.should respond_to(:add_user)
178
+ pkg.installers.first.class.should == Sprinkle::Installers::User
179
+ end
180
+
153
181
  it 'should allow multiple installer steps to be defined and respect order' do
154
182
  pkg = package @name do
155
183
  source 'archive'
@@ -179,7 +207,7 @@ CODE
179
207
  pkg.should respond_to(:source)
180
208
  pkg.installers.first.class.should == Sprinkle::Installers::Source
181
209
  end
182
-
210
+
183
211
  it 'should forward block to installer superclass' do
184
212
  check_block_forwarding_on(:source)
185
213
  end
@@ -192,13 +220,13 @@ CODE
192
220
  end
193
221
 
194
222
  end
195
-
223
+
196
224
  describe 'with an apt installer' do
197
225
  it 'should forward block to installer superclass' do
198
226
  check_block_forwarding_on(:apt)
199
227
  end
200
228
  end
201
-
229
+
202
230
  describe 'with an rpm installer' do
203
231
  it 'should forward block to installer superclass' do
204
232
  check_block_forwarding_on(:rpm)
@@ -213,7 +241,7 @@ CODE
213
241
  end
214
242
  pkg.recommends.should include(:rubygems)
215
243
  end
216
-
244
+
217
245
  it 'should forward block to installer superclass' do
218
246
  check_block_forwarding_on(:gem)
219
247
  end
@@ -256,7 +284,7 @@ CODE
256
284
  end
257
285
 
258
286
  end
259
-
287
+
260
288
  describe 'with verifications' do
261
289
  before do
262
290
  @pkg = create_package_with_blank_verify(3)
@@ -264,47 +292,47 @@ CODE
264
292
  @installer.stub!(:defaults)
265
293
  @installer.stub!(:process)
266
294
  end
267
-
295
+
268
296
  describe 'with forcing' do
269
297
  before do
270
298
  # Being explicit
271
299
  Sprinkle::OPTIONS[:force] = true
272
300
  end
273
-
301
+
274
302
  it 'should process verifications only once' do
275
303
  @pkg.should_receive(:process_verifications).once
276
304
  @pkg.process(@deployment, @roles)
277
305
  end
278
-
306
+
279
307
  after do
280
308
  # Being explicit
281
309
  Sprinkle::OPTIONS[:force] = false
282
310
  end
283
311
  end
284
-
312
+
285
313
  describe 'without forcing' do
286
314
  before do
287
315
  # Being explicit
288
316
  Sprinkle::OPTIONS[:force] = false
289
317
  end
290
-
318
+
291
319
  it 'should process verifications twice' do
292
320
  @pkg.should_receive(:process_verifications).once.with(@deployment, @roles, true).and_raise(Sprinkle::VerificationFailed.new(@pkg, ''))
293
321
  @pkg.should_receive(:process_verifications).once.with(@deployment, @roles).and_raise(Sprinkle::VerificationFailed.new(@pkg, ''))
294
322
  end
295
-
323
+
296
324
  it 'should continue with installation if pre-verification fails' do
297
325
  @pkg.should_receive(:process_verifications).twice.and_raise(Sprinkle::VerificationFailed.new(@pkg, ''))
298
326
  @installer.should_receive(:defaults)
299
327
  @installer.should_receive(:process)
300
328
  end
301
-
329
+
302
330
  it 'should only process verifications once and should not process installer if verifications succeed' do
303
331
  @pkg.should_receive(:process_verifications).once.and_return(nil)
304
332
  @installer.should_not_receive(:defaults)
305
333
  @installer.should_not_receive(:process)
306
334
  end
307
-
335
+
308
336
  after do
309
337
  begin
310
338
  @pkg.process(@deployment, @roles)
@@ -314,7 +342,7 @@ CODE
314
342
  end
315
343
 
316
344
  end
317
-
345
+
318
346
  describe 'when processing verifications' do
319
347
  before do
320
348
  @deployment = mock(Sprinkle::Deployment)
@@ -327,7 +355,7 @@ CODE
327
355
  @logger = mock(ActiveSupport::BufferedLogger, :debug => true, :debug? => true)
328
356
  @logger.stub!(:info)
329
357
  end
330
-
358
+
331
359
  it 'should request _each_ verification to configure itself against the deployment context' do
332
360
  @pkg.verifications.each do |v|
333
361
  v.should_receive(:defaults).with(@deployment).once
@@ -341,16 +369,16 @@ CODE
341
369
  v.should_receive(:process).with(@roles).once
342
370
  end
343
371
  end
344
-
372
+
345
373
  it 'should enter a log info event to notify user whats happening' do
346
374
  @pkg.verifications.each do |v|
347
375
  v.stub!(:defaults)
348
376
  v.stub!(:process)
349
377
  end
350
-
378
+
351
379
  @pkg.should_receive(:logger).once.and_return(@logger)
352
380
  end
353
-
381
+
354
382
  after do
355
383
  @pkg.process_verifications(@deployment, @roles)
356
384
  end
@@ -419,7 +447,7 @@ CODE
419
447
  @v1 = package :v1, :provides => :virtual do; end
420
448
  @v2 = package :v2, :provides => :virtual do; end
421
449
  end
422
-
450
+
423
451
  it 'should select package for an array' do
424
452
  @a.should_receive(:select_package).with(:virtual, [@v1,@v2]).and_return(@v1)
425
453
  @a.tree do; end
@@ -440,31 +468,31 @@ CODE
440
468
  end
441
469
 
442
470
  end
443
-
444
- describe 'with verifications' do
471
+
472
+ describe 'with verifications' do
445
473
  it 'should create a Sprinkle::Verification object for the verify block' do
446
474
  Sprinkle::Verify.should_receive(:new).once
447
-
475
+
448
476
  create_package_with_blank_verify
449
477
  end
450
-
478
+
451
479
  it 'should create multiple Sprinkle::Verification objects for multiple verify blocks' do
452
480
  Sprinkle::Verify.should_receive(:new).twice
453
-
481
+
454
482
  create_package_with_blank_verify(2)
455
483
  end
456
-
484
+
457
485
  it 'should add each Sprinkle::Verificaton object to the @verifications array' do
458
486
  @pkg = create_package_with_blank_verify(3)
459
487
  @pkg.verifications.length.should eql(3)
460
488
  end
461
-
489
+
462
490
  it 'should initialize Sprinkle::Verification with the package name, description, and block' do
463
491
  Sprinkle::Verify.should_receive(:new) do |pkg, desc|
464
492
  pkg.name.should eql(@name)
465
493
  desc.should eql('stuff happens')
466
494
  end
467
-
495
+
468
496
  # We do a should_not raise_error because if a block was NOT passed, an error
469
497
  # is raised. This is specced in verification_spec.rb
470
498
  lambda { create_package_with_blank_verify }.should_not raise_error
@@ -14,6 +14,18 @@ describe Sprinkle::Verify do
14
14
 
15
15
  # Check a directory exists
16
16
  has_directory 'mydir'
17
+
18
+ # Check for a user
19
+ has_user "bob"
20
+
21
+ # Check for user with old API
22
+ user_present "someuser"
23
+
24
+ # Check for user in a group
25
+ has_user "alf", :in_group => "alien"
26
+
27
+ # Check for a group
28
+ has_group "bobgroup"
17
29
 
18
30
  # Check a symlink exists
19
31
  has_symlink 'mypointer'
@@ -64,6 +76,22 @@ describe Sprinkle::Verify do
64
76
  it 'should do a "test -d" on the has_directory check' do
65
77
  @verification.commands.should include('test -d mydir')
66
78
  end
79
+
80
+ it 'should use id to check for user in group' do
81
+ @verification.commands.should include("id -G alf | xargs -n1 echo | grep alien")
82
+ end
83
+
84
+ it 'should use id to check for user' do
85
+ @verification.commands.should include('id bob')
86
+ end
87
+
88
+ it 'should use id to check for user via user_present' do
89
+ @verification.commands.should include('id someuser')
90
+ end
91
+
92
+ it 'should use id to check for group' do
93
+ @verification.commands.should include('id -g bobgroup')
94
+ end
67
95
 
68
96
  it 'should do a "test -L" to check something is a symbolic link' do
69
97
  @verification.commands.should include('test -L mypointer')
@@ -90,7 +118,7 @@ describe Sprinkle::Verify do
90
118
  end
91
119
 
92
120
  it 'should check that a ruby gem is installed' do
93
- @verification.commands.should include("sudo gem list 'rails' --installed --version '2.1.0' > /dev/null")
121
+ @verification.commands.should include("gem list 'rails' --installed --version '2.1.0' > /dev/null")
94
122
  end
95
123
 
96
124
  it 'should check that an RPM is installed' do
data/sprinkle.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "sprinkle"
8
- s.version = "0.3.6"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcus Crafter"]
12
- s.date = "2011-09-10"
12
+ s.date = "2011-09-18"
13
13
  s.description = "Ruby DSL based software provisioning tool"
14
14
  s.email = "crafterm@redartisan.com"
15
15
  s.executables = ["sprinkle"]
@@ -65,10 +65,10 @@ Gem::Specification.new do |s|
65
65
  "lib/sprinkle/installers/freebsd_pkg.rb",
66
66
  "lib/sprinkle/installers/freebsd_portinstall.rb",
67
67
  "lib/sprinkle/installers/gem.rb",
68
+ "lib/sprinkle/installers/group.rb",
68
69
  "lib/sprinkle/installers/install_package.rb",
69
70
  "lib/sprinkle/installers/installer.rb",
70
71
  "lib/sprinkle/installers/mac_port.rb",
71
- "lib/sprinkle/installers/noop.rb",
72
72
  "lib/sprinkle/installers/openbsd_pkg.rb",
73
73
  "lib/sprinkle/installers/opensolaris_pkg.rb",
74
74
  "lib/sprinkle/installers/pacman.rb",
@@ -96,7 +96,7 @@ Gem::Specification.new do |s|
96
96
  "lib/sprinkle/verifiers/rpm.rb",
97
97
  "lib/sprinkle/verifiers/ruby.rb",
98
98
  "lib/sprinkle/verifiers/symlink.rb",
99
- "lib/sprinkle/verifiers/user.rb",
99
+ "lib/sprinkle/verifiers/users_groups.rb",
100
100
  "lib/sprinkle/verify.rb",
101
101
  "script/console",
102
102
  "script/destroy",
@@ -117,7 +117,6 @@ Gem::Specification.new do |s|
117
117
  "spec/sprinkle/installers/gem_spec.rb",
118
118
  "spec/sprinkle/installers/installer_spec.rb",
119
119
  "spec/sprinkle/installers/mac_port_spec.rb",
120
- "spec/sprinkle/installers/noop_spec.rb",
121
120
  "spec/sprinkle/installers/openbsd_pkg_spec.rb",
122
121
  "spec/sprinkle/installers/opensolaris_pkg_spec.rb",
123
122
  "spec/sprinkle/installers/push_text_spec.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprinkle
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 6
10
- version: 0.3.6
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcus Crafter
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-10 00:00:00 Z
18
+ date: 2011-09-18 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -137,10 +137,10 @@ files:
137
137
  - lib/sprinkle/installers/freebsd_pkg.rb
138
138
  - lib/sprinkle/installers/freebsd_portinstall.rb
139
139
  - lib/sprinkle/installers/gem.rb
140
+ - lib/sprinkle/installers/group.rb
140
141
  - lib/sprinkle/installers/install_package.rb
141
142
  - lib/sprinkle/installers/installer.rb
142
143
  - lib/sprinkle/installers/mac_port.rb
143
- - lib/sprinkle/installers/noop.rb
144
144
  - lib/sprinkle/installers/openbsd_pkg.rb
145
145
  - lib/sprinkle/installers/opensolaris_pkg.rb
146
146
  - lib/sprinkle/installers/pacman.rb
@@ -168,7 +168,7 @@ files:
168
168
  - lib/sprinkle/verifiers/rpm.rb
169
169
  - lib/sprinkle/verifiers/ruby.rb
170
170
  - lib/sprinkle/verifiers/symlink.rb
171
- - lib/sprinkle/verifiers/user.rb
171
+ - lib/sprinkle/verifiers/users_groups.rb
172
172
  - lib/sprinkle/verify.rb
173
173
  - script/console
174
174
  - script/destroy
@@ -189,7 +189,6 @@ files:
189
189
  - spec/sprinkle/installers/gem_spec.rb
190
190
  - spec/sprinkle/installers/installer_spec.rb
191
191
  - spec/sprinkle/installers/mac_port_spec.rb
192
- - spec/sprinkle/installers/noop_spec.rb
193
192
  - spec/sprinkle/installers/openbsd_pkg_spec.rb
194
193
  - spec/sprinkle/installers/opensolaris_pkg_spec.rb
195
194
  - spec/sprinkle/installers/push_text_spec.rb
@@ -1,20 +0,0 @@
1
- module Sprinkle
2
- module Installers
3
- # = Noop Installer
4
- #
5
- # This installer does nothing, it's simply useful for running pre / post hooks by themselves.
6
- #
7
- class Noop < Installer
8
- def initialize(parent, name, options = {}, &block) #:nodoc:
9
- super parent, options, &block
10
- end
11
-
12
- protected
13
-
14
- def install_commands #:nodoc:
15
- 'echo noop'
16
- end
17
-
18
- end
19
- end
20
- end
@@ -1,15 +0,0 @@
1
- module Sprinkle
2
- module Verifiers
3
- # = User Verifier
4
- # This was added so we dont have to verify a file to see if user was created
5
- # Defines a verify which can be used to test the existence of a user.
6
- module Users
7
- Sprinkle::Verify.register(Sprinkle::Verifiers::Users)
8
-
9
- # Tests that the user exists
10
- def has_user(user)
11
- @commands << "id #{user}"
12
- end
13
- end
14
- end
15
- end
@@ -1,23 +0,0 @@
1
- require File.expand_path("../../spec_helper", File.dirname(__FILE__))
2
-
3
- describe Sprinkle::Installers::Noop do
4
-
5
- before do
6
- @package = mock(Sprinkle::Package, :name => 'spec')
7
- end
8
-
9
- def create_noop(names, options = {}, &block)
10
- Sprinkle::Installers::Noop.new(@package, options, &block)
11
- end
12
-
13
- describe 'during installation' do
14
-
15
- it 'should always be empty' do
16
- @installer = create_noop 'spec'
17
- @install_commands = @installer.send :install_commands
18
- @install_commands.should == 'echo noop'
19
- end
20
-
21
- end
22
-
23
- end