serverspec 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.swp
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
@@ -145,6 +145,25 @@ module Serverspec
145
145
  end
146
146
  end
147
147
 
148
+ def check_routing_table(example, expected_attr)
149
+ @example = example
150
+ return false if ! expected_attr[:destination]
151
+ ret = run_command(commands.check_routing_table(expected_attr[:destination]))
152
+ return false if ret[:exit_status] != 0
153
+
154
+ ret[:stdout] =~ /^(\S+)(?: via (\S+))? dev (\S+).+\r\n(?:default via (\S+))?/
155
+ actual_attr = {
156
+ :destination => $1,
157
+ :gateway => $2 ? $2 : $4,
158
+ :interface => expected_attr[:interface] ? $3 : nil
159
+ }
160
+
161
+ expected_attr.each do |key, val|
162
+ return false if actual_attr[key] != val
163
+ end
164
+ true
165
+ end
166
+
148
167
  def check_os
149
168
  if run_command('ls /etc/redhat-release')[:exit_status] == 0
150
169
  'RedHat'
@@ -18,6 +18,10 @@ module Serverspec
18
18
  "mount | grep -w -- #{escape(regexp)}"
19
19
  end
20
20
 
21
+ def check_routing_table destination
22
+ "ip route | grep -E '^#{destination} |^default '"
23
+ end
24
+
21
25
  def check_reachable host, port, proto, timeout
22
26
  if port.nil?
23
27
  "ping -n #{escape(host)} -w #{escape(timeout)} -c 2"
@@ -3,6 +3,7 @@ require 'serverspec/matchers/be_resolvable'
3
3
  require 'serverspec/matchers/be_enabled'
4
4
  require 'serverspec/matchers/be_file'
5
5
  require 'serverspec/matchers/be_reachable'
6
+ require 'serverspec/matchers/be_default_gateway'
6
7
  require 'serverspec/matchers/be_directory'
7
8
  require 'serverspec/matchers/be_installed'
8
9
  require 'serverspec/matchers/be_listening'
@@ -13,6 +14,7 @@ require 'serverspec/matchers/be_group'
13
14
  require 'serverspec/matchers/be_mode'
14
15
  require 'serverspec/matchers/be_owned_by'
15
16
  require 'serverspec/matchers/be_grouped_into'
17
+ require 'serverspec/matchers/have_entry'
16
18
  require 'serverspec/matchers/have_cron_entry'
17
19
  require 'serverspec/matchers/be_linked_to'
18
20
  require 'serverspec/matchers/be_installed_by_gem'
@@ -0,0 +1,15 @@
1
+ RSpec::Matchers.define :be_default_gateway do
2
+ match do |ip_address|
3
+ backend.check_routing_table(
4
+ example,
5
+ {
6
+ :destination => 'default',
7
+ :gateway => ip_address,
8
+ :interface => @interface
9
+ }
10
+ )
11
+ end
12
+ chain :with_interface do |interface|
13
+ @interface = interface
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :have_entry do |attr|
2
+ match do |subject|
3
+ backend.check_routing_table(example, attr)
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -25,6 +25,11 @@ describe 'check_reachable', :os => :darwin do
25
25
  end
26
26
  end
27
27
 
28
+ describe 'check_routing_table', :os => :darwin do
29
+ subject { commands.check_routing_table('192.168.100.0/24') }
30
+ it { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" }
31
+ end
32
+
28
33
  describe 'check_resolvable', :os => :darwin do
29
34
  context "resolve localhost by hosts" do
30
35
  subject { commands.check_resolvable('localhost', 'hosts') }
@@ -79,4 +79,7 @@ describe 'Serverspec matchers of Darwin', :os => :darwin do
79
79
  it_behaves_like 'support linux kernel parameter checking with integer', 'net.ipv4.tcp_syncookies', 1
80
80
  it_behaves_like 'support linux kernel parameter checking with string', 'kernel.osrelease', '2.6.32-131.0.15.el6.x86_64'
81
81
  it_behaves_like 'support linux kernel parameter checking with regexp', 'net.ipv4.tcp_wmem', /4096\t16384\t4194304/
82
+
83
+ it_behaves_like 'support have_entry matcher'
84
+ it_behaves_like 'support be_default_gateway matcher'
82
85
  end
@@ -15,6 +15,11 @@ describe 'check_mounted', :os => :debian do
15
15
  it { should eq "mount | grep -w -- on\\ /" }
16
16
  end
17
17
 
18
+ describe 'check_routing_table', :os => :debian do
19
+ subject { commands.check_routing_table('192.168.100.0/24') }
20
+ it { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" }
21
+ end
22
+
18
23
  describe 'check_reachable', :os => :debian do
19
24
  context "connect with name from /etc/services to localhost" do
20
25
  subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
@@ -82,4 +82,7 @@ describe 'Serverspec matchers of Debian family', :os => :debian do
82
82
  it_behaves_like 'support linux kernel parameter checking with integer', 'net.ipv4.tcp_syncookies', 1
83
83
  it_behaves_like 'support linux kernel parameter checking with string', 'kernel.osrelease', '2.6.32-131.0.15.el6.x86_64'
84
84
  it_behaves_like 'support linux kernel parameter checking with regexp', 'net.ipv4.tcp_wmem', /4096\t16384\t4194304/
85
+
86
+ it_behaves_like 'support have_entry matcher'
87
+ it_behaves_like 'support be_default_gateway matcher'
85
88
  end
@@ -15,6 +15,11 @@ describe 'check_mounted', :os => :gentoo do
15
15
  it { should eq "mount | grep -w -- on\\ /" }
16
16
  end
17
17
 
18
+ describe 'check_routing_table', :os => :gentoo do
19
+ subject { commands.check_routing_table('192.168.100.0/24') }
20
+ it { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" }
21
+ end
22
+
18
23
  describe 'check_reachable', :os => :gentoo do
19
24
  context "connect with name from /etc/services to localhost" do
20
25
  subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
@@ -83,4 +83,7 @@ describe 'Serverspec matchers of Gentoo family', :os => :gentoo do
83
83
  it_behaves_like 'support linux kernel parameter checking with integer', 'net.ipv4.tcp_syncookies', 1
84
84
  it_behaves_like 'support linux kernel parameter checking with string', 'kernel.osrelease', '2.6.32-131.0.15.el6.x86_64'
85
85
  it_behaves_like 'support linux kernel parameter checking with regexp', 'net.ipv4.tcp_wmem', /4096\t16384\t4194304/
86
+
87
+ it_behaves_like 'support have_entry matcher'
88
+ it_behaves_like 'support be_default_gateway matcher'
86
89
  end
@@ -15,6 +15,11 @@ describe 'check_mounted', :os => :redhat do
15
15
  it { should eq "mount | grep -w -- on\\ /" }
16
16
  end
17
17
 
18
+ describe 'check_routing_table', :os => :redhat do
19
+ subject { commands.check_routing_table('192.168.100.0/24') }
20
+ it { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" }
21
+ end
22
+
18
23
  describe 'check_reachable', :os => :redhat do
19
24
  context "connect with name from /etc/services to localhost" do
20
25
  subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
@@ -88,4 +88,7 @@ describe 'Serverspec matchers of Red Hat family', :os => :redhat do
88
88
  it_behaves_like 'support linux kernel parameter checking with integer', 'net.ipv4.tcp_syncookies', 1
89
89
  it_behaves_like 'support linux kernel parameter checking with string', 'kernel.osrelease', '2.6.32-131.0.15.el6.x86_64'
90
90
  it_behaves_like 'support linux kernel parameter checking with regexp', 'net.ipv4.tcp_wmem', /4096\t16384\t4194304/
91
+
92
+ it_behaves_like 'support have_entry matcher'
93
+ it_behaves_like 'support be_default_gateway matcher'
91
94
  end
@@ -15,6 +15,11 @@ describe 'check_mounted', :os => :solaris do
15
15
  it { should eq "mount | grep -w -- on\\ /" }
16
16
  end
17
17
 
18
+ describe 'check_routing_table', :os => :solaris do
19
+ subject { commands.check_routing_table('192.168.100.0/24') }
20
+ it { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" }
21
+ end
22
+
18
23
  describe 'check_reachable', :os => :solaris do
19
24
  context "connect with name from /etc/services to localhost" do
20
25
  subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
@@ -82,4 +82,7 @@ describe 'Serverspec matchers of Solaris family', :os => :solaris do
82
82
 
83
83
  it_behaves_like 'support return_stderr matcher', 'cat /foo', 'cat: /foo: No such file or directory'
84
84
  it_behaves_like 'support return_stderr matcher with regexp', 'cat /foo', /No such file or directory/
85
+
86
+ it_behaves_like 'support have_entry matcher'
87
+ it_behaves_like 'support be_default_gateway matcher'
85
88
  end
@@ -253,6 +253,159 @@ shared_examples_for 'support be_mounted.only_with matcher' do |valid_mount|
253
253
  end
254
254
 
255
255
 
256
+ shared_examples_for 'support be_default_gateway matcher' do
257
+ describe 'be_default_gateway' do
258
+ before :all do
259
+ RSpec.configure do |c|
260
+ c.stdout = "default via 192.168.1.1 dev eth1 \r\n"
261
+ end
262
+ end
263
+
264
+ describe '192.168.1.1' do
265
+ it { should be_default_gateway }
266
+ it { should be_default_gateway.with_interface('eth1') }
267
+ it { should_not be_default_gateway.with_interface('eth0') }
268
+ end
269
+
270
+ describe '192.168.1.100' do
271
+ it { should_not be_default_gateway }
272
+ it { should_not be_default_gateway.with_interface('eth1') }
273
+ end
274
+ end
275
+ end
276
+
277
+ shared_examples_for 'support have_entry matcher' do
278
+ describe 'have_entry' do
279
+ before :all do
280
+ RSpec.configure do |c|
281
+ c.stdout = "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n"
282
+ end
283
+ end
284
+
285
+ describe 'routing table' do
286
+ it { should have_entry( :destination => '192.168.100.0/24' ) }
287
+ it { should_not have_entry( :destination => '192.168.100.100/24' ) }
288
+
289
+ it do
290
+ should have_entry(
291
+ :destination => '192.168.100.0/24',
292
+ :gateway => '192.168.100.1'
293
+ )
294
+ end
295
+
296
+ it do
297
+ should have_entry(
298
+ :destination => '192.168.100.0/24',
299
+ :gateway => '192.168.100.1',
300
+ :interface => 'eth1'
301
+ )
302
+ end
303
+
304
+ it do
305
+ should_not have_entry(
306
+ :gateway => '192.168.100.1',
307
+ :interface => 'eth1'
308
+ )
309
+ end
310
+
311
+ it do
312
+ should_not have_entry(
313
+ :destination => '192.168.100.0/32',
314
+ :gateway => '192.168.100.1',
315
+ :interface => 'eth1'
316
+ )
317
+ end
318
+ end
319
+ end
320
+
321
+ describe 'have_entry' do
322
+ before :all do
323
+ RSpec.configure do |c|
324
+ c.stdout = "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n"
325
+ end
326
+ end
327
+
328
+ describe 'routing table' do
329
+ it { should have_entry( :destination => '192.168.200.0/24' ) }
330
+ it { should_not have_entry( :destination => '192.168.200.200/24' ) }
331
+
332
+ it do
333
+ should have_entry(
334
+ :destination => '192.168.200.0/24',
335
+ :gateway => '192.168.200.1'
336
+ )
337
+ end
338
+
339
+ it do
340
+ should have_entry(
341
+ :destination => '192.168.200.0/24',
342
+ :gateway => '192.168.200.1',
343
+ :interface => 'eth0'
344
+ )
345
+ end
346
+
347
+ it do
348
+ should_not have_entry(
349
+ :gateway => '192.168.200.1',
350
+ :interface => 'eth0'
351
+ )
352
+ end
353
+
354
+ it do
355
+ should_not have_entry(
356
+ :destination => '192.168.200.0/32',
357
+ :gateway => '192.168.200.1',
358
+ :interface => 'eth0'
359
+ )
360
+ end
361
+ end
362
+ end
363
+
364
+ describe 'have_entry' do
365
+ before :all do
366
+ RSpec.configure do |c|
367
+ c.stdout = "default via 10.0.2.2 dev eth0 \r\n"
368
+ end
369
+ end
370
+
371
+ describe 'routing table' do
372
+ it { should have_entry( :destination => 'default' ) }
373
+ it { should_not have_entry( :destination => 'defaulth' ) }
374
+
375
+ it do
376
+ should have_entry(
377
+ :destination => 'default',
378
+ :gateway => '10.0.2.2'
379
+ )
380
+ end
381
+
382
+ it do
383
+ should have_entry(
384
+ :destination => 'default',
385
+ :gateway => '10.0.2.2',
386
+ :interface => 'eth0'
387
+ )
388
+ end
389
+
390
+ it do
391
+ should_not have_entry(
392
+ :gateway => '10.0.2.2',
393
+ :interface => 'eth0'
394
+ )
395
+ end
396
+
397
+ it do
398
+ should_not have_entry(
399
+ :destination => 'default',
400
+ :gateway => '10.0.2.1',
401
+ :interface => 'eth0'
402
+ )
403
+ end
404
+ end
405
+ end
406
+ end
407
+
408
+
256
409
  shared_examples_for 'support be_resolvable matcher' do |valid_name|
257
410
  describe 'be_resolvable' do
258
411
  describe valid_name do
metadata CHANGED
@@ -1,105 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Gosuke Miyashita
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-05-13 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-05-14 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: net-ssh
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- requirement: !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
33
25
  none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
38
33
  type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
39
37
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: highline
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
49
39
  none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
54
47
  type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: highline
55
51
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
57
53
  none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
63
64
  name: bundler
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: '1.3'
70
- type: :development
71
65
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
66
+ requirement: &id004 !ruby/object:Gem::Requirement
73
67
  none: false
74
- requirements:
68
+ requirements:
75
69
  - - ~>
76
- - !ruby/object:Gem::Version
77
- version: '1.3'
78
- - !ruby/object:Gem::Dependency
79
- name: rake
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
70
+ - !ruby/object:Gem::Version
71
+ hash: 9
72
+ segments:
73
+ - 1
74
+ - 3
75
+ version: "1.3"
86
76
  type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
87
80
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
81
+ requirement: &id005 !ruby/object:Gem::Requirement
89
82
  none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- description: RSpec tests for your servers provisioned by Puppet, Chef or anything
95
- else
96
- email:
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ description: RSpec tests for your servers provisioned by Puppet, Chef or anything else
93
+ email:
97
94
  - gosukenator@gmail.com
98
- executables:
95
+ executables:
99
96
  - serverspec-init
100
97
  extensions: []
98
+
101
99
  extra_rdoc_files: []
102
- files:
100
+
101
+ files:
103
102
  - .gitignore
104
103
  - .travis.yml
105
104
  - Gemfile
@@ -134,6 +133,7 @@ files:
134
133
  - lib/serverspec/helper/solaris.rb
135
134
  - lib/serverspec/helper/ssh.rb
136
135
  - lib/serverspec/matchers.rb
136
+ - lib/serverspec/matchers/be_default_gateway.rb
137
137
  - lib/serverspec/matchers/be_directory.rb
138
138
  - lib/serverspec/matchers/be_disabled.rb
139
139
  - lib/serverspec/matchers/be_enabled.rb
@@ -162,6 +162,7 @@ files:
162
162
  - lib/serverspec/matchers/get_stdout.rb
163
163
  - lib/serverspec/matchers/have_authorized_key.rb
164
164
  - lib/serverspec/matchers/have_cron_entry.rb
165
+ - lib/serverspec/matchers/have_entry.rb
165
166
  - lib/serverspec/matchers/have_gid.rb
166
167
  - lib/serverspec/matchers/have_home_directory.rb
167
168
  - lib/serverspec/matchers/have_ipfilter_rule.rb
@@ -192,32 +193,41 @@ files:
192
193
  - spec/solaris/matchers_spec.rb
193
194
  - spec/spec_helper.rb
194
195
  - spec/support/shared_matcher_examples.rb
196
+ has_rdoc: true
195
197
  homepage: http://serverspec.org/
196
- licenses:
198
+ licenses:
197
199
  - MIT
198
200
  post_install_message:
199
201
  rdoc_options: []
200
- require_paths:
202
+
203
+ require_paths:
201
204
  - lib
202
- required_ruby_version: !ruby/object:Gem::Requirement
205
+ required_ruby_version: !ruby/object:Gem::Requirement
203
206
  none: false
204
- requirements:
205
- - - ! '>='
206
- - !ruby/object:Gem::Version
207
- version: '0'
208
- required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ hash: 3
211
+ segments:
212
+ - 0
213
+ version: "0"
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
215
  none: false
210
- requirements:
211
- - - ! '>='
212
- - !ruby/object:Gem::Version
213
- version: '0'
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ hash: 3
220
+ segments:
221
+ - 0
222
+ version: "0"
214
223
  requirements: []
224
+
215
225
  rubyforge_project:
216
- rubygems_version: 1.8.25
226
+ rubygems_version: 1.3.7
217
227
  signing_key:
218
228
  specification_version: 3
219
229
  summary: RSpec tests for your servers provisioned by Puppet, Chef or anything else
220
- test_files:
230
+ test_files:
221
231
  - spec/darwin/commands_spec.rb
222
232
  - spec/darwin/matchers_spec.rb
223
233
  - spec/debian/commands_spec.rb