puppet 2.7.9 → 2.7.11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (187) hide show
  1. data/CHANGELOG +413 -0
  2. data/README_DEVELOPER.md +28 -0
  3. data/conf/redhat/puppet.spec +10 -1
  4. data/conf/solaris/pkginfo +1 -1
  5. data/conf/suse/puppet.spec +7 -4
  6. data/ext/envpuppet.bat +13 -0
  7. data/ext/rack/files/apache2.conf +4 -0
  8. data/install.rb +4 -8
  9. data/lib/puppet.rb +1 -1
  10. data/lib/puppet/agent.rb +7 -0
  11. data/lib/puppet/agent/disabler.rb +27 -0
  12. data/lib/puppet/agent/locker.rb +0 -10
  13. data/lib/puppet/application.rb +3 -0
  14. data/lib/puppet/application/agent.rb +13 -3
  15. data/lib/puppet/application/apply.rb +6 -6
  16. data/lib/puppet/application/cert.rb +5 -5
  17. data/lib/puppet/application/instrumentation_data.rb +4 -0
  18. data/lib/puppet/application/instrumentation_listener.rb +4 -0
  19. data/lib/puppet/application/instrumentation_probe.rb +4 -0
  20. data/lib/puppet/configurer.rb +3 -1
  21. data/lib/puppet/configurer/downloader.rb +4 -2
  22. data/lib/puppet/configurer/fact_handler.rb +0 -21
  23. data/lib/puppet/daemon.rb +3 -4
  24. data/lib/puppet/defaults.rb +2 -2
  25. data/lib/puppet/face/instrumentation_data.rb +28 -0
  26. data/lib/puppet/face/instrumentation_listener.rb +96 -0
  27. data/lib/puppet/face/instrumentation_probe.rb +77 -0
  28. data/lib/puppet/face/module/list.rb +64 -0
  29. data/lib/puppet/face/module/uninstall.rb +50 -0
  30. data/lib/puppet/face/node/clean.rb +1 -4
  31. data/lib/puppet/feature/base.rb +1 -0
  32. data/lib/puppet/file_serving/content.rb +1 -1
  33. data/lib/puppet/indirector/facts/facter.rb +20 -7
  34. data/lib/puppet/indirector/facts/inventory_active_record.rb +14 -11
  35. data/lib/puppet/indirector/indirection.rb +7 -0
  36. data/lib/puppet/indirector/instrumentation_data.rb +3 -0
  37. data/lib/puppet/indirector/instrumentation_data/local.rb +19 -0
  38. data/lib/puppet/indirector/instrumentation_data/rest.rb +5 -0
  39. data/lib/puppet/indirector/instrumentation_listener.rb +3 -0
  40. data/lib/puppet/indirector/instrumentation_listener/local.rb +23 -0
  41. data/lib/puppet/indirector/instrumentation_listener/rest.rb +5 -0
  42. data/lib/puppet/indirector/instrumentation_probe.rb +3 -0
  43. data/lib/puppet/indirector/instrumentation_probe/local.rb +24 -0
  44. data/lib/puppet/indirector/instrumentation_probe/rest.rb +5 -0
  45. data/lib/puppet/indirector/rest.rb +1 -1
  46. data/lib/puppet/module.rb +13 -17
  47. data/lib/puppet/module_tool/applications.rb +1 -0
  48. data/lib/puppet/module_tool/applications/uninstaller.rb +33 -0
  49. data/lib/puppet/module_tool/contents_description.rb +1 -1
  50. data/lib/puppet/network/server.rb +2 -3
  51. data/lib/puppet/node/environment.rb +16 -3
  52. data/lib/puppet/parser/ast/leaf.rb +1 -1
  53. data/lib/puppet/parser/functions/create_resources.rb +1 -1
  54. data/lib/puppet/parser/type_loader.rb +1 -1
  55. data/lib/puppet/property.rb +46 -14
  56. data/lib/puppet/provider.rb +13 -4
  57. data/lib/puppet/provider/augeas/augeas.rb +6 -4
  58. data/lib/puppet/provider/group/pw.rb +24 -10
  59. data/lib/puppet/provider/nameservice/directoryservice.rb +146 -37
  60. data/lib/puppet/provider/package/pip.rb +1 -1
  61. data/lib/puppet/provider/package/yum.rb +1 -2
  62. data/lib/puppet/provider/service/debian.rb +14 -0
  63. data/lib/puppet/provider/service/launchd.rb +1 -1
  64. data/lib/puppet/provider/service/smf.rb +2 -2
  65. data/lib/puppet/provider/user/pw.rb +56 -2
  66. data/lib/puppet/provider/user/user_role_add.rb +32 -22
  67. data/lib/puppet/provider/user/windows_adsi.rb +1 -0
  68. data/lib/puppet/rails/benchmark.rb +1 -1
  69. data/lib/puppet/reports/store.rb +8 -1
  70. data/lib/puppet/resource/catalog.rb +5 -1
  71. data/lib/puppet/simple_graph.rb +11 -14
  72. data/lib/puppet/transaction.rb +10 -4
  73. data/lib/puppet/transaction/report.rb +9 -3
  74. data/lib/puppet/type.rb +19 -7
  75. data/lib/puppet/type/exec.rb +1 -1
  76. data/lib/puppet/type/file.rb +4 -1
  77. data/lib/puppet/type/file/ensure.rb +5 -1
  78. data/lib/puppet/type/file/mode.rb +45 -10
  79. data/lib/puppet/type/file/source.rb +4 -0
  80. data/lib/puppet/type/host.rb +17 -3
  81. data/lib/puppet/type/k5login.rb +3 -2
  82. data/lib/puppet/type/schedule.rb +3 -2
  83. data/lib/puppet/util.rb +83 -27
  84. data/lib/puppet/util/anonymous_filelock.rb +36 -0
  85. data/lib/puppet/util/docs.rb +18 -2
  86. data/lib/puppet/util/instrumentation.rb +173 -0
  87. data/lib/puppet/util/instrumentation/data.rb +34 -0
  88. data/lib/puppet/util/instrumentation/indirection_probe.rb +29 -0
  89. data/lib/puppet/util/instrumentation/instrumentable.rb +143 -0
  90. data/lib/puppet/util/instrumentation/listener.rb +60 -0
  91. data/lib/puppet/util/instrumentation/listeners/log.rb +29 -0
  92. data/lib/puppet/util/instrumentation/listeners/performance.rb +30 -0
  93. data/lib/puppet/util/monkey_patches.rb +8 -0
  94. data/lib/puppet/util/pidlock.rb +21 -25
  95. data/lib/puppet/util/rdoc/parser.rb +2 -2
  96. data/lib/puppet/util/reference.rb +8 -23
  97. data/lib/puppet/util/retryaction.rb +48 -0
  98. data/lib/puppet/util/suidmanager.rb +70 -39
  99. data/lib/puppet/util/symbolic_file_mode.rb +140 -0
  100. data/spec/integration/configurer_spec.rb +5 -0
  101. data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
  102. data/spec/integration/indirector/file_content/file_server_spec.rb +7 -7
  103. data/spec/integration/provider/package_spec.rb +7 -0
  104. data/spec/unit/agent/disabler_spec.rb +60 -0
  105. data/spec/unit/agent/locker_spec.rb +0 -12
  106. data/spec/unit/agent_spec.rb +8 -0
  107. data/spec/unit/application/agent_spec.rb +38 -1
  108. data/spec/unit/application/apply_spec.rb +34 -40
  109. data/spec/unit/application/cert_spec.rb +1 -1
  110. data/spec/unit/application_spec.rb +6 -0
  111. data/spec/unit/configurer/downloader_spec.rb +29 -10
  112. data/spec/unit/configurer/fact_handler_spec.rb +5 -29
  113. data/spec/unit/configurer_spec.rb +8 -8
  114. data/spec/unit/daemon_spec.rb +12 -26
  115. data/spec/unit/face/instrumentation_data.rb +7 -0
  116. data/spec/unit/face/instrumentation_listener.rb +38 -0
  117. data/spec/unit/face/instrumentation_probe.rb +21 -0
  118. data/spec/unit/face/node_spec.rb +111 -111
  119. data/spec/unit/file_serving/content_spec.rb +2 -2
  120. data/spec/unit/indirector/facts/facter_spec.rb +25 -3
  121. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +14 -4
  122. data/spec/unit/indirector/instrumentation_data/local_spec.rb +52 -0
  123. data/spec/unit/indirector/instrumentation_data/rest_spec.rb +11 -0
  124. data/spec/unit/indirector/instrumentation_listener/local_spec.rb +65 -0
  125. data/spec/unit/indirector/instrumentation_listener/rest_spec.rb +11 -0
  126. data/spec/unit/indirector/instrumentation_probe/local_spec.rb +65 -0
  127. data/spec/unit/indirector/instrumentation_probe/rest_spec.rb +11 -0
  128. data/spec/unit/module_spec.rb +39 -125
  129. data/spec/unit/module_tool/uninstaller_spec.rb +44 -0
  130. data/spec/unit/network/server_spec.rb +2 -20
  131. data/spec/unit/node/environment_spec.rb +76 -58
  132. data/spec/unit/parser/ast/asthash_spec.rb +1 -2
  133. data/spec/unit/parser/ast/leaf_spec.rb +16 -0
  134. data/spec/unit/property/keyvalue_spec.rb +5 -2
  135. data/spec/unit/property_spec.rb +260 -159
  136. data/spec/unit/provider/augeas/augeas_spec.rb +2 -2
  137. data/spec/unit/provider/group/pw_spec.rb +81 -0
  138. data/spec/unit/provider/nameservice/directoryservice_spec.rb +102 -0
  139. data/spec/unit/provider/package/pip_spec.rb +7 -0
  140. data/spec/unit/provider/package/yum_spec.rb +45 -1
  141. data/spec/unit/provider/service/debian_spec.rb +15 -0
  142. data/spec/unit/provider/service/launchd_spec.rb +48 -43
  143. data/spec/unit/provider/service/smf_spec.rb +3 -3
  144. data/spec/unit/provider/user/pw_spec.rb +183 -0
  145. data/spec/unit/provider/user/user_role_add_spec.rb +46 -39
  146. data/spec/unit/provider/user/windows_adsi_spec.rb +1 -0
  147. data/spec/unit/provider_spec.rb +32 -0
  148. data/spec/unit/reports/store_spec.rb +19 -1
  149. data/spec/unit/simple_graph_spec.rb +34 -19
  150. data/spec/unit/ssl/certificate_factory_spec.rb +3 -3
  151. data/spec/unit/transaction/report_spec.rb +29 -1
  152. data/spec/unit/transaction_spec.rb +32 -46
  153. data/spec/unit/type/file/mode_spec.rb +1 -1
  154. data/spec/unit/type/file/source_spec.rb +28 -3
  155. data/spec/unit/type/file_spec.rb +17 -16
  156. data/spec/unit/type/host_spec.rb +527 -0
  157. data/spec/unit/type/k5login_spec.rb +115 -0
  158. data/spec/unit/type/schedule_spec.rb +6 -6
  159. data/spec/unit/type_spec.rb +51 -0
  160. data/spec/unit/util/anonymous_filelock_spec.rb +78 -0
  161. data/spec/unit/util/execution_stub_spec.rb +2 -1
  162. data/spec/unit/util/instrumentation/data_spec.rb +44 -0
  163. data/spec/unit/util/instrumentation/indirection_probe_spec.rb +19 -0
  164. data/spec/unit/util/instrumentation/instrumentable_spec.rb +186 -0
  165. data/spec/unit/util/instrumentation/listener_spec.rb +100 -0
  166. data/spec/unit/util/instrumentation/listeners/log_spec.rb +34 -0
  167. data/spec/unit/util/instrumentation/listeners/performance_spec.rb +36 -0
  168. data/spec/unit/util/instrumentation_spec.rb +181 -0
  169. data/spec/unit/util/pidlock_spec.rb +208 -0
  170. data/spec/unit/util/rdoc/parser_spec.rb +1 -1
  171. data/spec/unit/util/reference_spec.rb +16 -6
  172. data/spec/unit/util/retryaction_spec.rb +62 -0
  173. data/spec/unit/util/suidmanager_spec.rb +101 -83
  174. data/spec/unit/util/symbolic_file_mode_spec.rb +182 -0
  175. data/spec/unit/util_spec.rb +126 -0
  176. data/tasks/rake/apple.rake +176 -0
  177. data/tasks/rake/templates/prototype.plist.erb +38 -0
  178. metadata +61 -13
  179. data/lib/puppet/application/module.rb +0 -3
  180. data/lib/puppet/face/module.rb +0 -12
  181. data/spec/unit/face/module/build_spec.rb +0 -30
  182. data/spec/unit/face/module/changes_spec.rb +0 -30
  183. data/spec/unit/face/module/clean_spec.rb +0 -30
  184. data/spec/unit/face/module/generate_spec.rb +0 -30
  185. data/spec/unit/face/module/install_spec.rb +0 -75
  186. data/spec/unit/face/module/search_spec.rb +0 -40
  187. data/test/util/pidlock.rb +0 -126
@@ -0,0 +1,34 @@
1
+ require 'puppet/indirector'
2
+ require 'puppet/util/instrumentation'
3
+
4
+ # This is just a transport class to be used through the instrumentation_data
5
+ # indirection. All the data resides in the real underlying listeners which this
6
+ # class delegates to.
7
+ class Puppet::Util::Instrumentation::Data
8
+ extend Puppet::Indirector
9
+
10
+ indirects :instrumentation_data, :terminus_class => :local
11
+
12
+ attr_reader :listener
13
+
14
+ def initialize(listener_name)
15
+ @listener = Puppet::Util::Instrumentation[listener_name]
16
+ raise "Listener #{listener_name} wasn't registered" unless @listener
17
+ end
18
+
19
+ def name
20
+ @listener.name
21
+ end
22
+
23
+ def to_pson(*args)
24
+ result = {
25
+ 'document_type' => "Puppet::Util::Instrumentation::Data",
26
+ 'data' => { :name => name }.merge(@listener.respond_to?(:data) ? @listener.data : {})
27
+ }
28
+ result.to_pson(*args)
29
+ end
30
+
31
+ def self.from_pson(data)
32
+ data
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ require 'puppet/indirector'
2
+ require 'puppet/util/instrumentation'
3
+
4
+ # We need to use a class other than Probe for the indirector because
5
+ # the Indirection class might declare some probes, and this would be a huge unbreakable
6
+ # dependency cycle.
7
+ class Puppet::Util::Instrumentation::IndirectionProbe
8
+ extend Puppet::Indirector
9
+
10
+ indirects :instrumentation_probe, :terminus_class => :local
11
+
12
+ attr_reader :probe_name
13
+
14
+ def initialize(probe_name)
15
+ @probe_name = probe_name
16
+ end
17
+
18
+ def to_pson(*args)
19
+ result = {
20
+ :document_type => "Puppet::Util::Instrumentation::IndirectionProbe",
21
+ :data => { :name => probe_name }
22
+ }
23
+ result.to_pson(*args)
24
+ end
25
+
26
+ def self.from_pson(data)
27
+ self.new(data["name"])
28
+ end
29
+ end
@@ -0,0 +1,143 @@
1
+ require 'monitor'
2
+ require 'puppet/util/instrumentation'
3
+
4
+ # This is the central point of all declared probes.
5
+ # Every class needed to declare probes should include this module
6
+ # and declare the methods that are subject to instrumentation:
7
+ #
8
+ # class MyClass
9
+ # extend Puppet::Util::Instrumentation::Instrumentable
10
+ #
11
+ # probe :mymethod
12
+ #
13
+ # def mymethod
14
+ # ... this is code to be instrumented ...
15
+ # end
16
+ # end
17
+ module Puppet::Util::Instrumentation::Instrumentable
18
+ INSTRUMENTED_CLASSES = {}.extend(MonitorMixin)
19
+
20
+ attr_reader :probes
21
+
22
+ class Probe
23
+ attr_reader :klass, :method, :label, :data
24
+
25
+ def initialize(method, klass, options = {})
26
+ @method = method
27
+ @klass = klass
28
+
29
+ @label = options[:label] || method
30
+ @data = options[:data] || {}
31
+ end
32
+
33
+ def enable
34
+ raise "Probe already enabled" if enabled?
35
+
36
+ # We're forced to perform this copy because in the class_eval'uated
37
+ # block below @method would be evaluated in the class context. It's better
38
+ # to close on locally-scoped variables than to resort to complex namespacing
39
+ # to get access to the probe instance variables.
40
+ method = @method; label = @label; data = @data
41
+ klass.class_eval {
42
+ alias_method("instrumented_#{method}", method)
43
+ define_method(method) do |*args|
44
+ id = nil
45
+ instrumentation_data = nil
46
+ begin
47
+ instrumentation_label = label.respond_to?(:call) ? label.call(self, args) : label
48
+ instrumentation_data = data.respond_to?(:call) ? data.call(self, args) : data
49
+ id = Puppet::Util::Instrumentation.start(instrumentation_label, instrumentation_data)
50
+ send("instrumented_#{method}".to_sym, *args)
51
+ ensure
52
+ Puppet::Util::Instrumentation.stop(instrumentation_label, id, instrumentation_data || {})
53
+ end
54
+ end
55
+ }
56
+ @enabled = true
57
+ end
58
+
59
+ def disable
60
+ raise "Probe is not enabled" unless enabled?
61
+
62
+ # For the same reason as in #enable, we're forced to do a local
63
+ # copy
64
+ method = @method
65
+ klass.class_eval do
66
+ alias_method(method, "instrumented_#{method}")
67
+ remove_method("instrumented_#{method}".to_sym)
68
+ end
69
+ @enabled = false
70
+ end
71
+
72
+ def enabled?
73
+ !!@enabled
74
+ end
75
+ end
76
+
77
+ # Declares a new probe
78
+ #
79
+ # It is possible to pass several options that will be later on evaluated
80
+ # and sent to the instrumentation layer.
81
+ #
82
+ # label::
83
+ # this can either be a static symbol/string or a block. If it's a block
84
+ # this one will be evaluated on every call of the instrumented method and
85
+ # should return a string or a symbol
86
+ #
87
+ # data::
88
+ # this can be a hash or a block. If it's a block this one will be evaluated
89
+ # on every call of the instrumented method and should return a hash.
90
+ #
91
+ #Example:
92
+ #
93
+ # class MyClass
94
+ # extend Instrumentable
95
+ #
96
+ # probe :mymethod, :data => Proc.new { |args| { :data => args[1] } }, :label => Proc.new { |args| args[0] }
97
+ #
98
+ # def mymethod(name, options)
99
+ # end
100
+ #
101
+ # end
102
+ #
103
+ def probe(method, options = {})
104
+ INSTRUMENTED_CLASSES.synchronize {
105
+ (@probes ||= []) << Probe.new(method, self, options)
106
+ INSTRUMENTED_CLASSES[self] = @probes
107
+ }
108
+ end
109
+
110
+ def self.probes
111
+ @probes
112
+ end
113
+
114
+ def self.probe_names
115
+ probe_names = []
116
+ each_probe { |probe| probe_names << "#{probe.klass}.#{probe.method}" }
117
+ probe_names
118
+ end
119
+
120
+ def self.enable_probes
121
+ each_probe { |probe| probe.enable }
122
+ end
123
+
124
+ def self.disable_probes
125
+ each_probe { |probe| probe.disable }
126
+ end
127
+
128
+ def self.clear_probes
129
+ INSTRUMENTED_CLASSES.synchronize {
130
+ INSTRUMENTED_CLASSES.clear
131
+ }
132
+ nil # do not leak our probes to the exterior world
133
+ end
134
+
135
+ def self.each_probe
136
+ INSTRUMENTED_CLASSES.synchronize {
137
+ INSTRUMENTED_CLASSES.each_key do |klass|
138
+ klass.probes.each { |probe| yield probe }
139
+ end
140
+ }
141
+ nil # do not leak our probes to the exterior world
142
+ end
143
+ end
@@ -0,0 +1,60 @@
1
+ require 'puppet/indirector'
2
+ require 'puppet/util/instrumentation'
3
+ require 'puppet/util/instrumentation/data'
4
+
5
+ class Puppet::Util::Instrumentation::Listener
6
+ include Puppet::Util
7
+ include Puppet::Util::Warnings
8
+ extend Puppet::Indirector
9
+
10
+ indirects :instrumentation_listener, :terminus_class => :local
11
+
12
+ attr_reader :pattern, :listener
13
+ attr_accessor :enabled
14
+
15
+ def initialize(listener, pattern = nil, enabled = false)
16
+ @pattern = pattern.is_a?(Symbol) ? pattern.to_s : pattern
17
+ raise "Listener isn't a correct listener (it doesn't provide the notify method)" unless listener.respond_to?(:notify)
18
+ @listener = listener
19
+ @enabled = enabled
20
+ end
21
+
22
+ def notify(label, event, data)
23
+ listener.notify(label, event, data)
24
+ rescue => e
25
+ warnonce("Error during instrumentation notification: #{e}")
26
+ end
27
+
28
+ def listen_to?(label)
29
+ enabled? and (!@pattern || @pattern === label.to_s)
30
+ end
31
+
32
+ def enabled?
33
+ !!@enabled
34
+ end
35
+
36
+ def name
37
+ @listener.name.to_s
38
+ end
39
+
40
+ def data
41
+ { :data => @listener.data }
42
+ end
43
+
44
+ def to_pson(*args)
45
+ result = {
46
+ :document_type => "Puppet::Util::Instrumentation::Listener",
47
+ :data => {
48
+ :name => name,
49
+ :pattern => pattern,
50
+ :enabled => enabled?
51
+ }
52
+ }
53
+ result.to_pson(*args)
54
+ end
55
+
56
+ def self.from_pson(data)
57
+ result = Puppet::Util::Instrumentation[data["name"]]
58
+ self.new(result.listener, result.pattern, data["enabled"])
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ require 'monitor'
2
+
3
+ # This is an example instrumentation listener that stores the last
4
+ # 20 instrumented probe run time.
5
+ Puppet::Util::Instrumentation.new_listener(:log) do
6
+
7
+ SIZE = 20
8
+
9
+ attr_accessor :last_logs
10
+
11
+ def initialize
12
+ @last_logs = {}.extend(MonitorMixin)
13
+ end
14
+
15
+ def notify(label, event, data)
16
+ return if event == :start
17
+ log_line = "#{label} took #{data[:finished] - data[:started]}"
18
+ @last_logs.synchronize {
19
+ (@last_logs[label] ||= []) << log_line
20
+ @last_logs[label].shift if @last_logs[label].length > SIZE
21
+ }
22
+ end
23
+
24
+ def data
25
+ @last_logs.synchronize {
26
+ @last_logs.dup
27
+ }
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ require 'monitor'
2
+
3
+ Puppet::Util::Instrumentation.new_listener(:performance) do
4
+
5
+ attr_reader :samples
6
+
7
+ def initialize
8
+ @samples = {}.extend(MonitorMixin)
9
+ end
10
+
11
+ def notify(label, event, data)
12
+ return if event == :start
13
+
14
+ duration = data[:finished] - data[:started]
15
+ samples.synchronize do
16
+ @samples[label] ||= { :count => 0, :max => 0, :min => nil, :sum => 0, :average => 0 }
17
+ @samples[label][:count] += 1
18
+ @samples[label][:sum] += duration
19
+ @samples[label][:max] = [ @samples[label][:max], duration ].max
20
+ @samples[label][:min] = [ @samples[label][:min], duration ].reject { |val| val.nil? }.min
21
+ @samples[label][:average] = @samples[label][:sum] / @samples[label][:count]
22
+ end
23
+ end
24
+
25
+ def data
26
+ samples.synchronize do
27
+ @samples.dup
28
+ end
29
+ end
30
+ end
@@ -130,3 +130,11 @@ class IO
130
130
  lines
131
131
  end
132
132
  end
133
+
134
+ # Ruby 1.8.5 doesn't have tap
135
+ module Kernel
136
+ def tap
137
+ yield(self)
138
+ self
139
+ end unless method_defined?(:tap)
140
+ end
@@ -1,11 +1,7 @@
1
1
  require 'fileutils'
2
+ require 'puppet/util/anonymous_filelock'
2
3
 
3
- class Puppet::Util::Pidlock
4
- attr_reader :lockfile
5
-
6
- def initialize(lockfile)
7
- @lockfile = lockfile
8
- end
4
+ class Puppet::Util::Pidlock < Puppet::Util::AnonymousFilelock
9
5
 
10
6
  def locked?
11
7
  clear_if_stale
@@ -17,37 +13,36 @@ class Puppet::Util::Pidlock
17
13
  end
18
14
 
19
15
  def anonymous?
20
- return false unless File.exists?(@lockfile)
21
- File.read(@lockfile) == ""
16
+ false
22
17
  end
23
18
 
24
- def lock(opts = {})
25
- opts = {:anonymous => false}.merge(opts)
19
+ def lock
20
+ return mine? if locked?
26
21
 
27
- if locked?
28
- mine?
29
- else
30
- if opts[:anonymous]
31
- File.open(@lockfile, 'w') { |fd| true }
32
- else
33
- File.open(@lockfile, "w") { |fd| fd.write(Process.pid) }
34
- end
35
- true
36
- end
22
+ File.open(@lockfile, "w") { |fd| fd.write(Process.pid) }
23
+ true
37
24
  end
38
25
 
39
26
  def unlock(opts = {})
40
- opts = {:anonymous => false}.merge(opts)
41
-
42
- if mine? or (opts[:anonymous] and anonymous?)
43
- File.unlink(@lockfile)
27
+ if mine?
28
+ begin
29
+ File.unlink(@lockfile)
30
+ rescue Errno::ENOENT
31
+ # Someone deleted it for us ...and so we do nothing. No point whining
32
+ # about a problem that the user can't actually do anything about.
33
+ rescue SystemCallError => e
34
+ # This one is a real failure though. No idea what went wrong, but it
35
+ # is most likely "read only file(system)" or wrong permissions or
36
+ # something like that.
37
+ Puppet.err "Could not remove PID file #{@lockfile}: #{e}"
38
+ puts e.backtrace if Puppet[:trace]
39
+ end
44
40
  true
45
41
  else
46
42
  false
47
43
  end
48
44
  end
49
45
 
50
- private
51
46
  def lock_pid
52
47
  if File.exists? @lockfile
53
48
  File.read(@lockfile).to_i
@@ -56,6 +51,7 @@ class Puppet::Util::Pidlock
56
51
  end
57
52
  end
58
53
 
54
+ private
59
55
  def clear_if_stale
60
56
  return if lock_pid.nil?
61
57
 
@@ -99,7 +99,7 @@ class Parser
99
99
  modpath = $1
100
100
  name = $2
101
101
  Puppet.debug "rdoc: module #{name} into #{modpath} ?"
102
- Puppet::Module.modulepath.each do |mp|
102
+ Puppet::Node::Environment.new.modulepath.each do |mp|
103
103
  if File.identical?(modpath,mp)
104
104
  Puppet.debug "rdoc: found module #{name}"
105
105
  return name
@@ -110,7 +110,7 @@ class Parser
110
110
  # there can be paths we don't want to scan under modules
111
111
  # imagine a ruby or manifest that would be distributed as part as a module
112
112
  # but we don't want those to be hosted under <site>
113
- Puppet::Module.modulepath.each do |mp|
113
+ Puppet::Node::Environment.new.modulepath.each do |mp|
114
114
  # check that fullpath is a descendant of mp
115
115
  dirname = fullpath
116
116
  previous = dirname
@@ -36,14 +36,15 @@ class Puppet::Util::Reference
36
36
 
37
37
  def self.pdf(text)
38
38
  puts "creating pdf"
39
- Puppet::Util.secure_open("/tmp/puppetdoc.txt", "w") do |f|
40
- f.puts text
41
- end
42
- rst2latex = which('rst2latex') || which('rst2latex.py') || raise("Could not find rst2latex")
39
+ rst2latex = which('rst2latex') || which('rst2latex.py') ||
40
+ raise("Could not find rst2latex")
41
+
43
42
  cmd = %{#{rst2latex} /tmp/puppetdoc.txt > /tmp/puppetdoc.tex}
44
- Puppet::Util.secure_open("/tmp/puppetdoc.tex","w") do |f|
45
- # If we get here without an error, /tmp/puppetdoc.tex isn't a tricky cracker's symlink
46
- end
43
+ Puppet::Util.replace_file("/tmp/puppetdoc.txt") {|f| f.puts text }
44
+ # There used to be an attempt to use secure_open / replace_file to secure
45
+ # the target, too, but that did nothing: the race was still here. We can
46
+ # get exactly the same benefit from running this effort:
47
+ File.unlink('/tmp/puppetdoc.tex') rescue nil
47
48
  output = %x{#{cmd}}
48
49
  unless $CHILD_STATUS == 0
49
50
  $stderr.puts "rst2latex failed"
@@ -64,8 +65,6 @@ class Puppet::Util::Reference
64
65
  loaded_instances(:reference).sort { |a,b| a.to_s <=> b.to_s }
65
66
  end
66
67
 
67
- HEADER_LEVELS = [nil, "#", "##", "###", "####", "#####"]
68
-
69
68
  attr_accessor :page, :depth, :header, :title, :dynamic
70
69
  attr_writer :doc
71
70
 
@@ -81,20 +80,6 @@ class Puppet::Util::Reference
81
80
  self.dynamic
82
81
  end
83
82
 
84
- def markdown_header(name, level)
85
- "#{HEADER_LEVELS[level]} #{name}\n\n"
86
- end
87
-
88
- def markdown_definitionlist(term, definition)
89
- lines = definition.split("\n")
90
- str = "#{term}\n: #{lines.shift}\n"
91
- lines.each do |line|
92
- str << " " if line =~ /\S/
93
- str << "#{line}\n"
94
- end
95
- str << "\n"
96
- end
97
-
98
83
  def initialize(name, options = {}, &block)
99
84
  @name = name
100
85
  options.each do |option, value|