sprinkle 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGELOG.md +18 -14
  2. data/Gemfile.lock +11 -11
  3. data/lib/sprinkle.rb +19 -9
  4. data/lib/sprinkle/actors/capistrano.rb +2 -1
  5. data/lib/sprinkle/actors/dummy.rb +3 -3
  6. data/lib/sprinkle/actors/local.rb +7 -9
  7. data/lib/sprinkle/actors/ssh.rb +5 -5
  8. data/lib/sprinkle/deployment.rb +2 -1
  9. data/lib/sprinkle/extensions/sudo.rb +8 -4
  10. data/lib/sprinkle/installers/installer.rb +48 -37
  11. data/lib/sprinkle/installers/npm.rb +31 -30
  12. data/lib/sprinkle/installers/source.rb +6 -6
  13. data/lib/sprinkle/installers/user.rb +7 -6
  14. data/lib/sprinkle/package.rb +55 -51
  15. data/lib/sprinkle/package/chooser.rb +5 -4
  16. data/lib/sprinkle/package/rendering.rb +2 -2
  17. data/lib/sprinkle/policy.rb +13 -13
  18. data/lib/sprinkle/script.rb +5 -1
  19. data/lib/sprinkle/verify.rb +1 -0
  20. data/lib/sprinkle/version.rb +1 -1
  21. data/spec/spec_helper.rb +13 -7
  22. data/spec/sprinkle/actors/capistrano_spec.rb +18 -18
  23. data/spec/sprinkle/actors/local_spec.rb +3 -3
  24. data/spec/sprinkle/deployment_spec.rb +3 -3
  25. data/spec/sprinkle/installers/apt_spec.rb +1 -1
  26. data/spec/sprinkle/installers/binary_spec.rb +1 -1
  27. data/spec/sprinkle/installers/brew_spec.rb +1 -1
  28. data/spec/sprinkle/installers/bsd_port_spec.rb +1 -1
  29. data/spec/sprinkle/installers/file_spec.rb +9 -9
  30. data/spec/sprinkle/installers/freebsd_pkg_spec.rb +1 -1
  31. data/spec/sprinkle/installers/freebsd_portinstall_spec.rb +1 -1
  32. data/spec/sprinkle/installers/gem_spec.rb +1 -1
  33. data/spec/sprinkle/installers/installer_spec.rb +62 -25
  34. data/spec/sprinkle/installers/mac_port_spec.rb +1 -1
  35. data/spec/sprinkle/installers/npm_spec.rb +1 -1
  36. data/spec/sprinkle/installers/openbsd_pkg_spec.rb +1 -1
  37. data/spec/sprinkle/installers/opensolaris_pkg_spec.rb +1 -1
  38. data/spec/sprinkle/installers/pear_spec.rb +1 -1
  39. data/spec/sprinkle/installers/push_text_spec.rb +12 -12
  40. data/spec/sprinkle/installers/rake_spec.rb +1 -1
  41. data/spec/sprinkle/installers/replace_text_spec.rb +10 -10
  42. data/spec/sprinkle/installers/rpm_spec.rb +1 -1
  43. data/spec/sprinkle/installers/runner_spec.rb +9 -9
  44. data/spec/sprinkle/installers/smart_spec.rb +1 -1
  45. data/spec/sprinkle/installers/source_spec.rb +22 -27
  46. data/spec/sprinkle/installers/thor_spec.rb +1 -1
  47. data/spec/sprinkle/installers/transfer_spec.rb +35 -35
  48. data/spec/sprinkle/installers/user_spec.rb +13 -7
  49. data/spec/sprinkle/installers/yum_spec.rb +1 -1
  50. data/spec/sprinkle/installers/zypper_spec.rb +1 -1
  51. data/spec/sprinkle/package/package_repository_spec.rb +7 -7
  52. data/spec/sprinkle/package_spec.rb +58 -58
  53. data/spec/sprinkle/policy_spec.rb +20 -20
  54. data/spec/sprinkle/script_spec.rb +1 -1
  55. data/spec/sprinkle/verify_spec.rb +2 -2
  56. metadata +2 -2
@@ -11,7 +11,7 @@ module Sprinkle::Package
11
11
 
12
12
  def template(src, context=binding)
13
13
  eruby = Erubis::Eruby.new(src)
14
- output = eruby.result(context)
14
+ eruby.result(context)
15
15
  rescue Object => e
16
16
  raise Sprinkle::Errors::TemplateError.new(e, src, context)
17
17
  end
@@ -41,4 +41,4 @@ module Sprinkle::Package
41
41
  end
42
42
 
43
43
  end
44
- end
44
+ end
@@ -6,7 +6,7 @@ module Sprinkle
6
6
  @name = name
7
7
  @roles = roles
8
8
  end
9
-
9
+
10
10
  def to_s
11
11
  "Policy #{@name} is to be installed on #{@roles.inspect} but no server has such a role."
12
12
  end
@@ -17,8 +17,8 @@ module Sprinkle
17
17
  # Policies define a set of packages which are required for a certain
18
18
  # role (app, database, etc.). All policies defined will be run and all
19
19
  # packages required by the policy will be installed. So whereas defining
20
- # a Sprinkle::Package merely defines it, defining a Sprinkle::Policy
21
- # actually causes those packages to install.
20
+ # a Sprinkle::Package merely defines it, defining a Sprinkle::Policy
21
+ # actually causes those packages to install.
22
22
  #
23
23
  # == Example
24
24
  #
@@ -28,11 +28,11 @@ module Sprinkle
28
28
  # requires :rails
29
29
  # end
30
30
  #
31
- # This says that for the blog on the app role, it requires certain
31
+ # This says that for the blog on the app role, it requires certain
32
32
  # packages. The :roles option is <em>exactly</em> the same as a capistrano
33
33
  # or vlad role. A role merely defines what server the commands are run
34
34
  # on. This way, a single Sprinkle script can provision an entire group
35
- # of servers.
35
+ # of servers.
36
36
  #
37
37
  # To define a role, put in your actor specific configuration file (recipe or
38
38
  # script file):
@@ -50,11 +50,11 @@ module Sprinkle
50
50
  # multiple packages within the same role without having to wait for
51
51
  # that package to install repeatedly.
52
52
  class Policy
53
- attr_reader :name
53
+ attr_reader :name
54
54
  # roles for which a policy should be installed [required]
55
- attr_reader :roles
55
+ attr_reader :roles
56
56
 
57
- # creates a new policy,
57
+ # creates a new policy,
58
58
  # although policies are typically not created directly but
59
59
  # rather via the Core#policy helper.
60
60
  def initialize(name, metadata = {}, &block)
@@ -71,19 +71,19 @@ module Sprinkle
71
71
  def requires(package, *args)
72
72
  @packages << [package, args]
73
73
  end
74
-
74
+
75
75
  def packages #:nodoc:
76
- @packages.map {|x| x.first }
77
- end
76
+ @packages.map {|x| x.first }
77
+ end
78
78
 
79
79
  def to_s #:nodoc:
80
80
  name; end
81
81
 
82
82
  def process(deployment) #:nodoc:
83
83
  raise NoMatchingServersError.new(@name, @roles) unless deployment.style.servers_for_role?(@roles)
84
-
84
+
85
85
  all = []
86
-
86
+
87
87
  logger.info "[#{name}]"
88
88
 
89
89
  cloud_info "--> Cloud hierarchy for policy #{@name}"
@@ -5,7 +5,11 @@ module Sprinkle
5
5
  # sprinkle script.
6
6
  class Script
7
7
  include Sprinkle::Deployment
8
-
8
+
9
+ def initialize
10
+ @deployment = nil
11
+ end
12
+
9
13
  # Run a given sprinkle script. This method is <b>blocking</b> so
10
14
  # it will not return until the sprinkling is complete or fails.
11
15
  #--
@@ -86,6 +86,7 @@ module Sprinkle
86
86
  @commands = []
87
87
  @options ||= {}
88
88
  @options[:padding] = 4
89
+ @delivery = nil
89
90
 
90
91
  self.instance_eval(&block)
91
92
  end
@@ -1,3 +1,3 @@
1
1
  module Sprinkle
2
- Version = "0.7.4"
2
+ Version = "0.7.5"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,18 @@
1
1
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
2
  require 'sprinkle'
3
3
 
4
- class Object
5
- def logger
6
- # ActiveSupport::BufferedLogger was deprecated and replaced by ActiveSupport::Logger in Rails 4.
7
- # Use ActiveSupport::Logger if available.
8
- active_support_logger = defined?(ActiveSupport::Logger) ? ActiveSupport::Logger : ActiveSupport::BufferedLogger
9
- @@__log_file__ ||= StringIO.new
10
- @@__log__ = active_support_logger.new @@__log_file__, active_support_logger::Severity::INFO
4
+ module Sprinkle
5
+ module TestLogger
6
+ def logger
7
+ # ActiveSupport::BufferedLogger was deprecated and replaced by ActiveSupport::Logger in Rails 4.
8
+ # Use ActiveSupport::Logger if available.
9
+ active_support_logger = defined?(ActiveSupport::Logger) ? ActiveSupport::Logger : ActiveSupport::BufferedLogger
10
+ @@__log_file__ ||= StringIO.new
11
+ @@__log__ = active_support_logger.new @@__log_file__, active_support_logger::Severity::INFO
12
+ end
11
13
  end
12
14
  end
15
+
16
+ class Object
17
+ include Sprinkle::TestLogger
18
+ end
@@ -5,12 +5,12 @@ describe Sprinkle::Actors::Capistrano do
5
5
  before do
6
6
  @recipes = 'deploy'
7
7
  @cap = ::Capistrano::Configuration.new
8
- ::Capistrano::Configuration.stub!(:new).and_return(@cap)
9
- @cap.stub!(:load).and_return
8
+ ::Capistrano::Configuration.stub(:new).and_return(@cap)
9
+ @cap.stub(:load).and_return
10
10
  end
11
11
 
12
12
  def create_cap(&block)
13
- Sprinkle::Actors::Capistrano.new &block
13
+ Sprinkle::Actors::Capistrano.new(&block)
14
14
  end
15
15
 
16
16
  describe 'when created' do
@@ -63,7 +63,7 @@ describe Sprinkle::Actors::Capistrano do
63
63
  describe 'without a block' do
64
64
 
65
65
  it 'should automatically load the default capistrano configuration' do
66
- File.stub!(:exist?).with("Capfile").and_return true
66
+ File.stub(:exist?).with("Capfile").and_return true
67
67
  @cap.should_receive(:load).with('Capfile').and_return
68
68
  end
69
69
 
@@ -94,19 +94,19 @@ describe Sprinkle::Actors::Capistrano do
94
94
  before do
95
95
  @commands = %w( op1 op2 )
96
96
  @roles = %w( app )
97
- @package = stub(:name => "name")
97
+ @package = double(:name => "name")
98
98
  @cap = create_cap
99
- @verifier = stub(:package => @package, :commands => ["op1", "op2"])
99
+ @verifier = double(:package => @package, :commands => ["op1", "op2"])
100
100
  end
101
101
 
102
102
  it "should return true if successful" do
103
- @cap.stub!(:run).and_return
103
+ @cap.stub(:run).and_return
104
104
  res = @cap.verify(@verifier, @roles)
105
105
  res.should == true
106
106
  end
107
107
 
108
108
  it "should return false if there was an error" do
109
- @cap.stub!(:run).and_raise(::Capistrano::CommandError)
109
+ @cap.stub(:run).and_raise(::Capistrano::CommandError)
110
110
  res = @cap.verify(@verifier, @roles)
111
111
  res.should == false
112
112
  end
@@ -121,7 +121,7 @@ describe Sprinkle::Actors::Capistrano do
121
121
  @name = 'name'
122
122
 
123
123
  @cap = create_cap do; recipes 'deploy'; end
124
- @cap.stub!(:run).and_return
124
+ @cap.stub(:run).and_return
125
125
 
126
126
  @testing_errors = false
127
127
  end
@@ -130,8 +130,8 @@ describe Sprinkle::Actors::Capistrano do
130
130
  # pretend the package or installer has also added sudo
131
131
  @commands =["sudo op1"]
132
132
  @cap.stub(:sudo_command).and_return("sudo")
133
- @cap.config.stub!(:fetch).and_return(:sudo)
134
- @cap.unstub!(:run)
133
+ @cap.config.stub(:fetch).and_return(:sudo)
134
+ @cap.unstub(:run)
135
135
  @cap.config.should_receive(:invoke_command).with('op1', :via => :sudo).ordered.and_return
136
136
  end
137
137
 
@@ -166,7 +166,7 @@ describe Sprinkle::Actors::Capistrano do
166
166
  @name = 'name'
167
167
 
168
168
  @cap = create_cap do; recipes 'deploy'; end
169
- @cap.stub!(:run).and_return
169
+ @cap.stub(:run).and_return
170
170
 
171
171
  @package = Package.new(@name) {}
172
172
  @installer = Sprinkle::Installers::Transfer.new(@package, "file.txt","/tmp/file.txt")
@@ -202,7 +202,7 @@ describe Sprinkle::Actors::Capistrano do
202
202
  @name = 'name'
203
203
 
204
204
  @cap = create_cap do; recipes 'deploy'; end
205
- @cap.config.stub!(:invoke_command).and_return
205
+ @cap.config.stub(:invoke_command).and_return
206
206
  end
207
207
 
208
208
  it 'should run the supplied commands by default' do
@@ -217,7 +217,7 @@ describe Sprinkle::Actors::Capistrano do
217
217
  end
218
218
 
219
219
  it 'should be applicable for the supplied roles' do
220
- @cap.stub!(:run).and_return
220
+ @cap.stub(:run).and_return
221
221
  @cap.config.should_receive(:task).with(:install_name, :roles => @roles).and_return
222
222
  end
223
223
 
@@ -235,7 +235,7 @@ describe Sprinkle::Actors::Capistrano do
235
235
  @name = 'name'
236
236
 
237
237
  @cap = create_cap do; recipes 'deploy'; end
238
- @cap.config.stub!(:upload).and_return
238
+ @cap.config.stub(:upload).and_return
239
239
 
240
240
  @package = Package.new(@name) {}
241
241
  @installer = Sprinkle::Installers::Transfer.new(@package, @source, @dest, :recursive => true)
@@ -247,7 +247,7 @@ describe Sprinkle::Actors::Capistrano do
247
247
  end
248
248
 
249
249
  it 'should be applicable for the supplied roles' do
250
- @cap.stub!(:run).and_return
250
+ @cap.stub(:run).and_return
251
251
  @cap.config.should_receive(:task).with(:install_name, :roles => @roles).and_return
252
252
  end
253
253
 
@@ -265,7 +265,7 @@ describe Sprinkle::Actors::Capistrano do
265
265
  @name = 'name'
266
266
 
267
267
  @cap = create_cap do; recipes 'deploy'; end
268
- @cap.config.stub!(:upload).and_return
268
+ @cap.config.stub(:upload).and_return
269
269
 
270
270
  @package = Package.new(@name) {}
271
271
  @installer = Sprinkle::Installers::Transfer.new(@package, @source,@dest, :recursive => false)
@@ -277,7 +277,7 @@ describe Sprinkle::Actors::Capistrano do
277
277
  end
278
278
 
279
279
  it 'should be applicable for the supplied roles' do
280
- @cap.stub!(:run).and_return
280
+ @cap.stub(:run).and_return
281
281
  @cap.config.should_receive(:task).with(:install_name, :roles => @roles).and_return
282
282
  end
283
283
 
@@ -16,7 +16,7 @@ describe Sprinkle::Actors::Local do
16
16
  @roles = %w( app )
17
17
  @name = 'name'
18
18
 
19
- @local.stub!(:run_command).and_return(0)
19
+ @local.stub(:run_command).and_return(0)
20
20
  end
21
21
 
22
22
  it 'should run the commands on the local system' do
@@ -36,13 +36,13 @@ describe Sprinkle::Actors::Local do
36
36
  end
37
37
 
38
38
  it 'should return false when verification fails' do
39
- @local.stub!(:run_command).and_return(1)
39
+ @local.stub(:run_command).and_return(1)
40
40
  res = @local.verify @verifier, @roles
41
41
  res.should == false
42
42
  end
43
43
 
44
44
  it 'should run the commands on the local system' do
45
- @local.stub!(:run_command).and_return(0)
45
+ @local.stub(:run_command).and_return(0)
46
46
  res = @local.verify @verifier, @roles
47
47
  res.should == true
48
48
  end
@@ -39,8 +39,8 @@ describe Sprinkle::Deployment do
39
39
  describe 'delivery specification' do
40
40
 
41
41
  before do
42
- @actor = mock(Sprinkle::Actors::Capistrano)
43
- Sprinkle::Actors::Capistrano.stub!(:new).and_return(@actor)
42
+ @actor = double(Sprinkle::Actors::Capistrano)
43
+ Sprinkle::Actors::Capistrano.stub(:new).and_return(@actor)
44
44
  end
45
45
 
46
46
  it 'should automatically instantiate the delivery type' do
@@ -64,7 +64,7 @@ describe Sprinkle::Deployment do
64
64
  describe 'when processing policies' do
65
65
 
66
66
  before do
67
- @policy = mock(Sprinkle::Policy, :process => true)
67
+ @policy = double(Sprinkle::Policy, :process => true)
68
68
  Sprinkle::POLICIES.clear
69
69
  Sprinkle::POLICIES << @policy
70
70
  @deployment = create_deployment
@@ -13,7 +13,7 @@ describe Sprinkle::Installers::Apt do
13
13
  end
14
14
 
15
15
  def create_apt(*debs, &block)
16
- installer=@package.apt *debs, &block
16
+ @package.apt(*debs, &block)
17
17
  end
18
18
 
19
19
  describe 'when created' do
@@ -23,7 +23,7 @@ describe Sprinkle::Installers::Binary do
23
23
  end
24
24
 
25
25
  def create_binary(binary, version = nil, &block)
26
- @package = mock(Sprinkle::Package, :name => 'package', :version => version)
26
+ @package = double(Sprinkle::Package, :name => 'package', :version => version)
27
27
  Sprinkle::Installers::Binary.new(@package, binary, &block)
28
28
  end
29
29
 
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
  describe Sprinkle::Installers::Brew do
4
4
 
5
5
  before do
6
- @formula = mock(Sprinkle::Package, :name => 'formula', :sudo? => false)
6
+ @formula = double(Sprinkle::Package, :name => 'formula', :sudo? => false)
7
7
  end
8
8
 
9
9
  def create_brew(*formulas, &block)
@@ -3,7 +3,7 @@ require File.expand_path("../../spec_helper", File.dirname(__FILE__))
3
3
  describe Sprinkle::Installers::BsdPort do
4
4
 
5
5
  before do
6
- @package = mock(Sprinkle::Package, :name => 'package')
6
+ @package = double(Sprinkle::Package, :name => 'package')
7
7
  end
8
8
 
9
9
  def create_port(ports, &block)
@@ -4,9 +4,9 @@ describe Sprinkle::Installers::FileInstaller do
4
4
  include Sprinkle::Deployment
5
5
 
6
6
  before do
7
- @package = mock(Sprinkle::Package, :name => 'package', :sudo? => false)
7
+ @package = double(Sprinkle::Package, :name => 'package', :sudo? => false)
8
8
  @empty = Proc.new { }
9
- @delivery = mock(Sprinkle::Deployment, :install => true)
9
+ @delivery = double(Sprinkle::Deployment, :install => true)
10
10
  @source = 'source'
11
11
  @destination = 'destination'
12
12
  @contents = "hi"
@@ -26,8 +26,8 @@ describe Sprinkle::Installers::FileInstaller do
26
26
 
27
27
  describe 'when created' do
28
28
  it 'should accept a source and destination to install' do
29
- @installer.contents.should == @contents
30
- @installer.destination.should == @destination
29
+ @installer.contents.should eq @contents
30
+ @installer.destination.should eq @destination
31
31
  end
32
32
  end
33
33
 
@@ -63,7 +63,7 @@ describe Sprinkle::Installers::FileInstaller do
63
63
  end
64
64
 
65
65
  it "should run commands in correct order" do
66
- @installer_commands.should == [
66
+ @installer_commands.should eq [
67
67
  :TRANSFER,
68
68
  "sudo mv /tmp/sprinkle_#{@destination} #{@destination}",
69
69
  "sudo chmod 744 #{@destination}",
@@ -82,7 +82,7 @@ describe Sprinkle::Installers::FileInstaller do
82
82
  end
83
83
 
84
84
  it "should run commands in correct order" do
85
- @installer_commands.should == [
85
+ @installer_commands.should eq [
86
86
  :TRANSFER,
87
87
  "sudo mv /tmp/sprinkle_#{@destination} #{@destination}",
88
88
  "sudo chown root #{@destination}",
@@ -104,7 +104,7 @@ describe Sprinkle::Installers::FileInstaller do
104
104
  end
105
105
 
106
106
  it "should call the pre and post install commands around the file transfer" do
107
- @installer_commands.should == ["op1",:TRANSFER, "op2"]
107
+ @installer_commands.should eq ["op1",:TRANSFER, "op2"]
108
108
  end
109
109
 
110
110
  end
@@ -121,7 +121,7 @@ describe Sprinkle::Installers::FileInstaller do
121
121
  end
122
122
 
123
123
  it "should call the pre and post install commands around the file transfer" do
124
- @installer_commands.should == ["op1",:TRANSFER,
124
+ @installer_commands.should eq ["op1",:TRANSFER,
125
125
  "sudo mv /tmp/sprinkle_destination destination", "op2"]
126
126
  end
127
127
  end
@@ -137,7 +137,7 @@ describe Sprinkle::Installers::FileInstaller do
137
137
  end
138
138
 
139
139
  it "should call the pre and post install commands around the file transfer" do
140
- @installer_commands.should == ["op1","op1-1",:TRANSFER, "op2","op2-1"]
140
+ @installer_commands.should eq ["op1","op1-1",:TRANSFER, "op2","op2-1"]
141
141
  end
142
142
 
143
143
  end
@@ -3,7 +3,7 @@ require File.expand_path("../../spec_helper", File.dirname(__FILE__))
3
3
  describe Sprinkle::Installers::FreebsdPkg do
4
4
 
5
5
  before do
6
- @package = mock(Sprinkle::Package, :name => 'package')
6
+ @package = double(Sprinkle::Package, :name => 'package')
7
7
  end
8
8
 
9
9
  def create_pkg(pkgs, &block)
@@ -3,7 +3,7 @@ require File.expand_path("../../spec_helper", File.dirname(__FILE__))
3
3
  describe Sprinkle::Installers::FreebsdPortinstall do
4
4
 
5
5
  before do
6
- @package = mock(Sprinkle::Package, :name => 'package')
6
+ @package = double(Sprinkle::Package, :name => 'package')
7
7
  end
8
8
 
9
9
  def create_port(ports, &block)
@@ -9,7 +9,7 @@ describe Sprinkle::Installers::Gem do
9
9
  end
10
10
 
11
11
  def create_gem(gem, version = nil, options = {}, &block)
12
- # @package = mock(Sprinkle::Package, :name => gem, :version => version)
12
+ # @package = double(Sprinkle::Package, :name => gem, :version => version)
13
13
  @package = Package.new "test" do; end
14
14
  @package.version version
15
15
  Sprinkle::Installers::Gem.new(@package, gem, options, &block)