puppet 2.7.18 → 2.7.19

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 (137) hide show
  1. data/CHANGELOG +82 -0
  2. data/CONTRIBUTING.md +114 -171
  3. data/README.md +8 -0
  4. data/README_DEVELOPER.md +38 -3
  5. data/Rakefile +19 -3
  6. data/conf/osx/createpackage.sh +3 -1
  7. data/conf/redhat/logrotate +1 -1
  8. data/conf/redhat/puppet.spec +35 -8
  9. data/lib/puppet.rb +1 -1
  10. data/lib/puppet/application/agent.rb +2 -0
  11. data/lib/puppet/application/master.rb +2 -0
  12. data/lib/puppet/configurer.rb +2 -3
  13. data/lib/puppet/defaults.rb +6 -5
  14. data/lib/puppet/face/module/install.rb +2 -1
  15. data/lib/puppet/file_bucket/dipper.rb +1 -1
  16. data/lib/puppet/indirector/file_content.rb +2 -2
  17. data/lib/puppet/indirector/file_metadata.rb +2 -2
  18. data/lib/puppet/indirector/indirection.rb +3 -4
  19. data/lib/puppet/indirector/rest.rb +12 -6
  20. data/lib/puppet/interface/action_manager.rb +1 -2
  21. data/lib/puppet/module_tool/applications/unpacker.rb +22 -3
  22. data/lib/puppet/network/handler/fileserver.rb +2 -2
  23. data/lib/puppet/parser/ast/resource.rb +9 -2
  24. data/lib/puppet/parser/functions/fqdn_rand.rb +2 -1
  25. data/lib/puppet/parser/functions/md5.rb +2 -2
  26. data/lib/puppet/parser/functions/sha1.rb +2 -2
  27. data/lib/puppet/parser/functions/template.rb +0 -2
  28. data/lib/puppet/parser/type_loader.rb +1 -2
  29. data/lib/puppet/provider/augeas/augeas.rb +19 -1
  30. data/lib/puppet/provider/confine.rb +1 -1
  31. data/lib/puppet/provider/package/msi.rb +97 -51
  32. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +1 -0
  33. data/lib/puppet/provider/service/gentoo.rb +0 -2
  34. data/lib/puppet/provider/service/openrc.rb +69 -0
  35. data/lib/puppet/provider/service/windows.rb +6 -4
  36. data/lib/puppet/provider/user/aix.rb +8 -4
  37. data/lib/puppet/provider/user/useradd.rb +6 -0
  38. data/lib/puppet/rails/benchmark.rb +2 -2
  39. data/lib/puppet/reports/store.rb +9 -9
  40. data/lib/puppet/resource/catalog.rb +2 -1
  41. data/lib/puppet/resource/type_collection.rb +2 -1
  42. data/lib/puppet/ssl/base.rb +1 -2
  43. data/lib/puppet/ssl/certificate_authority/interface.rb +1 -0
  44. data/lib/puppet/test/test_helper.rb +2 -1
  45. data/lib/puppet/type.rb +1 -1
  46. data/lib/puppet/type/augeas.rb +1 -1
  47. data/lib/puppet/type/file.rb +4 -2
  48. data/lib/puppet/type/scheduled_task.rb +8 -10
  49. data/lib/puppet/type/tidy.rb +1 -1
  50. data/lib/puppet/util.rb +63 -25
  51. data/lib/puppet/util/autoload.rb +6 -4
  52. data/lib/puppet/util/checksums.rb +3 -8
  53. data/lib/puppet/util/diff.rb +2 -1
  54. data/lib/puppet/util/filetype.rb +1 -3
  55. data/lib/puppet/util/run_mode.rb +2 -1
  56. data/lib/puppet/util/suidmanager.rb +1 -1
  57. data/lib/puppet/util/windows.rb +1 -0
  58. data/lib/puppet/util/windows/file.rb +27 -0
  59. data/lib/puppet/util/windows/user.rb +1 -2
  60. data/man/man8/puppet-agent.8 +4 -0
  61. data/man/man8/puppet-master.8 +4 -0
  62. data/man/man8/puppetmasterd.8 +4 -0
  63. data/spec/fixtures/unit/provider/augeas/augeas/augeas/lenses/test.aug +13 -0
  64. data/spec/fixtures/unit/provider/augeas/augeas/etc/fstab +10 -0
  65. data/spec/fixtures/unit/provider/augeas/augeas/etc/hosts +6 -0
  66. data/spec/fixtures/unit/provider/augeas/augeas/etc/test +3 -0
  67. data/spec/fixtures/unit/provider/augeas/augeas/test.aug +13 -0
  68. data/spec/fixtures/unit/provider/service/openrc/rcservice_list +8 -0
  69. data/spec/fixtures/unit/provider/service/openrc/rcstatus +43 -0
  70. data/spec/integration/defaults_spec.rb +3 -3
  71. data/spec/integration/network/server/mongrel_spec.rb +8 -6
  72. data/spec/integration/parser/parser_spec.rb +1 -1
  73. data/spec/integration/type/file_spec.rb +49 -12
  74. data/spec/lib/puppet_spec/database.rb +5 -3
  75. data/spec/lib/puppet_spec/files.rb +2 -1
  76. data/spec/monkey_patches/alias_should_to_must.rb +15 -2
  77. data/spec/shared_behaviours/file_serving_model.rb +9 -6
  78. data/spec/shared_behaviours/path_parameters.rb +5 -5
  79. data/spec/shared_behaviours/things_that_declare_options.rb +5 -5
  80. data/spec/unit/application/facts_spec.rb +1 -1
  81. data/spec/unit/application_spec.rb +10 -8
  82. data/spec/unit/configurer_spec.rb +11 -2
  83. data/spec/unit/face/ca_spec.rb +15 -15
  84. data/spec/unit/face/help_spec.rb +5 -5
  85. data/spec/unit/face/module/install_spec.rb +13 -2
  86. data/spec/unit/face/node_spec.rb +7 -6
  87. data/spec/unit/indirector/certificate_request/ca_spec.rb +1 -1
  88. data/spec/unit/indirector/envelope_spec.rb +0 -13
  89. data/spec/unit/indirector/facts/inventory_service_spec.rb +1 -1
  90. data/spec/unit/indirector/queue_spec.rb +3 -3
  91. data/spec/unit/indirector/rest_spec.rb +31 -20
  92. data/spec/unit/indirector_spec.rb +5 -5
  93. data/spec/unit/interface/action_builder_spec.rb +3 -2
  94. data/spec/unit/interface/action_manager_spec.rb +1 -1
  95. data/spec/unit/interface/action_spec.rb +4 -3
  96. data/spec/unit/interface/face_collection_spec.rb +1 -1
  97. data/spec/unit/interface/option_spec.rb +13 -9
  98. data/spec/unit/interface_spec.rb +5 -5
  99. data/spec/unit/module_tool/applications/unpacker_spec.rb +61 -0
  100. data/spec/unit/network/handler/fileserver_spec.rb +3 -3
  101. data/spec/unit/other/transbucket_spec.rb +6 -9
  102. data/spec/unit/parser/ast/resource_spec.rb +27 -0
  103. data/spec/unit/parser/functions/create_resources_spec.rb +12 -12
  104. data/spec/unit/parser/lexer_spec.rb +5 -5
  105. data/spec/unit/provider/augeas/augeas_spec.rb +78 -0
  106. data/spec/unit/provider/nameservice/directoryservice_spec.rb +6 -6
  107. data/spec/unit/provider/package/freebsd_spec.rb +2 -2
  108. data/spec/unit/provider/package/msi_spec.rb +181 -114
  109. data/spec/unit/provider/package/openbsd_spec.rb +1 -0
  110. data/spec/unit/provider/package/pkgdmg_spec.rb +3 -3
  111. data/spec/unit/provider/scheduled_task/win32_taskscheduler_spec.rb +1 -1
  112. data/spec/unit/provider/service/openrc_spec.rb +209 -0
  113. data/spec/unit/provider/service/windows_spec.rb +57 -59
  114. data/spec/unit/provider/user/useradd_spec.rb +7 -0
  115. data/spec/unit/reports/store_spec.rb +13 -13
  116. data/spec/unit/resource/catalog_spec.rb +29 -24
  117. data/spec/unit/resource_spec.rb +13 -13
  118. data/spec/unit/simple_graph_spec.rb +12 -12
  119. data/spec/unit/ssl/certificate_authority/interface_spec.rb +3 -3
  120. data/spec/unit/ssl/certificate_authority_spec.rb +11 -10
  121. data/spec/unit/transaction_spec.rb +3 -3
  122. data/spec/unit/type/cron_spec.rb +171 -171
  123. data/spec/unit/type/exec_spec.rb +29 -27
  124. data/spec/unit/type/file_spec.rb +22 -13
  125. data/spec/unit/type/interface_spec.rb +1 -1
  126. data/spec/unit/type/scheduled_task_spec.rb +15 -14
  127. data/spec/unit/type/tidy_spec.rb +2 -2
  128. data/spec/unit/type/user_spec.rb +15 -15
  129. data/spec/unit/type/vlan_spec.rb +1 -1
  130. data/spec/unit/type_spec.rb +22 -25
  131. data/spec/unit/util/autoload_spec.rb +13 -7
  132. data/spec/unit/util/backups_spec.rb +36 -67
  133. data/spec/unit/util/storage_spec.rb +2 -9
  134. data/spec/unit/util/suidmanager_spec.rb +1 -1
  135. data/spec/unit/util_spec.rb +20 -28
  136. data/test/ral/manager/attributes.rb +1 -1
  137. metadata +1553 -1542
@@ -71,6 +71,7 @@ describe provider_class do
71
71
 
72
72
  name == provider.resource[:name]
73
73
  end
74
+ provider.expects(:execpipe).with(%w{/bin/pkg_info -I bash}).yields('')
74
75
 
75
76
  provider.install
76
77
  ENV.should_not be_key 'PKG_PATH'
@@ -14,12 +14,12 @@ describe Puppet::Type.type(:package).provider(:pkgdmg) do
14
14
  end
15
15
 
16
16
  it "no source is specified" do
17
- expect { provider.install }.should raise_error(Puppet::Error, /must specify a package source/)
17
+ expect { provider.install }.to raise_error(Puppet::Error, /must specify a package source/)
18
18
  end
19
19
 
20
20
  it "the source does not end in .dmg or .pkg" do
21
21
  resource[:source] = "bar"
22
- expect { provider.install }.should raise_error(Puppet::Error, /must specify a source string ending in .*dmg.*pkg/)
22
+ expect { provider.install }.to raise_error(Puppet::Error, /must specify a source string ending in .*dmg.*pkg/)
23
23
  end
24
24
  end
25
25
 
@@ -40,7 +40,7 @@ describe Puppet::Type.type(:package).provider(:pkgdmg) do
40
40
 
41
41
  it "should fail when a disk image with no system entities is mounted" do
42
42
  described_class.stubs(:hdiutil).returns(empty_hdiutil_plist)
43
- expect { provider.install }.should raise_error(Puppet::Error, /No disk entities/)
43
+ expect { provider.install }.to raise_error(Puppet::Error, /No disk entities/)
44
44
  end
45
45
 
46
46
  it "should call hdiutil to mount and eject the disk image" do
@@ -1539,7 +1539,7 @@ describe Puppet::Type.type(:scheduled_task).provider(:win32_taskscheduler), :if
1539
1539
  end
1540
1540
 
1541
1541
  it 'should set the arguments' do
1542
- resource.provider.expects(:arguments=).with([@arguments])
1542
+ resource.provider.expects(:arguments=).with(@arguments)
1543
1543
 
1544
1544
  resource.provider.create
1545
1545
  end
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Puppet::Type.type(:service).provider(:openrc) do
6
+
7
+ before :each do
8
+ Puppet::Type.type(:service).stubs(:defaultprovider).returns described_class
9
+ ['/sbin/rc-service', '/bin/rc-status', '/sbin/rc-update'].each do |command|
10
+ described_class.stubs(:which).with(command).returns(command)
11
+ end
12
+ end
13
+
14
+ describe ".instances" do
15
+
16
+ it "should have an instances method" do
17
+ described_class.should respond_to :instances
18
+ end
19
+
20
+ it "should get a list of services from rc-service --list" do
21
+ described_class.expects(:rcservice).with('-C','--list').returns File.read(my_fixture('rcservice_list'))
22
+ described_class.instances.map(&:name).should == [
23
+ 'alsasound',
24
+ 'consolefont',
25
+ 'lvm-monitoring',
26
+ 'pydoc-2.7',
27
+ 'pydoc-3.2',
28
+ 'wpa_supplicant',
29
+ 'xdm',
30
+ 'xdm-setup'
31
+ ]
32
+ end
33
+ end
34
+
35
+ describe "#start" do
36
+ it "should use the supplied start command if specified" do
37
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :start => '/bin/foo'))
38
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => true, :squelch => true)
39
+ provider.start
40
+ end
41
+ it "should start the service with rc-service start otherwise" do
42
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
43
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:start], :failonfail => true, :squelch => true)
44
+ provider.start
45
+ end
46
+ end
47
+
48
+ describe "#stop" do
49
+ it "should use the supplied stop command if specified" do
50
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :stop => '/bin/foo'))
51
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => true, :squelch => true)
52
+ provider.stop
53
+ end
54
+ it "should stop the service with rc-service stop otherwise" do
55
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
56
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:stop], :failonfail => true, :squelch => true)
57
+ provider.stop
58
+ end
59
+ end
60
+
61
+ describe "#enabled?" do
62
+
63
+ before :each do
64
+ described_class.any_instance.stubs(:rcstatus).with('-C','-a').returns File.read(my_fixture('rcstatus'))
65
+ end
66
+
67
+ it "should run rc-status to get a list of enabled services" do
68
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
69
+ provider.expects(:rcstatus).with('-C','-a').returns "\n"
70
+ provider.enabled?
71
+ end
72
+
73
+ ['hwclock', 'modules', 'urandom'].each do |service|
74
+ it "should consider service #{service} in runlevel boot as enabled" do
75
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => service))
76
+ provider.enabled?.should == :true
77
+ end
78
+ end
79
+
80
+ ['netmount', 'xdm', 'local', 'foo_with_very_very_long_servicename_no_still_not_the_end_wait_for_it_almost_there_almost_there_now_finally_the_end'].each do |service|
81
+ it "should consider service #{service} in runlevel default as enabled" do
82
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => service))
83
+ provider.enabled?.should == :true
84
+ end
85
+ end
86
+
87
+ ['net.eth0', 'pcscd'].each do |service|
88
+ it "should consider service #{service} in dynamic runlevel: hotplugged as disabled" do
89
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => service))
90
+ provider.enabled?.should == :false
91
+ end
92
+ end
93
+
94
+ ['sysfs', 'udev-mount'].each do |service|
95
+ it "should consider service #{service} in dynamic runlevel: needed as disabled" do
96
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => service))
97
+ provider.enabled?.should == :false
98
+ end
99
+ end
100
+
101
+ ['sshd'].each do |service|
102
+ it "should consider service #{service} in dynamic runlevel: manual as disabled" do
103
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => service))
104
+ provider.enabled?.should == :false
105
+ end
106
+ end
107
+
108
+ end
109
+
110
+ describe "#enable" do
111
+ it "should run rc-update add to enable a service" do
112
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
113
+ provider.expects(:rcupdate).with('-C', :add, 'sshd')
114
+ provider.enable
115
+ end
116
+ end
117
+
118
+ describe "#disable" do
119
+ it "should run rc-update del to disable a service" do
120
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
121
+ provider.expects(:rcupdate).with('-C', :del, 'sshd')
122
+ provider.disable
123
+ end
124
+ end
125
+
126
+ describe "#status" do
127
+
128
+ describe "when a special status command if specified" do
129
+ it "should use the status command from the resource" do
130
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :status => '/bin/foo'))
131
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:status], :failonfail => false, :squelch => true).never
132
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => false, :squelch => true)
133
+ provider.status
134
+ end
135
+
136
+ it "should return :stopped when status command returns with a non-zero exitcode" do
137
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :status => '/bin/foo'))
138
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:status], :failonfail => false, :squelch => true).never
139
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => false, :squelch => true)
140
+ $CHILD_STATUS.stubs(:exitstatus).returns 3
141
+ provider.status.should == :stopped
142
+ end
143
+
144
+ it "should return :running when status command returns with a zero exitcode" do
145
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :status => '/bin/foo'))
146
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:status], :failonfail => false, :squelch => true).never
147
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => false, :squelch => true)
148
+ $CHILD_STATUS.stubs(:exitstatus).returns 0
149
+ provider.status.should == :running
150
+ end
151
+ end
152
+
153
+ describe "when hasstatus is false" do
154
+ it "should return running if a pid can be found" do
155
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasstatus => false))
156
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:status], :failonfail => false, :squelch => true).never
157
+ provider.expects(:getpid).returns 1000
158
+ provider.status.should == :running
159
+ end
160
+
161
+ it "should return stopped if no pid can be found" do
162
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasstatus => false))
163
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:status], :failonfail => false, :squelch => true).never
164
+ provider.expects(:getpid).returns nil
165
+ provider.status.should == :stopped
166
+ end
167
+ end
168
+
169
+ describe "when hasstatus is true" do
170
+ it "should return running if rc-service status exits with a zero exitcode" do
171
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasstatus => true))
172
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:status], :failonfail => false, :squelch => true)
173
+ $CHILD_STATUS.stubs(:exitstatus).returns 0
174
+ provider.status.should == :running
175
+ end
176
+
177
+ it "should return stopped if rc-service status exits with a non-zero exitcode" do
178
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasstatus => true))
179
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:status], :failonfail => false, :squelch => true)
180
+ $CHILD_STATUS.stubs(:exitstatus).returns 3
181
+ provider.status.should == :stopped
182
+ end
183
+ end
184
+ end
185
+
186
+ describe "#restart" do
187
+ it "should use the supplied restart command if specified" do
188
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :restart => '/bin/foo'))
189
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:restart], :failonfail => true, :squelch => true).never
190
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => true, :squelch => true)
191
+ provider.restart
192
+ end
193
+
194
+ it "should restart the service with rc-service restart if hasrestart is true" do
195
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasrestart => true))
196
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:restart], :failonfail => true, :squelch => true)
197
+ provider.restart
198
+ end
199
+
200
+ it "should restart the service with rc-service stop/start if hasrestart is false" do
201
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :hasrestart => false))
202
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:restart], :failonfail => true, :squelch => true).never
203
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:stop], :failonfail => true, :squelch => true)
204
+ provider.expects(:execute).with(['/sbin/rc-service','sshd',:start], :failonfail => true, :squelch => true)
205
+ provider.restart
206
+ end
207
+ end
208
+
209
+ end
@@ -8,16 +8,19 @@ require 'spec_helper'
8
8
  require 'win32/service' if Puppet.features.microsoft_windows?
9
9
 
10
10
  describe Puppet::Type.type(:service).provider(:windows), :if => Puppet.features.microsoft_windows? do
11
+ let(:name) { 'nonexistentservice' }
12
+ let(:resource) { Puppet::Type.type(:service).new(:name => name, :provider => :windows) }
13
+ let(:provider) { resource.provider }
14
+ let(:config) { Struct::ServiceConfigInfo.new }
15
+ let(:status) { Struct::ServiceStatus.new }
11
16
 
12
17
  before :each do
13
- @resource = Puppet::Type.type(:service).new(:name => 'snmptrap', :provider => :windows)
18
+ # make sure we never actually execute anything (there are two execute methods)
19
+ provider.class.expects(:execute).never
20
+ provider.expects(:execute).never
14
21
 
15
- @config = Struct::ServiceConfigInfo.new
16
-
17
- @status = Struct::ServiceStatus.new
18
-
19
- Win32::Service.stubs(:config_info).with(@resource[:name]).returns(@config)
20
- Win32::Service.stubs(:status).with(@resource[:name]).returns(@status)
22
+ Win32::Service.stubs(:config_info).with(name).returns(config)
23
+ Win32::Service.stubs(:status).with(name).returns(status)
21
24
  end
22
25
 
23
26
  describe ".instances" do
@@ -30,102 +33,98 @@ describe Puppet::Type.type(:service).provider(:windows), :if => Puppet.features.
30
33
  end
31
34
 
32
35
  describe "#start" do
33
- it "should call out to the Win32::Service API to start the service" do
34
- @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START)
36
+ before :each do
37
+ config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START)
38
+ end
35
39
 
36
- Win32::Service.expects(:start).with( @resource[:name] )
40
+ it "should start the service" do
41
+ provider.expects(:net).with(:start, name)
37
42
 
38
- @resource.provider.start
43
+ provider.start
39
44
  end
40
45
 
41
- it "should handle when Win32::Service.start raises a Win32::Service::Error" do
42
- @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START)
43
-
44
- Win32::Service.expects(:start).with( @resource[:name] ).raises(
45
- Win32::Service::Error.new("The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.")
46
- )
46
+ it "should raise an error if the start command fails" do
47
+ provider.expects(:net).with(:start, name).raises(Puppet::ExecutionFailure, "The service name is invalid.")
47
48
 
48
- expect { @resource.provider.start }.to raise_error(
49
- Puppet::Error,
50
- /Cannot start .*, error was: The service cannot be started, either/
51
- )
49
+ expect {
50
+ provider.start
51
+ }.to raise_error(Puppet::Error, /Cannot start #{name}, error was: The service name is invalid./)
52
52
  end
53
53
 
54
54
  describe "when the service is disabled" do
55
55
  before :each do
56
- @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_DISABLED)
57
- Win32::Service.stubs(:start).with(@resource[:name])
56
+ config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_DISABLED)
58
57
  end
59
58
 
60
59
  it "should refuse to start if not managing enable" do
61
- expect { @resource.provider.start }.to raise_error(Puppet::Error, /Will not start disabled service/)
60
+ expect { provider.start }.to raise_error(Puppet::Error, /Will not start disabled service/)
62
61
  end
63
62
 
64
63
  it "should enable if managing enable and enable is true" do
65
- @resource[:enable] = :true
64
+ resource[:enable] = :true
66
65
 
67
- Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_AUTO_START).returns(Win32::Service)
66
+ provider.expects(:net).with(:start, name)
67
+ Win32::Service.expects(:configure).with('service_name' => name, 'start_type' => Win32::Service::SERVICE_AUTO_START).returns(Win32::Service)
68
68
 
69
- @resource.provider.start
69
+ provider.start
70
70
  end
71
71
 
72
72
  it "should manual start if managing enable and enable is false" do
73
- @resource[:enable] = :false
73
+ resource[:enable] = :false
74
74
 
75
- Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DEMAND_START).returns(Win32::Service)
75
+ provider.expects(:net).with(:start, name)
76
+ Win32::Service.expects(:configure).with('service_name' => name, 'start_type' => Win32::Service::SERVICE_DEMAND_START).returns(Win32::Service)
76
77
 
77
- @resource.provider.start
78
+ provider.start
78
79
  end
79
80
  end
80
81
  end
81
82
 
82
83
  describe "#stop" do
83
- it "should call out to the Win32::Service API to stop the service" do
84
- Win32::Service.expects(:stop).with( @resource[:name] )
85
- @resource.provider.stop
86
- end
84
+ it "should stop a running service" do
85
+ provider.expects(:net).with(:stop, name)
86
+
87
+ provider.stop
88
+ end
87
89
 
88
- it "should handle when Win32::Service.stop raises a Win32::Service::Error" do
89
- Win32::Service.expects(:stop).with( @resource[:name] ).raises(
90
- Win32::Service::Error.new("should not try to stop an already stopped service.")
91
- )
90
+ it "should raise an error if the stop command fails" do
91
+ provider.expects(:net).with(:stop, name).raises(Puppet::ExecutionFailure, 'The service name is invalid.')
92
92
 
93
- expect { @resource.provider.stop }.to raise_error(
94
- Puppet::Error,
95
- /Cannot stop .*, error was: should not try to stop an already stopped service/
96
- )
93
+ expect {
94
+ provider.stop
95
+ }.to raise_error(Puppet::Error, /Cannot stop #{name}, error was: The service name is invalid./)
97
96
  end
98
97
  end
99
98
 
100
99
  describe "#status" do
101
100
  ['stopped', 'paused', 'stop pending', 'pause pending'].each do |state|
102
101
  it "should report a #{state} service as stopped" do
103
- @status.current_state = state
102
+ status.current_state = state
104
103
 
105
- @resource.provider.status.should == :stopped
104
+ provider.status.should == :stopped
106
105
  end
107
106
  end
108
107
 
109
108
  ["running", "continue pending", "start pending" ].each do |state|
110
109
  it "should report a #{state} service as running" do
111
- @status.current_state = state
110
+ status.current_state = state
112
111
 
113
- @resource.provider.status.should == :running
112
+ provider.status.should == :running
114
113
  end
115
114
  end
116
115
  end
117
116
 
118
117
  describe "#enabled?" do
119
118
  it "should report a service with a startup type of manual as manual" do
120
- @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_DEMAND_START)
119
+ config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_DEMAND_START)
121
120
 
122
- @resource.provider.enabled?.should == :manual
121
+ provider.enabled?.should == :manual
123
122
  end
124
123
 
125
124
  it "should report a service with a startup type of disabled as false" do
126
- @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_DISABLED)
125
+ config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_DISABLED)
127
126
 
128
- @resource.provider.enabled?.should == :false
127
+ provider.enabled?.should == :false
129
128
  end
130
129
 
131
130
  # We need to guard this section explicitly since rspec will always
@@ -134,9 +133,9 @@ describe Puppet::Type.type(:service).provider(:windows), :if => Puppet.features.
134
133
  [Win32::Service::SERVICE_AUTO_START, Win32::Service::SERVICE_BOOT_START, Win32::Service::SERVICE_SYSTEM_START].each do |start_type_const|
135
134
  start_type = Win32::Service.get_start_type(start_type_const)
136
135
  it "should report a service with a startup type of '#{start_type}' as true" do
137
- @config.start_type = start_type
136
+ config.start_type = start_type
138
137
 
139
- @resource.provider.enabled?.should == :true
138
+ provider.enabled?.should == :true
140
139
  end
141
140
  end
142
141
  end
@@ -144,23 +143,22 @@ describe Puppet::Type.type(:service).provider(:windows), :if => Puppet.features.
144
143
 
145
144
  describe "#enable" do
146
145
  it "should set service start type to Service_Auto_Start when enabled" do
147
- Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_AUTO_START).returns(Win32::Service)
148
- @resource.provider.enable
146
+ Win32::Service.expects(:configure).with('service_name' => name, 'start_type' => Win32::Service::SERVICE_AUTO_START).returns(Win32::Service)
147
+ provider.enable
149
148
  end
150
149
  end
151
150
 
152
151
  describe "#disable" do
153
152
  it "should set service start type to Service_Disabled when disabled" do
154
- Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DISABLED).returns(Win32::Service)
155
- @resource.provider.disable
153
+ Win32::Service.expects(:configure).with('service_name' => name, 'start_type' => Win32::Service::SERVICE_DISABLED).returns(Win32::Service)
154
+ provider.disable
156
155
  end
157
156
  end
158
157
 
159
158
  describe "#manual_start" do
160
159
  it "should set service start type to Service_Demand_Start (manual) when manual" do
161
- Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DEMAND_START).returns(Win32::Service)
162
- @resource.provider.manual_start
160
+ Win32::Service.expects(:configure).with('service_name' => name, 'start_type' => Win32::Service::SERVICE_DEMAND_START).returns(Win32::Service)
161
+ provider.manual_start
163
162
  end
164
163
  end
165
-
166
164
  end