puppet 2.7.13 → 2.7.14

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 (215) hide show
  1. data/CHANGELOG +144 -1
  2. data/conf/osx/preflight +1 -1
  3. data/conf/redhat/puppet.spec +9 -5
  4. data/conf/suse/puppet.spec +4 -1
  5. data/conf/windows/eventlog/Rakefile +32 -0
  6. data/conf/windows/eventlog/puppetres.dll +0 -0
  7. data/conf/windows/eventlog/puppetres.mc +18 -0
  8. data/ext/rack/files/apache2.conf +3 -0
  9. data/install.rb +23 -1
  10. data/lib/puppet.rb +1 -1
  11. data/lib/puppet/agent.rb +1 -14
  12. data/lib/puppet/application/kick.rb +1 -1
  13. data/lib/puppet/application/module.rb +11 -0
  14. data/lib/puppet/daemon.rb +74 -3
  15. data/lib/puppet/defaults.rb +1 -1
  16. data/lib/puppet/face/certificate.rb +1 -1
  17. data/lib/puppet/face/help/man.erb +1 -1
  18. data/lib/puppet/face/module.rb +17 -0
  19. data/lib/puppet/face/module/build.rb +10 -4
  20. data/lib/puppet/face/module/changes.rb +5 -5
  21. data/lib/puppet/face/module/generate.rb +6 -4
  22. data/lib/puppet/face/module/install.rb +122 -32
  23. data/lib/puppet/face/module/list.rb +234 -33
  24. data/lib/puppet/face/module/search.rb +56 -23
  25. data/lib/puppet/face/module/uninstall.rb +33 -38
  26. data/lib/puppet/face/module/upgrade.rb +84 -0
  27. data/lib/puppet/feature/eventlog.rb +6 -0
  28. data/lib/puppet/forge.rb +67 -122
  29. data/lib/puppet/forge/cache.rb +1 -1
  30. data/lib/puppet/forge/repository.rb +6 -25
  31. data/lib/puppet/indirector/facts/network_device.rb +1 -1
  32. data/lib/puppet/interface/action.rb +1 -1
  33. data/lib/puppet/module.rb +79 -28
  34. data/lib/puppet/module_tool.rb +72 -34
  35. data/lib/puppet/module_tool/applications.rb +12 -14
  36. data/lib/puppet/module_tool/applications/application.rb +21 -19
  37. data/lib/puppet/module_tool/applications/builder.rb +4 -4
  38. data/lib/puppet/module_tool/applications/checksummer.rb +12 -3
  39. data/lib/puppet/module_tool/applications/generator.rb +1 -1
  40. data/lib/puppet/module_tool/applications/installer.rb +163 -34
  41. data/lib/puppet/module_tool/applications/searcher.rb +2 -3
  42. data/lib/puppet/module_tool/applications/uninstaller.rb +84 -36
  43. data/lib/puppet/module_tool/applications/unpacker.rb +4 -26
  44. data/lib/puppet/module_tool/applications/upgrader.rb +109 -0
  45. data/lib/puppet/module_tool/checksums.rb +2 -2
  46. data/lib/puppet/module_tool/contents_description.rb +1 -1
  47. data/lib/puppet/module_tool/dependency.rb +2 -2
  48. data/lib/puppet/module_tool/errors.rb +9 -0
  49. data/lib/puppet/module_tool/errors/base.rb +15 -0
  50. data/lib/puppet/module_tool/errors/installer.rb +90 -0
  51. data/lib/puppet/module_tool/errors/shared.rb +115 -0
  52. data/lib/puppet/module_tool/errors/uninstaller.rb +45 -0
  53. data/lib/puppet/module_tool/errors/upgrader.rb +72 -0
  54. data/lib/puppet/module_tool/metadata.rb +2 -2
  55. data/lib/puppet/module_tool/modulefile.rb +7 -7
  56. data/lib/puppet/module_tool/shared_behaviors.rb +161 -0
  57. data/lib/puppet/module_tool/skeleton.rb +1 -1
  58. data/lib/puppet/node/environment.rb +4 -2
  59. data/lib/puppet/parser/ast/leaf.rb +1 -1
  60. data/lib/puppet/parser/functions/create_resources.rb +3 -2
  61. data/lib/puppet/parser/scope.rb +44 -9
  62. data/lib/puppet/provider/augeas/augeas.rb +2 -2
  63. data/lib/puppet/provider/exec.rb +8 -3
  64. data/lib/puppet/provider/exec/shell.rb +1 -2
  65. data/lib/puppet/provider/nameservice/directoryservice.rb +10 -4
  66. data/lib/puppet/provider/package/gem.rb +1 -1
  67. data/lib/puppet/provider/package/pkg.rb +10 -21
  68. data/lib/puppet/provider/selmodule/semodule.rb +1 -2
  69. data/lib/puppet/provider/service/upstart.rb +33 -17
  70. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +1 -1
  71. data/lib/puppet/rails/inventory_node.rb +7 -7
  72. data/lib/puppet/reports/http.rb +4 -1
  73. data/lib/puppet/reports/tagmail.rb +8 -1
  74. data/lib/puppet/resource/type.rb +1 -1
  75. data/lib/puppet/test/test_helper.rb +138 -0
  76. data/lib/puppet/type.rb +9 -1
  77. data/lib/puppet/type/file.rb +18 -10
  78. data/lib/puppet/type/package.rb +13 -9
  79. data/lib/puppet/type/resources.rb +1 -1
  80. data/lib/puppet/type/ssh_authorized_key.rb +3 -4
  81. data/lib/puppet/type/sshkey.rb +4 -4
  82. data/lib/puppet/type/user.rb +1 -0
  83. data/lib/puppet/type/vlan.rb +1 -1
  84. data/lib/puppet/util.rb +31 -14
  85. data/lib/puppet/util/autoload.rb +1 -1
  86. data/lib/puppet/util/command_line.rb +2 -6
  87. data/lib/puppet/util/instrumentation/indirection_probe.rb +1 -1
  88. data/lib/puppet/util/instrumentation/instrumentable.rb +1 -1
  89. data/lib/puppet/util/instrumentation/listeners/log.rb +1 -1
  90. data/lib/puppet/util/instrumentation/listeners/performance.rb +1 -1
  91. data/lib/puppet/util/log.rb +3 -1
  92. data/lib/puppet/util/log/destinations.rb +38 -0
  93. data/lib/puppet/util/monkey_patches.rb +45 -0
  94. data/lib/puppet/util/network_device/base.rb +1 -1
  95. data/lib/puppet/util/network_device/cisco.rb +1 -1
  96. data/lib/puppet/util/network_device/cisco/facts.rb +1 -1
  97. data/lib/puppet/util/network_device/cisco/interface.rb +1 -1
  98. data/lib/puppet/util/network_device/config.rb +1 -1
  99. data/lib/puppet/util/network_device/ipcalc.rb +1 -1
  100. data/lib/puppet/util/network_device/transport.rb +1 -1
  101. data/lib/puppet/util/network_device/transport/base.rb +1 -1
  102. data/lib/puppet/util/network_device/transport/ssh.rb +1 -1
  103. data/lib/puppet/util/settings.rb +2 -11
  104. data/lib/puppet/util/settings/file_setting.rb +3 -5
  105. data/lib/puppet/util/terminal.rb +16 -0
  106. data/lib/puppet/util/zaml.rb +3 -1
  107. data/lib/semver.rb +15 -7
  108. data/spec/fixtures/releases/jamtur01-apache/metadata.json +1 -1
  109. data/spec/fixtures/unit/parser/lexer/arithmetic_expression.pp +1 -1
  110. data/spec/fixtures/unit/provider/package/pkg/dummy +1 -0
  111. data/spec/fixtures/unit/provider/package/pkg/incomplete +1 -0
  112. data/spec/fixtures/unit/provider/package/pkg/publisher +2 -0
  113. data/spec/fixtures/unit/provider/package/pkg/simple +4 -0
  114. data/spec/fixtures/unit/reports/tagmail/tagmail_email.conf +2 -0
  115. data/spec/fixtures/yaml/report0.25.x.yaml +1 -1
  116. data/spec/fixtures/yaml/report2.6.x.yaml +1 -1
  117. data/spec/integration/faces/documentation_spec.rb +1 -1
  118. data/spec/integration/network/rest_authconfig_spec.rb +1 -1
  119. data/spec/lib/puppet_spec/compiler.rb +6 -0
  120. data/spec/lib/puppet_spec/database.rb +30 -0
  121. data/spec/lib/puppet_spec/files.rb +4 -2
  122. data/spec/shared_behaviours/path_parameters.rb +2 -29
  123. data/spec/shared_contexts/platform.rb +43 -0
  124. data/spec/spec_helper.rb +36 -65
  125. data/spec/unit/agent_spec.rb +0 -32
  126. data/spec/unit/application/kick_spec.rb +2 -2
  127. data/spec/unit/daemon_spec.rb +1 -17
  128. data/spec/unit/face/module/install_spec.rb +158 -0
  129. data/spec/unit/face/module/list_spec.rb +182 -0
  130. data/spec/unit/face/module/search_spec.rb +163 -0
  131. data/spec/unit/face/module/uninstall_spec.rb +77 -0
  132. data/spec/unit/face/module/upgrade_spec.rb +26 -0
  133. data/spec/unit/forge/repository_spec.rb +0 -30
  134. data/spec/unit/forge_spec.rb +28 -86
  135. data/spec/unit/indirector/catalog/active_record_spec.rb +45 -65
  136. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +5 -18
  137. data/spec/unit/indirector/resource/active_record_spec.rb +2 -11
  138. data/spec/unit/indirector/resource/ral_spec.rb +7 -2
  139. data/spec/unit/module_spec.rb +240 -107
  140. data/spec/unit/module_tool/application_spec.rb +3 -5
  141. data/spec/unit/module_tool/applications/application_spec.rb +19 -0
  142. data/spec/unit/module_tool/applications/installer_spec.rb +205 -0
  143. data/spec/unit/module_tool/applications/uninstaller_spec.rb +206 -0
  144. data/spec/unit/module_tool/applications/upgrader_spec.rb +37 -0
  145. data/spec/unit/module_tool/metadata_spec.rb +2 -2
  146. data/spec/unit/module_tool_spec.rb +109 -1
  147. data/spec/unit/node/environment_spec.rb +16 -1
  148. data/spec/unit/parser/ast/leaf_spec.rb +16 -1
  149. data/spec/unit/parser/collector_spec.rb +2 -12
  150. data/spec/unit/parser/functions/create_resources_spec.rb +135 -86
  151. data/spec/unit/parser/functions/generate_spec.rb +2 -10
  152. data/spec/unit/parser/scope_spec.rb +345 -16
  153. data/spec/unit/provider/augeas/augeas_spec.rb +19 -0
  154. data/spec/unit/provider/exec/shell_spec.rb +17 -14
  155. data/spec/unit/provider/exec/windows_spec.rb +1 -7
  156. data/spec/unit/provider/exec_spec.rb +35 -0
  157. data/spec/unit/provider/nameservice/directoryservice_spec.rb +10 -0
  158. data/spec/unit/provider/package/dpkg_spec.rb +2 -1
  159. data/spec/unit/provider/package/gem_spec.rb +15 -0
  160. data/spec/unit/provider/package/openbsd_spec.rb +5 -4
  161. data/spec/unit/provider/package/pacman_spec.rb +3 -2
  162. data/spec/unit/provider/package/pkg_spec.rb +56 -33
  163. data/spec/unit/provider/selmodule_spec.rb +11 -4
  164. data/spec/unit/provider/service/redhat_spec.rb +1 -3
  165. data/spec/unit/provider/service/smf_spec.rb +1 -3
  166. data/spec/unit/provider/service/upstart_spec.rb +38 -0
  167. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +28 -0
  168. data/spec/unit/rails/host_spec.rb +6 -12
  169. data/spec/unit/rails/param_value_spec.rb +3 -8
  170. data/spec/unit/rails/resource_spec.rb +2 -8
  171. data/spec/unit/reports/http_spec.rb +47 -31
  172. data/spec/unit/reports/tagmail_spec.rb +77 -0
  173. data/spec/unit/resource/type_spec.rb +2 -2
  174. data/spec/unit/resource_spec.rb +18 -20
  175. data/spec/unit/semver_spec.rb +31 -13
  176. data/spec/unit/type/exec_spec.rb +8 -15
  177. data/spec/unit/type/group_spec.rb +0 -9
  178. data/spec/unit/type/package_spec.rb +10 -0
  179. data/spec/unit/type/resources_spec.rb +4 -5
  180. data/spec/unit/type/ssh_authorized_key_spec.rb +4 -15
  181. data/spec/unit/type/sshkey_spec.rb +9 -11
  182. data/spec/unit/type/user_spec.rb +123 -127
  183. data/spec/unit/type_spec.rb +20 -0
  184. data/spec/unit/util/command_line_spec.rb +2 -2
  185. data/spec/unit/util/instrumentation/data_spec.rb +1 -1
  186. data/spec/unit/util/instrumentation/indirection_probe_spec.rb +1 -1
  187. data/spec/unit/util/instrumentation/instrumentable_spec.rb +1 -1
  188. data/spec/unit/util/instrumentation/listener_spec.rb +1 -1
  189. data/spec/unit/util/instrumentation/listeners/log_spec.rb +1 -1
  190. data/spec/unit/util/instrumentation/listeners/performance_spec.rb +1 -1
  191. data/spec/unit/util/instrumentation_spec.rb +1 -1
  192. data/spec/unit/util/log/destinations_spec.rb +4 -8
  193. data/spec/unit/util/log_spec.rb +47 -0
  194. data/spec/unit/util/reference_spec.rb +1 -1
  195. data/spec/unit/util/settings/file_setting_spec.rb +9 -0
  196. data/spec/unit/util/settings_spec.rb +0 -53
  197. data/spec/unit/util/terminal_spec.rb +42 -0
  198. data/spec/unit/util/zaml_spec.rb +7 -0
  199. data/spec/unit/util_spec.rb +63 -20
  200. data/tasks/rake/manpages.rake +1 -1
  201. data/test/data/snippets/arithmetic_expression.pp +1 -1
  202. data/test/other/puppet.rb +0 -1
  203. data/test/util/log.rb +6 -6
  204. metadata +41 -16
  205. data/lib/puppet/external/event-loop.rb +0 -1
  206. data/lib/puppet/external/event-loop/better-definers.rb +0 -367
  207. data/lib/puppet/external/event-loop/event-loop.rb +0 -355
  208. data/lib/puppet/external/event-loop/signal-system.rb +0 -218
  209. data/lib/puppet/face/module/clean.rb +0 -30
  210. data/lib/puppet/module_tool/applications/cleaner.rb +0 -16
  211. data/lib/puppet/module_tool/skeleton/templates/generator/metadata.json +0 -12
  212. data/lib/puppet/module_tool/utils.rb +0 -5
  213. data/lib/puppet/module_tool/utils/interrogation.rb +0 -25
  214. data/spec/integration/module_tool_spec.rb +0 -475
  215. data/spec/unit/module_tool/uninstaller_spec.rb +0 -124
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'puppet/module_tool/applications'
3
+ require 'puppet_spec/modules'
4
+ require 'semver'
5
+
6
+ describe Puppet::ModuleTool::Applications::Upgrader, :fails_on_windows => true do
7
+ include PuppetSpec::Files
8
+
9
+ before do
10
+ end
11
+
12
+ it "should update the requested module"
13
+ it "should not update dependencies"
14
+ it "should fail when updating a dependency to an unsupported version"
15
+ it "should fail when updating a module that is not installed"
16
+ it "should warn when the latest version is already installed"
17
+ it "should warn when the best version is already installed"
18
+
19
+ context "when using the '--version' option" do
20
+ it "should update an installed module to the requested version"
21
+ end
22
+
23
+ context "when using the '--force' flag" do
24
+ it "should ignore missing dependencies"
25
+ it "should ignore version constraints"
26
+ it "should not update a module that is not installed"
27
+ end
28
+
29
+ context "when using the '--env' option" do
30
+ it "should use the correct environment"
31
+ end
32
+
33
+ context "when there are missing dependencies" do
34
+ it "should fail to upgrade the original module"
35
+ it "should raise an error"
36
+ end
37
+ end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
  require 'puppet/module_tool'
3
3
 
4
- describe Puppet::Module::Tool::Metadata do
4
+ describe Puppet::ModuleTool::Metadata do
5
5
  context "when using default values" do
6
6
  it "should set license to 'Apache License, Version 2.0'" do
7
- metadata = Puppet::Module::Tool::Metadata.new
7
+ metadata = Puppet::ModuleTool::Metadata.new
8
8
  metadata.license.should == "Apache License, Version 2.0"
9
9
  end
10
10
  end
@@ -1,5 +1,113 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
  require 'puppet/module_tool'
3
5
 
4
- describe Puppet::Module::Tool do
6
+ describe Puppet::ModuleTool, :fails_on_windows => true do
7
+ describe '.format_tree' do
8
+ it 'should return an empty tree when given an empty list' do
9
+ subject.format_tree([]).should == ''
10
+ end
11
+
12
+ it 'should return a shallow when given a list without dependencies' do
13
+ list = [ { :text => 'first' }, { :text => 'second' }, { :text => 'third' } ]
14
+ subject.format_tree(list).should == <<-TREE
15
+ ├── first
16
+ ├── second
17
+ └── third
18
+ TREE
19
+ end
20
+
21
+ it 'should return a deeply nested tree when given a list with deep dependencies' do
22
+ list = [
23
+ {
24
+ :text => 'first',
25
+ :dependencies => [
26
+ {
27
+ :text => 'second',
28
+ :dependencies => [
29
+ { :text => 'third' }
30
+ ]
31
+ }
32
+ ]
33
+ },
34
+ ]
35
+ subject.format_tree(list).should == <<-TREE
36
+ └─┬ first
37
+ └─┬ second
38
+ └── third
39
+ TREE
40
+ end
41
+
42
+ it 'should show connectors when deep dependencies are not on the last node of the top level' do
43
+ list = [
44
+ {
45
+ :text => 'first',
46
+ :dependencies => [
47
+ {
48
+ :text => 'second',
49
+ :dependencies => [
50
+ { :text => 'third' }
51
+ ]
52
+ }
53
+ ]
54
+ },
55
+ { :text => 'fourth' }
56
+ ]
57
+ subject.format_tree(list).should == <<-TREE
58
+ ├─┬ first
59
+ │ └─┬ second
60
+ │ └── third
61
+ └── fourth
62
+ TREE
63
+ end
64
+
65
+ it 'should show connectors when deep dependencies are not on the last node of any level' do
66
+ list = [
67
+ {
68
+ :text => 'first',
69
+ :dependencies => [
70
+ {
71
+ :text => 'second',
72
+ :dependencies => [
73
+ { :text => 'third' }
74
+ ]
75
+ },
76
+ { :text => 'fourth' }
77
+ ]
78
+ }
79
+ ]
80
+ subject.format_tree(list).should == <<-TREE
81
+ └─┬ first
82
+ ├─┬ second
83
+ │ └── third
84
+ └── fourth
85
+ TREE
86
+ end
87
+
88
+ it 'should show connectors in every case when deep dependencies are not on the last node' do
89
+ list = [
90
+ {
91
+ :text => 'first',
92
+ :dependencies => [
93
+ {
94
+ :text => 'second',
95
+ :dependencies => [
96
+ { :text => 'third' }
97
+ ]
98
+ },
99
+ { :text => 'fourth' }
100
+ ]
101
+ },
102
+ { :text => 'fifth' }
103
+ ]
104
+ subject.format_tree(list).should == <<-TREE
105
+ ├─┬ first
106
+ │ ├─┬ second
107
+ │ │ └── third
108
+ │ └── fourth
109
+ └── fifth
110
+ TREE
111
+ end
112
+ end
5
113
  end
@@ -207,6 +207,22 @@ describe Puppet::Node::Environment do
207
207
  @second => [Puppet::Module.new('foo', :environment => env, :path => modpath2)]
208
208
  }
209
209
  end
210
+
211
+ it "should ignore modules with invalid names" do
212
+ FileUtils.mkdir_p(File.join(@first, 'foo'))
213
+ FileUtils.mkdir_p(File.join(@first, 'foo2'))
214
+ FileUtils.mkdir_p(File.join(@first, 'foo-bar'))
215
+ FileUtils.mkdir_p(File.join(@first, 'foo_bar'))
216
+ FileUtils.mkdir_p(File.join(@first, 'foo=bar'))
217
+ FileUtils.mkdir_p(File.join(@first, 'foo bar'))
218
+ FileUtils.mkdir_p(File.join(@first, 'foo.bar'))
219
+ FileUtils.mkdir_p(File.join(@first, '-foo'))
220
+ FileUtils.mkdir_p(File.join(@first, 'foo-'))
221
+ FileUtils.mkdir_p(File.join(@first, 'foo--bar'))
222
+
223
+ env.modules_by_path[@first].collect{|mod| mod.name}.sort.should == %w{foo foo-bar foo2 foo_bar}
224
+ end
225
+
210
226
  end
211
227
 
212
228
  describe "#module_requirements" do
@@ -336,7 +352,6 @@ describe Puppet::Node::Environment do
336
352
 
337
353
  it "should create modules with the correct environment" do
338
354
  FileUtils.mkdir_p(File.join(@first, 'foo'))
339
-
340
355
  env.modules.each {|mod| mod.environment.should == env }
341
356
  end
342
357
 
@@ -263,7 +263,7 @@ end
263
263
 
264
264
  describe Puppet::Parser::AST::Regex do
265
265
  before :each do
266
- @scope = stub 'scope'
266
+ @scope = stub 'scope', :ephemeral_from => true
267
267
  end
268
268
 
269
269
  describe "when initializing" do
@@ -323,6 +323,21 @@ describe Puppet::Parser::AST::Regex do
323
323
  end
324
324
  end
325
325
 
326
+ it "should match undef to the empty string" do
327
+ regex = Puppet::Parser::AST::Regex.new(:value => "^$")
328
+ regex.evaluate_match(:undef, @scope).should be_true
329
+ end
330
+
331
+ it "should not match undef to a non-empty string" do
332
+ regex = Puppet::Parser::AST::Regex.new(:value => '\w')
333
+ regex.evaluate_match(:undef, @scope).should be_false
334
+ end
335
+
336
+ it "should match a string against a string" do
337
+ regex = Puppet::Parser::AST::Regex.new(:value => '\w')
338
+ regex.evaluate_match('foo', @scope).should be_true
339
+ end
340
+
326
341
  it "should return the regex source with to_s" do
327
342
  regex = stub 'regex'
328
343
  Regexp.stubs(:new).returns(regex)
@@ -1,11 +1,5 @@
1
1
  #!/usr/bin/env rspec
2
2
  require 'spec_helper'
3
-
4
- begin
5
- require 'sqlite3'
6
- rescue LoadError
7
- end
8
-
9
3
  require 'puppet/rails'
10
4
  require 'puppet/parser/collector'
11
5
 
@@ -267,7 +261,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
267
261
  end
268
262
  end
269
263
 
270
- describe Puppet::Parser::Collector, "when collecting exported resources", :if => (Puppet.features.rails? and defined? SQLite3) do
264
+ describe Puppet::Parser::Collector, "when collecting exported resources", :if => can_use_scratch_database? do
271
265
  include PuppetSpec::Files
272
266
 
273
267
  before do
@@ -287,14 +281,10 @@ describe Puppet::Parser::Collector, "when collecting exported resources", :if =>
287
281
 
288
282
  context "with storeconfigs enabled" do
289
283
  before :each do
290
- dir = Pathname(tmpdir('puppet-var'))
291
- Puppet[:vardir] = dir.to_s
292
- Puppet[:dbadapter] = 'sqlite3'
293
- Puppet[:dblocation] = (dir + 'storeconfigs.sqlite').to_s
284
+ setup_scratch_database
294
285
  Puppet[:storeconfigs] = true
295
286
  Puppet[:environment] = "production"
296
287
  Puppet[:storeconfigs_backend] = "active_record"
297
- Puppet::Rails.init
298
288
  end
299
289
 
300
290
  it "should return all matching resources from the current compile and mark them non-virtual and non-exported" do
@@ -1,154 +1,203 @@
1
1
  require 'puppet'
2
2
  require 'spec_helper'
3
+ require 'puppet_spec/compiler'
3
4
 
4
5
  describe 'function for dynamically creating resources' do
6
+ include PuppetSpec::Compiler
5
7
 
6
- def get_scope
7
- @topscope = Puppet::Parser::Scope.new
8
- # This is necessary so we don't try to use the compiler to discover our parent.
9
- @topscope.parent = nil
8
+ before :each do
10
9
  @scope = Puppet::Parser::Scope.new
11
10
  @scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("floppy", :environment => 'production'))
12
- @scope.parent = @topscope
11
+ @topscope = @scope.compiler.topscope
13
12
  @compiler = @scope.compiler
14
- end
15
- before :each do
16
- get_scope
13
+ @scope.parent = @topscope
17
14
  Puppet::Parser::Functions.function(:create_resources)
18
15
  end
19
16
 
20
17
  it "should exist" do
21
18
  Puppet::Parser::Functions.function(:create_resources).should == "function_create_resources"
22
19
  end
20
+
23
21
  it 'should require two or three arguments' do
24
- lambda { @scope.function_create_resources(['foo']) }.should raise_error(ArgumentError, 'create_resources(): wrong number of arguments (1; must be 2 or 3)')
25
- lambda { @scope.function_create_resources(['foo', 'bar', 'blah', 'baz']) }.should raise_error(ArgumentError, 'create_resources(): wrong number of arguments (4; must be 2 or 3)')
22
+ expect { @scope.function_create_resources(['foo']) }.should raise_error(ArgumentError, 'create_resources(): wrong number of arguments (1; must be 2 or 3)')
23
+ expect { @scope.function_create_resources(['foo', 'bar', 'blah', 'baz']) }.should raise_error(ArgumentError, 'create_resources(): wrong number of arguments (4; must be 2 or 3)')
26
24
  end
27
- describe 'when creating native types' do
28
- before :each do
29
- Puppet[:code]='notify{test:}'
30
- get_scope
31
- @scope.resource=Puppet::Parser::Resource.new('class', 't', :scope => @scope)
25
+
26
+ describe 'when the caller does not supply a name parameter' do
27
+ it 'should set a default resource name equal to the resource title' do
28
+ Puppet::Parser::Resource.any_instance.expects(:set_parameter).with(:name, 'test').once
29
+ @scope.function_create_resources(['notify', {'test'=>{}}])
30
+ end
31
+ end
32
+
33
+ describe 'when the caller supplies a name parameter' do
34
+ it 'should set the resource name to the value provided' do
35
+ Puppet::Parser::Resource.any_instance.expects(:set_parameter).with(:name, 'user_supplied').once
36
+ Puppet::Parser::Resource.any_instance.expects(:set_parameter).with(:name, 'test').never
37
+ @scope.function_create_resources(['notify', {'test'=>{'name' => 'user_supplied'}}])
32
38
  end
39
+ end
40
+
41
+ describe 'when creating native types' do
33
42
  it 'empty hash should not cause resources to be added' do
34
- @scope.function_create_resources(['file', {}])
35
- @compiler.catalog.resources.size == 1
43
+ noop_catalog = compile_to_catalog("create_resources('file', {})")
44
+ empty_catalog = compile_to_catalog("")
45
+ noop_catalog.resources.size.should == empty_catalog.resources.size
36
46
  end
47
+
37
48
  it 'should be able to add' do
38
- @scope.function_create_resources(['file', {'/etc/foo'=>{'ensure'=>'present'}}])
39
- @compiler.catalog.resource(:file, "/etc/foo")['ensure'].should == 'present'
49
+ catalog = compile_to_catalog("create_resources('file', {'/etc/foo'=>{'ensure'=>'present'}})")
50
+ catalog.resource(:file, "/etc/foo")['ensure'].should == 'present'
40
51
  end
52
+
41
53
  it 'should accept multiple types' do
42
- type_hash = {}
43
- type_hash['foo'] = {'message' => 'one'}
44
- type_hash['bar'] = {'message' => 'two'}
45
- @scope.function_create_resources(['notify', type_hash])
46
- @compiler.catalog.resource(:notify, "foo")['message'].should == 'one'
47
- @compiler.catalog.resource(:notify, "bar")['message'].should == 'two'
54
+ catalog = compile_to_catalog("create_resources('notify', {'foo'=>{'message'=>'one'}, 'bar'=>{'message'=>'two'}})")
55
+ catalog.resource(:notify, "foo")['message'].should == 'one'
56
+ catalog.resource(:notify, "bar")['message'].should == 'two'
48
57
  end
58
+
49
59
  it 'should fail to add non-existing type' do
50
- lambda { @scope.function_create_resources(['foo', {}]) }.should raise_error(ArgumentError, 'could not create resource of unknown type foo')
60
+ expect { @scope.function_create_resources(['create-resource-foo', {}]) }.should raise_error(ArgumentError, 'could not create resource of unknown type create-resource-foo')
51
61
  end
62
+
52
63
  it 'should be able to add edges' do
53
- @scope.function_create_resources(['notify', {'foo'=>{'require' => 'Notify[test]'}}])
54
- @scope.compiler.compile
55
- rg = @scope.compiler.catalog.to_ral.relationship_graph
64
+ catalog = compile_to_catalog("notify { test: }\n create_resources('notify', {'foo'=>{'require'=>'Notify[test]'}})")
65
+ rg = catalog.to_ral.relationship_graph
56
66
  test = rg.vertices.find { |v| v.title == 'test' }
57
67
  foo = rg.vertices.find { |v| v.title == 'foo' }
58
68
  test.should be
59
69
  foo.should be
60
70
  rg.path_between(test,foo).should be
61
71
  end
72
+
62
73
  it 'should account for default values' do
63
- @scope.function_create_resources(['file', {'/etc/foo'=>{'ensure'=>'present'}, '/etc/baz'=>{'group'=>'food'}}, {'group' => 'bar'}])
64
- @compiler.catalog.resource(:file, "/etc/foo")['group'].should == 'bar'
65
- @compiler.catalog.resource(:file, "/etc/baz")['group'].should == 'food'
74
+ catalog = compile_to_catalog("create_resources('file', {'/etc/foo'=>{'ensure'=>'present'}, '/etc/baz'=>{'group'=>'food'}}, {'group' => 'bar'})")
75
+ catalog.resource(:file, "/etc/foo")['group'].should == 'bar'
76
+ catalog.resource(:file, "/etc/baz")['group'].should == 'food'
66
77
  end
67
78
  end
68
79
  describe 'when dynamically creating resource types' do
69
- before :each do
70
- Puppet[:code]=
71
- 'define foo($one){notify{$name: message => $one}}
72
- notify{test:}
73
- '
74
- get_scope
75
- @scope.resource=Puppet::Parser::Resource.new('class', 't', :scope => @scope)
76
- Puppet::Parser::Functions.function(:create_resources)
77
- end
78
80
  it 'should be able to create defined resoure types' do
79
- @scope.function_create_resources(['foo', {'blah'=>{'one'=>'two'}}])
80
- # still have to compile for this to work...
81
- # I am not sure if this constraint ruins the tests
82
- @scope.compiler.compile
83
- @compiler.catalog.resource(:notify, "blah")['message'].should == 'two'
81
+ catalog = compile_to_catalog(<<-MANIFEST)
82
+ define foocreateresource($one) {
83
+ notify { $name: message => $one }
84
+ }
85
+
86
+ create_resources('foocreateresource', {'blah'=>{'one'=>'two'}})
87
+ MANIFEST
88
+ catalog.resource(:notify, "blah")['message'].should == 'two'
84
89
  end
90
+
85
91
  it 'should fail if defines are missing params' do
86
- @scope.function_create_resources(['foo', {'blah'=>{}}])
87
- lambda { @scope.compiler.compile }.should raise_error(Puppet::ParseError, 'Must pass one to Foo[blah] at line 1')
92
+ expect {
93
+ compile_to_catalog(<<-MANIFEST)
94
+ define foocreateresource($one) {
95
+ notify { $name: message => $one }
96
+ }
97
+
98
+ create_resources('foocreateresource', {'blah'=>{}})
99
+ MANIFEST
100
+ }.should raise_error(Puppet::Error, 'Must pass one to Foocreateresource[blah] at line 1 on node foonode')
88
101
  end
102
+
89
103
  it 'should be able to add multiple defines' do
90
- hash = {}
91
- hash['blah'] = {'one' => 'two'}
92
- hash['blaz'] = {'one' => 'three'}
93
- @scope.function_create_resources(['foo', hash])
94
- # still have to compile for this to work...
95
- # I am not sure if this constraint ruins the tests
96
- @scope.compiler.compile
97
- @compiler.catalog.resource(:notify, "blah")['message'].should == 'two'
98
- @compiler.catalog.resource(:notify, "blaz")['message'].should == 'three'
104
+ catalog = compile_to_catalog(<<-MANIFEST)
105
+ define foocreateresource($one) {
106
+ notify { $name: message => $one }
107
+ }
108
+
109
+ create_resources('foocreateresource', {'blah'=>{'one'=>'two'}, 'blaz'=>{'one'=>'three'}})
110
+ MANIFEST
111
+
112
+ catalog.resource(:notify, "blah")['message'].should == 'two'
113
+ catalog.resource(:notify, "blaz")['message'].should == 'three'
99
114
  end
115
+
100
116
  it 'should be able to add edges' do
101
- @scope.function_create_resources(['foo', {'blah'=>{'one'=>'two', 'require' => 'Notify[test]'}}])
102
- @scope.compiler.compile
103
- rg = @scope.compiler.catalog.to_ral.relationship_graph
117
+ catalog = compile_to_catalog(<<-MANIFEST)
118
+ define foocreateresource($one) {
119
+ notify { $name: message => $one }
120
+ }
121
+
122
+ notify { test: }
123
+
124
+ create_resources('foocreateresource', {'blah'=>{'one'=>'two', 'require' => 'Notify[test]'}})
125
+ MANIFEST
126
+
127
+ rg = catalog.to_ral.relationship_graph
104
128
  test = rg.vertices.find { |v| v.title == 'test' }
105
129
  blah = rg.vertices.find { |v| v.title == 'blah' }
106
130
  test.should be
107
131
  blah.should be
108
- # (Yoda speak like we do)
109
132
  rg.path_between(test,blah).should be
110
- @compiler.catalog.resource(:notify, "blah")['message'].should == 'two'
133
+ catalog.resource(:notify, "blah")['message'].should == 'two'
111
134
  end
135
+
112
136
  it 'should account for default values' do
113
- @scope.function_create_resources(['foo', {'blah'=>{}}, {'one' => 'two'}])
114
- @scope.compiler.compile
115
- @compiler.catalog.resource(:notify, "blah")['message'].should == 'two'
137
+ catalog = compile_to_catalog(<<-MANIFEST)
138
+ define foocreateresource($one) {
139
+ notify { $name: message => $one }
140
+ }
141
+
142
+ create_resources('foocreateresource', {'blah'=>{}}, {'one' => 'two'})
143
+ MANIFEST
144
+
145
+ catalog.resource(:notify, "blah")['message'].should == 'two'
116
146
  end
117
147
  end
148
+
118
149
  describe 'when creating classes' do
119
- before :each do
120
- Puppet[:code]=
121
- 'class bar($one){notify{test: message => $one}}
122
- notify{tester:}
123
- '
124
- get_scope
125
- @scope.resource=Puppet::Parser::Resource.new('class', 't', :scope => @scope)
126
- Puppet::Parser::Functions.function(:create_resources)
127
- end
128
150
  it 'should be able to create classes' do
129
- @scope.function_create_resources(['class', {'bar'=>{'one'=>'two'}}])
130
- @scope.compiler.compile
131
- @compiler.catalog.resource(:notify, "test")['message'].should == 'two'
132
- @compiler.catalog.resource(:class, "bar").should_not be_nil#['message'].should == 'two'
151
+ catalog = compile_to_catalog(<<-MANIFEST)
152
+ class bar($one) {
153
+ notify { test: message => $one }
154
+ }
155
+
156
+ create_resources('class', {'bar'=>{'one'=>'two'}})
157
+ MANIFEST
158
+
159
+ catalog.resource(:notify, "test")['message'].should == 'two'
160
+ catalog.resource(:class, "bar").should_not be_nil
133
161
  end
162
+
134
163
  it 'should fail to create non-existing classes' do
135
- lambda { @scope.function_create_resources(['class', {'blah'=>{'one'=>'two'}}]) }.should raise_error(ArgumentError ,'could not find hostclass blah')
164
+ expect {
165
+ compile_to_catalog(<<-MANIFEST)
166
+ create_resources('class', {'blah'=>{'one'=>'two'}})
167
+ MANIFEST
168
+ }.should raise_error(Puppet::Error ,'could not find hostclass blah at line 1 on node foonode')
136
169
  end
170
+
137
171
  it 'should be able to add edges' do
138
- @scope.function_create_resources(['class', {'bar'=>{'one'=>'two', 'require' => 'Notify[tester]'}}])
139
- @scope.compiler.compile
140
- rg = @scope.compiler.catalog.to_ral.relationship_graph
172
+ catalog = compile_to_catalog(<<-MANIFEST)
173
+ class bar($one) {
174
+ notify { test: message => $one }
175
+ }
176
+
177
+ notify { tester: }
178
+
179
+ create_resources('class', {'bar'=>{'one'=>'two', 'require' => 'Notify[tester]'}})
180
+ MANIFEST
181
+
182
+ rg = catalog.to_ral.relationship_graph
141
183
  test = rg.vertices.find { |v| v.title == 'test' }
142
184
  tester = rg.vertices.find { |v| v.title == 'tester' }
143
185
  test.should be
144
186
  tester.should be
145
187
  rg.path_between(tester,test).should be
146
188
  end
189
+
147
190
  it 'should account for default values' do
148
- @scope.function_create_resources(['class', {'bar'=>{}}, {'one' => 'two'}])
149
- @scope.compiler.compile
150
- @compiler.catalog.resource(:notify, "test")['message'].should == 'two'
151
- @compiler.catalog.resource(:class, "bar").should_not be_nil#['message'].should == 'two'
191
+ catalog = compile_to_catalog(<<-MANIFEST)
192
+ class bar($one) {
193
+ notify { test: message => $one }
194
+ }
195
+
196
+ create_resources('class', {'bar'=>{}}, {'one' => 'two'})
197
+ MANIFEST
198
+
199
+ catalog.resource(:notify, "test")['message'].should == 'two'
200
+ catalog.resource(:class, "bar").should_not be_nil
152
201
  end
153
202
  end
154
203
  end