puppet 2.7.9 → 2.7.11

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 (187) hide show
  1. data/CHANGELOG +413 -0
  2. data/README_DEVELOPER.md +28 -0
  3. data/conf/redhat/puppet.spec +10 -1
  4. data/conf/solaris/pkginfo +1 -1
  5. data/conf/suse/puppet.spec +7 -4
  6. data/ext/envpuppet.bat +13 -0
  7. data/ext/rack/files/apache2.conf +4 -0
  8. data/install.rb +4 -8
  9. data/lib/puppet.rb +1 -1
  10. data/lib/puppet/agent.rb +7 -0
  11. data/lib/puppet/agent/disabler.rb +27 -0
  12. data/lib/puppet/agent/locker.rb +0 -10
  13. data/lib/puppet/application.rb +3 -0
  14. data/lib/puppet/application/agent.rb +13 -3
  15. data/lib/puppet/application/apply.rb +6 -6
  16. data/lib/puppet/application/cert.rb +5 -5
  17. data/lib/puppet/application/instrumentation_data.rb +4 -0
  18. data/lib/puppet/application/instrumentation_listener.rb +4 -0
  19. data/lib/puppet/application/instrumentation_probe.rb +4 -0
  20. data/lib/puppet/configurer.rb +3 -1
  21. data/lib/puppet/configurer/downloader.rb +4 -2
  22. data/lib/puppet/configurer/fact_handler.rb +0 -21
  23. data/lib/puppet/daemon.rb +3 -4
  24. data/lib/puppet/defaults.rb +2 -2
  25. data/lib/puppet/face/instrumentation_data.rb +28 -0
  26. data/lib/puppet/face/instrumentation_listener.rb +96 -0
  27. data/lib/puppet/face/instrumentation_probe.rb +77 -0
  28. data/lib/puppet/face/module/list.rb +64 -0
  29. data/lib/puppet/face/module/uninstall.rb +50 -0
  30. data/lib/puppet/face/node/clean.rb +1 -4
  31. data/lib/puppet/feature/base.rb +1 -0
  32. data/lib/puppet/file_serving/content.rb +1 -1
  33. data/lib/puppet/indirector/facts/facter.rb +20 -7
  34. data/lib/puppet/indirector/facts/inventory_active_record.rb +14 -11
  35. data/lib/puppet/indirector/indirection.rb +7 -0
  36. data/lib/puppet/indirector/instrumentation_data.rb +3 -0
  37. data/lib/puppet/indirector/instrumentation_data/local.rb +19 -0
  38. data/lib/puppet/indirector/instrumentation_data/rest.rb +5 -0
  39. data/lib/puppet/indirector/instrumentation_listener.rb +3 -0
  40. data/lib/puppet/indirector/instrumentation_listener/local.rb +23 -0
  41. data/lib/puppet/indirector/instrumentation_listener/rest.rb +5 -0
  42. data/lib/puppet/indirector/instrumentation_probe.rb +3 -0
  43. data/lib/puppet/indirector/instrumentation_probe/local.rb +24 -0
  44. data/lib/puppet/indirector/instrumentation_probe/rest.rb +5 -0
  45. data/lib/puppet/indirector/rest.rb +1 -1
  46. data/lib/puppet/module.rb +13 -17
  47. data/lib/puppet/module_tool/applications.rb +1 -0
  48. data/lib/puppet/module_tool/applications/uninstaller.rb +33 -0
  49. data/lib/puppet/module_tool/contents_description.rb +1 -1
  50. data/lib/puppet/network/server.rb +2 -3
  51. data/lib/puppet/node/environment.rb +16 -3
  52. data/lib/puppet/parser/ast/leaf.rb +1 -1
  53. data/lib/puppet/parser/functions/create_resources.rb +1 -1
  54. data/lib/puppet/parser/type_loader.rb +1 -1
  55. data/lib/puppet/property.rb +46 -14
  56. data/lib/puppet/provider.rb +13 -4
  57. data/lib/puppet/provider/augeas/augeas.rb +6 -4
  58. data/lib/puppet/provider/group/pw.rb +24 -10
  59. data/lib/puppet/provider/nameservice/directoryservice.rb +146 -37
  60. data/lib/puppet/provider/package/pip.rb +1 -1
  61. data/lib/puppet/provider/package/yum.rb +1 -2
  62. data/lib/puppet/provider/service/debian.rb +14 -0
  63. data/lib/puppet/provider/service/launchd.rb +1 -1
  64. data/lib/puppet/provider/service/smf.rb +2 -2
  65. data/lib/puppet/provider/user/pw.rb +56 -2
  66. data/lib/puppet/provider/user/user_role_add.rb +32 -22
  67. data/lib/puppet/provider/user/windows_adsi.rb +1 -0
  68. data/lib/puppet/rails/benchmark.rb +1 -1
  69. data/lib/puppet/reports/store.rb +8 -1
  70. data/lib/puppet/resource/catalog.rb +5 -1
  71. data/lib/puppet/simple_graph.rb +11 -14
  72. data/lib/puppet/transaction.rb +10 -4
  73. data/lib/puppet/transaction/report.rb +9 -3
  74. data/lib/puppet/type.rb +19 -7
  75. data/lib/puppet/type/exec.rb +1 -1
  76. data/lib/puppet/type/file.rb +4 -1
  77. data/lib/puppet/type/file/ensure.rb +5 -1
  78. data/lib/puppet/type/file/mode.rb +45 -10
  79. data/lib/puppet/type/file/source.rb +4 -0
  80. data/lib/puppet/type/host.rb +17 -3
  81. data/lib/puppet/type/k5login.rb +3 -2
  82. data/lib/puppet/type/schedule.rb +3 -2
  83. data/lib/puppet/util.rb +83 -27
  84. data/lib/puppet/util/anonymous_filelock.rb +36 -0
  85. data/lib/puppet/util/docs.rb +18 -2
  86. data/lib/puppet/util/instrumentation.rb +173 -0
  87. data/lib/puppet/util/instrumentation/data.rb +34 -0
  88. data/lib/puppet/util/instrumentation/indirection_probe.rb +29 -0
  89. data/lib/puppet/util/instrumentation/instrumentable.rb +143 -0
  90. data/lib/puppet/util/instrumentation/listener.rb +60 -0
  91. data/lib/puppet/util/instrumentation/listeners/log.rb +29 -0
  92. data/lib/puppet/util/instrumentation/listeners/performance.rb +30 -0
  93. data/lib/puppet/util/monkey_patches.rb +8 -0
  94. data/lib/puppet/util/pidlock.rb +21 -25
  95. data/lib/puppet/util/rdoc/parser.rb +2 -2
  96. data/lib/puppet/util/reference.rb +8 -23
  97. data/lib/puppet/util/retryaction.rb +48 -0
  98. data/lib/puppet/util/suidmanager.rb +70 -39
  99. data/lib/puppet/util/symbolic_file_mode.rb +140 -0
  100. data/spec/integration/configurer_spec.rb +5 -0
  101. data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
  102. data/spec/integration/indirector/file_content/file_server_spec.rb +7 -7
  103. data/spec/integration/provider/package_spec.rb +7 -0
  104. data/spec/unit/agent/disabler_spec.rb +60 -0
  105. data/spec/unit/agent/locker_spec.rb +0 -12
  106. data/spec/unit/agent_spec.rb +8 -0
  107. data/spec/unit/application/agent_spec.rb +38 -1
  108. data/spec/unit/application/apply_spec.rb +34 -40
  109. data/spec/unit/application/cert_spec.rb +1 -1
  110. data/spec/unit/application_spec.rb +6 -0
  111. data/spec/unit/configurer/downloader_spec.rb +29 -10
  112. data/spec/unit/configurer/fact_handler_spec.rb +5 -29
  113. data/spec/unit/configurer_spec.rb +8 -8
  114. data/spec/unit/daemon_spec.rb +12 -26
  115. data/spec/unit/face/instrumentation_data.rb +7 -0
  116. data/spec/unit/face/instrumentation_listener.rb +38 -0
  117. data/spec/unit/face/instrumentation_probe.rb +21 -0
  118. data/spec/unit/face/node_spec.rb +111 -111
  119. data/spec/unit/file_serving/content_spec.rb +2 -2
  120. data/spec/unit/indirector/facts/facter_spec.rb +25 -3
  121. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +14 -4
  122. data/spec/unit/indirector/instrumentation_data/local_spec.rb +52 -0
  123. data/spec/unit/indirector/instrumentation_data/rest_spec.rb +11 -0
  124. data/spec/unit/indirector/instrumentation_listener/local_spec.rb +65 -0
  125. data/spec/unit/indirector/instrumentation_listener/rest_spec.rb +11 -0
  126. data/spec/unit/indirector/instrumentation_probe/local_spec.rb +65 -0
  127. data/spec/unit/indirector/instrumentation_probe/rest_spec.rb +11 -0
  128. data/spec/unit/module_spec.rb +39 -125
  129. data/spec/unit/module_tool/uninstaller_spec.rb +44 -0
  130. data/spec/unit/network/server_spec.rb +2 -20
  131. data/spec/unit/node/environment_spec.rb +76 -58
  132. data/spec/unit/parser/ast/asthash_spec.rb +1 -2
  133. data/spec/unit/parser/ast/leaf_spec.rb +16 -0
  134. data/spec/unit/property/keyvalue_spec.rb +5 -2
  135. data/spec/unit/property_spec.rb +260 -159
  136. data/spec/unit/provider/augeas/augeas_spec.rb +2 -2
  137. data/spec/unit/provider/group/pw_spec.rb +81 -0
  138. data/spec/unit/provider/nameservice/directoryservice_spec.rb +102 -0
  139. data/spec/unit/provider/package/pip_spec.rb +7 -0
  140. data/spec/unit/provider/package/yum_spec.rb +45 -1
  141. data/spec/unit/provider/service/debian_spec.rb +15 -0
  142. data/spec/unit/provider/service/launchd_spec.rb +48 -43
  143. data/spec/unit/provider/service/smf_spec.rb +3 -3
  144. data/spec/unit/provider/user/pw_spec.rb +183 -0
  145. data/spec/unit/provider/user/user_role_add_spec.rb +46 -39
  146. data/spec/unit/provider/user/windows_adsi_spec.rb +1 -0
  147. data/spec/unit/provider_spec.rb +32 -0
  148. data/spec/unit/reports/store_spec.rb +19 -1
  149. data/spec/unit/simple_graph_spec.rb +34 -19
  150. data/spec/unit/ssl/certificate_factory_spec.rb +3 -3
  151. data/spec/unit/transaction/report_spec.rb +29 -1
  152. data/spec/unit/transaction_spec.rb +32 -46
  153. data/spec/unit/type/file/mode_spec.rb +1 -1
  154. data/spec/unit/type/file/source_spec.rb +28 -3
  155. data/spec/unit/type/file_spec.rb +17 -16
  156. data/spec/unit/type/host_spec.rb +527 -0
  157. data/spec/unit/type/k5login_spec.rb +115 -0
  158. data/spec/unit/type/schedule_spec.rb +6 -6
  159. data/spec/unit/type_spec.rb +51 -0
  160. data/spec/unit/util/anonymous_filelock_spec.rb +78 -0
  161. data/spec/unit/util/execution_stub_spec.rb +2 -1
  162. data/spec/unit/util/instrumentation/data_spec.rb +44 -0
  163. data/spec/unit/util/instrumentation/indirection_probe_spec.rb +19 -0
  164. data/spec/unit/util/instrumentation/instrumentable_spec.rb +186 -0
  165. data/spec/unit/util/instrumentation/listener_spec.rb +100 -0
  166. data/spec/unit/util/instrumentation/listeners/log_spec.rb +34 -0
  167. data/spec/unit/util/instrumentation/listeners/performance_spec.rb +36 -0
  168. data/spec/unit/util/instrumentation_spec.rb +181 -0
  169. data/spec/unit/util/pidlock_spec.rb +208 -0
  170. data/spec/unit/util/rdoc/parser_spec.rb +1 -1
  171. data/spec/unit/util/reference_spec.rb +16 -6
  172. data/spec/unit/util/retryaction_spec.rb +62 -0
  173. data/spec/unit/util/suidmanager_spec.rb +101 -83
  174. data/spec/unit/util/symbolic_file_mode_spec.rb +182 -0
  175. data/spec/unit/util_spec.rb +126 -0
  176. data/tasks/rake/apple.rake +176 -0
  177. data/tasks/rake/templates/prototype.plist.erb +38 -0
  178. metadata +61 -13
  179. data/lib/puppet/application/module.rb +0 -3
  180. data/lib/puppet/face/module.rb +0 -12
  181. data/spec/unit/face/module/build_spec.rb +0 -30
  182. data/spec/unit/face/module/changes_spec.rb +0 -30
  183. data/spec/unit/face/module/clean_spec.rb +0 -30
  184. data/spec/unit/face/module/generate_spec.rb +0 -30
  185. data/spec/unit/face/module/install_spec.rb +0 -75
  186. data/spec/unit/face/module/search_spec.rb +0 -40
  187. data/test/util/pidlock.rb +0 -126
@@ -92,7 +92,7 @@ describe provider_class do
92
92
 
93
93
  it "should always execute external command 'svcadm enable /system/myservice'" do
94
94
  @provider.stubs(:status).returns :running
95
- @provider.expects(:texecute).with(:start, ["/usr/sbin/svcadm", :enable, "/system/myservice"], true)
95
+ @provider.expects(:texecute).with(:start, ["/usr/sbin/svcadm", :enable, "-s", "/system/myservice"], true)
96
96
  @provider.start
97
97
  end
98
98
 
@@ -112,7 +112,7 @@ describe provider_class do
112
112
 
113
113
  it "should import the manifest if service is missing" do
114
114
  @provider.expects(:svccfg).with(:import, "/tmp/myservice.xml")
115
- @provider.expects(:texecute).with(:start, ["/usr/sbin/svcadm", :enable, "/system/myservice"], true)
115
+ @provider.expects(:texecute).with(:start, ["/usr/sbin/svcadm", :enable, "-s", "/system/myservice"], true)
116
116
  @provider.expects(:svcs).with('-H', '-o', 'state,nstate', "/system/myservice").returns("online\t-")
117
117
  @provider.start
118
118
  end
@@ -125,7 +125,7 @@ describe provider_class do
125
125
 
126
126
  describe "when stopping" do
127
127
  it "should execute external command 'svcadm disable /system/myservice'" do
128
- @provider.expects(:texecute).with(:stop, ["/usr/sbin/svcadm", :disable, "/system/myservice"], true)
128
+ @provider.expects(:texecute).with(:stop, ["/usr/sbin/svcadm", :disable, "-s", "/system/myservice"], true)
129
129
  @provider.stop
130
130
  end
131
131
  end
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
3
+
4
+ provider_class = Puppet::Type.type(:user).provider(:pw)
5
+
6
+ describe provider_class do
7
+ let :resource do
8
+ Puppet::Type.type(:user).new(:name => "testuser", :provider => :pw)
9
+ end
10
+
11
+ describe "when creating users" do
12
+ let :provider do
13
+ prov = resource.provider
14
+ prov.expects(:exists?).returns nil
15
+ prov
16
+ end
17
+
18
+ it "should run pw with no additional flags when no properties are given" do
19
+ provider.addcmd.must == [provider_class.command(:pw), "useradd", "testuser"]
20
+ provider.expects(:execute).with([provider_class.command(:pw), "useradd", "testuser"])
21
+ provider.create
22
+ end
23
+
24
+ it "should use -o when allowdupe is enabled" do
25
+ resource[:allowdupe] = true
26
+ provider.expects(:execute).with(includes("-o"))
27
+ provider.create
28
+ end
29
+
30
+ it "should use -c with the correct argument when the comment property is set" do
31
+ resource[:comment] = "Testuser Name"
32
+ provider.expects(:execute).with(all_of(includes("-c"), includes("Testuser Name")))
33
+ provider.create
34
+ end
35
+
36
+ it "should use -e with the correct argument when the expiry property is set" do
37
+ resource[:expiry] = "2010-02-19"
38
+ provider.expects(:execute).with(all_of(includes("-e"), includes("19-02-2010")))
39
+ provider.create
40
+ end
41
+
42
+ it "should use -g with the correct argument when the gid property is set" do
43
+ resource[:gid] = 12345
44
+ provider.expects(:execute).with(all_of(includes("-g"), includes(12345)))
45
+ provider.create
46
+ end
47
+
48
+ it "should use -G with the correct argument when the groups property is set" do
49
+ resource[:groups] = "group1"
50
+ provider.expects(:execute).with(all_of(includes("-G"), includes("group1")))
51
+ provider.create
52
+ end
53
+
54
+ it "should use -G with all the given groups when the groups property is set to an array" do
55
+ resource[:groups] = ["group1", "group2"]
56
+ provider.expects(:execute).with(all_of(includes("-G"), includes("group1,group2")))
57
+ provider.create
58
+ end
59
+
60
+ it "should use -d with the correct argument when the home property is set" do
61
+ resource[:home] = "/home/testuser"
62
+ provider.expects(:execute).with(all_of(includes("-d"), includes("/home/testuser")))
63
+ provider.create
64
+ end
65
+
66
+ it "should use -m when the managehome property is enabled" do
67
+ resource[:managehome] = true
68
+ provider.expects(:execute).with(includes("-m"))
69
+ provider.create
70
+ end
71
+
72
+ it "should call the password set function with the correct argument when the password property is set" do
73
+ resource[:password] = "*"
74
+ provider.expects(:execute)
75
+ provider.expects(:password=).with("*")
76
+ provider.create
77
+ end
78
+
79
+ it "should use -s with the correct argument when the shell property is set" do
80
+ resource[:shell] = "/bin/sh"
81
+ provider.expects(:execute).with(all_of(includes("-s"), includes("/bin/sh")))
82
+ provider.create
83
+ end
84
+
85
+ it "should use -u with the correct argument when the uid property is set" do
86
+ resource[:uid] = 12345
87
+ provider.expects(:execute).with(all_of(includes("-u"), includes(12345)))
88
+ provider.create
89
+ end
90
+
91
+ # (#7500) -p should not be used to set a password (it means something else)
92
+ it "should not use -p when a password is given" do
93
+ resource[:password] = "*"
94
+ provider.addcmd.should_not include("-p")
95
+ provider.expects(:password=)
96
+ provider.expects(:execute).with(Not(includes("-p")))
97
+ provider.create
98
+ end
99
+ end
100
+
101
+ describe "when deleting users" do
102
+ it "should run pw with no additional flags" do
103
+ provider = resource.provider
104
+ provider.expects(:exists?).returns true
105
+ provider.deletecmd.must == [provider_class.command(:pw), "userdel", "testuser"]
106
+ provider.expects(:execute).with([provider_class.command(:pw), "userdel", "testuser"])
107
+ provider.delete
108
+ end
109
+ end
110
+
111
+ describe "when modifying users" do
112
+ let :provider do
113
+ resource.provider
114
+ end
115
+
116
+ it "should run pw with the correct arguments" do
117
+ provider.modifycmd("uid", 12345).must == [provider_class.command(:pw), "usermod", "testuser", "-u", 12345]
118
+ provider.expects(:execute).with([provider_class.command(:pw), "usermod", "testuser", "-u", 12345])
119
+ provider.uid = 12345
120
+ end
121
+
122
+ it "should use -c with the correct argument when the comment property is changed" do
123
+ resource[:comment] = "Testuser Name"
124
+ provider.expects(:execute).with(all_of(includes("-c"), includes("Testuser New Name")))
125
+ provider.comment = "Testuser New Name"
126
+ end
127
+
128
+ it "should use -e with the correct argument when the expiry property is changed" do
129
+ resource[:expiry] = "2010-02-19"
130
+ provider.expects(:execute).with(all_of(includes("-e"), includes("19-02-2011")))
131
+ provider.expiry = "2011-02-19"
132
+ end
133
+
134
+ it "should use -g with the correct argument when the gid property is changed" do
135
+ resource[:gid] = 12345
136
+ provider.expects(:execute).with(all_of(includes("-g"), includes(54321)))
137
+ provider.gid = 54321
138
+ end
139
+
140
+ it "should use -G with the correct argument when the groups property is changed" do
141
+ resource[:groups] = "group1"
142
+ provider.expects(:execute).with(all_of(includes("-G"), includes("group2")))
143
+ provider.groups = "group2"
144
+ end
145
+
146
+ it "should use -G with all the given groups when the groups property is changed with an array" do
147
+ resource[:groups] = ["group1", "group2"]
148
+ provider.expects(:execute).with(all_of(includes("-G"), includes("group3,group4")))
149
+ provider.groups = "group3,group4"
150
+ end
151
+
152
+ it "should use -d with the correct argument when the home property is changed" do
153
+ resource[:home] = "/home/testuser"
154
+ provider.expects(:execute).with(all_of(includes("-d"), includes("/newhome/testuser")))
155
+ provider.home = "/newhome/testuser"
156
+ end
157
+
158
+ it "should use -m and -d with the correct argument when the home property is changed and managehome is enabled" do
159
+ resource[:home] = "/home/testuser"
160
+ resource[:managehome] = true
161
+ provider.expects(:execute).with(all_of(includes("-d"), includes("/newhome/testuser"), includes("-m")))
162
+ provider.home = "/newhome/testuser"
163
+ end
164
+
165
+ it "should call the password set function with the correct argument when the password property is changed" do
166
+ resource[:password] = "*"
167
+ provider.expects(:password=).with("!")
168
+ provider.password = "!"
169
+ end
170
+
171
+ it "should use -s with the correct argument when the shell property is changed" do
172
+ resource[:shell] = "/bin/sh"
173
+ provider.expects(:execute).with(all_of(includes("-s"), includes("/bin/tcsh")))
174
+ provider.shell = "/bin/tcsh"
175
+ end
176
+
177
+ it "should use -u with the correct argument when the uid property is changed" do
178
+ resource[:uid] = 12345
179
+ provider.expects(:execute).with(all_of(includes("-u"), includes(54321)))
180
+ provider.uid = 54321
181
+ end
182
+ end
183
+ end
@@ -1,10 +1,10 @@
1
- #!/usr/bin/env rspec
2
1
  require 'spec_helper'
3
2
  require 'puppet_spec/files'
3
+ require 'tempfile'
4
4
 
5
5
  provider_class = Puppet::Type.type(:user).provider(:user_role_add)
6
6
 
7
- describe provider_class do
7
+ describe provider_class, :unless => Puppet.features.microsoft_windows? do
8
8
  include PuppetSpec::Files
9
9
 
10
10
  before do
@@ -246,44 +246,51 @@ describe provider_class do
246
246
  end
247
247
 
248
248
  describe "when setting the password" do
249
- before :each do
250
- @shadow_file = tmpfile('shadow')
251
- File.open(@shadow_file, 'w') do |f|
252
- f.puts 'fakeval:password:0'
253
- end
254
- @provider.stubs(:shadow_file).returns(@shadow_file)
255
- end
256
-
257
- it 'opens #shadow_file for reading' do
258
- File.expects(:open).with(@shadow_file, "r")
259
- File.stubs(:rename)
260
-
261
- @provider.password = "hashedpassword"
262
- end
263
-
264
- it 'writes to "#{shadow_file}_tmp"' do
265
- File.stubs(:rename)
266
- File.stubs(:unlink)
267
- @provider.password = 'hashedpassword'
268
-
269
- File.read("#{@shadow_file}_tmp").should =~ /hashedpassword/
270
- end
271
-
272
- it 'renames "#{shadow_file}_tmp" to shadow_file' do
273
- File.stubs(:open)
274
- File.expects(:rename).with("#{@shadow_file}_tmp", @shadow_file)
275
-
276
- @provider.password = "hashedpassword"
277
- end
249
+ let(:path) { tmpfile('etc-shadow') }
278
250
 
279
- it 'updates the last changed field' do
280
- Time.stubs(:now).returns(42 * 86400)
281
-
282
- File.read(@shadow_file).should == "fakeval:password:0\n"
283
-
284
- @provider.password = 'hashedpassword'
285
-
286
- File.read(@shadow_file).should == "fakeval:hashedpassword:42"
251
+ before :each do
252
+ @provider.stubs(:target_file_path).returns(path)
253
+ end
254
+
255
+ def write_fixture(content)
256
+ File.open(path, 'w') { |f| f.print(content) }
257
+ end
258
+
259
+ it "should update the target user" do
260
+ write_fixture <<FIXTURE
261
+ fakeval:seriously:15315:0:99999:7:::
262
+ FIXTURE
263
+ @provider.password = "totally"
264
+ File.read(path).should =~ /^fakeval:totally:/
265
+ end
266
+
267
+ it "should only update the target user" do
268
+ write_fixture <<FIXTURE
269
+ before:seriously:15315:0:99999:7:::
270
+ fakeval:seriously:15315:0:99999:7:::
271
+ fakevalish:seriously:15315:0:99999:7:::
272
+ after:seriously:15315:0:99999:7:::
273
+ FIXTURE
274
+ @provider.password = "totally"
275
+ File.read(path).should == <<EOT
276
+ before:seriously:15315:0:99999:7:::
277
+ fakeval:totally:15315:0:99999:7:::
278
+ fakevalish:seriously:15315:0:99999:7:::
279
+ after:seriously:15315:0:99999:7:::
280
+ EOT
281
+ end
282
+
283
+ # This preserves the current semantics, but is it right? --daniel 2012-02-05
284
+ it "should do nothing if the target user is missing" do
285
+ fixture = <<FIXTURE
286
+ before:seriously:15315:0:99999:7:::
287
+ fakevalish:seriously:15315:0:99999:7:::
288
+ after:seriously:15315:0:99999:7:::
289
+ FIXTURE
290
+
291
+ write_fixture fixture
292
+ @provider.password = "totally"
293
+ File.read(path).should == fixture
287
294
  end
288
295
  end
289
296
 
@@ -74,6 +74,7 @@ describe Puppet::Type.type(:user).provider(:windows_adsi) do
74
74
  user.stubs(:groups).returns(['group2', 'group3'])
75
75
 
76
76
  create = sequence('create')
77
+ user.expects(:password=).in_sequence(create)
77
78
  user.expects(:commit).in_sequence(create)
78
79
  user.expects(:set_groups).with('group1,group2', false).in_sequence(create)
79
80
  user.expects(:[]=).with('Description', 'a test user')
@@ -27,4 +27,36 @@ describe Puppet::Provider do
27
27
 
28
28
  two.specificity.should > one.specificity
29
29
  end
30
+
31
+ it "should be Comparable" do
32
+ res = Puppet::Type.type(:notify).new(:name => "res")
33
+
34
+ # Normally I wouldn't like the stubs, but the only way to name a class
35
+ # otherwise is to assign it to a constant, and that hurts more here in
36
+ # testing world. --daniel 2012-01-29
37
+ a = Class.new(Puppet::Provider).new(res)
38
+ a.class.stubs(:name).returns "Puppet::Provider::Notify::A"
39
+
40
+ b = Class.new(Puppet::Provider).new(res)
41
+ b.class.stubs(:name).returns "Puppet::Provider::Notify::B"
42
+
43
+ c = Class.new(Puppet::Provider).new(res)
44
+ c.class.stubs(:name).returns "Puppet::Provider::Notify::C"
45
+
46
+ [[a, b, c], [a, c, b], [b, a, c], [b, c, a], [c, a, b], [c, b, a]].each do |this|
47
+ this.sort.should == [a, b, c]
48
+ end
49
+
50
+ a.should be < b
51
+ a.should be < c
52
+ b.should be > a
53
+ b.should be < c
54
+ c.should be > a
55
+ c.should be > b
56
+
57
+ [a, b, c].each {|x| a.should be <= x }
58
+ [a, b, c].each {|x| c.should be >= x }
59
+
60
+ b.should be_between(a, c)
61
+ end
30
62
  end
@@ -3,6 +3,9 @@ require 'spec_helper'
3
3
 
4
4
  require 'puppet/reports'
5
5
  require 'time'
6
+ require 'pathname'
7
+ require 'tempfile'
8
+ require 'fileutils'
6
9
 
7
10
  processor = Puppet::Reports.report(:store)
8
11
 
@@ -10,7 +13,7 @@ describe processor do
10
13
  describe "#process" do
11
14
  include PuppetSpec::Files
12
15
  before :each do
13
- Puppet[:reportdir] = tmpdir('reports') << '/reports'
16
+ Puppet[:reportdir] = File.join(tmpdir('reports'), 'reports')
14
17
  @report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report2.6.x.yaml')).extend processor
15
18
  end
16
19
 
@@ -26,5 +29,20 @@ describe processor do
26
29
 
27
30
  File.read(File.join(Puppet[:reportdir], @report.host, "201101061200.yaml")).should == @report.to_yaml
28
31
  end
32
+
33
+ it "should write to the report directory in the correct sequence" do
34
+ # By doing things in this sequence we should protect against race
35
+ # conditions
36
+ Time.stubs(:now).returns(Time.parse("2011-01-06 12:00:00 UTC"))
37
+ writeseq = sequence("write")
38
+ file = mock "file"
39
+ Tempfile.expects(:new).in_sequence(writeseq).returns(file)
40
+ file.expects(:chmod).in_sequence(writeseq).with(0640)
41
+ file.expects(:print).with(@report.to_yaml).in_sequence(writeseq)
42
+ file.expects(:close).in_sequence(writeseq)
43
+ file.stubs(:path).returns(File.join(Dir.tmpdir, "foo123"))
44
+ FileUtils.expects(:mv).in_sequence(writeseq).with(File.join(Dir.tmpdir, "foo123"), File.join(Puppet[:reportdir], @report.host, "201101061200.yaml"))
45
+ @report.process
46
+ end
29
47
  end
30
48
  end
@@ -268,9 +268,24 @@ describe Puppet::SimpleGraph do
268
268
  @graph = Puppet::SimpleGraph.new
269
269
  end
270
270
 
271
+ # This works with `add_edges` to auto-vivify the resource instances.
272
+ let :vertex do
273
+ Hash.new do |hash, key|
274
+ hash[key] = Puppet::Type.type(:notify).new(:name => key.to_s)
275
+ end
276
+ end
277
+
271
278
  def add_edges(hash)
272
279
  hash.each do |a,b|
273
- @graph.add_edge(a, b)
280
+ @graph.add_edge(vertex[a], vertex[b])
281
+ end
282
+ end
283
+
284
+ def simplify(cycles)
285
+ cycles.map do |x|
286
+ x.map do |y|
287
+ y.to_s.match(/^Notify\[(.*)\]$/)[1]
288
+ end
274
289
  end
275
290
  end
276
291
 
@@ -298,7 +313,7 @@ describe Puppet::SimpleGraph do
298
313
  add_edges :a => :b, :b => :a
299
314
  # cycle detection starts from a or b randomly
300
315
  # so we need to check for either ordering in the error message
301
- want = %r{Found 1 dependency cycle:\n\((a => b => a|b => a => b)\)\nTry}
316
+ want = %r{Found 1 dependency cycle:\n\((Notify\[a\] => Notify\[b\] => Notify\[a\]|Notify\[b\] => Notify\[a\] => Notify\[b\])\)\nTry}
302
317
  expect { @graph.report_cycles_in_graph }.to raise_error(Puppet::Error, want)
303
318
  end
304
319
 
@@ -308,8 +323,8 @@ describe Puppet::SimpleGraph do
308
323
  add_edges "b" => "c"
309
324
 
310
325
  cycles = nil
311
- expect { cycles = @graph.find_cycles_in_graph.sort }.should_not raise_error
312
- cycles.should be == [["a", "b"]]
326
+ expect { cycles = @graph.find_cycles_in_graph }.should_not raise_error
327
+ simplify(cycles).should be == [["a", "b"]]
313
328
  end
314
329
 
315
330
  it "cycle discovery should handle two distinct cycles" do
@@ -317,8 +332,8 @@ describe Puppet::SimpleGraph do
317
332
  add_edges "b" => "b1", "b1" => "b"
318
333
 
319
334
  cycles = nil
320
- expect { cycles = @graph.find_cycles_in_graph.sort }.should_not raise_error
321
- cycles.should be == [["a", "a1"], ["b", "b1"]]
335
+ expect { cycles = @graph.find_cycles_in_graph }.should_not raise_error
336
+ simplify(cycles).should be == [["a1", "a"], ["b1", "b"]]
322
337
  end
323
338
 
324
339
  it "cycle discovery should handle two cycles in a connected graph" do
@@ -327,8 +342,8 @@ describe Puppet::SimpleGraph do
327
342
  add_edges "c" => "c1", "c1" => "c2", "c2" => "c3", "c3" => "c"
328
343
 
329
344
  cycles = nil
330
- expect { cycles = @graph.find_cycles_in_graph.sort }.should_not raise_error
331
- cycles.should be == [%w{a a1}, %w{c c1 c2 c3}]
345
+ expect { cycles = @graph.find_cycles_in_graph }.should_not raise_error
346
+ simplify(cycles).should be == [%w{a1 a}, %w{c1 c2 c3 c}]
332
347
  end
333
348
 
334
349
  it "cycle discovery should handle a complicated cycle" do
@@ -338,8 +353,8 @@ describe Puppet::SimpleGraph do
338
353
  add_edges "c" => "c2", "c2" => "b"
339
354
 
340
355
  cycles = nil
341
- expect { cycles = @graph.find_cycles_in_graph.sort }.should_not raise_error
342
- cycles.should be == [%w{a b c c1 c2}]
356
+ expect { cycles = @graph.find_cycles_in_graph }.should_not raise_error
357
+ simplify(cycles).should be == [%w{a b c1 c2 c}]
343
358
  end
344
359
 
345
360
  it "cycle discovery should not fail with large data sets" do
@@ -347,16 +362,16 @@ describe Puppet::SimpleGraph do
347
362
  (1..(limit - 1)).each do |n| add_edges n.to_s => (n+1).to_s end
348
363
 
349
364
  cycles = nil
350
- expect { cycles = @graph.find_cycles_in_graph.sort }.should_not raise_error
351
- cycles.should be == []
365
+ expect { cycles = @graph.find_cycles_in_graph }.should_not raise_error
366
+ simplify(cycles).should be == []
352
367
  end
353
368
 
354
369
  it "path finding should work with a simple cycle" do
355
370
  add_edges "a" => "b", "b" => "c", "c" => "a"
356
371
 
357
- cycles = @graph.find_cycles_in_graph.sort
372
+ cycles = @graph.find_cycles_in_graph
358
373
  paths = @graph.paths_in_cycle(cycles.first, 100)
359
- paths.should be == [%w{a b c a}]
374
+ simplify(paths).should be == [%w{a b c a}]
360
375
  end
361
376
 
362
377
  it "path finding should work with two independent cycles" do
@@ -364,28 +379,28 @@ describe Puppet::SimpleGraph do
364
379
  add_edges "a" => "b2"
365
380
  add_edges "b1" => "a", "b2" => "a"
366
381
 
367
- cycles = @graph.find_cycles_in_graph.sort
382
+ cycles = @graph.find_cycles_in_graph
368
383
  cycles.length.should be == 1
369
384
 
370
385
  paths = @graph.paths_in_cycle(cycles.first, 100)
371
- paths.sort.should be == [%w{a b1 a}, %w{a b2 a}]
386
+ simplify(paths).should be == [%w{a b1 a}, %w{a b2 a}]
372
387
  end
373
388
 
374
389
  it "path finding should prefer shorter paths in cycles" do
375
390
  add_edges "a" => "b", "b" => "c", "c" => "a"
376
391
  add_edges "b" => "a"
377
392
 
378
- cycles = @graph.find_cycles_in_graph.sort
393
+ cycles = @graph.find_cycles_in_graph
379
394
  cycles.length.should be == 1
380
395
 
381
396
  paths = @graph.paths_in_cycle(cycles.first, 100)
382
- paths.should be == [%w{a b a}, %w{a b c a}]
397
+ simplify(paths).should be == [%w{a b a}, %w{a b c a}]
383
398
  end
384
399
 
385
400
  it "path finding should respect the max_path value" do
386
401
  (1..20).each do |n| add_edges "a" => "b#{n}", "b#{n}" => "a" end
387
402
 
388
- cycles = @graph.find_cycles_in_graph.sort
403
+ cycles = @graph.find_cycles_in_graph
389
404
  cycles.length.should be == 1
390
405
 
391
406
  (1..20).each do |n|