puppet 2.7.1 → 2.7.3

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 (171) hide show
  1. data/CHANGELOG +225 -1
  2. data/CONTRIBUTING.md +299 -0
  3. data/README.md +0 -1
  4. data/conf/redhat/puppet.spec +132 -25
  5. data/conf/solaris/pkginfo +1 -1
  6. data/conf/suse/puppet.spec +5 -2
  7. data/ext/envpuppet +56 -3
  8. data/ext/vim/README +2 -1
  9. data/ext/vim/ftplugin/puppet.vim +94 -0
  10. data/ext/vim/indent/puppet.vim +76 -0
  11. data/lib/puppet.rb +2 -3
  12. data/lib/puppet/application/agent.rb +7 -7
  13. data/lib/puppet/application/apply.rb +20 -8
  14. data/lib/puppet/application/ca.rb +5 -0
  15. data/lib/puppet/application/cert.rb +2 -1
  16. data/lib/puppet/application/certificate.rb +0 -5
  17. data/lib/puppet/application/device.rb +4 -4
  18. data/lib/puppet/application/doc.rb +23 -12
  19. data/lib/puppet/application/face_base.rb +2 -1
  20. data/lib/puppet/application/inspect.rb +5 -2
  21. data/lib/puppet/configurer.rb +60 -56
  22. data/lib/puppet/configurer/fact_handler.rb +6 -1
  23. data/lib/puppet/defaults.rb +20 -1
  24. data/lib/puppet/face/ca.rb +233 -0
  25. data/lib/puppet/face/certificate.rb +15 -11
  26. data/lib/puppet/face/certificate_request.rb +9 -11
  27. data/lib/puppet/face/certificate_revocation_list.rb +5 -7
  28. data/lib/puppet/face/node/clean.rb +154 -0
  29. data/lib/puppet/face/status.rb +1 -0
  30. data/lib/puppet/file_serving/configuration/parser.rb +6 -13
  31. data/lib/puppet/indirector/exec.rb +3 -3
  32. data/lib/puppet/indirector/face.rb +17 -7
  33. data/lib/puppet/indirector/report/processor.rb +29 -16
  34. data/lib/puppet/indirector/rest.rb +42 -7
  35. data/lib/puppet/indirector/yaml.rb +5 -0
  36. data/lib/puppet/interface.rb +7 -2
  37. data/lib/puppet/interface/action.rb +57 -23
  38. data/lib/puppet/interface/action_manager.rb +10 -5
  39. data/lib/puppet/interface/face_collection.rb +43 -52
  40. data/lib/puppet/interface/option.rb +19 -0
  41. data/lib/puppet/interface/option_builder.rb +13 -0
  42. data/lib/puppet/interface/option_manager.rb +2 -1
  43. data/lib/puppet/metatype/manager.rb +7 -20
  44. data/lib/puppet/module.rb +4 -1
  45. data/lib/puppet/network/authconfig.rb +3 -1
  46. data/lib/puppet/network/authstore.rb +14 -5
  47. data/lib/puppet/network/handler/fileserver.rb +3 -0
  48. data/lib/puppet/network/http/webrick.rb +1 -1
  49. data/lib/puppet/network/rest_authconfig.rb +6 -1
  50. data/lib/puppet/network/rest_authorization.rb +1 -1
  51. data/lib/puppet/parser/compiler.rb +8 -11
  52. data/lib/puppet/parser/functions.rb +1 -6
  53. data/lib/puppet/parser/functions/create_resources.rb +6 -5
  54. data/lib/puppet/parser/functions/regsubst.rb +26 -0
  55. data/lib/puppet/parser/functions/shellquote.rb +26 -0
  56. data/lib/puppet/parser/functions/sprintf.rb +26 -0
  57. data/lib/puppet/parser/grammar.ra +34 -60
  58. data/lib/puppet/parser/lexer.rb +5 -5
  59. data/lib/puppet/parser/parser.rb +913 -1196
  60. data/lib/puppet/parser/resource.rb +18 -1
  61. data/lib/puppet/parser/scope.rb +2 -2
  62. data/lib/puppet/provider/augeas/augeas.rb +42 -17
  63. data/lib/puppet/provider/mount/parsed.rb +19 -1
  64. data/lib/puppet/provider/naginator.rb +9 -1
  65. data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
  66. data/lib/puppet/provider/network_device.rb +1 -1
  67. data/lib/puppet/provider/package/aptitude.rb +1 -0
  68. data/lib/puppet/provider/package/pacman.rb +94 -0
  69. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -6
  70. data/lib/puppet/rails/host.rb +7 -0
  71. data/lib/puppet/reports/store.rb +15 -0
  72. data/lib/puppet/resource/catalog.rb +15 -6
  73. data/lib/puppet/ssl/certificate.rb +6 -0
  74. data/lib/puppet/ssl/inventory.rb +2 -0
  75. data/lib/puppet/transaction.rb +9 -17
  76. data/lib/puppet/transaction/report.rb +3 -3
  77. data/lib/puppet/type.rb +13 -24
  78. data/lib/puppet/type/file.rb +8 -2
  79. data/lib/puppet/type/file/source.rb +2 -2
  80. data/lib/puppet/type/service.rb +20 -24
  81. data/lib/puppet/type/ssh_authorized_key.rb +12 -0
  82. data/lib/puppet/type/user.rb +8 -0
  83. data/lib/puppet/util.rb +0 -1
  84. data/lib/puppet/util/network_device.rb +3 -3
  85. data/lib/puppet/util/settings.rb +1 -1
  86. data/lib/puppet/util/settings/file_setting.rb +1 -0
  87. data/lib/semver.rb +65 -0
  88. data/spec/integration/defaults_spec.rb +23 -1
  89. data/spec/integration/network/rest_authconfig_spec.rb +145 -0
  90. data/spec/integration/node/facts_spec.rb +1 -1
  91. data/spec/integration/parser/functions_spec.rb +1 -1
  92. data/spec/integration/parser/parser_spec.rb +31 -0
  93. data/spec/integration/provider/ssh_authorized_key_spec.rb +207 -0
  94. data/spec/integration/type_spec.rb +11 -0
  95. data/spec/lib/puppet/face/1.0.0/huzzah.rb +8 -0
  96. data/spec/lib/puppet/face/huzzah.rb +1 -0
  97. data/spec/lib/puppet/face/huzzah/obsolete.rb +6 -0
  98. data/spec/shared_behaviours/things_that_declare_options.rb +115 -3
  99. data/spec/unit/application/agent_spec.rb +2 -2
  100. data/spec/unit/application/apply_spec.rb +74 -56
  101. data/spec/unit/application/cert_spec.rb +10 -0
  102. data/spec/unit/application/device_spec.rb +2 -3
  103. data/spec/unit/application/face_base_spec.rb +1 -0
  104. data/spec/unit/application/facts_spec.rb +1 -0
  105. data/spec/unit/application/inspect_spec.rb +5 -0
  106. data/spec/unit/configurer/fact_handler_spec.rb +45 -37
  107. data/spec/unit/configurer_spec.rb +405 -327
  108. data/spec/unit/face/ca_spec.rb +355 -0
  109. data/spec/unit/face/certificate_spec.rb +16 -4
  110. data/spec/unit/face/node_spec.rb +261 -1
  111. data/spec/unit/file_serving/configuration/parser_spec.rb +8 -0
  112. data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
  113. data/spec/unit/indirector/certificate_status/file_spec.rb +4 -0
  114. data/spec/unit/indirector/exec_spec.rb +4 -4
  115. data/spec/unit/indirector/face_spec.rb +3 -1
  116. data/spec/unit/indirector/facts/couch_spec.rb +2 -2
  117. data/spec/unit/indirector/facts/network_device_spec.rb +2 -6
  118. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  119. data/spec/unit/indirector/report/processor_spec.rb +31 -8
  120. data/spec/unit/indirector/rest_spec.rb +53 -5
  121. data/spec/unit/indirector/yaml_spec.rb +18 -0
  122. data/spec/unit/interface/action_spec.rb +112 -8
  123. data/spec/unit/interface/face_collection_spec.rb +46 -36
  124. data/spec/unit/interface/option_spec.rb +44 -0
  125. data/spec/unit/interface_spec.rb +11 -6
  126. data/spec/unit/module_spec.rb +38 -9
  127. data/spec/unit/network/authconfig_spec.rb +23 -0
  128. data/spec/unit/network/authstore_spec.rb +36 -4
  129. data/spec/unit/network/handler/fileserver_spec.rb +32 -0
  130. data/spec/unit/network/rest_authconfig_spec.rb +1 -1
  131. data/spec/unit/node_spec.rb +1 -0
  132. data/spec/unit/parser/compiler_spec.rb +8 -46
  133. data/spec/unit/parser/lexer_spec.rb +27 -17
  134. data/spec/unit/parser/resource_spec.rb +61 -3
  135. data/spec/unit/parser/scope_spec.rb +5 -1
  136. data/spec/unit/provider/augeas/augeas_spec.rb +106 -1
  137. data/spec/unit/provider/cisco_spec.rb +3 -4
  138. data/spec/unit/provider/interface/cisco_spec.rb +1 -2
  139. data/spec/unit/provider/mount/parsed_spec.rb +41 -0
  140. data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
  141. data/spec/unit/provider/network_device_spec.rb +1 -2
  142. data/spec/unit/provider/package/pacman_spec.rb +237 -0
  143. data/spec/unit/provider/package/pkgutil_spec.rb +2 -3
  144. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -32
  145. data/spec/unit/provider/vlan/cisco_spec.rb +1 -2
  146. data/spec/unit/rails/host_spec.rb +8 -0
  147. data/spec/unit/resource/catalog_spec.rb +55 -8
  148. data/spec/unit/semver_spec.rb +187 -0
  149. data/spec/unit/ssl/certificate_spec.rb +25 -0
  150. data/spec/unit/transaction/report_spec.rb +3 -3
  151. data/spec/unit/transaction_spec.rb +8 -2
  152. data/spec/unit/type/file_spec.rb +57 -0
  153. data/spec/unit/type/interface_spec.rb +1 -2
  154. data/spec/unit/type/schedule_spec.rb +73 -42
  155. data/spec/unit/type/ssh_authorized_key_spec.rb +180 -70
  156. data/spec/unit/type/user_spec.rb +8 -0
  157. data/spec/unit/type/vlan_spec.rb +1 -2
  158. data/spec/unit/type_spec.rb +66 -0
  159. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -2
  160. data/spec/unit/util/network_device/cisco/facts_spec.rb +2 -3
  161. data/spec/unit/util/network_device/cisco/interface_spec.rb +1 -2
  162. data/spec/unit/util/network_device/config_spec.rb +3 -4
  163. data/spec/unit/util/network_device/ipcalc_spec.rb +1 -2
  164. data/spec/unit/util/network_device/transport/base_spec.rb +1 -2
  165. data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -2
  166. data/spec/unit/util/network_device/transport/telnet_spec.rb +1 -2
  167. data/spec/unit/util/network_device_spec.rb +2 -2
  168. data/spec/unit/util/settings/file_setting_spec.rb +4 -0
  169. data/spec/unit/util/settings_spec.rb +11 -0
  170. data/test/lib/puppettest/railstesting.rb +0 -34
  171. metadata +19 -4
@@ -27,6 +27,12 @@ class Puppet::SSL::Certificate < Puppet::SSL::Base
27
27
  [:s]
28
28
  end
29
29
 
30
+ def alternate_names
31
+ alts = content.extensions.find{|ext| ext.oid == "subjectAltName"}
32
+ return [] unless alts
33
+ alts.value.split(/,\s+/).map{|al| al.sub(/^DNS:/,'')}
34
+ end
35
+
30
36
  def expiration
31
37
  return nil unless content
32
38
  content.not_after
@@ -48,5 +48,7 @@ class Puppet::SSL::Inventory
48
48
 
49
49
  return Integer($1)
50
50
  end
51
+
52
+ return nil
51
53
  end
52
54
  end
@@ -16,7 +16,7 @@ class Puppet::Transaction
16
16
  attr_accessor :configurator
17
17
 
18
18
  # The report, once generated.
19
- attr_accessor :report
19
+ attr_reader :report
20
20
 
21
21
  # Routes and stores any events and subscriptions.
22
22
  attr_reader :event_manager
@@ -92,25 +92,17 @@ class Puppet::Transaction
92
92
  # collects all of the changes, executes them, and responds to any
93
93
  # necessary events.
94
94
  def evaluate
95
- # Start logging.
96
- Puppet::Util::Log.newdestination(@report)
97
-
98
95
  prepare
99
96
 
100
97
  Puppet.info "Applying configuration version '#{catalog.version}'" if catalog.version
101
98
 
102
- begin
103
- relationship_graph.traverse do |resource|
104
- if resource.is_a?(Puppet::Type::Component)
105
- Puppet.warning "Somehow left a component in the relationship graph"
106
- else
107
- seconds = thinmark { eval_resource(resource) }
108
- resource.info "Evaluated in %0.2f seconds" % seconds if Puppet[:evaltrace] and @catalog.host_config?
109
- end
99
+ relationship_graph.traverse do |resource|
100
+ if resource.is_a?(Puppet::Type::Component)
101
+ Puppet.warning "Somehow left a component in the relationship graph"
102
+ else
103
+ seconds = thinmark { eval_resource(resource) }
104
+ resource.info "Evaluated in %0.2f seconds" % seconds if Puppet[:evaltrace] and @catalog.host_config?
110
105
  end
111
- ensure
112
- # And then close the transaction log.
113
- Puppet::Util::Log.close(@report)
114
106
  end
115
107
 
116
108
  Puppet.debug "Finishing transaction #{object_id}"
@@ -221,10 +213,10 @@ class Puppet::Transaction
221
213
 
222
214
  # this should only be called by a Puppet::Type::Component resource now
223
215
  # and it should only receive an array
224
- def initialize(catalog)
216
+ def initialize(catalog, report = nil)
225
217
  @catalog = catalog
226
218
 
227
- @report = Puppet::Transaction::Report.new("apply")
219
+ @report = report || Puppet::Transaction::Report.new("apply", catalog.version)
228
220
 
229
221
  @event_manager = Puppet::Transaction::EventManager.new(self)
230
222
 
@@ -10,8 +10,8 @@ class Puppet::Transaction::Report
10
10
 
11
11
  indirects :report, :terminus_class => :processor
12
12
 
13
- attr_accessor :configuration_version
14
- attr_reader :resource_statuses, :logs, :metrics, :host, :time, :kind, :status
13
+ attr_accessor :configuration_version, :host
14
+ attr_reader :resource_statuses, :logs, :metrics, :time, :kind, :status
15
15
 
16
16
  # This is necessary since Marshall doesn't know how to
17
17
  # dump hash with default proc (see below @records)
@@ -73,7 +73,7 @@ class Puppet::Transaction::Report
73
73
  @logs = []
74
74
  @resource_statuses = {}
75
75
  @external_times ||= {}
76
- @host = Puppet[:certname]
76
+ @host = Puppet[:node_name_value]
77
77
  @time = Time.now
78
78
  @kind = kind
79
79
  @report_format = 2
@@ -1442,9 +1442,8 @@ class Type
1442
1442
  def self.provide(name, options = {}, &block)
1443
1443
  name = Puppet::Util.symbolize(name)
1444
1444
 
1445
- if obj = provider_hash[name]
1445
+ if unprovide(name)
1446
1446
  Puppet.debug "Reloading #{name} #{self.name} provider"
1447
- unprovide(name)
1448
1447
  end
1449
1448
 
1450
1449
  parent = if pname = options[:parent]
@@ -1467,16 +1466,14 @@ class Type
1467
1466
 
1468
1467
  self.providify
1469
1468
 
1470
-
1471
- provider = genclass(
1472
- name,
1473
- :parent => parent,
1474
- :hash => provider_hash,
1475
- :prefix => "Provider",
1476
- :block => block,
1477
- :include => feature_module,
1478
- :extend => feature_module,
1479
-
1469
+ provider = genclass(
1470
+ name,
1471
+ :parent => parent,
1472
+ :hash => provider_hash,
1473
+ :prefix => "Provider",
1474
+ :block => block,
1475
+ :include => feature_module,
1476
+ :extend => feature_module,
1480
1477
  :attributes => options
1481
1478
  )
1482
1479
 
@@ -1536,18 +1533,11 @@ class Type
1536
1533
  end
1537
1534
 
1538
1535
  def self.unprovide(name)
1539
- if provider_hash.has_key? name
1540
-
1541
- rmclass(
1542
- name,
1543
- :hash => provider_hash,
1544
-
1545
- :prefix => "Provider"
1546
- )
1547
- if @defaultprovider and @defaultprovider.name == name
1548
- @defaultprovider = nil
1549
- end
1536
+ if @defaultprovider and @defaultprovider.name == name
1537
+ @defaultprovider = nil
1550
1538
  end
1539
+
1540
+ rmclass(name, :hash => provider_hash, :prefix => "Provider")
1551
1541
  end
1552
1542
 
1553
1543
  # Return an array of all of the suitable providers.
@@ -1607,7 +1597,6 @@ class Type
1607
1597
 
1608
1598
  # Collect the current prereqs
1609
1599
  list.each { |dep|
1610
- obj = nil
1611
1600
  # Support them passing objects directly, to save some effort.
1612
1601
  unless dep.is_a? Puppet::Type
1613
1602
  # Skip autorequires that we aren't managing
@@ -257,11 +257,17 @@ Puppet::Type.newtype(:file) do
257
257
  newvalues(:first, :all)
258
258
  end
259
259
 
260
- # Autorequire any parent directories.
260
+ # Autorequire the nearest ancestor directory found in the catalog.
261
261
  autorequire(:file) do
262
262
  basedir = ::File.dirname(self[:path])
263
263
  if basedir != self[:path]
264
- basedir
264
+ parents = []
265
+ until basedir == parents.last
266
+ parents << basedir
267
+ basedir = ::File.dirname(basedir)
268
+ end
269
+ # The filename of the first ancestor found, or nil
270
+ parents.find { |dir| catalog.resource(:file, dir) }
265
271
  else
266
272
  nil
267
273
  end
@@ -42,7 +42,7 @@ module Puppet
42
42
  on the local host, whereas `agent` will connect to the
43
43
  puppet server that it received the manifest from.
44
44
 
45
- See the [fileserver configuration documentation](http://projects.puppetlabs.com/projects/puppet/wiki/File_Serving_Configuration) for information on how to configure
45
+ See the [fileserver configuration documentation](http://docs.puppetlabs.com/guides/file_serving.html) for information on how to configure
46
46
  and use file services within Puppet.
47
47
 
48
48
  If you specify multiple file sources for a file, then the first
@@ -154,7 +154,7 @@ module Puppet
154
154
  fail detail, "Could not retrieve file metadata for #{source}: #{detail}"
155
155
  end
156
156
  end
157
- fail "Could not retrieve information from source(s) #{value.join(", ")}" unless result
157
+ fail "Could not retrieve information from environment #{Puppet[:environment]} source(s) #{value.join(", ")}" unless result
158
158
  result
159
159
  end
160
160
 
@@ -8,17 +8,15 @@ module Puppet
8
8
 
9
9
  newtype(:service) do
10
10
  @doc = "Manage running services. Service support unfortunately varies
11
- widely by platform --- some platforms have very little if any
12
- concept of a running service, and some have a very codified and
13
- powerful concept. Puppet's service support will generally be able
14
- to do the right thing regardless (e.g., if there is no
15
- 'status' command, then Puppet will look in the process table for a
16
- command matching the service name), but the more information you
17
- can provide, the better behaviour you will get. In particular, any
18
- virtual services that don't have a predictable entry in the process table
19
- (for example, `network` on Red Hat/CentOS systems) will manifest odd
20
- behavior on restarts if you don't specify `hasstatus` or a `status`
21
- command.
11
+ widely by platform --- some platforms have very little if any concept of a
12
+ running service, and some have a very codified and powerful concept.
13
+ Puppet's service support is usually capable of doing the right thing, but
14
+ the more information you can provide, the better behaviour you will get.
15
+
16
+ Puppet 2.7 and newer expect init scripts to have a working status command.
17
+ If this isn't the case for any of your services' init scripts, you will
18
+ need to set `hasstatus` to false and possibly specify a custom status
19
+ command in the `status` attribute.
22
20
 
23
21
  Note that if a `service` receives an event from another resource,
24
22
  the service will get restarted. The actual command to restart the
@@ -93,19 +91,17 @@ module Puppet
93
91
  end
94
92
 
95
93
  newparam(:hasstatus) do
96
- desc "Declare the the service's init script has a
97
- functional status command. Based on testing, it was found
98
- that a large number of init scripts on different platforms do
99
- not support any kind of status command; thus, you must specify
100
- manually whether the service you are running has such a
101
- command. Alternately, you can provide a specific command using the
102
- `status` attribute.
103
-
104
- If you specify neither of these, then Puppet will look for the
105
- service name in the process table. Be aware that 'virtual' init
106
- scripts such as networking will respond poorly to refresh events
107
- (via notify and subscribe relationships) if you don't override
108
- this default behavior."
94
+ desc "Declare whether the service's init script has a functional status
95
+ command; defaults to `true`. This attribute's default value changed in
96
+ Puppet 2.7.0.
97
+
98
+ If a service's init script does not support any kind of status command,
99
+ you should set `hasstatus` to false and either provide a specific
100
+ command using the `status` attribute or expect that Puppet will look for
101
+ the service name in the process table. Be aware that 'virtual' init
102
+ scripts (like 'network' under Red Hat systems) will respond poorly to
103
+ refresh events from other resources if you override the default behavior
104
+ without providing a status command."
109
105
 
110
106
  newvalues(:true, :false)
111
107
 
@@ -14,6 +14,10 @@ module Puppet
14
14
  system-wide primary key and therefore has to be unique."
15
15
 
16
16
  isnamevar
17
+
18
+ validate do |value|
19
+ raise Puppet::Error, "Resourcename must not contain whitespace: #{value}" if value =~ /\s/
20
+ end
17
21
  end
18
22
 
19
23
  newproperty(:type) do
@@ -28,6 +32,10 @@ module Puppet
28
32
 
29
33
  newproperty(:key) do
30
34
  desc "The key itself; generally a long string of hex digits."
35
+
36
+ validate do |value|
37
+ raise Puppet::Error, "Key must not contain whitespace: #{value}" if value =~ /\s/
38
+ end
31
39
  end
32
40
 
33
41
  newproperty(:user) do
@@ -82,6 +90,10 @@ module Puppet
82
90
  value.join(",")
83
91
  end
84
92
  end
93
+
94
+ validate do |value|
95
+ raise Puppet::Error, "Options must be provided as an array, not a comma separated list" if value != :absent and value.include?(',')
96
+ end
85
97
  end
86
98
 
87
99
  autorequire(:user) do
@@ -168,6 +168,14 @@ module Puppet
168
168
  return "changed password"
169
169
  end
170
170
  end
171
+
172
+ def is_to_s( currentvalue )
173
+ return '[old password hash redacted]'
174
+ end
175
+ def should_to_s( newvalue )
176
+ return '[new password hash redacted]'
177
+ end
178
+
171
179
  end
172
180
 
173
181
  newproperty(:password_min_age, :required_features => :manages_password_age) do
@@ -30,7 +30,6 @@ module Util
30
30
  end
31
31
  end
32
32
 
33
-
34
33
  def self.synchronize_on(x,type)
35
34
  sync_object,users = 0,1
36
35
  begin
@@ -10,8 +10,8 @@ class Puppet::Util::NetworkDevice
10
10
  raise "Can't load #{device.provider} for #{device.name}: #{detail}"
11
11
  end
12
12
 
13
- # for tests reset
14
- def self.clear
13
+ # Should only be used in tests
14
+ def self.teardown
15
15
  @current = nil
16
16
  end
17
- end
17
+ end
@@ -721,7 +721,7 @@ if @config.include?(:run_mode)
721
721
  end
722
722
 
723
723
  Puppet::Util::SUIDManager.asuser(*chown) do
724
- mode = obj.mode || 0640
724
+ mode = obj.mode ? obj.mode.to_i : 0640
725
725
  args << "w" if args.empty?
726
726
 
727
727
  args << mode
@@ -101,6 +101,7 @@ class Puppet::Util::Settings::FileSetting < Puppet::Util::Settings::Setting
101
101
 
102
102
  resource[:ensure] = type
103
103
  resource[:loglevel] = :debug
104
+ resource[:links] = :follow
104
105
  resource[:backup] = false
105
106
 
106
107
  resource.tag(self.section, self.name, "settings")
@@ -0,0 +1,65 @@
1
+ class SemVer
2
+ VERSION = /^v?(\d+)\.(\d+)\.(\d+)([A-Za-z][0-9A-Za-z-]*|)$/
3
+ SIMPLE_RANGE = /^v?(\d+|[xX])(?:\.(\d+|[xX])(?:\.(\d+|[xX]))?)?$/
4
+
5
+ include Comparable
6
+
7
+ def self.valid?(ver)
8
+ VERSION =~ ver
9
+ end
10
+
11
+ def self.find_matching(pattern, versions)
12
+ versions.select { |v| v.matched_by?("#{pattern}") }.sort.last
13
+ end
14
+
15
+ attr_reader :major, :minor, :tiny, :special
16
+
17
+ def initialize(ver)
18
+ unless SemVer.valid?(ver)
19
+ raise ArgumentError.new("Invalid version string '#{ver}'!")
20
+ end
21
+
22
+ @major, @minor, @tiny, @special = VERSION.match(ver).captures.map do |x|
23
+ # Because Kernel#Integer tries to interpret hex and octal strings, which
24
+ # we specifically do not want, and which cannot be overridden in 1.8.7.
25
+ Float(x).to_i rescue x
26
+ end
27
+ end
28
+
29
+ def <=>(other)
30
+ other = SemVer.new("#{other}") unless other.is_a? SemVer
31
+ return self.major <=> other.major unless self.major == other.major
32
+ return self.minor <=> other.minor unless self.minor == other.minor
33
+ return self.tiny <=> other.tiny unless self.tiny == other.tiny
34
+
35
+ return 0 if self.special == other.special
36
+ return 1 if self.special == ''
37
+ return -1 if other.special == ''
38
+
39
+ return self.special <=> other.special
40
+ end
41
+
42
+ def matched_by?(pattern)
43
+ # For the time being, this is restricted to exact version matches and
44
+ # simple range patterns. In the future, we should implement some or all of
45
+ # the comparison operators here:
46
+ # https://github.com/isaacs/node-semver/blob/d474801/semver.js#L340
47
+
48
+ case pattern
49
+ when SIMPLE_RANGE
50
+ pattern = SIMPLE_RANGE.match(pattern).captures
51
+ pattern[1] = @minor unless pattern[1] && pattern[1] !~ /x/i
52
+ pattern[2] = @tiny unless pattern[2] && pattern[2] !~ /x/i
53
+ [@major, @minor, @tiny] == pattern.map { |x| x.to_i }
54
+ when VERSION
55
+ self == SemVer.new(pattern)
56
+ else
57
+ false
58
+ end
59
+ end
60
+
61
+ def inspect
62
+ "v#{@major}.#{@minor}.#{@tiny}#{@special}"
63
+ end
64
+ alias :to_s :inspect
65
+ end
@@ -22,6 +22,28 @@ describe "Puppet defaults" do
22
22
  end
23
23
  end
24
24
 
25
+ describe "when setting :node_name_value" do
26
+ it "should default to the value of :certname" do
27
+ Puppet.settings[:certname] = 'blargle'
28
+ Puppet.settings[:node_name_value].should == 'blargle'
29
+ end
30
+ end
31
+
32
+ describe "when setting the :node_name_fact" do
33
+ it "should fail when also setting :node_name_value" do
34
+ lambda do
35
+ Puppet.settings[:node_name_value] = "some value"
36
+ Puppet.settings[:node_name_fact] = "some_fact"
37
+ end.should raise_error("Cannot specify both the node_name_value and node_name_fact settings")
38
+ end
39
+
40
+ it "should not fail when using the default for :node_name_value" do
41
+ lambda do
42
+ Puppet.settings[:node_name_fact] = "some_fact"
43
+ end.should_not raise_error
44
+ end
45
+ end
46
+
25
47
  describe "when configuring the :crl" do
26
48
  it "should warn if :cacrl is set to false" do
27
49
  Puppet.expects(:warning)
@@ -253,6 +275,6 @@ describe "Puppet defaults" do
253
275
 
254
276
  describe "reporturl" do
255
277
  subject { Puppet.settings[:reporturl] }
256
- it { should == "http://localhost:3000/reports" }
278
+ it { should == "http://localhost:3000/reports/upload" }
257
279
  end
258
280
  end