puppet 2.6.1 → 2.6.2

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 (79) hide show
  1. data/CHANGELOG +51 -195
  2. data/LICENSE +2 -2
  3. data/conf/suse/puppet.spec +13 -10
  4. data/install.rb +7 -13
  5. data/lib/puppet.rb +1 -1
  6. data/lib/puppet/application.rb +17 -21
  7. data/lib/puppet/defaults.rb +1 -1
  8. data/lib/puppet/dsl.rb +0 -4
  9. data/lib/puppet/dsl/resource_type_api.rb +16 -10
  10. data/lib/puppet/external/event-loop/event-loop.rb +15 -11
  11. data/lib/puppet/feature/base.rb +2 -1
  12. data/lib/puppet/feature/rails.rb +1 -3
  13. data/lib/puppet/network/http/webrick/rest.rb +1 -0
  14. data/lib/puppet/network/http_pool.rb +0 -12
  15. data/lib/puppet/parser/ast/function.rb +1 -1
  16. data/lib/puppet/parser/ast/resource.rb +1 -5
  17. data/lib/puppet/parser/functions/extlookup.rb +1 -1
  18. data/lib/puppet/parser/functions/versioncmp.rb +3 -3
  19. data/lib/puppet/parser/lexer.rb +1 -1
  20. data/lib/puppet/parser/parser_support.rb +4 -2
  21. data/lib/puppet/parser/resource.rb +8 -0
  22. data/lib/puppet/parser/type_loader.rb +50 -48
  23. data/lib/puppet/provider/nameservice.rb +1 -0
  24. data/lib/puppet/provider/nameservice/objectadd.rb +2 -1
  25. data/lib/puppet/provider/service/freebsd.rb +1 -1
  26. data/lib/puppet/provider/service/launchd.rb +16 -9
  27. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +7 -0
  28. data/lib/puppet/provider/user/hpux.rb +0 -1
  29. data/lib/puppet/provider/user/user_role_add.rb +21 -9
  30. data/lib/puppet/provider/user/useradd.rb +44 -3
  31. data/lib/puppet/rails.rb +3 -3
  32. data/lib/puppet/reference/configuration.rb +7 -12
  33. data/lib/puppet/reference/indirection.rb +2 -2
  34. data/lib/puppet/reference/metaparameter.rb +10 -9
  35. data/lib/puppet/reference/type.rb +6 -6
  36. data/lib/puppet/reports/rrdgraph.rb +1 -1
  37. data/lib/puppet/reports/tagmail.rb +1 -1
  38. data/lib/puppet/ssl/certificate_request.rb +1 -1
  39. data/lib/puppet/sslcertificates/ca.rb +4 -10
  40. data/lib/puppet/type.rb +3 -3
  41. data/lib/puppet/type/cron.rb +1 -1
  42. data/lib/puppet/type/tidy.rb +1 -0
  43. data/lib/puppet/type/user.rb +55 -0
  44. data/lib/puppet/type/whit.rb +4 -0
  45. data/lib/puppet/util.rb +8 -0
  46. data/lib/puppet/util/metric.rb +38 -9
  47. data/lib/puppet/util/rdoc/parser.rb +10 -7
  48. data/lib/puppet/util/reference.rb +4 -4
  49. data/lib/puppet/util/zaml.rb +0 -1
  50. data/spec/fixtures/yaml/report0.25.x.yaml +64 -0
  51. data/spec/fixtures/yaml/report2.6.x.yaml +190 -0
  52. data/spec/integration/application/doc_spec.rb +55 -0
  53. data/spec/integration/defaults_spec.rb +1 -1
  54. data/spec/integration/parser/compiler_spec.rb +21 -0
  55. data/spec/integration/parser/ruby_manifest_spec.rb +128 -0
  56. data/spec/lib/puppet_spec/files.rb +1 -0
  57. data/spec/spec_helper.rb +1 -0
  58. data/spec/unit/application_spec.rb +16 -25
  59. data/spec/unit/dsl/resource_type_api_spec.rb +32 -12
  60. data/spec/unit/indirector/node/active_record_spec.rb +0 -1
  61. data/spec/unit/parser/ast/function_spec.rb +14 -4
  62. data/spec/unit/parser/lexer_spec.rb +8 -0
  63. data/spec/unit/parser/parser_spec.rb +0 -9
  64. data/spec/unit/parser/type_loader_spec.rb +3 -16
  65. data/spec/unit/provider/service/launchd_spec.rb +8 -5
  66. data/spec/unit/provider/user/user_role_add_spec.rb +18 -1
  67. data/spec/unit/provider/user/useradd_spec.rb +19 -0
  68. data/spec/unit/rails_spec.rb +10 -4
  69. data/spec/unit/reports/rrdgraph_spec.rb +31 -0
  70. data/spec/unit/reports/tagmail_spec.rb +1 -0
  71. data/spec/unit/sslcertificates/ca_spec.rb +110 -0
  72. data/spec/unit/type/user_spec.rb +19 -1
  73. data/spec/unit/type/whit_spec.rb +11 -0
  74. data/spec/unit/type_spec.rb +7 -0
  75. data/spec/unit/util/rdoc/parser_spec.rb +18 -14
  76. data/spec/unit/util/zaml_spec.rb +2 -1
  77. metadata +11 -6
  78. data/conf/suse/ruby-env.patch +0 -17
  79. data/test/certmgr/ca.rb +0 -87
@@ -33,13 +33,16 @@ class Parser
33
33
 
34
34
  # main entry point
35
35
  def scan
36
- Puppet.info "rdoc: scanning #{@input_file_name}"
37
- if @input_file_name =~ /\.pp$/
38
- @parser = Puppet::Parser::Parser.new(Puppet[:environment])
39
- @parser.file = @input_file_name
40
- @ast = @parser.parse
36
+ env = Puppet::Node::Environment.new
37
+ unless env.known_resource_types.watching_file?(@input_file_name)
38
+ Puppet.info "rdoc: scanning #{@input_file_name}"
39
+ if @input_file_name =~ /\.pp$/
40
+ @parser = Puppet::Parser::Parser.new(env)
41
+ @parser.file = @input_file_name
42
+ @ast = @parser.parse
43
+ end
44
+ scan_top_level(@top_level)
41
45
  end
42
- scan_top_level(@top_level)
43
46
  @top_level
44
47
  end
45
48
 
@@ -205,7 +208,7 @@ class Parser
205
208
  Puppet.debug "rdoc: found resource: #{type}[#{title}]"
206
209
 
207
210
  param = []
208
- stmt.params.children.each do |p|
211
+ stmt.parameters.children.each do |p|
209
212
  res = {}
210
213
  res["name"] = p.param
211
214
  res["value"] = "#{p.value.to_s}" unless p.value.nil?
@@ -32,7 +32,7 @@ class Puppet::Util::Reference
32
32
  section = reference(name) or raise "Could not find section #{name}"
33
33
  depth = section.depth if section.depth < depth
34
34
  end
35
- text = "{:toc}\n\n"
35
+ text = "* TOC text.\n{:toc}\n\n"
36
36
  end
37
37
 
38
38
  def self.pdf(text)
@@ -72,7 +72,7 @@ class Puppet::Util::Reference
72
72
  loaded_instances(:reference).sort { |a,b| a.to_s <=> b.to_s }
73
73
  end
74
74
 
75
- HEADER_LEVELS = [nil, "=", "-", "+", "'", "~"]
75
+ HEADER_LEVELS = [nil, "#", "##", "###", "####", "#####"]
76
76
 
77
77
  attr_accessor :page, :depth, :header, :title, :dynamic
78
78
  attr_writer :doc
@@ -90,7 +90,7 @@ class Puppet::Util::Reference
90
90
  end
91
91
 
92
92
  def h(name, level)
93
- "#{name}\n#{HEADER_LEVELS[level] * name.to_s.length}\n\n"
93
+ "#{HEADER_LEVELS[level]} #{name}\n\n"
94
94
  end
95
95
 
96
96
  def initialize(name, options = {}, &block)
@@ -141,7 +141,7 @@ class Puppet::Util::Reference
141
141
  # First the header
142
142
  text = h(@title, 1)
143
143
  text += "\n\n**This page is autogenerated; any changes will get overwritten** *(last generated on #{Time.now.to_s})*\n\n"
144
- text += "{:toc}\n\n" if withcontents
144
+ text += "* TOC Text.\n{:toc}\n\n" if withcontents
145
145
 
146
146
  text += @header
147
147
 
@@ -243,7 +243,6 @@ class String
243
243
  when self =~ /\n/
244
244
  if self[-1..-1] == "\n" then z.emit('|+') else z.emit('|-') end
245
245
  z.nested { split("\n",-1).each { |line| z.nl; z.emit(line.chomp("\n")) } }
246
- z.nl
247
246
  else
248
247
  z.emit(self)
249
248
  end
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Puppet::Transaction::Report
2
+ host: mattmac.local
3
+ logs:
4
+ - !ruby/object:Puppet::Util::Log
5
+ level: !ruby/sym info
6
+ message: Applying configuration version '1285283846'
7
+ source: Puppet
8
+ tags:
9
+ - info
10
+ time: 2010-09-23 16:17:26.977750 -07:00
11
+ metrics:
12
+ time: !ruby/object:Puppet::Util::Metric
13
+ label: Time
14
+ name: time
15
+ values:
16
+ - - !ruby/sym config_retrieval
17
+ - Config retrieval
18
+ - 0.955046892166138
19
+ - - !ruby/sym schedule
20
+ - Schedule
21
+ - 0.00123691558837891
22
+ - - !ruby/sym total
23
+ - Total
24
+ - 0.956486701965332
25
+ - - !ruby/sym filebucket
26
+ - Filebucket
27
+ - 0.00020289421081543
28
+ resources: !ruby/object:Puppet::Util::Metric
29
+ label: Resources
30
+ name: resources
31
+ values:
32
+ - - !ruby/sym skipped
33
+ - Skipped
34
+ - 0
35
+ - - !ruby/sym scheduled
36
+ - Scheduled
37
+ - 7
38
+ - - !ruby/sym applied
39
+ - Applied
40
+ - 0
41
+ - - !ruby/sym restarted
42
+ - Restarted
43
+ - 0
44
+ - - !ruby/sym total
45
+ - Total
46
+ - 10
47
+ - - !ruby/sym failed_restarts
48
+ - Failed restarts
49
+ - 0
50
+ - - !ruby/sym out_of_sync
51
+ - Out of sync
52
+ - 0
53
+ - - !ruby/sym failed
54
+ - Failed
55
+ - 0
56
+ changes: !ruby/object:Puppet::Util::Metric
57
+ label: Changes
58
+ name: changes
59
+ values:
60
+ - - !ruby/sym total
61
+ - Total
62
+ - 0
63
+ records: {}
64
+ time: 2010-09-23 16:17:26.987789 -07:00
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Puppet::Transaction::Report
2
+ external_times:
3
+ !ruby/sym config_retrieval: 0.170313835144043
4
+ host: ubuntu1004desktop.localdomain
5
+ logs:
6
+ - !ruby/object:Puppet::Util::Log
7
+ level: !ruby/sym debug
8
+ message: Using cached certificate for ca
9
+ source: Puppet
10
+ tags:
11
+ - debug
12
+ time: 2010-09-23 15:44:06.244173 -07:00
13
+ version: &id001 2.6.1
14
+ - !ruby/object:Puppet::Util::Log
15
+ level: !ruby/sym debug
16
+ message: Using cached certificate for ubuntu1004desktop.localdomain
17
+ source: Puppet
18
+ tags:
19
+ - debug
20
+ time: 2010-09-23 15:44:06.244764 -07:00
21
+ version: *id001
22
+ - !ruby/object:Puppet::Util::Log
23
+ level: !ruby/sym debug
24
+ message: Using cached certificate_revocation_list for ca
25
+ source: Puppet
26
+ tags:
27
+ - debug
28
+ time: 2010-09-23 15:44:06.245677 -07:00
29
+ version: *id001
30
+ - !ruby/object:Puppet::Util::Log
31
+ level: !ruby/sym debug
32
+ message: "catalog supports formats: b64_zlib_yaml dot marshal pson raw yaml; using pson"
33
+ source: Puppet
34
+ tags:
35
+ - debug
36
+ time: 2010-09-23 15:44:06.247069 -07:00
37
+ version: *id001
38
+ - !ruby/object:Puppet::Util::Log
39
+ level: !ruby/sym info
40
+ message: Caching catalog for ubuntu1004desktop.localdomain
41
+ source: Puppet
42
+ tags:
43
+ - info
44
+ time: 2010-09-23 15:44:06.409109 -07:00
45
+ version: *id001
46
+ - !ruby/object:Puppet::Util::Log
47
+ level: !ruby/sym debug
48
+ message: Creating default schedules
49
+ source: Puppet
50
+ tags:
51
+ - debug
52
+ time: 2010-09-23 15:44:06.418755 -07:00
53
+ version: *id001
54
+ - !ruby/object:Puppet::Util::Log
55
+ level: !ruby/sym debug
56
+ message: Loaded state in 0.00 seconds
57
+ source: Puppet
58
+ tags:
59
+ - debug
60
+ time: 2010-09-23 15:44:06.427441 -07:00
61
+ version: *id001
62
+ - !ruby/object:Puppet::Util::Log
63
+ level: !ruby/sym info
64
+ message: Applying configuration version '1285281846'
65
+ source: Puppet
66
+ tags:
67
+ - info
68
+ time: 2010-09-23 15:44:06.429532 -07:00
69
+ version: *id001
70
+ metrics:
71
+ time: !ruby/object:Puppet::Util::Metric
72
+ label: Time
73
+ name: time
74
+ values:
75
+ - - config_retrieval
76
+ - Config retrieval
77
+ - 0.170313835144043
78
+ - - schedule
79
+ - Schedule
80
+ - 0.00077
81
+ - - filebucket
82
+ - Filebucket
83
+ - 0.000166
84
+ resources: !ruby/object:Puppet::Util::Metric
85
+ label: Resources
86
+ name: resources
87
+ values:
88
+ - - !ruby/sym total
89
+ - Total
90
+ - 7
91
+ events: !ruby/object:Puppet::Util::Metric
92
+ label: Events
93
+ name: events
94
+ values:
95
+ - - !ruby/sym total
96
+ - Total
97
+ - 0
98
+ changes: !ruby/object:Puppet::Util::Metric
99
+ label: Changes
100
+ name: changes
101
+ values:
102
+ - - !ruby/sym total
103
+ - Total
104
+ - 0
105
+ resource_statuses:
106
+ "Schedule[monthly]": !ruby/object:Puppet::Resource::Status
107
+ evaluation_time: 0.000121
108
+ events: []
109
+ file:
110
+ line:
111
+ resource: "Schedule[monthly]"
112
+ source_description: "/Schedule[monthly]"
113
+ tags:
114
+ - schedule
115
+ - monthly
116
+ time: 2010-09-23 15:44:06.430577 -07:00
117
+ version: 1285281846
118
+ "Filebucket[puppet]": !ruby/object:Puppet::Resource::Status
119
+ evaluation_time: 0.000166
120
+ events: []
121
+ file:
122
+ line:
123
+ resource: "Filebucket[puppet]"
124
+ source_description: "/Filebucket[puppet]"
125
+ tags:
126
+ - filebucket
127
+ - puppet
128
+ time: 2010-09-23 15:44:06.430998 -07:00
129
+ version: 1285281846
130
+ "Schedule[never]": !ruby/object:Puppet::Resource::Status
131
+ evaluation_time: 0.000119
132
+ events: []
133
+ file:
134
+ line:
135
+ resource: "Schedule[never]"
136
+ source_description: "/Schedule[never]"
137
+ tags:
138
+ - schedule
139
+ - never
140
+ time: 2010-09-23 15:44:06.433034 -07:00
141
+ version: 1285281846
142
+ "Schedule[weekly]": !ruby/object:Puppet::Resource::Status
143
+ evaluation_time: 0.000118
144
+ events: []
145
+ file:
146
+ line:
147
+ resource: "Schedule[weekly]"
148
+ source_description: "/Schedule[weekly]"
149
+ tags:
150
+ - schedule
151
+ - weekly
152
+ time: 2010-09-23 15:44:06.431443 -07:00
153
+ version: 1285281846
154
+ "Schedule[puppet]": !ruby/object:Puppet::Resource::Status
155
+ evaluation_time: 0.000129
156
+ events: []
157
+ file:
158
+ line:
159
+ resource: "Schedule[puppet]"
160
+ source_description: "/Schedule[puppet]"
161
+ tags:
162
+ - schedule
163
+ - puppet
164
+ time: 2010-09-23 15:44:06.432626 -07:00
165
+ version: 1285281846
166
+ "Schedule[daily]": !ruby/object:Puppet::Resource::Status
167
+ evaluation_time: 0.000154
168
+ events: []
169
+ file:
170
+ line:
171
+ resource: "Schedule[daily]"
172
+ source_description: "/Schedule[daily]"
173
+ tags:
174
+ - schedule
175
+ - daily
176
+ time: 2010-09-23 15:44:06.430130 -07:00
177
+ version: 1285281846
178
+ "Schedule[hourly]": !ruby/object:Puppet::Resource::Status
179
+ evaluation_time: 0.000129
180
+ events: []
181
+ file:
182
+ line:
183
+ resource: "Schedule[hourly]"
184
+ source_description: "/Schedule[hourly]"
185
+ tags:
186
+ - schedule
187
+ - hourly
188
+ time: 2010-09-23 15:44:06.432185 -07:00
189
+ version: 1285281846
190
+ time: 2010-09-23 15:44:05.894401 -07:00
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+ require 'puppet_spec/files'
5
+
6
+ describe Puppet::Application::Doc do
7
+ include PuppetSpec::Files
8
+
9
+ it "should not generate an error when module dir overlaps parent of site.pp (#4798)" do
10
+ begin
11
+ # Note: the directory structure below is more complex than it
12
+ # needs to be, but it's representative of the directory structure
13
+ # used in bug #4798.
14
+ old_dir = Dir.getwd # Note: can't use chdir with a block because it will generate bogus warnings
15
+ tmpdir = tmpfile('doc_spec')
16
+ Dir.mkdir(tmpdir)
17
+ Dir.chdir(tmpdir)
18
+ site_file = 'site.pp'
19
+ File.open(site_file, 'w') do |f|
20
+ f.puts '# A comment'
21
+ end
22
+ modules_dir = 'modules'
23
+ Dir.mkdir(modules_dir)
24
+ rt_dir = File.join(modules_dir, 'rt')
25
+ Dir.mkdir(rt_dir)
26
+ manifests_dir = File.join(rt_dir, 'manifests')
27
+ Dir.mkdir(manifests_dir)
28
+ rt_file = File.join(manifests_dir, 'rt.pp')
29
+ File.open(rt_file, 'w') do |f|
30
+ f.puts '# A class'
31
+ f.puts 'class foo { }'
32
+ f.puts '# A definition'
33
+ f.puts 'define bar { }'
34
+ end
35
+
36
+ puppet = Puppet::Application[:doc]
37
+ Puppet[:modulepath] = modules_dir
38
+ Puppet[:manifest] = site_file
39
+ puppet.options[:mode] = :rdoc
40
+ puppet.expects(:exit).with(0)
41
+ puppet.run_command
42
+
43
+ File.should be_exist('doc')
44
+ ensure
45
+ Dir.chdir(old_dir)
46
+ end
47
+ end
48
+
49
+ it "should respect the -o option" do
50
+ puppetdoc = Puppet::Application[:doc]
51
+ puppetdoc.command_line.stubs(:args).returns(['foo', '-o', 'bar'])
52
+ puppetdoc.parse_options
53
+ puppetdoc.options[:outputdir].should == 'bar'
54
+ end
55
+ end
@@ -227,7 +227,7 @@ describe "Puppet defaults" do
227
227
 
228
228
  it "should have a :caname setting that defaults to the cert name" do
229
229
  Puppet.settings[:certname] = "foo"
230
- Puppet.settings[:ca_name].should == "foo"
230
+ Puppet.settings[:ca_name].should == "Puppet CA: foo"
231
231
  end
232
232
 
233
233
  it "should have a 'prerun_command' that defaults to the empty string" do
@@ -27,6 +27,27 @@ describe Puppet::Parser::Compiler do
27
27
  @compiler.catalog.version.should == version
28
28
  end
29
29
 
30
+ it "should not create duplicate resources when a class is referenced both directly and indirectly by the node classifier (4792)" do
31
+ Puppet[:code] = <<-PP
32
+ class foo
33
+ {
34
+ notify { foo_notify: }
35
+ include bar
36
+ }
37
+ class bar
38
+ {
39
+ notify { bar_notify: }
40
+ }
41
+ PP
42
+
43
+ @node.stubs(:classes).returns(['foo', 'bar'])
44
+
45
+ catalog = Puppet::Parser::Compiler.compile(@node)
46
+
47
+ catalog.resource("Notify[foo_notify]").should_not be_nil
48
+ catalog.resource("Notify[bar_notify]").should_not be_nil
49
+ end
50
+
30
51
  describe "when resolving class references" do
31
52
  it "should favor local scope, even if there's an included class in topscope" do
32
53
  Puppet[:code] = <<-PP
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ require 'tempfile'
6
+ require 'puppet_spec/files'
7
+
8
+ describe "Pure ruby manifests" do
9
+ include PuppetSpec::Files
10
+
11
+ before do
12
+ @node = Puppet::Node.new "testnode"
13
+
14
+ @scope_resource = stub 'scope_resource', :builtin? => true, :finish => nil, :ref => 'Class[main]'
15
+ @scope = stub 'scope', :resource => @scope_resource, :source => mock("source")
16
+ @test_dir = tmpdir('ruby_manifest_test')
17
+ end
18
+
19
+ after do
20
+ Puppet.settings.clear
21
+ end
22
+
23
+ def write_file(name, contents)
24
+ path = File.join(@test_dir, name)
25
+ File.open(path, "w") { |f| f.write(contents) }
26
+ path
27
+ end
28
+
29
+ def compile(contents)
30
+ Puppet[:code] = contents
31
+ Dir.chdir(@test_dir) do
32
+ Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode"))
33
+ end
34
+ end
35
+
36
+ it "should allow classes" do
37
+ write_file('foo.rb', ["hostclass 'one' do notify('one_notify') end",
38
+ "hostclass 'two' do notify('two_notify') end"].join("\n"))
39
+ catalog = compile("import 'foo'\ninclude one")
40
+ catalog.resource("Notify[one_notify]").should_not be_nil
41
+ catalog.resource("Notify[two_notify]").should be_nil
42
+ end
43
+
44
+ it "should allow defines" do
45
+ write_file('foo.rb', 'define "bar", :arg do notify("bar_#{@name}_#{@arg}") end')
46
+ catalog = compile("import 'foo'\nbar { instance: arg => 'xyz' }")
47
+ catalog.resource("Notify[bar_instance_xyz]").should_not be_nil
48
+ catalog.resource("Bar[instance]").should_not be_nil
49
+ end
50
+
51
+ it "should allow node declarations" do
52
+ write_file('foo.rb', "node 'mynode' do notify('mynode') end")
53
+ catalog = compile("import 'foo'")
54
+ node_declaration = catalog.resource("Notify[mynode]")
55
+ node_declaration.should_not be_nil
56
+ node_declaration.title.should == 'mynode'
57
+ end
58
+
59
+ it "should allow access to the environment" do
60
+ write_file('foo.rb', ["hostclass 'bar' do",
61
+ " if environment.is_a? Puppet::Node::Environment",
62
+ " notify('success')",
63
+ " end",
64
+ "end"].join("\n"))
65
+ compile("import 'foo'\ninclude bar").resource("Notify[success]").should_not be_nil
66
+ end
67
+
68
+ it "should allow creation of resources of built-in types" do
69
+ write_file('foo.rb', "hostclass 'bar' do file 'test_file', :owner => 'root', :mode => '644' end")
70
+ catalog = compile("import 'foo'\ninclude bar")
71
+ file = catalog.resource("File[test_file]")
72
+ file.should be_a Puppet::Resource
73
+ file.type.should == 'File'
74
+ file.title.should == 'test_file'
75
+ file.exported.should_not be
76
+ file.virtual.should_not be
77
+ file[:owner].should == 'root'
78
+ file[:mode].should == '644'
79
+ file[:stage].should be_nil # TODO: is this correct behavior?
80
+ end
81
+
82
+ it "should allow calling user-defined functions" do
83
+ write_file('foo.rb', "hostclass 'bar' do user_func 'name', :arg => 'xyz' end")
84
+ catalog = compile(['define user_func($arg) { notify {"n_$arg": } }',
85
+ 'import "foo"',
86
+ 'include bar'].join("\n"))
87
+ catalog.resource("Notify[n_xyz]").should_not be_nil
88
+ catalog.resource("User_func[name]").should_not be_nil
89
+ end
90
+
91
+ it "should be properly cached for multiple compiles" do
92
+ # Note: we can't test this by calling compile() twice, because
93
+ # that sets Puppet[:code], which clears out all cached
94
+ # environments.
95
+ Puppet[:filetimeout] = 1000
96
+ write_file('foo.rb', "hostclass 'bar' do notify('success') end")
97
+ Puppet[:code] = "import 'foo'\ninclude bar"
98
+
99
+ # Compile the catalog and check it
100
+ catalog = Dir.chdir(@test_dir) do
101
+ Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode"))
102
+ end
103
+ catalog.resource("Notify[success]").should_not be_nil
104
+
105
+ # Secretly change the file to make it invalid. This change
106
+ # shouldn't be noticed because the we've set a high
107
+ # Puppet[:filetimeout].
108
+ write_file('foo.rb', "raise 'should not be executed'")
109
+
110
+ # Compile the catalog a second time and make sure it's still ok.
111
+ catalog = Dir.chdir(@test_dir) do
112
+ Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode"))
113
+ end
114
+ catalog.resource("Notify[success]").should_not be_nil
115
+ end
116
+
117
+ it "should be properly reloaded when stale" do
118
+ Puppet[:filetimeout] = -1 # force stale check to happen all the time
119
+ write_file('foo.rb', "hostclass 'bar' do notify('version1') end")
120
+ catalog = compile("import 'foo'\ninclude bar")
121
+ catalog.resource("Notify[version1]").should_not be_nil
122
+ sleep 1 # so that timestamp will change forcing file reload
123
+ write_file('foo.rb', "hostclass 'bar' do notify('version2') end")
124
+ catalog = compile("import 'foo'\ninclude bar")
125
+ catalog.resource("Notify[version1]").should be_nil
126
+ catalog.resource("Notify[version2]").should_not be_nil
127
+ end
128
+ end