puppet 2.7.14 → 2.7.16

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (111) hide show
  1. data/CHANGELOG +85 -0
  2. data/conf/redhat/puppet.spec +31 -4
  3. data/lib/puppet.rb +1 -1
  4. data/lib/puppet/defaults.rb +2 -3
  5. data/lib/puppet/face/module/install.rb +3 -3
  6. data/lib/puppet/face/module/search.rb +3 -3
  7. data/lib/puppet/indirector/face.rb +1 -1
  8. data/lib/puppet/network/http_pool.rb +17 -8
  9. data/lib/puppet/node/environment.rb +1 -3
  10. data/lib/puppet/parser/ast.rb +1 -1
  11. data/lib/puppet/parser/compiler.rb +2 -10
  12. data/lib/puppet/parser/functions/template.rb +2 -1
  13. data/lib/puppet/parser/lexer.rb +2 -2
  14. data/lib/puppet/parser/scope.rb +3 -2
  15. data/lib/puppet/provider/package/gem.rb +3 -1
  16. data/lib/puppet/provider/package/pkg.rb +18 -2
  17. data/lib/puppet/provider/service/gentoo.rb +5 -0
  18. data/lib/puppet/provider/service/init.rb +12 -14
  19. data/lib/puppet/provider/service/redhat.rb +1 -1
  20. data/lib/puppet/provider/service/upstart.rb +257 -7
  21. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +6 -9
  22. data/lib/puppet/reports/http.rb +1 -1
  23. data/lib/puppet/reports/tagmail.rb +1 -1
  24. data/lib/puppet/type/cron.rb +5 -0
  25. data/lib/puppet/type/filebucket.rb +12 -0
  26. data/lib/puppet/util.rb +15 -9
  27. data/lib/puppet/util/colors.rb +94 -64
  28. data/lib/puppet/util/platform.rb +15 -0
  29. data/man/man5/puppet.conf.5 +73 -27
  30. data/man/man8/filebucket.8 +1 -1
  31. data/man/man8/pi.8 +1 -1
  32. data/man/man8/puppet-agent.8 +17 -17
  33. data/man/man8/puppet-apply.8 +8 -3
  34. data/man/man8/puppet-ca.8 +183 -0
  35. data/man/man8/puppet-catalog.8 +17 -10
  36. data/man/man8/puppet-cert.8 +1 -1
  37. data/man/man8/puppet-certificate.8 +27 -11
  38. data/man/man8/puppet-certificate_request.8 +12 -11
  39. data/man/man8/puppet-certificate_revocation_list.8 +11 -10
  40. data/man/man8/puppet-config.8 +1 -1
  41. data/man/man8/puppet-describe.8 +1 -1
  42. data/man/man8/puppet-device.8 +2 -2
  43. data/man/man8/puppet-doc.8 +15 -3
  44. data/man/man8/puppet-facts.8 +18 -8
  45. data/man/man8/puppet-file.8 +13 -22
  46. data/man/man8/puppet-filebucket.8 +1 -1
  47. data/man/man8/puppet-help.8 +1 -1
  48. data/man/man8/puppet-inspect.8 +10 -2
  49. data/man/man8/puppet-instrumentation_data.8 +145 -0
  50. data/man/man8/puppet-instrumentation_listener.8 +222 -0
  51. data/man/man8/puppet-instrumentation_probe.8 +207 -0
  52. data/man/man8/puppet-key.8 +11 -7
  53. data/man/man8/puppet-kick.8 +35 -3
  54. data/man/man8/puppet-man.8 +1 -1
  55. data/man/man8/puppet-master.8 +1 -1
  56. data/man/man8/puppet-module.8 +451 -0
  57. data/man/man8/puppet-node.8 +64 -22
  58. data/man/man8/puppet-parser.8 +1 -1
  59. data/man/man8/puppet-plugin.8 +1 -1
  60. data/man/man8/puppet-queue.8 +1 -1
  61. data/man/man8/puppet-report.8 +12 -8
  62. data/man/man8/puppet-resource.8 +1 -1
  63. data/man/man8/puppet-resource_type.8 +11 -7
  64. data/man/man8/puppet-secret_agent.8 +1 -1
  65. data/man/man8/puppet-status.8 +11 -7
  66. data/man/man8/puppet.8 +1 -1
  67. data/man/man8/puppetca.8 +1 -1
  68. data/man/man8/puppetd.8 +17 -17
  69. data/man/man8/puppetdoc.8 +15 -3
  70. data/man/man8/puppetmasterd.8 +1 -1
  71. data/man/man8/puppetqd.8 +1 -1
  72. data/man/man8/puppetrun.8 +35 -3
  73. data/man/man8/ralsh.8 +1 -1
  74. data/spec/fixtures/unit/provider/package/gem/line-with-1.8.5-warning +14 -0
  75. data/spec/fixtures/unit/provider/package/pkg/{dummy → dummy_solaris10} +0 -0
  76. data/spec/fixtures/unit/provider/package/pkg/dummy_solaris11 +1 -0
  77. data/spec/fixtures/unit/provider/package/pkg/solaris11 +12 -0
  78. data/spec/fixtures/unit/provider/package/pkg/unknown_status +12 -0
  79. data/spec/fixtures/unit/provider/service/gentoo/rc_update_show +30 -0
  80. data/spec/integration/defaults_spec.rb +2 -7
  81. data/spec/integration/network/server/mongrel_spec.rb +16 -10
  82. data/spec/integration/network/server/webrick_spec.rb +16 -9
  83. data/spec/integration/provider/service/init_spec.rb +20 -4
  84. data/spec/integration/provider/ssh_authorized_key_spec.rb +119 -107
  85. data/spec/unit/face/module/install_spec.rb +16 -4
  86. data/spec/unit/network/http/api/v1_spec.rb +8 -0
  87. data/spec/unit/network/http_pool_spec.rb +80 -74
  88. data/spec/unit/node/environment_spec.rb +9 -4
  89. data/spec/unit/parser/ast/leaf_spec.rb +2 -2
  90. data/spec/unit/parser/ast_spec.rb +3 -3
  91. data/spec/unit/parser/compiler_spec.rb +0 -17
  92. data/spec/unit/parser/lexer_spec.rb +45 -2
  93. data/spec/unit/parser/scope_spec.rb +181 -14
  94. data/spec/unit/provider/package/gem_spec.rb +17 -1
  95. data/spec/unit/provider/package/pkg_spec.rb +70 -22
  96. data/spec/unit/provider/service/gentoo_spec.rb +237 -0
  97. data/spec/unit/provider/service/init_spec.rb +2 -2
  98. data/spec/unit/provider/service/redhat_spec.rb +2 -2
  99. data/spec/unit/provider/service/upstart_spec.rb +414 -5
  100. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +24 -0
  101. data/spec/unit/reports/tagmail_spec.rb +50 -0
  102. data/spec/unit/type/cron_spec.rb +21 -1
  103. data/spec/unit/type/filebucket_spec.rb +39 -9
  104. data/spec/unit/util/colors_spec.rb +69 -0
  105. data/spec/unit/util/log/destinations_spec.rb +17 -9
  106. data/spec/unit/util/log_spec.rb +2 -1
  107. data/spec/unit/util_spec.rb +11 -0
  108. data/tasks/rake/gem.rake +1 -1
  109. data/tasks/rake/manpages.rake +11 -3
  110. data/test/network/handler/fileserver.rb +7 -1
  111. metadata +22 -10
@@ -0,0 +1,237 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Puppet::Type.type(:service).provider(:gentoo) do
6
+
7
+ before :each do
8
+ Puppet::Type.type(:service).stubs(:defaultprovider).returns described_class
9
+ FileTest.stubs(:file?).with('/sbin/rc-update').returns true
10
+ FileTest.stubs(:executable?).with('/sbin/rc-update').returns true
11
+ Facter.stubs(:value).with(:operatingsystem).returns 'Gentoo'
12
+
13
+ # The initprovider (parent of the gentoo provider) does a stat call
14
+ # before it even tries to execute an initscript. We use sshd in all the
15
+ # tests so make sure it is considered present.
16
+ File.stubs(:stat).with('/etc/init.d/sshd')
17
+ end
18
+
19
+ let :initscripts do
20
+ [
21
+ 'alsasound',
22
+ 'bootmisc',
23
+ 'functions.sh',
24
+ 'hwclock',
25
+ 'reboot.sh',
26
+ 'rsyncd',
27
+ 'shutdown.sh',
28
+ 'sshd',
29
+ 'vixie-cron',
30
+ 'wpa_supplicant',
31
+ 'xdm-setup'
32
+ ]
33
+ end
34
+
35
+ let :helperscripts do
36
+ [
37
+ 'functions.sh',
38
+ 'reboot.sh',
39
+ 'shutdown.sh'
40
+ ]
41
+ end
42
+
43
+ describe ".instances" do
44
+
45
+ it "should have an instances method" do
46
+ described_class.should respond_to :instances
47
+ end
48
+
49
+ it "should get a list of services from /etc/init.d but exclude helper scripts" do
50
+ FileTest.expects(:directory?).with('/etc/init.d').returns true
51
+ Dir.expects(:entries).with('/etc/init.d').returns initscripts
52
+ (initscripts - helperscripts).each do |script|
53
+ FileTest.expects(:executable?).with("/etc/init.d/#{script}").returns true
54
+ end
55
+ helperscripts.each do |script|
56
+ FileTest.expects(:executable?).with("/etc/init.d/#{script}").never
57
+ end
58
+ described_class.instances.map(&:name).should == [
59
+ 'alsasound',
60
+ 'bootmisc',
61
+ 'hwclock',
62
+ 'rsyncd',
63
+ 'sshd',
64
+ 'vixie-cron',
65
+ 'wpa_supplicant',
66
+ 'xdm-setup'
67
+ ]
68
+ end
69
+ end
70
+
71
+ describe "#start" do
72
+ it "should use the supplied start command if specified" do
73
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :start => '/bin/foo'))
74
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => true, :squelch => true)
75
+ provider.start
76
+ end
77
+ it "should start the service with <initscript> start otherwise" do
78
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
79
+ provider.expects(:execute).with(['/etc/init.d/sshd',:start], :failonfail => true, :squelch => true)
80
+ provider.expects(:search).with('sshd').returns('/etc/init.d/sshd')
81
+ provider.start
82
+ end
83
+ end
84
+
85
+ describe "#stop" do
86
+ it "should use the supplied stop command if specified" do
87
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :stop => '/bin/foo'))
88
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => true, :squelch => true)
89
+ provider.stop
90
+ end
91
+ it "should stop the service with <initscript> stop otherwise" do
92
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
93
+ provider.expects(:execute).with(['/etc/init.d/sshd',:stop], :failonfail => true, :squelch => true)
94
+ provider.expects(:search).with('sshd').returns('/etc/init.d/sshd')
95
+ provider.stop
96
+ end
97
+ end
98
+
99
+ describe "#enabled?" do
100
+
101
+ before :each do
102
+ described_class.any_instance.stubs(:update).with(:show).returns File.read(my_fixture('rc_update_show'))
103
+ end
104
+
105
+ it "should run rc-update show to get a list of enabled services" do
106
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
107
+ provider.expects(:update).with(:show).returns "\n"
108
+ provider.enabled?
109
+ end
110
+
111
+ ['hostname', 'net.lo', 'procfs'].each do |service|
112
+ it "should consider service #{service} in runlevel boot as enabled" do
113
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => service))
114
+ provider.enabled?.should == :true
115
+ end
116
+ end
117
+
118
+ ['alsasound', 'xdm', 'netmount'].each do |service|
119
+ it "should consider service #{service} in runlevel default as enabled" do
120
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => service))
121
+ provider.enabled?.should == :true
122
+ end
123
+ end
124
+
125
+ ['rsyncd', 'lighttpd', 'mysql'].each do |service|
126
+ it "should consider unused service #{service} as disabled" do
127
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => service))
128
+ provider.enabled?.should == :false
129
+ end
130
+ end
131
+
132
+ end
133
+
134
+ describe "#enable" do
135
+ it "should run rc-update add to enable a service" do
136
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
137
+ provider.expects(:update).with(:add, 'sshd', :default)
138
+ provider.enable
139
+ end
140
+ end
141
+
142
+ describe "#disable" do
143
+ it "should run rc-update del to disable a service" do
144
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
145
+ provider.expects(:update).with(:del, 'sshd', :default)
146
+ provider.disable
147
+ end
148
+ end
149
+
150
+ describe "#status" do
151
+
152
+ describe "when a special status command is specified" do
153
+ it "should use the status command from the resource" do
154
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :status => '/bin/foo'))
155
+ provider.expects(:execute).with(['/etc/init.d/sshd',:status], :failonfail => false, :squelch => true).never
156
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => false, :squelch => true)
157
+ provider.status
158
+ end
159
+
160
+ it "should return :stopped when the status command returns with a non-zero exitcode" do
161
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :status => '/bin/foo'))
162
+ provider.expects(:execute).with(['/etc/init.d/sshd',:status], :failonfail => false, :squelch => true).never
163
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => false, :squelch => true)
164
+ $CHILD_STATUS.stubs(:exitstatus).returns 3
165
+ provider.status.should == :stopped
166
+ end
167
+
168
+ it "should return :running when the status command returns with a zero exitcode" do
169
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :status => '/bin/foo'))
170
+ provider.expects(:execute).with(['/etc/init.d/sshd',:status], :failonfail => false, :squelch => true).never
171
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => false, :squelch => true)
172
+ $CHILD_STATUS.stubs(:exitstatus).returns 0
173
+ provider.status.should == :running
174
+ end
175
+ end
176
+
177
+ describe "when hasstatus is false" do
178
+ it "should return running if a pid can be found" do
179
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasstatus => false))
180
+ provider.expects(:execute).with(['/etc/init.d/sshd',:status], :failonfail => false, :squelch => true).never
181
+ provider.expects(:getpid).returns 1000
182
+ provider.status.should == :running
183
+ end
184
+
185
+ it "should return stopped if no pid can be found" do
186
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasstatus => false))
187
+ provider.expects(:execute).with(['/etc/init.d/sshd',:status], :failonfail => false, :squelch => true).never
188
+ provider.expects(:getpid).returns nil
189
+ provider.status.should == :stopped
190
+ end
191
+ end
192
+
193
+ describe "when hasstatus is true" do
194
+ it "should return running if <initscript> status exits with a zero exitcode" do
195
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasstatus => true))
196
+ provider.expects(:search).with('sshd').returns('/etc/init.d/sshd')
197
+ provider.expects(:execute).with(['/etc/init.d/sshd',:status], :failonfail => false, :squelch => true)
198
+ $CHILD_STATUS.stubs(:exitstatus).returns 0
199
+ provider.status.should == :running
200
+ end
201
+
202
+ it "should return stopped if <initscript> status exits with a non-zero exitcode" do
203
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasstatus => true))
204
+ provider.expects(:search).with('sshd').returns('/etc/init.d/sshd')
205
+ provider.expects(:execute).with(['/etc/init.d/sshd',:status], :failonfail => false, :squelch => true)
206
+ $CHILD_STATUS.stubs(:exitstatus).returns 3
207
+ provider.status.should == :stopped
208
+ end
209
+ end
210
+ end
211
+
212
+ describe "#restart" do
213
+ it "should use the supplied restart command if specified" do
214
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :restart => '/bin/foo'))
215
+ provider.expects(:execute).with(['/etc/init.d/sshd',:restart], :failonfail => true, :squelch => true).never
216
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => true, :squelch => true)
217
+ provider.restart
218
+ end
219
+
220
+ it "should restart the service with <initscript> restart if hasrestart is true" do
221
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasrestart => true))
222
+ provider.expects(:search).with('sshd').returns('/etc/init.d/sshd')
223
+ provider.expects(:execute).with(['/etc/init.d/sshd',:restart], :failonfail => true, :squelch => true)
224
+ provider.restart
225
+ end
226
+
227
+ it "should restart the service with <initscript> stop/start if hasrestart is false" do
228
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasrestart => false))
229
+ provider.expects(:search).with('sshd').returns('/etc/init.d/sshd')
230
+ provider.expects(:execute).with(['/etc/init.d/sshd',:restart], :failonfail => true, :squelch => true).never
231
+ provider.expects(:execute).with(['/etc/init.d/sshd',:stop], :failonfail => true, :squelch => true)
232
+ provider.expects(:execute).with(['/etc/init.d/sshd',:start], :failonfail => true, :squelch => true)
233
+ provider.restart
234
+ end
235
+ end
236
+
237
+ end
@@ -46,9 +46,9 @@ describe provider_class do
46
46
  results = (@services-exclude).collect {|x| "#{x}_instance"}
47
47
  @class.get_services(@class.defpath, exclude).should == results
48
48
  end
49
- it "should omit a single service from the exclude list", :'fails_on_ruby_1.9.2' => true do
49
+ it "should omit a single service from the exclude list" do
50
50
  exclude = 'two'
51
- (@services-exclude.to_a).each do |inst|
51
+ (@services-[exclude]).each do |inst|
52
52
  @class.expects(:new).with{|hash| hash[:name] == inst}.returns("#{inst}_instance")
53
53
  end
54
54
  results = @services.reject{|x| x==exclude }.collect {|x| "#{x}_instance"}
@@ -24,8 +24,8 @@ describe provider_class, :as_platform => :posix do
24
24
  # test self.instances
25
25
  describe "when getting all service instances" do
26
26
  before :each do
27
- @services = ['one', 'two', 'three', 'four', 'kudzu', 'functions', 'halt', 'killall', 'single', 'linuxconf']
28
- @not_services = ['functions', 'halt', 'killall', 'single', 'linuxconf']
27
+ @services = ['one', 'two', 'three', 'four', 'kudzu', 'functions', 'halt', 'killall', 'single', 'linuxconf', 'boot', 'reboot']
28
+ @not_services = ['functions', 'halt', 'killall', 'single', 'linuxconf', 'reboot', 'boot']
29
29
  Dir.stubs(:entries).returns @services
30
30
  FileTest.stubs(:directory?).returns(true)
31
31
  FileTest.stubs(:executable?).returns(true)
@@ -3,7 +3,20 @@ require 'spec_helper'
3
3
 
4
4
  provider_class = Puppet::Type.type(:service).provider(:upstart)
5
5
 
6
- describe provider_class do
6
+ describe provider_class, :unless => Puppet.features.microsoft_windows? do
7
+ let(:manual) { "\nmanual" }
8
+ let(:start_on_default_runlevels) { "\nstart on runlevel [2,3,4,5]" }
9
+
10
+ def given_contents_of(file, content)
11
+ File.open(file, 'w') do |file|
12
+ file.write(content)
13
+ end
14
+ end
15
+
16
+ def then_contents_of(file)
17
+ File.open(file).read
18
+ end
19
+
7
20
  describe "#instances" do
8
21
  it "should be able to find all instances" do
9
22
  processes = ["rc stop/waiting", "ssh start/running, process 712"].join("\n")
@@ -49,17 +62,18 @@ describe provider_class do
49
62
  provider.expects(:status_exec).with(["foostartbar"]).returns("foostartbar stop/waiting")
50
63
  Process::Status.any_instance.stubs(:exitstatus).returns(0)
51
64
  provider.status.should == :stopped
52
- end
65
+ end
53
66
  end
67
+
54
68
  describe "inheritance" do
55
69
  let :resource do
56
70
  resource = Puppet::Type.type(:service).new(:name => "foo", :provider => :upstart)
57
71
  end
58
-
72
+
59
73
  let :provider do
60
74
  provider = provider_class.new(resource)
61
75
  end
62
-
76
+
63
77
  describe "when upstart job" do
64
78
  before(:each) do
65
79
  provider.stubs(:is_upstart?).returns(true)
@@ -73,7 +87,7 @@ describe provider_class do
73
87
  provider.statuscmd.should be_nil
74
88
  end
75
89
  end
76
-
90
+
77
91
  describe "when init script" do
78
92
  before(:each) do
79
93
  provider.stubs(:is_upstart?).returns(false)
@@ -85,6 +99,401 @@ describe provider_class do
85
99
  end
86
100
  end
87
101
  end
102
+ end
103
+
104
+ describe "should be enableable" do
105
+ let :resource do
106
+ Puppet::Type.type(:service).new(:name => "foo", :provider => :upstart)
107
+ end
108
+
109
+ let :provider do
110
+ provider_class.new(resource)
111
+ end
112
+
113
+ let :init_script do
114
+ PuppetSpec::Files.tmpfile("foo.conf")
115
+ end
116
+
117
+ let :over_script do
118
+ PuppetSpec::Files.tmpfile("foo.override")
119
+ end
120
+
121
+ let :disabled_content do
122
+ "\t # \t start on\nother file stuff"
123
+ end
124
+
125
+ let :multiline_disabled do
126
+ "# \t start on other file stuff (\n" +
127
+ "# more stuff ( # )))))inline comment\n" +
128
+ "# finishing up )\n" +
129
+ "# and done )\n" +
130
+ "this line shouldn't be touched\n"
131
+ end
132
+
133
+ let :multiline_disabled_bad do
134
+ "# \t start on other file stuff (\n" +
135
+ "# more stuff ( # )))))inline comment\n" +
136
+ "# finishing up )\n" +
137
+ "# and done )\n" +
138
+ "# this is a comment i want to be a comment\n" +
139
+ "this line shouldn't be touched\n"
140
+ end
141
+
142
+ let :multiline_enabled_bad do
143
+ " \t start on other file stuff (\n" +
144
+ " more stuff ( # )))))inline comment\n" +
145
+ " finishing up )\n" +
146
+ " and done )\n" +
147
+ "# this is a comment i want to be a comment\n" +
148
+ "this line shouldn't be touched\n"
149
+ end
150
+
151
+ let :multiline_enabled do
152
+ " \t start on other file stuff (\n" +
153
+ " more stuff ( # )))))inline comment\n" +
154
+ " finishing up )\n" +
155
+ " and done )\n" +
156
+ "this line shouldn't be touched\n"
157
+ end
158
+
159
+ let :multiline_enabled_standalone do
160
+ " \t start on other file stuff (\n" +
161
+ " more stuff ( # )))))inline comment\n" +
162
+ " finishing up )\n" +
163
+ " and done )\n"
164
+ end
165
+
166
+ let :enabled_content do
167
+ "\t \t start on\nother file stuff"
168
+ end
169
+
170
+ let :content do
171
+ "just some text"
172
+ end
173
+
174
+ describe "Upstart version < 0.6.7" do
175
+ before(:each) do
176
+ provider.stubs(:is_upstart?).returns(true)
177
+ provider.stubs(:upstart_version).returns("0.6.5")
178
+ provider.stubs(:search).returns(init_script)
179
+ end
180
+
181
+ [:enabled?,:enable,:disable].each do |enableable|
182
+ it "should respond to #{enableable}" do
183
+ provider.should respond_to(enableable)
184
+ end
185
+ end
186
+
187
+ describe "when enabling" do
188
+ it "should open and uncomment the '#start on' line" do
189
+ given_contents_of(init_script, disabled_content)
190
+
191
+ provider.enable
192
+
193
+ then_contents_of(init_script).should == enabled_content
194
+ end
195
+
196
+ it "should add a 'start on' line if none exists" do
197
+ given_contents_of(init_script, "this is a file")
198
+
199
+ provider.enable
200
+
201
+ then_contents_of(init_script).should == "this is a file" + start_on_default_runlevels
202
+ end
203
+
204
+ it "should handle multiline 'start on' stanzas" do
205
+ given_contents_of(init_script, multiline_disabled)
206
+
207
+ provider.enable
208
+
209
+ then_contents_of(init_script).should == multiline_enabled
210
+ end
211
+
212
+ it "should leave not 'start on' comments alone" do
213
+ given_contents_of(init_script, multiline_disabled_bad)
214
+
215
+ provider.enable
216
+
217
+ then_contents_of(init_script).should == multiline_enabled_bad
218
+ end
219
+ end
220
+
221
+ describe "when disabling" do
222
+ it "should open and comment the 'start on' line" do
223
+ given_contents_of(init_script, enabled_content)
224
+
225
+ provider.disable
226
+
227
+ then_contents_of(init_script).should == "#" + enabled_content
228
+ end
229
+
230
+ it "should handle multiline 'start on' stanzas" do
231
+ given_contents_of(init_script, multiline_enabled)
232
+
233
+ provider.disable
234
+
235
+ then_contents_of(init_script).should == multiline_disabled
236
+ end
237
+ end
238
+
239
+ describe "when checking whether it is enabled" do
240
+ it "should consider 'start on ...' to be enabled" do
241
+ given_contents_of(init_script, enabled_content)
242
+
243
+ provider.enabled?.should == :true
244
+ end
245
+
246
+ it "should consider '#start on ...' to be disabled" do
247
+ given_contents_of(init_script, disabled_content)
248
+
249
+ provider.enabled?.should == :false
250
+ end
251
+
252
+ it "should consider no start on line to be disabled" do
253
+ given_contents_of(init_script, content)
254
+
255
+ provider.enabled?.should == :false
256
+ end
257
+ end
258
+ end
259
+
260
+ describe "Upstart version < 0.9.0" do
261
+ before(:each) do
262
+ provider.stubs(:is_upstart?).returns(true)
263
+ provider.stubs(:upstart_version).returns("0.7.0")
264
+ provider.stubs(:search).returns(init_script)
265
+ end
266
+
267
+ [:enabled?,:enable,:disable].each do |enableable|
268
+ it "should respond to #{enableable}" do
269
+ provider.should respond_to(enableable)
270
+ end
271
+ end
272
+
273
+ describe "when enabling" do
274
+ it "should open and uncomment the '#start on' line" do
275
+ given_contents_of(init_script, disabled_content)
276
+
277
+ provider.enable
278
+
279
+ then_contents_of(init_script).should == enabled_content
280
+ end
281
+
282
+ it "should add a 'start on' line if none exists" do
283
+ given_contents_of(init_script, "this is a file")
284
+
285
+ provider.enable
286
+
287
+ then_contents_of(init_script).should == "this is a file" + start_on_default_runlevels
288
+ end
289
+
290
+ it "should handle multiline 'start on' stanzas" do
291
+ given_contents_of(init_script, multiline_disabled)
292
+
293
+ provider.enable
294
+
295
+ then_contents_of(init_script).should == multiline_enabled
296
+ end
297
+
298
+ it "should remove manual stanzas" do
299
+ given_contents_of(init_script, multiline_enabled + manual)
300
+
301
+ provider.enable
302
+
303
+ then_contents_of(init_script).should == multiline_enabled
304
+ end
305
+
306
+ it "should leave not 'start on' comments alone" do
307
+ given_contents_of(init_script, multiline_disabled_bad)
308
+
309
+ provider.enable
310
+
311
+ then_contents_of(init_script).should == multiline_enabled_bad
312
+ end
313
+ end
314
+
315
+ describe "when disabling" do
316
+ it "should add a manual stanza" do
317
+ given_contents_of(init_script, enabled_content)
318
+
319
+ provider.disable
320
+
321
+ then_contents_of(init_script).should == enabled_content + manual
322
+ end
323
+
324
+ it "should remove manual stanzas before adding new ones" do
325
+ given_contents_of(init_script, multiline_enabled + manual + "\n" + multiline_enabled)
326
+
327
+ provider.disable
328
+
329
+ then_contents_of(init_script).should == multiline_enabled + "\n" + multiline_enabled + manual
330
+ end
331
+
332
+ it "should handle multiline 'start on' stanzas" do
333
+ given_contents_of(init_script, multiline_enabled)
334
+
335
+ provider.disable
336
+
337
+ then_contents_of(init_script).should == multiline_enabled + manual
338
+ end
339
+ end
340
+
341
+ describe "when checking whether it is enabled" do
342
+ describe "with no manual stanza" do
343
+ it "should consider 'start on ...' to be enabled" do
344
+ given_contents_of(init_script, enabled_content)
345
+
346
+ provider.enabled?.should == :true
347
+ end
348
+
349
+ it "should consider '#start on ...' to be disabled" do
350
+ given_contents_of(init_script, disabled_content)
351
+
352
+ provider.enabled?.should == :false
353
+ end
354
+
355
+ it "should consider no start on line to be disabled" do
356
+ given_contents_of(init_script, content)
357
+
358
+ provider.enabled?.should == :false
359
+ end
360
+ end
361
+
362
+ describe "with manual stanza" do
363
+ it "should consider 'start on ...' to be disabled if there is a trailing manual stanza" do
364
+ given_contents_of(init_script, enabled_content + manual + "\nother stuff")
365
+
366
+ provider.enabled?.should == :false
367
+ end
368
+
369
+ it "should consider two start on lines with a manual in the middle to be enabled" do
370
+ given_contents_of(init_script, enabled_content + manual + "\n" + enabled_content)
371
+
372
+ provider.enabled?.should == :true
373
+ end
374
+ end
375
+ end
376
+ end
88
377
 
378
+ describe "Upstart version > 0.9.0" do
379
+ before(:each) do
380
+ provider.stubs(:is_upstart?).returns(true)
381
+ provider.stubs(:upstart_version).returns("0.9.5")
382
+ provider.stubs(:search).returns(init_script)
383
+ provider.stubs(:overscript).returns(over_script)
384
+ end
385
+
386
+ [:enabled?,:enable,:disable].each do |enableable|
387
+ it "should respond to #{enableable}" do
388
+ provider.should respond_to(enableable)
389
+ end
390
+ end
391
+
392
+ describe "when enabling" do
393
+ it "should add a 'start on' line if none exists" do
394
+ given_contents_of(init_script, "this is a file")
395
+
396
+ provider.enable
397
+
398
+ then_contents_of(init_script).should == "this is a file"
399
+ then_contents_of(over_script).should == start_on_default_runlevels
400
+ end
401
+
402
+ it "should handle multiline 'start on' stanzas" do
403
+ given_contents_of(init_script, multiline_disabled)
404
+
405
+ provider.enable
406
+
407
+ then_contents_of(init_script).should == multiline_disabled
408
+ then_contents_of(over_script).should == start_on_default_runlevels
409
+ end
410
+
411
+ it "should remove any manual stanzas from the override file" do
412
+ given_contents_of(over_script, manual)
413
+ given_contents_of(init_script, enabled_content)
414
+
415
+ provider.enable
416
+
417
+ then_contents_of(init_script).should == enabled_content
418
+ then_contents_of(over_script).should == ""
419
+ end
420
+
421
+ it "should copy existing start on from conf file if conf file is disabled" do
422
+ given_contents_of(init_script, multiline_enabled_standalone + manual)
423
+
424
+ provider.enable
425
+
426
+ then_contents_of(init_script).should == multiline_enabled_standalone + manual
427
+ then_contents_of(over_script).should == multiline_enabled_standalone
428
+ end
429
+
430
+ it "should leave not 'start on' comments alone" do
431
+ given_contents_of(init_script, multiline_disabled_bad)
432
+ given_contents_of(over_script, "")
433
+
434
+ provider.enable
435
+
436
+ then_contents_of(init_script).should == multiline_disabled_bad
437
+ then_contents_of(over_script).should == start_on_default_runlevels
438
+ end
439
+ end
440
+
441
+ describe "when disabling" do
442
+ it "should add a manual stanza to the override file" do
443
+ given_contents_of(init_script, enabled_content)
444
+
445
+ provider.disable
446
+
447
+ then_contents_of(init_script).should == enabled_content
448
+ then_contents_of(over_script).should == manual
449
+ end
450
+
451
+ it "should handle multiline 'start on' stanzas" do
452
+ given_contents_of(init_script, multiline_enabled)
453
+
454
+ provider.disable
455
+
456
+ then_contents_of(init_script).should == multiline_enabled
457
+ then_contents_of(over_script).should == manual
458
+ end
459
+ end
460
+
461
+ describe "when checking whether it is enabled" do
462
+ describe "with no override file" do
463
+ it "should consider 'start on ...' to be enabled" do
464
+ given_contents_of(init_script, enabled_content)
465
+
466
+ provider.enabled?.should == :true
467
+ end
468
+
469
+ it "should consider '#start on ...' to be disabled" do
470
+ given_contents_of(init_script, disabled_content)
471
+
472
+ provider.enabled?.should == :false
473
+ end
474
+
475
+ it "should consider no start on line to be disabled" do
476
+ given_contents_of(init_script, content)
477
+
478
+ provider.enabled?.should == :false
479
+ end
480
+ end
481
+ describe "with override file" do
482
+ it "should consider 'start on ...' to be disabled if there is manual in override file" do
483
+ given_contents_of(init_script, enabled_content)
484
+ given_contents_of(over_script, manual + "\nother stuff")
485
+
486
+ provider.enabled?.should == :false
487
+ end
488
+
489
+ it "should consider '#start on ...' to be enabled if there is a start on in the override file" do
490
+ given_contents_of(init_script, disabled_content)
491
+ given_contents_of(over_script, "start on stuff")
492
+
493
+ provider.enabled?.should == :true
494
+ end
495
+ end
496
+ end
497
+ end
89
498
  end
90
499
  end