puppet 2.7.11 → 2.7.12

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 (220) hide show
  1. data/CHANGELOG +188 -0
  2. data/conf/osx/createpackage.sh +1 -0
  3. data/conf/redhat/puppet.spec +12 -9
  4. data/conf/suse/puppet.spec +4 -1
  5. data/install.rb +9 -22
  6. data/lib/puppet.rb +1 -31
  7. data/lib/puppet/agent.rb +3 -5
  8. data/lib/puppet/agent/locker.rb +15 -1
  9. data/lib/puppet/application.rb +7 -4
  10. data/lib/puppet/application/agent.rb +4 -25
  11. data/lib/puppet/application/apply.rb +3 -3
  12. data/lib/puppet/application/device.rb +2 -16
  13. data/lib/puppet/application/doc.rb +2 -2
  14. data/lib/puppet/application/face_base.rb +22 -5
  15. data/lib/puppet/application/filebucket.rb +2 -0
  16. data/lib/puppet/application/inspect.rb +2 -1
  17. data/lib/puppet/application/kick.rb +25 -9
  18. data/lib/puppet/application/queue.rb +0 -23
  19. data/lib/puppet/configurer.rb +1 -0
  20. data/lib/puppet/configurer/downloader.rb +7 -3
  21. data/lib/puppet/defaults.rb +34 -29
  22. data/lib/puppet/face/ca.rb +1 -1
  23. data/lib/puppet/face/catalog.rb +1 -0
  24. data/lib/puppet/face/file/store.rb +1 -1
  25. data/lib/puppet/face/module/list.rb +23 -3
  26. data/lib/puppet/face/module/search.rb +21 -32
  27. data/lib/puppet/face/module/uninstall.rb +56 -15
  28. data/lib/puppet/file_bucket/dipper.rb +2 -2
  29. data/lib/puppet/file_serving/base.rb +6 -5
  30. data/lib/puppet/file_serving/configuration/parser.rb +1 -1
  31. data/lib/puppet/file_serving/content.rb +1 -1
  32. data/lib/puppet/forge.rb +153 -0
  33. data/lib/puppet/{module_tool → forge}/cache.rb +1 -2
  34. data/lib/puppet/{module_tool → forge}/repository.rb +46 -4
  35. data/lib/puppet/indirector/exec.rb +1 -1
  36. data/lib/puppet/indirector/file_bucket_file/file.rb +3 -3
  37. data/lib/puppet/interface/action.rb +6 -2
  38. data/lib/puppet/module.rb +70 -10
  39. data/lib/puppet/module_tool.rb +2 -38
  40. data/lib/puppet/module_tool/applications.rb +15 -11
  41. data/lib/puppet/module_tool/applications/application.rb +2 -5
  42. data/lib/puppet/module_tool/applications/cleaner.rb +1 -1
  43. data/lib/puppet/module_tool/applications/installer.rb +10 -45
  44. data/lib/puppet/module_tool/applications/searcher.rb +2 -26
  45. data/lib/puppet/module_tool/applications/uninstaller.rb +39 -13
  46. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  47. data/lib/puppet/module_tool/dependency.rb +1 -1
  48. data/lib/puppet/network/authconfig.rb +1 -1
  49. data/lib/puppet/network/handler/fileserver.rb +1 -1
  50. data/lib/puppet/network/http/handler.rb +4 -1
  51. data/lib/puppet/network/http/webrick.rb +4 -2
  52. data/lib/puppet/node/environment.rb +32 -6
  53. data/lib/puppet/parameter/path.rb +0 -4
  54. data/lib/puppet/parser/ast/relationship.rb +3 -16
  55. data/lib/puppet/parser/collector.rb +5 -3
  56. data/lib/puppet/parser/compiler.rb +2 -1
  57. data/lib/puppet/parser/functions/file.rb +1 -1
  58. data/lib/puppet/parser/functions/generate.rb +8 -2
  59. data/lib/puppet/parser/grammar.ra +16 -15
  60. data/lib/puppet/parser/parser.rb +959 -881
  61. data/lib/puppet/parser/relationship.rb +32 -15
  62. data/lib/puppet/parser/resource.rb +0 -1
  63. data/lib/puppet/parser/type_loader.rb +1 -2
  64. data/lib/puppet/provider/augeas/augeas.rb +17 -29
  65. data/lib/puppet/provider/exec/windows.rb +25 -3
  66. data/lib/puppet/provider/file/posix.rb +1 -1
  67. data/lib/puppet/provider/file/windows.rb +1 -1
  68. data/lib/puppet/provider/group/windows_adsi.rb +1 -1
  69. data/lib/puppet/provider/package/aix.rb +1 -1
  70. data/lib/puppet/provider/package/appdmg.rb +1 -1
  71. data/lib/puppet/provider/package/dpkg.rb +1 -1
  72. data/lib/puppet/provider/package/gem.rb +21 -23
  73. data/lib/puppet/provider/package/macports.rb +1 -1
  74. data/lib/puppet/provider/package/msi.rb +7 -1
  75. data/lib/puppet/provider/package/openbsd.rb +13 -16
  76. data/lib/puppet/provider/package/pacman.rb +1 -1
  77. data/lib/puppet/provider/package/pip.rb +3 -0
  78. data/lib/puppet/provider/package/pkg.rb +1 -1
  79. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  80. data/lib/puppet/provider/package/pkgutil.rb +1 -1
  81. data/lib/puppet/provider/package/portage.rb +2 -2
  82. data/lib/puppet/provider/package/rpm.rb +1 -1
  83. data/lib/puppet/provider/package/sun.rb +1 -1
  84. data/lib/puppet/provider/package/zypper.rb +35 -3
  85. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +6 -2
  86. data/lib/puppet/provider/selmodule/semodule.rb +2 -2
  87. data/lib/puppet/provider/service/base.rb +1 -1
  88. data/lib/puppet/provider/service/launchd.rb +4 -0
  89. data/lib/puppet/provider/service/src.rb +2 -2
  90. data/lib/puppet/provider/service/upstart.rb +1 -1
  91. data/lib/puppet/provider/service/windows.rb +5 -4
  92. data/lib/puppet/provider/user/aix.rb +3 -3
  93. data/lib/puppet/provider/user/pw.rb +6 -0
  94. data/lib/puppet/provider/user/windows_adsi.rb +1 -1
  95. data/lib/puppet/resource/catalog.rb +6 -6
  96. data/lib/puppet/resource/type.rb +2 -0
  97. data/lib/puppet/ssl/certificate_request.rb +0 -70
  98. data/lib/puppet/transaction.rb +1 -1
  99. data/lib/puppet/transaction/report.rb +3 -2
  100. data/lib/puppet/type.rb +1 -1
  101. data/lib/puppet/type/cron.rb +5 -2
  102. data/lib/puppet/type/exec.rb +8 -0
  103. data/lib/puppet/type/file.rb +27 -18
  104. data/lib/puppet/type/file/checksum.rb +2 -2
  105. data/lib/puppet/type/file/content.rb +14 -9
  106. data/lib/puppet/type/file/ensure.rb +5 -4
  107. data/lib/puppet/type/file/group.rb +10 -2
  108. data/lib/puppet/type/file/mode.rb +46 -18
  109. data/lib/puppet/type/file/owner.rb +10 -2
  110. data/lib/puppet/type/file/source.rb +27 -40
  111. data/lib/puppet/type/file/target.rb +6 -6
  112. data/lib/puppet/type/group.rb +13 -9
  113. data/lib/puppet/type/k5login.rb +1 -1
  114. data/lib/puppet/type/package.rb +24 -8
  115. data/lib/puppet/type/scheduled_task.rb +77 -131
  116. data/lib/puppet/type/service.rb +22 -8
  117. data/lib/puppet/type/user.rb +29 -9
  118. data/lib/puppet/util.rb +24 -33
  119. data/lib/puppet/util/colors.rb +98 -0
  120. data/lib/puppet/util/diff.rb +3 -1
  121. data/lib/puppet/util/log.rb +5 -1
  122. data/lib/puppet/util/log/destinations.rb +37 -44
  123. data/lib/puppet/util/monkey_patches.rb +32 -0
  124. data/lib/puppet/util/pidlock.rb +70 -21
  125. data/lib/puppet/util/rdoc/parser.rb +4 -2
  126. data/lib/puppet/util/selinux.rb +1 -1
  127. data/lib/puppet/util/suidmanager.rb +2 -12
  128. data/lib/puppet/util/windows.rb +2 -0
  129. data/lib/puppet/util/windows/process.rb +33 -0
  130. data/lib/puppet/util/windows/security.rb +6 -4
  131. data/lib/puppet/util/windows/user.rb +44 -0
  132. data/lib/semver.rb +55 -4
  133. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.detail +19 -0
  134. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.list +10 -0
  135. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.query +1 -0
  136. data/spec/fixtures/unit/provider/package/zypper/zypper-list-updates-SLES11sp1.out +369 -0
  137. data/spec/integration/defaults_spec.rb +10 -0
  138. data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
  139. data/spec/integration/module_tool_spec.rb +10 -12
  140. data/spec/integration/parser/compiler_spec.rb +147 -0
  141. data/spec/integration/type/file_spec.rb +1 -1
  142. data/spec/integration/util/windows/user_spec.rb +59 -0
  143. data/spec/lib/puppet/face/basetest.rb +5 -0
  144. data/spec/lib/puppet_spec/modules.rb +26 -0
  145. data/spec/spec_helper.rb +25 -0
  146. data/spec/unit/agent/locker_spec.rb +12 -0
  147. data/spec/unit/agent_backward_compatibility_spec.rb +152 -0
  148. data/spec/unit/agent_spec.rb +28 -8
  149. data/spec/unit/application/agent_spec.rb +4 -36
  150. data/spec/unit/application/device_spec.rb +55 -10
  151. data/spec/unit/application/face_base_spec.rb +32 -10
  152. data/spec/unit/application/filebucket_spec.rb +5 -0
  153. data/spec/unit/application/kick_spec.rb +6 -0
  154. data/spec/unit/application_spec.rb +8 -1
  155. data/spec/unit/configurer/downloader_spec.rb +4 -5
  156. data/spec/unit/face/ca_spec.rb +15 -4
  157. data/spec/unit/file_bucket/dipper_spec.rb +1 -1
  158. data/spec/unit/file_serving/base_spec.rb +60 -42
  159. data/spec/unit/file_serving/configuration/parser_spec.rb +5 -3
  160. data/spec/unit/file_serving/content_spec.rb +26 -27
  161. data/spec/unit/file_serving/metadata_spec.rb +22 -21
  162. data/spec/unit/forge/repository_spec.rb +86 -0
  163. data/spec/unit/forge_spec.rb +114 -0
  164. data/spec/unit/indirector/exec_spec.rb +8 -6
  165. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +0 -1
  166. data/spec/unit/indirector/file_bucket_file/file_spec.rb +1 -1
  167. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  168. data/spec/unit/indirector/resource/active_record_spec.rb +0 -4
  169. data/spec/unit/interface/action_builder_spec.rb +7 -5
  170. data/spec/unit/module_spec.rb +228 -9
  171. data/spec/unit/module_tool/application_spec.rb +3 -3
  172. data/spec/unit/module_tool/uninstaller_spec.rb +107 -27
  173. data/spec/unit/module_tool_spec.rb +0 -33
  174. data/spec/unit/network/authconfig_spec.rb +22 -21
  175. data/spec/unit/network/http/webrick_spec.rb +13 -9
  176. data/spec/unit/node/environment_spec.rb +159 -66
  177. data/spec/unit/parser/collector_spec.rb +16 -8
  178. data/spec/unit/parser/functions/generate_spec.rb +60 -18
  179. data/spec/unit/parser/resource_spec.rb +44 -0
  180. data/spec/unit/provider/augeas/augeas_spec.rb +160 -179
  181. data/spec/unit/provider/confine/feature_spec.rb +3 -5
  182. data/spec/unit/provider/package/dpkg_spec.rb +4 -2
  183. data/spec/unit/provider/package/gem_spec.rb +59 -43
  184. data/spec/unit/provider/package/openbsd_spec.rb +114 -0
  185. data/spec/unit/provider/package/pacman_spec.rb +1 -1
  186. data/spec/unit/provider/package/pip_spec.rb +10 -4
  187. data/spec/unit/provider/package/zypper_spec.rb +56 -14
  188. data/spec/unit/provider/selmodule_spec.rb +3 -3
  189. data/spec/unit/provider/service/launchd_spec.rb +22 -21
  190. data/spec/unit/provider/service/{upstart.rb → upstart_spec.rb} +7 -3
  191. data/spec/unit/provider/user/pw_spec.rb +19 -0
  192. data/spec/unit/resource/catalog_spec.rb +3 -3
  193. data/spec/unit/semver_spec.rb +117 -24
  194. data/spec/unit/transaction/report_spec.rb +11 -1
  195. data/spec/unit/type/cron_spec.rb +200 -213
  196. data/spec/unit/type/exec_spec.rb +7 -0
  197. data/spec/unit/type/file/content_spec.rb +2 -2
  198. data/spec/unit/type/file_spec.rb +12 -9
  199. data/spec/unit/type/package_spec.rb +25 -0
  200. data/spec/unit/type/schedule_spec.rb +31 -31
  201. data/spec/unit/util/diff_spec.rb +30 -0
  202. data/spec/unit/util/execution_stub_spec.rb +1 -2
  203. data/spec/unit/util/log/destinations_spec.rb +51 -0
  204. data/spec/unit/util/log_spec.rb +17 -1
  205. data/spec/unit/util/monkey_patches_spec.rb +119 -0
  206. data/spec/unit/util/rdoc/parser_spec.rb +25 -1
  207. data/spec/unit/util/selinux_spec.rb +2 -2
  208. data/spec/unit/util/suidmanager_spec.rb +6 -51
  209. data/spec/unit/util_spec.rb +82 -24
  210. data/test/lib/puppettest/certificates.rb +16 -0
  211. data/test/lib/puppettest/servertest.rb +4 -0
  212. data/test/util/pidlock.rb +125 -0
  213. metadata +23 -14
  214. data/ext/puppetstoredconfigclean.rb +0 -103
  215. data/lib/puppet/agent/disabler.rb +0 -27
  216. data/lib/puppet/util/anonymous_filelock.rb +0 -36
  217. data/spec/unit/agent/disabler_spec.rb +0 -60
  218. data/spec/unit/module_tool/repository_spec.rb +0 -52
  219. data/spec/unit/util/anonymous_filelock_spec.rb +0 -78
  220. data/spec/unit/util/pidlock_spec.rb +0 -208
@@ -4,14 +4,22 @@ require 'spec_helper'
4
4
  provider_class = Puppet::Type.type(:augeas).provider(:augeas)
5
5
 
6
6
  describe provider_class do
7
- describe "command parsing" do
8
- before do
9
- @resource = stub("resource")
10
- @provider = provider_class.new(@resource)
11
- end
7
+ before(:each) do
8
+ @resource = Puppet::Type.type(:augeas).new(
9
+ :name => "test",
10
+ :root => my_fixture_dir,
11
+ :provider => :augeas
12
+ )
13
+ @provider = provider_class.new(@resource)
14
+ end
15
+
16
+ after(:each) do
17
+ @provider.close_augeas
18
+ end
12
19
 
20
+ describe "command parsing" do
13
21
  it "should break apart a single line into three tokens and clean up the context" do
14
- @resource.stubs(:[]).returns("/context")
22
+ @resource[:context] = "/context"
15
23
  tokens = @provider.parse_commands("set Jar/Jar Binks")
16
24
  tokens.size.should == 1
17
25
  tokens[0].size.should == 3
@@ -21,7 +29,6 @@ describe provider_class do
21
29
  end
22
30
 
23
31
  it "should break apart a multiple line into six tokens" do
24
- @resource.stubs(:[]).returns("")
25
32
  tokens = @provider.parse_commands("set /Jar/Jar Binks\nrm anakin")
26
33
  tokens.size.should == 2
27
34
  tokens[0].size.should == 3
@@ -34,7 +41,6 @@ describe provider_class do
34
41
  end
35
42
 
36
43
  it "should strip whitespace and ignore blank lines" do
37
- @resource.stubs(:[]).returns("")
38
44
  tokens = @provider.parse_commands(" set /Jar/Jar Binks \t\n \n\n rm anakin ")
39
45
  tokens.size.should == 2
40
46
  tokens[0].size.should == 3
@@ -47,7 +53,7 @@ describe provider_class do
47
53
  end
48
54
 
49
55
  it "should handle arrays" do
50
- @resource.stubs(:[]).returns("/foo/")
56
+ @resource[:context] = "/foo/"
51
57
  commands = ["set /Jar/Jar Binks", "rm anakin"]
52
58
  tokens = @provider.parse_commands(commands)
53
59
  tokens.size.should == 2
@@ -72,7 +78,7 @@ describe provider_class do
72
78
  #end
73
79
 
74
80
  it "should accept spaces in the value and single ticks" do
75
- @resource.stubs(:[]).returns("/foo/")
81
+ @resource[:context] = "/foo/"
76
82
  tokens = @provider.parse_commands("set JarJar 'Binks is my copilot'")
77
83
  tokens.size.should == 1
78
84
  tokens[0].size.should == 3
@@ -82,7 +88,7 @@ describe provider_class do
82
88
  end
83
89
 
84
90
  it "should accept spaces in the value and double ticks" do
85
- @resource.stubs(:[]).returns("/foo/")
91
+ @resource[:context] = "/foo/"
86
92
  tokens = @provider.parse_commands('set /JarJar "Binks is my copilot"')
87
93
  tokens.size.should == 1
88
94
  tokens[0].size.should == 3
@@ -92,7 +98,7 @@ describe provider_class do
92
98
  end
93
99
 
94
100
  it "should accept mixed ticks" do
95
- @resource.stubs(:[]).returns("/foo/")
101
+ @resource[:context] = "/foo/"
96
102
  tokens = @provider.parse_commands('set JarJar "Some \'Test\'"')
97
103
  tokens.size.should == 1
98
104
  tokens[0].size.should == 3
@@ -102,59 +108,59 @@ describe provider_class do
102
108
  end
103
109
 
104
110
  it "should handle predicates with literals" do
105
- @resource.stubs(:[]).returns("/foo/")
111
+ @resource[:context] = "/foo/"
106
112
  tokens = @provider.parse_commands("rm */*[module='pam_console.so']")
107
113
  tokens.should == [["rm", "/foo/*/*[module='pam_console.so']"]]
108
114
  end
109
115
 
110
116
  it "should handle whitespace in predicates" do
111
- @resource.stubs(:[]).returns("/foo/")
117
+ @resource[:context] = "/foo/"
112
118
  tokens = @provider.parse_commands("ins 42 before /files/etc/hosts/*/ipaddr[ . = '127.0.0.1' ]")
113
119
  tokens.should == [["ins", "42", "before","/files/etc/hosts/*/ipaddr[ . = '127.0.0.1' ]"]]
114
120
  end
115
121
 
116
122
  it "should handle multiple predicates" do
117
- @resource.stubs(:[]).returns("/foo/")
123
+ @resource[:context] = "/foo/"
118
124
  tokens = @provider.parse_commands("clear pam.d/*/*[module = 'system-auth'][type = 'account']")
119
125
  tokens.should == [["clear", "/foo/pam.d/*/*[module = 'system-auth'][type = 'account']"]]
120
126
  end
121
127
 
122
128
  it "should handle nested predicates" do
123
- @resource.stubs(:[]).returns("/foo/")
129
+ @resource[:context] = "/foo/"
124
130
  args = ["clear", "/foo/pam.d/*/*[module[ ../type = 'type] = 'system-auth'][type[last()] = 'account']"]
125
131
  tokens = @provider.parse_commands(args.join(" "))
126
132
  tokens.should == [ args ]
127
133
  end
128
134
 
129
135
  it "should handle escaped doublequotes in doublequoted string" do
130
- @resource.stubs(:[]).returns("/foo/")
136
+ @resource[:context] = "/foo/"
131
137
  tokens = @provider.parse_commands("set /foo \"''\\\"''\"")
132
138
  tokens.should == [[ "set", "/foo", "''\\\"''" ]]
133
139
  end
134
140
 
135
141
  it "should allow escaped spaces and brackets in paths" do
136
- @resource.stubs(:[]).returns("/foo/")
142
+ @resource[:context] = "/foo/"
137
143
  args = [ "set", "/white\\ space/\\[section", "value" ]
138
144
  tokens = @provider.parse_commands(args.join(" \t "))
139
145
  tokens.should == [ args ]
140
146
  end
141
147
 
142
148
  it "should allow single quoted escaped spaces in paths" do
143
- @resource.stubs(:[]).returns("/foo/")
149
+ @resource[:context] = "/foo/"
144
150
  args = [ "set", "'/white\\ space/key'", "value" ]
145
151
  tokens = @provider.parse_commands(args.join(" \t "))
146
152
  tokens.should == [[ "set", "/white\\ space/key", "value" ]]
147
153
  end
148
154
 
149
155
  it "should allow double quoted escaped spaces in paths" do
150
- @resource.stubs(:[]).returns("/foo/")
156
+ @resource[:context] = "/foo/"
151
157
  args = [ "set", '"/white\\ space/key"', "value" ]
152
158
  tokens = @provider.parse_commands(args.join(" \t "))
153
159
  tokens.should == [[ "set", "/white\\ space/key", "value" ]]
154
160
  end
155
161
 
156
162
  it "should remove trailing slashes" do
157
- @resource.stubs(:[]).returns("/foo/")
163
+ @resource[:context] = "/foo/"
158
164
  tokens = @provider.parse_commands("set foo/ bar")
159
165
  tokens.should == [[ "set", "/foo/foo", "bar" ]]
160
166
  end
@@ -162,9 +168,9 @@ describe provider_class do
162
168
 
163
169
  describe "get filters" do
164
170
  before do
165
- augeas_stub = stub("augeas", :get => "value")
166
- @provider = provider_class.new
167
- @provider.aug= augeas_stub
171
+ augeas = stub("augeas", :get => "value")
172
+ augeas.stubs("close")
173
+ @provider.aug = augeas
168
174
  end
169
175
 
170
176
  it "should return false for a = nonmatch" do
@@ -190,10 +196,10 @@ describe provider_class do
190
196
 
191
197
  describe "match filters" do
192
198
  before do
193
- resource = stub("resource", :[] => "")
194
- augeas_stub = stub("augeas", :match => ["set", "of", "values"])
195
- @provider = provider_class.new(resource)
196
- @provider.aug= augeas_stub
199
+ augeas = stub("augeas", :match => ["set", "of", "values"])
200
+ augeas.stubs("close")
201
+ @provider = provider_class.new(@resource)
202
+ @provider.aug = augeas
197
203
  end
198
204
 
199
205
  it "should return true for size match" do
@@ -248,126 +254,89 @@ describe provider_class do
248
254
  end
249
255
 
250
256
  describe "need to run" do
257
+ before(:each) do
258
+ @augeas = stub("augeas")
259
+ @augeas.stubs("close")
260
+ @provider.aug = @augeas
261
+
262
+ # These tests pretend to be an earlier version so the provider doesn't
263
+ # attempt to make the change in the need_to_run? method
264
+ @provider.stubs(:get_augeas_version).returns("0.3.5")
265
+ end
266
+
251
267
  it "should handle no filters" do
252
- resource = stub("resource")
253
- resource.stubs(:[]).returns(false).then.returns("").then.returns("")
254
- resource.stubs(:noop?).returns(false)
255
- augeas_stub = stub("augeas", :match => ["set", "of", "values"])
256
- augeas_stub.stubs("close")
257
- provider = provider_class.new(resource)
258
- provider.aug= augeas_stub
259
- provider.stubs(:get_augeas_version).returns("0.3.5")
260
- provider.need_to_run?.should == true
268
+ @augeas.stubs("match").returns(["set", "of", "values"])
269
+ @provider.need_to_run?.should == true
261
270
  end
262
271
 
263
272
  it "should return true when a get filter matches" do
264
- resource = stub("resource")
265
- resource.stubs(:[]).returns(false).then.returns("get path == value").then.returns("")
266
- resource.stubs(:noop?).returns(false)
267
- provider = provider_class.new(resource)
268
- augeas_stub = stub("augeas", :get => "value")
269
- augeas_stub.stubs("close")
270
- provider.aug= augeas_stub
271
- provider.stubs(:get_augeas_version).returns("0.3.5")
272
- provider.need_to_run?.should == true
273
+ @resource[:onlyif] = "get path == value"
274
+ @augeas.stubs("get").returns("value")
275
+ @provider.need_to_run?.should == true
273
276
  end
274
277
 
275
278
  it "should return false when a get filter does not match" do
276
- resource = stub("resource")
277
- resource.stubs(:[]).returns(false).then.returns("get path == another value").then.returns("")
278
- provider = provider_class.new(resource)
279
- augeas_stub = stub("augeas", :get => "value")
280
- augeas_stub.stubs("close")
281
- provider.aug= augeas_stub
282
- provider.stubs(:get_augeas_version).returns("0.3.5")
283
- provider.need_to_run?.should == false
279
+ @resource[:onlyif] = "get path == another value"
280
+ @augeas.stubs("get").returns("value")
281
+ @provider.need_to_run?.should == false
284
282
  end
285
283
 
286
284
  it "should return true when a match filter matches" do
287
- resource = stub("resource")
288
- resource.stubs(:[]).returns(false).then.returns("match path size == 3").then.returns("")
289
- resource.stubs(:noop?).returns(false)
290
- provider = provider_class.new(resource)
291
- augeas_stub = stub("augeas", :match => ["set", "of", "values"])
292
- augeas_stub.stubs("close")
293
- provider.aug= augeas_stub
294
- provider.stubs(:get_augeas_version).returns("0.3.5")
295
- provider.need_to_run?.should == true
285
+ @resource[:onlyif] = "match path size == 3"
286
+ @augeas.stubs("match").returns(["set", "of", "values"])
287
+ @provider.need_to_run?.should == true
296
288
  end
297
289
 
298
290
  it "should return false when a match filter does not match" do
299
- resource = stub("resource")
300
- resource.stubs(:[]).returns(false).then.returns("match path size == 2").then.returns("")
301
- provider = provider_class.new(resource)
302
- augeas_stub = stub("augeas", :match => ["set", "of", "values"])
303
- augeas_stub.stubs("close")
304
- provider.aug= augeas_stub
305
- provider.stubs(:get_augeas_version).returns("0.3.5")
306
- provider.need_to_run?.should == false
291
+ @resource[:onlyif] = "match path size == 2"
292
+ @augeas.stubs("match").returns(["set", "of", "values"])
293
+ @provider.need_to_run?.should == false
307
294
  end
308
295
 
309
- #This is a copy of the last one, with setting the force to true
296
+ # Now setting force to true
310
297
  it "setting force should not change the above logic" do
311
- resource = stub("resource")
312
- resource.stubs(:[]).returns(true).then.returns("match path size == 2").then.returns("")
313
- provider = provider_class.new(resource)
314
- augeas_stub = stub("augeas", :match => ["set", "of", "values"])
315
- augeas_stub.stubs("close")
316
- provider.aug= augeas_stub
317
- provider.stubs(:get_augeas_version).returns("0.3.5")
318
- provider.need_to_run?.should == false
298
+ @resource[:force] = true
299
+ @resource[:onlyif] = "match path size == 2"
300
+ @augeas.stubs("match").returns(["set", "of", "values"])
301
+ @provider.need_to_run?.should == false
319
302
  end
320
303
 
321
304
  #Ticket 5211 testing
322
305
  it "should return true when a size != the provided value" do
323
- resource = stub("resource")
324
- resource.stubs(:[]).returns(false).then.returns("match path size != 17").then.returns("")
325
- resource.stubs(:noop?).returns(false)
326
- provider = provider_class.new(resource)
327
- augeas_stub = stub("augeas", :match => ["set", "of", "values"])
328
- augeas_stub.stubs("close")
329
- provider.aug= augeas_stub
330
- provider.stubs(:get_augeas_version).returns("0.3.5")
331
- provider.need_to_run?.should == true
306
+ @resource[:onlyif] = "match path size != 17"
307
+ @augeas.stubs("match").returns(["set", "of", "values"])
308
+ @provider.need_to_run?.should == true
332
309
  end
333
310
 
334
311
  #Ticket 5211 testing
335
312
  it "should return false when a size doeas equal the provided value" do
336
- resource = stub("resource")
337
- resource.stubs(:[]).returns(false).then.returns("match path size != 3").then.returns("")
338
- provider = provider_class.new(resource)
339
- augeas_stub = stub("augeas", :match => ["set", "of", "values"])
340
- augeas_stub.stubs("close")
341
- provider.aug= augeas_stub
342
- provider.stubs(:get_augeas_version).returns("0.3.5")
343
- provider.need_to_run?.should == false
313
+ @resource[:onlyif] = "match path size != 3"
314
+ @augeas.stubs("match").returns(["set", "of", "values"])
315
+ @provider.need_to_run?.should == false
344
316
  end
345
317
 
346
318
  # Ticket 2728 (diff files)
347
- describe "and Puppet[:show_diff] is set", :if => Puppet.features.augeas? do
348
- before do
319
+ describe "and Puppet[:show_diff] is set" do
320
+ before(:each) do
349
321
  Puppet[:show_diff] = true
350
322
 
351
- @resource = Puppet::Type.type(:augeas).new(:name => "test")
352
- @provider = provider_class.new(@resource)
353
- @augeas_stub = stub("augeas")
354
- @provider.aug = @augeas_stub
355
-
356
- @augeas_stub.stubs("get").with("/augeas/version").returns("0.10.0")
357
- @augeas_stub.stubs(:set).returns(true)
358
- @augeas_stub.stubs(:save).returns(true)
323
+ @resource[:root] = ""
324
+ @provider.stubs(:get_augeas_version).returns("0.10.0")
325
+ @augeas.stubs(:set).returns(true)
326
+ @augeas.stubs(:save).returns(true)
359
327
  end
360
328
 
361
329
  it "should call diff when a file is shown to have been changed" do
362
330
  file = "/etc/hosts"
331
+ File.stubs(:delete)
363
332
 
364
333
  @resource[:context] = "/files"
365
334
  @resource[:changes] = ["set #{file}/foo bar"]
366
335
 
367
- @augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
368
- @augeas_stub.stubs(:get).with("/augeas/events/saved").returns(["/files#{file}"])
369
- @augeas_stub.expects(:set).with("/augeas/save", "newfile")
370
- @augeas_stub.expects(:close).never()
336
+ @augeas.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
337
+ @augeas.stubs(:get).with("/augeas/events/saved").returns("/files#{file}")
338
+ @augeas.expects(:set).with("/augeas/save", "newfile")
339
+ @augeas.expects(:close).never()
371
340
 
372
341
  @provider.expects("diff").with("#{file}", "#{file}.augnew").returns("")
373
342
  @provider.should be_need_to_run
@@ -376,15 +345,16 @@ describe provider_class do
376
345
  it "should call diff for each file thats changed" do
377
346
  file1 = "/etc/hosts"
378
347
  file2 = "/etc/resolv.conf"
348
+ File.stubs(:delete)
379
349
 
380
350
  @resource[:context] = "/files"
381
351
  @resource[:changes] = ["set #{file1}/foo bar", "set #{file2}/baz biz"]
382
352
 
383
- @augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved[1]", "/augeas/events/saved[2]"])
384
- @augeas_stub.stubs(:get).with("/augeas/events/saved[1]").returns(["/files#{file1}"])
385
- @augeas_stub.stubs(:get).with("/augeas/events/saved[2]").returns(["/files#{file2}"])
386
- @augeas_stub.expects(:set).with("/augeas/save", "newfile")
387
- @augeas_stub.expects(:close).never()
353
+ @augeas.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved[1]", "/augeas/events/saved[2]"])
354
+ @augeas.stubs(:get).with("/augeas/events/saved[1]").returns("/files#{file1}")
355
+ @augeas.stubs(:get).with("/augeas/events/saved[2]").returns("/files#{file2}")
356
+ @augeas.expects(:set).with("/augeas/save", "newfile")
357
+ @augeas.expects(:close).never()
388
358
 
389
359
  @provider.expects(:diff).with("#{file1}", "#{file1}.augnew").returns("")
390
360
  @provider.expects(:diff).with("#{file2}", "#{file2}.augnew").returns("")
@@ -395,15 +365,16 @@ describe provider_class do
395
365
  it "should call diff when a file is shown to have been changed" do
396
366
  root = "/tmp/foo"
397
367
  file = "/etc/hosts"
368
+ File.stubs(:delete)
398
369
 
399
370
  @resource[:context] = "/files"
400
371
  @resource[:changes] = ["set #{file}/foo bar"]
401
372
  @resource[:root] = root
402
373
 
403
- @augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
404
- @augeas_stub.stubs(:get).with("/augeas/events/saved").returns(["/files#{file}"])
405
- @augeas_stub.expects(:set).with("/augeas/save", "newfile")
406
- @augeas_stub.expects(:close).never()
374
+ @augeas.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
375
+ @augeas.stubs(:get).with("/augeas/events/saved").returns("/files#{file}")
376
+ @augeas.expects(:set).with("/augeas/save", "newfile")
377
+ @augeas.expects(:close).never()
407
378
 
408
379
  @provider.expects(:diff).with("#{root}#{file}", "#{root}#{file}.augnew").returns("")
409
380
  @provider.should be_need_to_run
@@ -416,26 +387,25 @@ describe provider_class do
416
387
  @resource[:context] = "/files"
417
388
  @resource[:changes] = ["set #{file}/foo bar"]
418
389
 
419
- @augeas_stub.stubs(:match).with("/augeas/events/saved").returns([])
420
- @augeas_stub.expects(:set).with("/augeas/save", "newfile")
421
- @augeas_stub.expects(:get).with("/augeas/events/saved").never()
422
- @augeas_stub.expects(:close)
390
+ @augeas.stubs(:match).with("/augeas/events/saved").returns([])
391
+ @augeas.expects(:set).with("/augeas/save", "newfile")
392
+ @augeas.expects(:get).with("/augeas/events/saved").never()
393
+ @augeas.expects(:close)
423
394
 
424
395
  @provider.expects(:diff).never()
425
396
  @provider.should_not be_need_to_run
426
397
  end
427
398
 
428
- it "should cleanup when in noop mode" do
399
+ it "should cleanup the .augnew file" do
429
400
  file = "/etc/hosts"
430
401
 
431
- @resource[:noop] = true
432
402
  @resource[:context] = "/files"
433
403
  @resource[:changes] = ["set #{file}/foo bar"]
434
404
 
435
- @augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
436
- @augeas_stub.stubs(:get).with("/augeas/events/saved").returns(["/files#{file}"])
437
- @augeas_stub.expects(:set).with("/augeas/save", "newfile")
438
- @augeas_stub.expects(:close)
405
+ @augeas.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
406
+ @augeas.stubs(:get).with("/augeas/events/saved").returns("/files#{file}")
407
+ @augeas.expects(:set).with("/augeas/save", "newfile")
408
+ @augeas.expects(:close)
439
409
 
440
410
  File.expects(:delete).with(file + ".augnew")
441
411
 
@@ -449,9 +419,9 @@ describe provider_class do
449
419
  @resource[:context] = "/files"
450
420
  @resource[:changes] = ["set #{file}/foo bar"]
451
421
 
452
- @augeas_stub.stubs(:save).returns(false)
453
- @augeas_stub.stubs(:match).with("/augeas/events/saved").returns([])
454
- @augeas_stub.expects(:close)
422
+ @augeas.stubs(:save).returns(false)
423
+ @augeas.stubs(:match).with("/augeas/events/saved").returns([])
424
+ @augeas.expects(:close)
455
425
 
456
426
  @provider.expects(:diff).never()
457
427
  lambda { @provider.need_to_run? }.should raise_error
@@ -460,20 +430,18 @@ describe provider_class do
460
430
  end
461
431
 
462
432
  describe "augeas execution integration" do
463
-
464
433
  before do
465
- @resource = stub("resource")
466
- @provider = provider_class.new(@resource)
467
- @augeas = stub("augeas")
468
- @provider.aug= @augeas
469
- @provider.stubs(:get_augeas_version).returns("0.3.5")
434
+ @augeas = stub("augeas", :load)
435
+ @augeas.stubs("close")
470
436
  @augeas.stubs(:match).with("/augeas/events/saved").returns([])
437
+
438
+ @provider.aug = @augeas
439
+ @provider.stubs(:get_augeas_version).returns("0.3.5")
471
440
  end
472
441
 
473
442
  it "should handle set commands" do
474
- command = "set JarJar Binks"
475
- context = "/some/path/"
476
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
443
+ @resource[:changes] = "set JarJar Binks"
444
+ @resource[:context] = "/some/path/"
477
445
  @augeas.expects(:set).with("/some/path/JarJar", "Binks").returns(true)
478
446
  @augeas.expects(:save).returns(true)
479
447
  @augeas.expects(:close)
@@ -481,9 +449,7 @@ describe provider_class do
481
449
  end
482
450
 
483
451
  it "should handle rm commands" do
484
- command = "rm /Jar/Jar"
485
- context = ""
486
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
452
+ @resource[:changes] = "rm /Jar/Jar"
487
453
  @augeas.expects(:rm).with("/Jar/Jar")
488
454
  @augeas.expects(:save).returns(true)
489
455
  @augeas.expects(:close)
@@ -491,9 +457,7 @@ describe provider_class do
491
457
  end
492
458
 
493
459
  it "should handle remove commands" do
494
- command = "remove /Jar/Jar"
495
- context = ""
496
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
460
+ @resource[:changes] = "remove /Jar/Jar"
497
461
  @augeas.expects(:rm).with("/Jar/Jar")
498
462
  @augeas.expects(:save).returns(true)
499
463
  @augeas.expects(:close)
@@ -501,20 +465,17 @@ describe provider_class do
501
465
  end
502
466
 
503
467
  it "should handle clear commands" do
504
- command = "clear Jar/Jar"
505
- context = "/foo/"
506
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
468
+ @resource[:changes] = "clear Jar/Jar"
469
+ @resource[:context] = "/foo/"
507
470
  @augeas.expects(:clear).with("/foo/Jar/Jar").returns(true)
508
471
  @augeas.expects(:save).returns(true)
509
472
  @augeas.expects(:close)
510
473
  @provider.execute_changes.should == :executed
511
474
  end
512
475
 
513
-
514
476
  it "should handle ins commands with before" do
515
- command = "ins Binks before Jar/Jar"
516
- context = "/foo"
517
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
477
+ @resource[:changes] = "ins Binks before Jar/Jar"
478
+ @resource[:context] = "/foo"
518
479
  @augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", true)
519
480
  @augeas.expects(:save).returns(true)
520
481
  @augeas.expects(:close)
@@ -522,9 +483,8 @@ describe provider_class do
522
483
  end
523
484
 
524
485
  it "should handle ins commands with after" do
525
- command = "ins Binks after /Jar/Jar"
526
- context = "/foo"
527
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
486
+ @resource[:changes] = "ins Binks after /Jar/Jar"
487
+ @resource[:context] = "/foo"
528
488
  @augeas.expects(:insert).with("/Jar/Jar", "Binks", false)
529
489
  @augeas.expects(:save).returns(true)
530
490
  @augeas.expects(:close)
@@ -532,9 +492,7 @@ describe provider_class do
532
492
  end
533
493
 
534
494
  it "should handle ins with no context" do
535
- command = "ins Binks after /Jar/Jar"
536
- context = "" # this is the default
537
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
495
+ @resource[:changes] = "ins Binks after /Jar/Jar"
538
496
  @augeas.expects(:insert).with("/Jar/Jar", "Binks", false)
539
497
  @augeas.expects(:save).returns(true)
540
498
  @augeas.expects(:close)
@@ -542,9 +500,8 @@ describe provider_class do
542
500
  end
543
501
 
544
502
  it "should handle multiple commands" do
545
- command = ["ins Binks after /Jar/Jar", "clear Jar/Jar"]
546
- context = "/foo/"
547
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
503
+ @resource[:changes] = ["ins Binks after /Jar/Jar", "clear Jar/Jar"]
504
+ @resource[:context] = "/foo/"
548
505
  @augeas.expects(:insert).with("/Jar/Jar", "Binks", false)
549
506
  @augeas.expects(:clear).with("/foo/Jar/Jar").returns(true)
550
507
  @augeas.expects(:save).returns(true)
@@ -553,9 +510,8 @@ describe provider_class do
553
510
  end
554
511
 
555
512
  it "should handle defvar commands" do
556
- command = "defvar myjar Jar/Jar"
557
- context = "/foo/"
558
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
513
+ @resource[:changes] = "defvar myjar Jar/Jar"
514
+ @resource[:context] = "/foo/"
559
515
  @augeas.expects(:defvar).with("myjar", "/foo/Jar/Jar").returns(true)
560
516
  @augeas.expects(:save).returns(true)
561
517
  @augeas.expects(:close)
@@ -563,9 +519,8 @@ describe provider_class do
563
519
  end
564
520
 
565
521
  it "should pass through augeas variables without context" do
566
- command = ["defvar myjar Jar/Jar","set $myjar/Binks 1"]
567
- context = "/foo/"
568
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
522
+ @resource[:changes] = ["defvar myjar Jar/Jar","set $myjar/Binks 1"]
523
+ @resource[:context] = "/foo/"
569
524
  @augeas.expects(:defvar).with("myjar", "/foo/Jar/Jar").returns(true)
570
525
  # this is the important bit, shouldn't be /foo/$myjar/Binks
571
526
  @augeas.expects(:set).with("$myjar/Binks", "1").returns(true)
@@ -575,9 +530,8 @@ describe provider_class do
575
530
  end
576
531
 
577
532
  it "should handle defnode commands" do
578
- command = "defnode newjar Jar/Jar[last()+1] Binks"
579
- context = "/foo/"
580
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
533
+ @resource[:changes] = "defnode newjar Jar/Jar[last()+1] Binks"
534
+ @resource[:context] = "/foo/"
581
535
  @augeas.expects(:defnode).with("newjar", "/foo/Jar/Jar[last()+1]", "Binks").returns(true)
582
536
  @augeas.expects(:save).returns(true)
583
537
  @augeas.expects(:close)
@@ -585,9 +539,8 @@ describe provider_class do
585
539
  end
586
540
 
587
541
  it "should handle mv commands" do
588
- command = "mv Jar/Jar Binks"
589
- context = "/foo/"
590
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
542
+ @resource[:changes] = "mv Jar/Jar Binks"
543
+ @resource[:context] = "/foo/"
591
544
  @augeas.expects(:mv).with("/foo/Jar/Jar", "/foo/Binks").returns(true)
592
545
  @augeas.expects(:save).returns(true)
593
546
  @augeas.expects(:close)
@@ -595,9 +548,8 @@ describe provider_class do
595
548
  end
596
549
 
597
550
  it "should handle setm commands" do
598
- command = ["set test[1]/Jar/Jar Foo","set test[2]/Jar/Jar Bar","setm test Jar/Jar Binks"]
599
- context = "/foo/"
600
- @resource.expects(:[]).times(2).returns(command).then.returns(context)
551
+ @resource[:changes] = ["set test[1]/Jar/Jar Foo","set test[2]/Jar/Jar Bar","setm test Jar/Jar Binks"]
552
+ @resource[:context] = "/foo/"
601
553
  @augeas.expects(:set).with("/foo/test[1]/Jar/Jar", "Foo").returns(true)
602
554
  @augeas.expects(:set).with("/foo/test[2]/Jar/Jar", "Bar").returns(true)
603
555
  @augeas.expects(:setm).with("/foo/test", "Jar/Jar", "Binks").returns(true)
@@ -606,4 +558,33 @@ describe provider_class do
606
558
  @provider.execute_changes.should == :executed
607
559
  end
608
560
  end
561
+
562
+ describe "when making changes", :if => Puppet.features.augeas? do
563
+ include PuppetSpec::Files
564
+
565
+ it "should not clobber the file if it's a symlink" do
566
+ Puppet::Util::Storage.stubs(:store)
567
+
568
+ link = tmpfile('link')
569
+ target = tmpfile('target')
570
+ FileUtils.touch(target)
571
+ FileUtils.symlink(target, link)
572
+
573
+ resource = Puppet::Type.type(:augeas).new(
574
+ :name => 'test',
575
+ :incl => link,
576
+ :lens => 'Sshd.lns',
577
+ :changes => "set PermitRootLogin no"
578
+ )
579
+
580
+ catalog = Puppet::Resource::Catalog.new
581
+ catalog.add_resource resource
582
+
583
+ catalog.apply
584
+
585
+ File.ftype(link).should == 'link'
586
+ File.readlink(link).should == target
587
+ File.read(target).should =~ /PermitRootLogin no/
588
+ end
589
+ end
609
590
  end