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
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+ require 'semver'
3
+
4
+ describe SemVer do
5
+ describe '::valid?' do
6
+ it 'should validate basic version strings' do
7
+ %w[ 0.0.0 999.999.999 v0.0.0 v999.999.999 ].each do |vstring|
8
+ SemVer.valid?(vstring).should be_true
9
+ end
10
+ end
11
+
12
+ it 'should validate special version strings' do
13
+ %w[ 0.0.0foo 999.999.999bar v0.0.0a v999.999.999beta ].each do |vstring|
14
+ SemVer.valid?(vstring).should be_true
15
+ end
16
+ end
17
+
18
+ it 'should fail to validate invalid version strings' do
19
+ %w[ nope 0.0foo 999.999 x0.0.0 z.z.z 1.2.3-beta 1.x.y ].each do |vstring|
20
+ SemVer.valid?(vstring).should be_false
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '::find_matching' do
26
+ before :all do
27
+ @versions = %w[
28
+ 0.0.1
29
+ 0.0.2
30
+ 1.0.0rc1
31
+ 1.0.0rc2
32
+ 1.0.0
33
+ 1.0.1
34
+ 1.1.0
35
+ 1.1.1
36
+ 1.1.2
37
+ 1.1.3
38
+ 1.1.4
39
+ 1.2.0
40
+ 1.2.1
41
+ 2.0.0rc1
42
+ ].map { |v| SemVer.new(v) }
43
+ end
44
+
45
+ it 'should match exact versions by string' do
46
+ @versions.each do |version|
47
+ SemVer.find_matching(version, @versions).should == version
48
+ end
49
+ end
50
+
51
+ it 'should return nil if no versions match' do
52
+ %w[ 3.0.0 2.0.0rc2 1.0.0alpha ].each do |v|
53
+ SemVer.find_matching(v, @versions).should be_nil
54
+ end
55
+ end
56
+
57
+ it 'should find the greatest match for partial versions' do
58
+ SemVer.find_matching('1.0', @versions).should == 'v1.0.1'
59
+ SemVer.find_matching('1.1', @versions).should == 'v1.1.4'
60
+ SemVer.find_matching('1', @versions).should == 'v1.2.1'
61
+ SemVer.find_matching('2', @versions).should == 'v2.0.0rc1'
62
+ SemVer.find_matching('2.1', @versions).should == nil
63
+ end
64
+
65
+
66
+ it 'should find the greatest match for versions with placeholders' do
67
+ SemVer.find_matching('1.0.x', @versions).should == 'v1.0.1'
68
+ SemVer.find_matching('1.1.x', @versions).should == 'v1.1.4'
69
+ SemVer.find_matching('1.x', @versions).should == 'v1.2.1'
70
+ SemVer.find_matching('1.x.x', @versions).should == 'v1.2.1'
71
+ SemVer.find_matching('2.x', @versions).should == 'v2.0.0rc1'
72
+ SemVer.find_matching('2.x.x', @versions).should == 'v2.0.0rc1'
73
+ SemVer.find_matching('2.1.x', @versions).should == nil
74
+ end
75
+ end
76
+
77
+ describe 'instantiation' do
78
+ it 'should raise an exception when passed an invalid version string' do
79
+ expect { SemVer.new('invalidVersion') }.to raise_exception ArgumentError
80
+ end
81
+
82
+ it 'should populate the appropriate fields for a basic version string' do
83
+ version = SemVer.new('1.2.3')
84
+ version.major.should == 1
85
+ version.minor.should == 2
86
+ version.tiny.should == 3
87
+ version.special.should == ''
88
+ end
89
+
90
+ it 'should populate the appropriate fields for a special version string' do
91
+ version = SemVer.new('3.4.5beta6')
92
+ version.major.should == 3
93
+ version.minor.should == 4
94
+ version.tiny.should == 5
95
+ version.special.should == 'beta6'
96
+ end
97
+ end
98
+
99
+ describe '#matched_by?' do
100
+ subject { SemVer.new('v1.2.3beta') }
101
+
102
+ describe 'should match against' do
103
+ describe 'literal version strings' do
104
+ it { should be_matched_by('1.2.3beta') }
105
+
106
+ it { should_not be_matched_by('1.2.3alpha') }
107
+ it { should_not be_matched_by('1.2.4beta') }
108
+ it { should_not be_matched_by('1.3.3beta') }
109
+ it { should_not be_matched_by('2.2.3beta') }
110
+ end
111
+
112
+ describe 'partial version strings' do
113
+ it { should be_matched_by('1.2.3') }
114
+ it { should be_matched_by('1.2') }
115
+ it { should be_matched_by('1') }
116
+ end
117
+
118
+ describe 'version strings with placeholders' do
119
+ it { should be_matched_by('1.2.x') }
120
+ it { should be_matched_by('1.x.3') }
121
+ it { should be_matched_by('1.x.x') }
122
+ it { should be_matched_by('1.x') }
123
+ end
124
+ end
125
+ end
126
+
127
+ describe 'comparisons' do
128
+ describe 'against a string' do
129
+ it 'should just work' do
130
+ SemVer.new('1.2.3').should == '1.2.3'
131
+ end
132
+ end
133
+
134
+ describe 'against a symbol' do
135
+ it 'should just work' do
136
+ SemVer.new('1.2.3').should == :'1.2.3'
137
+ end
138
+ end
139
+
140
+ describe 'on a basic version (v1.2.3)' do
141
+ subject { SemVer.new('v1.2.3') }
142
+
143
+ it { should == SemVer.new('1.2.3') }
144
+
145
+ # Different major versions
146
+ it { should > SemVer.new('0.2.3') }
147
+ it { should < SemVer.new('2.2.3') }
148
+
149
+ # Different minor versions
150
+ it { should > SemVer.new('1.1.3') }
151
+ it { should < SemVer.new('1.3.3') }
152
+
153
+ # Different tiny versions
154
+ it { should > SemVer.new('1.2.2') }
155
+ it { should < SemVer.new('1.2.4') }
156
+
157
+ # Against special versions
158
+ it { should > SemVer.new('1.2.3beta') }
159
+ it { should < SemVer.new('1.2.4beta') }
160
+ end
161
+
162
+ describe 'on a special version (v1.2.3beta)' do
163
+ subject { SemVer.new('v1.2.3beta') }
164
+
165
+ it { should == SemVer.new('1.2.3beta') }
166
+
167
+ # Same version, final release
168
+ it { should < SemVer.new('1.2.3') }
169
+
170
+ # Different major versions
171
+ it { should > SemVer.new('0.2.3') }
172
+ it { should < SemVer.new('2.2.3') }
173
+
174
+ # Different minor versions
175
+ it { should > SemVer.new('1.1.3') }
176
+ it { should < SemVer.new('1.3.3') }
177
+
178
+ # Different tiny versions
179
+ it { should > SemVer.new('1.2.2') }
180
+ it { should < SemVer.new('1.2.4') }
181
+
182
+ # Against special versions
183
+ it { should > SemVer.new('1.2.3alpha') }
184
+ it { should < SemVer.new('1.2.3beta2') }
185
+ end
186
+ end
187
+ end
@@ -89,6 +89,31 @@ describe Puppet::SSL::Certificate do
89
89
  @certificate.should respond_to(:content)
90
90
  end
91
91
 
92
+ describe "#alternate_names" do
93
+ before do
94
+ Puppet[:certdnsnames] = 'foo:bar:baz'
95
+ @csr = OpenSSL::X509::Request.new
96
+ @csr.subject = OpenSSL::X509::Name.new([['CN', 'quux']])
97
+ @csr.public_key = OpenSSL::PKey::RSA.generate(Puppet[:keylength]).public_key
98
+ end
99
+
100
+ it "should list all alternate names when the extension is present" do
101
+ cert = Puppet::SSL::CertificateFactory.new('server', @csr, @csr, 14).result
102
+
103
+ @certificate = @class.from_s(cert.to_pem)
104
+
105
+ @certificate.alternate_names.should =~ ['foo', 'bar', 'baz', 'quux']
106
+ end
107
+
108
+ it "should return an empty list of names if the extension is absent" do
109
+ cert = Puppet::SSL::CertificateFactory.new('client', @csr, @csr, 14).result
110
+
111
+ @certificate = @class.from_s(cert.to_pem)
112
+
113
+ @certificate.alternate_names.should == []
114
+ end
115
+ end
116
+
92
117
  it "should return a nil expiration if there is no actual certificate" do
93
118
  @certificate.stubs(:content).returns nil
94
119
 
@@ -9,9 +9,9 @@ describe Puppet::Transaction::Report do
9
9
  Puppet::Util::Storage.stubs(:store)
10
10
  end
11
11
 
12
- it "should set its host name to the certname" do
13
- Puppet.settings.expects(:value).with(:certname).returns "myhost"
14
- Puppet::Transaction::Report.new("apply").host.should == "myhost"
12
+ it "should set its host name to the node_name_value" do
13
+ Puppet[:node_name_value] = 'mynode'
14
+ Puppet::Transaction::Report.new("apply").host.should == "mynode"
15
15
  end
16
16
 
17
17
  it "should return its host name as its name" do
@@ -87,13 +87,19 @@ describe Puppet::Transaction do
87
87
  @transaction.should_not be_any_failed
88
88
  end
89
89
 
90
- it "should be possible to replace the report object" do
90
+ it "should use the provided report object" do
91
91
  report = Puppet::Transaction::Report.new("apply")
92
- @transaction.report = report
92
+ @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new, report)
93
93
 
94
94
  @transaction.report.should == report
95
95
  end
96
96
 
97
+ it "should create a report if none is provided" do
98
+ @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new)
99
+
100
+ @transaction.report.should be_kind_of Puppet::Transaction::Report
101
+ end
102
+
97
103
  describe "when initializing" do
98
104
  it "should create an event manager" do
99
105
  @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new)
@@ -168,6 +168,25 @@ describe Puppet::Type.type(:file) do
168
168
  reqs[0].target.must == file
169
169
  end
170
170
 
171
+ it "should autorequire its nearest ancestor directory" do
172
+ file = Puppet::Type::File.new(:path => "/foo/bar/baz")
173
+ dir = Puppet::Type::File.new(:path => "/foo")
174
+ root = Puppet::Type::File.new(:path => "/")
175
+ @catalog.add_resource file
176
+ @catalog.add_resource dir
177
+ @catalog.add_resource root
178
+ reqs = file.autorequire
179
+ reqs.length.must == 1
180
+ reqs[0].source.must == dir
181
+ reqs[0].target.must == file
182
+ end
183
+
184
+ it "should not autorequire anything when there is no nearest ancestor directory" do
185
+ file = Puppet::Type::File.new(:path => "/foo/bar/baz")
186
+ @catalog.add_resource file
187
+ file.autorequire.should be_empty
188
+ end
189
+
171
190
  it "should not autorequire its parent dir if its parent dir is itself" do
172
191
  file = Puppet::Type::File.new(:path => "/")
173
192
  @catalog.add_resource file
@@ -241,6 +260,25 @@ describe Puppet::Type.type(:file) do
241
260
  reqs[0].target.must == file
242
261
  end
243
262
 
263
+ it "should autorequire its nearest ancestor directory" do
264
+ file = Puppet::Type::File.new(:path => "X:/foo/bar/baz")
265
+ dir = Puppet::Type::File.new(:path => "X:/foo")
266
+ root = Puppet::Type::File.new(:path => "X:/")
267
+ @catalog.add_resource file
268
+ @catalog.add_resource dir
269
+ @catalog.add_resource root
270
+ reqs = file.autorequire
271
+ reqs.length.must == 1
272
+ reqs[0].source.must == dir
273
+ reqs[0].target.must == file
274
+ end
275
+
276
+ it "should not autorequire anything when there is no nearest ancestor directory" do
277
+ file = Puppet::Type::File.new(:path => "X:/foo/bar/baz")
278
+ @catalog.add_resource file
279
+ file.autorequire.should be_empty
280
+ end
281
+
244
282
  it "should not autorequire its parent dir if its parent dir is itself" do
245
283
  file = Puppet::Type::File.new(:path => "X:/")
246
284
  @catalog.add_resource file
@@ -302,6 +340,25 @@ describe Puppet::Type.type(:file) do
302
340
  reqs[0].target.must == file
303
341
  end
304
342
 
343
+ it "should autorequire its nearest ancestor directory" do
344
+ file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux")
345
+ dir = Puppet::Type::File.new(:path => "//server/foo/bar")
346
+ root = Puppet::Type::File.new(:path => "//server/foo")
347
+ @catalog.add_resource file
348
+ @catalog.add_resource dir
349
+ @catalog.add_resource root
350
+ reqs = file.autorequire
351
+ reqs.length.must == 1
352
+ reqs[0].source.must == dir
353
+ reqs[0].target.must == file
354
+ end
355
+
356
+ it "should not autorequire anything when there is no nearest ancestor directory" do
357
+ file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux")
358
+ @catalog.add_resource file
359
+ file.autorequire.should be_empty
360
+ end
361
+
305
362
  it "should not autorequire its parent dir if its parent dir is itself" do
306
363
  file = Puppet::Type::File.new(:path => "//server/foo")
307
364
  @catalog.add_resource file
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env rspec
2
-
3
- require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'spec_helper'
4
3
 
5
4
  describe Puppet::Type.type(:interface) do
6
5
 
@@ -3,10 +3,6 @@ require 'spec_helper'
3
3
 
4
4
  module ScheduleTesting
5
5
 
6
- def format(time)
7
- time.strftime("%H:%M:%S")
8
- end
9
-
10
6
  def diff(unit, incr, method, count)
11
7
  diff = Time.now.to_i.send(method, incr * count)
12
8
  Time.at(diff)
@@ -54,7 +50,7 @@ describe Puppet::Type.type(:schedule) do
54
50
 
55
51
  it "should never match when the period is :never" do
56
52
  @schedule[:period] = :never
57
- @schedule.match?.should be_false
53
+ @schedule.should_not be_match
58
54
  end
59
55
  end
60
56
 
@@ -80,19 +76,44 @@ describe Puppet::Type.type(:schedule) do
80
76
  describe Puppet::Type.type(:schedule), "when matching ranges" do
81
77
  include ScheduleTesting
82
78
 
79
+ before do
80
+ Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0))
81
+ end
82
+
83
83
  it "should match when the start time is before the current time and the end time is after the current time" do
84
- @schedule[:range] = "#{format(Time.now - 10)} - #{format(Time.now + 10)}"
85
- @schedule.match?.should be_true
84
+ @schedule[:range] = "10:59:50 - 11:00:10"
85
+ @schedule.should be_match
86
86
  end
87
87
 
88
88
  it "should not match when the start time is after the current time" do
89
- @schedule[:range] = "#{format(Time.now + 5)} - #{format(Time.now + 10)}"
90
- @schedule.match?.should be_false
89
+ @schedule[:range] = "11:00:05 - 11:00:10"
90
+ @schedule.should_not be_match
91
91
  end
92
92
 
93
93
  it "should not match when the end time is previous to the current time" do
94
- @schedule[:range] = "#{format(Time.now - 10)} - #{format(Time.now - 5)}"
95
- @schedule.match?.should be_false
94
+ @schedule[:range] = "10:59:50 - 10:59:55"
95
+ @schedule.should be_match
96
+ end
97
+
98
+ it "should throw an error if the upper limit is less than the lower limit" do
99
+ pending "bug #7639"
100
+ @schedule[:range] = "01:02:03 - 01:00:00"
101
+ @schedule.should_throw Puppet::Error
102
+ end
103
+
104
+ it "should not match the current time fails between an array of ranges" do
105
+ @schedule[:range] = ["4-6", "20-23"]
106
+ @schedule.should_not be_match
107
+ end
108
+
109
+ it "should match the lower array of ranges" do
110
+ @schedule[:range] = ["9-11", "14-16"]
111
+ @schedule.should be_match
112
+ end
113
+
114
+ it "should match the upper array of ranges" do
115
+ @schedule[:range] = ["4-6", "11-12"]
116
+ @schedule.should be_match
96
117
  end
97
118
  end
98
119
 
@@ -102,18 +123,20 @@ describe Puppet::Type.type(:schedule) do
102
123
  before do
103
124
  @schedule[:period] = :hourly
104
125
  @schedule[:periodmatch] = :distance
126
+
127
+ Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0))
105
128
  end
106
129
 
107
- it "should match an hour ago" do
108
- @schedule.match?(hour("-", 1)).should be_true
130
+ it "should match when the previous time was an hour ago" do
131
+ @schedule.should be_match(hour("-", 1))
109
132
  end
110
133
 
111
- it "should not match now" do
112
- @schedule.match?(Time.now).should be_false
134
+ it "should not match when the previous time was now" do
135
+ @schedule.should_not be_match(Time.now)
113
136
  end
114
137
 
115
- it "should not match 59 minutes ago" do
116
- @schedule.match?(min("-", 59)).should be_false
138
+ it "should not match when the previous time was 59 minutes ago" do
139
+ @schedule.should_not be_match(min("-", 59))
117
140
  end
118
141
  end
119
142
 
@@ -123,18 +146,20 @@ describe Puppet::Type.type(:schedule) do
123
146
  before do
124
147
  @schedule[:period] = :daily
125
148
  @schedule[:periodmatch] = :distance
149
+
150
+ Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0))
126
151
  end
127
152
 
128
153
  it "should match when the previous time was one day ago" do
129
- @schedule.match?(day("-", 1)).should be_true
154
+ @schedule.should be_match(day("-", 1))
130
155
  end
131
156
 
132
157
  it "should not match when the previous time is now" do
133
- @schedule.match?(Time.now).should be_false
158
+ @schedule.should_not be_match(Time.now)
134
159
  end
135
160
 
136
161
  it "should not match when the previous time was 23 hours ago" do
137
- @schedule.match?(hour("-", 23)).should be_false
162
+ @schedule.should_not be_match(hour("-", 23))
138
163
  end
139
164
  end
140
165
 
@@ -144,18 +169,20 @@ describe Puppet::Type.type(:schedule) do
144
169
  before do
145
170
  @schedule[:period] = :weekly
146
171
  @schedule[:periodmatch] = :distance
172
+
173
+ Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0))
147
174
  end
148
175
 
149
- it "should match seven days ago" do
150
- @schedule.match?(day("-", 7)).should be_true
176
+ it "should match when the previous time was seven days ago" do
177
+ @schedule.should be_match(day("-", 7))
151
178
  end
152
179
 
153
- it "should not match now" do
154
- @schedule.match?(Time.now).should be_false
180
+ it "should not match when the previous time was now" do
181
+ @schedule.should be_match(Time.now)
155
182
  end
156
183
 
157
- it "should not match six days ago" do
158
- @schedule.match?(day("-", 6)).should be_false
184
+ it "should not match when the previous time was six days ago" do
185
+ @schedule.should_not be_match(day("-", 6))
159
186
  end
160
187
  end
161
188
 
@@ -165,18 +192,20 @@ describe Puppet::Type.type(:schedule) do
165
192
  before do
166
193
  @schedule[:period] = :monthly
167
194
  @schedule[:periodmatch] = :distance
195
+
196
+ Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0))
168
197
  end
169
198
 
170
- it "should match 32 days ago" do
171
- @schedule.match?(day("-", 32)).should be_true
199
+ it "should match when the previous time was 32 days ago" do
200
+ @schedule.should be_match(day("-", 32))
172
201
  end
173
202
 
174
- it "should not match now" do
175
- @schedule.match?(Time.now).should be_false
203
+ it "should not match when the previous time was now" do
204
+ @schedule.should_not be_match(Time.now)
176
205
  end
177
206
 
178
- it "should not match 27 days ago" do
179
- @schedule.match?(day("-", 27)).should be_false
207
+ it "should not match when the previous time was 27 days ago" do
208
+ @schedule.should_not be_match(day("-", 27))
180
209
  end
181
210
  end
182
211
 
@@ -193,7 +222,7 @@ describe Puppet::Type.type(:schedule) do
193
222
  previous = Time.utc(2007, 12, 31, 23, 59, 0)
194
223
 
195
224
  Time.stubs(:now).returns(current)
196
- @schedule.match?(previous).should be_true
225
+ @schedule.should be_match(previous)
197
226
  end
198
227
 
199
228
  it "should not match if the times are 59 minutes apart and the current minute is 59" do
@@ -201,7 +230,7 @@ describe Puppet::Type.type(:schedule) do
201
230
  previous = Time.utc(2009, 2, 1, 12, 0, 0)
202
231
 
203
232
  Time.stubs(:now).returns(current)
204
- @schedule.match?(previous).should be_false
233
+ @schedule.should_not be_match(previous)
205
234
  end
206
235
  end
207
236
 
@@ -220,7 +249,7 @@ describe Puppet::Type.type(:schedule) do
220
249
  previous = current - 60
221
250
 
222
251
  Time.stubs(:now).returns(current)
223
- @schedule.match?(previous).should be_true
252
+ @schedule.should be_match(previous)
224
253
  end
225
254
 
226
255
  it "should not match if the times are 23 hours and 58 minutes apart and the current hour is 23 and the current minute is 59" do
@@ -232,7 +261,7 @@ describe Puppet::Type.type(:schedule) do
232
261
  now = previous + (23 * 3600) + (59 * 60)
233
262
 
234
263
  Time.stubs(:now).returns(now)
235
- @schedule.match?(previous).should be_false
264
+ @schedule.should_not be_match(previous)
236
265
  end
237
266
  end
238
267
 
@@ -249,7 +278,7 @@ describe Puppet::Type.type(:schedule) do
249
278
  Time.stubs(:now).returns(now)
250
279
  previous = Time.utc(2010, "nov", 6, 23, 59, 59) # Sat
251
280
 
252
- @schedule.match?(previous).should be_true
281
+ @schedule.should be_match(previous)
253
282
  end
254
283
 
255
284
  it "should not match if the previous time is after the most recent Saturday" do
@@ -257,7 +286,7 @@ describe Puppet::Type.type(:schedule) do
257
286
  Time.stubs(:now).returns(now)
258
287
  previous = Time.utc(2010, "nov", 7, 0, 0, 0) # Sunday
259
288
 
260
- @schedule.match?(previous).should be_false
289
+ @schedule.should_not be_match(previous)
261
290
  end
262
291
  end
263
292
 
@@ -274,7 +303,7 @@ describe Puppet::Type.type(:schedule) do
274
303
  Time.stubs(:now).returns(now)
275
304
  previous = Time.utc(2010, "oct", 31, 23, 59, 59)
276
305
 
277
- @schedule.match?(previous).should be_true
306
+ @schedule.should be_match(previous)
278
307
  end
279
308
 
280
309
  it "should not match when the previous time is after the last day of last month" do
@@ -282,7 +311,7 @@ describe Puppet::Type.type(:schedule) do
282
311
  Time.stubs(:now).returns(now)
283
312
  previous = Time.utc(2010, "nov", 1, 0, 0, 0)
284
313
 
285
- @schedule.match?(previous).should be_false
314
+ @schedule.should_not be_match(previous)
286
315
  end
287
316
  end
288
317
 
@@ -292,6 +321,8 @@ describe Puppet::Type.type(:schedule) do
292
321
  before do
293
322
  @schedule[:period] = :daily
294
323
  @schedule[:repeat] = 2
324
+
325
+ Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 0, 0))
295
326
  end
296
327
 
297
328
  it "should fail if the periodmatch is 'number'" do
@@ -301,12 +332,12 @@ describe Puppet::Type.type(:schedule) do
301
332
 
302
333
  it "should match if the previous run was further away than the distance divided by the repeat" do
303
334
  previous = Time.now - (3600 * 13)
304
- @schedule.match?(previous).should be_true
335
+ @schedule.should be_match(previous)
305
336
  end
306
337
 
307
338
  it "should not match if the previous run was closer than the distance divided by the repeat" do
308
339
  previous = Time.now - (3600 * 11)
309
- @schedule.match?(previous).should be_false
340
+ @schedule.should_not be_match(previous)
310
341
  end
311
342
  end
312
343
  end