serverspec 0.2.21 → 0.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,14 @@ module Serverspec
11
11
  "mount | grep -w 'on #{path}'"
12
12
  end
13
13
 
14
+ def check_reachable host, port, proto, timeout
15
+ if port.nil?
16
+ "ping -n #{host} -w #{timeout} -c 2"
17
+ else
18
+ "nc -vvvvz#{proto[0].chr} #{host} #{port} -w #{timeout}"
19
+ end
20
+ end
21
+
14
22
  def check_resolvable name, type
15
23
  if type == "dns"
16
24
  "nslookup -timeout=1 #{name}"
@@ -2,6 +2,7 @@ require 'serverspec/matchers/be_mounted'
2
2
  require 'serverspec/matchers/be_resolvable'
3
3
  require 'serverspec/matchers/be_enabled'
4
4
  require 'serverspec/matchers/be_file'
5
+ require 'serverspec/matchers/be_reachable'
5
6
  require 'serverspec/matchers/be_directory'
6
7
  require 'serverspec/matchers/be_installed'
7
8
  require 'serverspec/matchers/be_listening'
@@ -0,0 +1,16 @@
1
+ RSpec::Matchers.define :be_reachable do
2
+ match do |host|
3
+ proto = 'tcp'
4
+ timeout = 5
5
+ if @attr
6
+ port = @attr[:port]
7
+ proto = @attr[:proto] if @attr[:proto]
8
+ timeout = @attr[:timeout] if @attr[:timeout]
9
+ end
10
+
11
+ backend.check_reachable(example, host, port, proto, timeout)
12
+ end
13
+ chain :with do |attr|
14
+ @attr = attr
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.2.21"
2
+ VERSION = "0.2.22"
3
3
  end
@@ -15,6 +15,21 @@ describe 'check_mounted', :os => :debian do
15
15
  it { should eq "mount | grep -w 'on /'" }
16
16
  end
17
17
 
18
+ describe 'check_reachable', :os => :debian do
19
+ context "connect with name from /etc/services to localhost" do
20
+ subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
21
+ it { should eq "nc -vvvvzt localhost ssh -w 1" }
22
+ end
23
+ context "connect with ip and port 11111 and timeout of 5" do
24
+ subject { commands.check_reachable('127.0.0.1', '11111', 'udp', 5) }
25
+ it { should eq "nc -vvvvzu 127.0.0.1 11111 -w 5" }
26
+ end
27
+ context "do a ping" do
28
+ subject { commands.check_reachable('127.0.0.1', nil, 'icmp', 1) }
29
+ it { should eq "ping -n 127.0.0.1 -w 1 -c 2" }
30
+ end
31
+ end
32
+
18
33
  describe 'check_resolvable', :os => :debian do
19
34
  context "resolve localhost by hosts" do
20
35
  subject { commands.check_resolvable('localhost', 'hosts') }
@@ -12,6 +12,9 @@ describe 'Serverspec matchers of Debian family', :os => :debian do
12
12
  it_behaves_like 'support be_mounted.with matcher', '/'
13
13
  it_behaves_like 'support be_mounted.only_with matcher', '/'
14
14
 
15
+ it_behaves_like 'support be_reachable matcher', '127.0.0.1:11111', '1.1.1.1:ssh'
16
+ it_behaves_like 'support be_reachable.with matcher', '127.0.0.1:11111', '1.1.1.1:ssh'
17
+
15
18
  it_behaves_like 'support be_resolvable matcher', 'localhost'
16
19
  it_behaves_like 'support be_resolvable.by matcher', 'localhost', 'hosts'
17
20
  it_behaves_like 'support be_resolvable.by matcher', 'localhost', 'dns'
@@ -10,12 +10,27 @@ describe 'check_file', :os => :gentoo do
10
10
  it { should eq 'test -f /etc/passwd' }
11
11
  end
12
12
 
13
- describe 'check_mounted', :os => :debian do
13
+ describe 'check_mounted', :os => :gentoo do
14
14
  subject { commands.check_mounted('/') }
15
15
  it { should eq "mount | grep -w 'on /'" }
16
16
  end
17
17
 
18
- describe 'check_resolvable', :os => :debian do
18
+ describe 'check_reachable', :os => :gentoo do
19
+ context "connect with name from /etc/services to localhost" do
20
+ subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
21
+ it { should eq "nc -vvvvzt localhost ssh -w 1" }
22
+ end
23
+ context "connect with ip and port 11111 and timeout of 5" do
24
+ subject { commands.check_reachable('127.0.0.1', '11111', 'udp' ,5) }
25
+ it { should eq "nc -vvvvzu 127.0.0.1 11111 -w 5" }
26
+ end
27
+ context "do a ping" do
28
+ subject { commands.check_reachable('127.0.0.1', nil, 'icmp', 1) }
29
+ it { should eq "ping -n 127.0.0.1 -w 1 -c 2" }
30
+ end
31
+ end
32
+
33
+ describe 'check_resolvable', :os => :gentoo do
19
34
  context "resolve localhost by hosts" do
20
35
  subject { commands.check_resolvable('localhost', 'hosts') }
21
36
  it { should eq "grep -w localhost /etc/hosts" }
@@ -12,6 +12,9 @@ describe 'Serverspec matchers of Gentoo family', :os => :gentoo do
12
12
  it_behaves_like 'support be_mounted.with matcher', '/'
13
13
  it_behaves_like 'support be_mounted.only_with matcher', '/'
14
14
 
15
+ it_behaves_like 'support be_reachable matcher', '127.0.0.1:11111', '1.1.1.1:ssh'
16
+ it_behaves_like 'support be_reachable.with matcher', '127.0.0.1:11111', '1.1.1.1:ssh'
17
+
15
18
  it_behaves_like 'support be_resolvable matcher', 'localhost'
16
19
  it_behaves_like 'support be_resolvable.by matcher', 'localhost', 'hosts'
17
20
  it_behaves_like 'support be_resolvable.by matcher', 'localhost', 'dns'
@@ -10,12 +10,27 @@ describe 'check_file', :os => :redhat do
10
10
  it { should eq 'test -f /etc/passwd' }
11
11
  end
12
12
 
13
- describe 'check_mounted', :os => :debian do
13
+ describe 'check_mounted', :os => :redhat do
14
14
  subject { commands.check_mounted('/') }
15
15
  it { should eq "mount | grep -w 'on /'" }
16
16
  end
17
17
 
18
- describe 'check_resolvable', :os => :debian do
18
+ describe 'check_reachable', :os => :redhat do
19
+ context "connect with name from /etc/services to localhost" do
20
+ subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
21
+ it { should eq "nc -vvvvzt localhost ssh -w 1" }
22
+ end
23
+ context "connect with ip and port 11111 and timeout of 5" do
24
+ subject { commands.check_reachable('127.0.0.1', '11111', 'udp', 5) }
25
+ it { should eq "nc -vvvvzu 127.0.0.1 11111 -w 5" }
26
+ end
27
+ context "do a ping" do
28
+ subject { commands.check_reachable('127.0.0.1', nil, 'icmp', 1) }
29
+ it { should eq "ping -n 127.0.0.1 -w 1 -c 2" }
30
+ end
31
+ end
32
+
33
+ describe 'check_resolvable', :os => :redhat do
19
34
  context "resolve localhost by hosts" do
20
35
  subject { commands.check_resolvable('localhost', 'hosts') }
21
36
  it { should eq "grep -w localhost /etc/hosts" }
@@ -13,6 +13,9 @@ describe 'Serverspec matchers of Red Hat family', :os => :redhat do
13
13
  it_behaves_like 'support be_mounted.with matcher', '/'
14
14
  it_behaves_like 'support be_mounted.only_with matcher', '/'
15
15
 
16
+ it_behaves_like 'support be_reachable matcher', '127.0.0.1:11111', '1.1.1.1:ssh'
17
+ it_behaves_like 'support be_reachable.with matcher', '127.0.0.1:11111', '1.1.1.1:ssh'
18
+
16
19
  it_behaves_like 'support be_resolvable matcher', 'localhost'
17
20
  it_behaves_like 'support be_resolvable.by matcher', 'localhost', 'hosts'
18
21
  it_behaves_like 'support be_resolvable.by matcher', 'localhost', 'dns'
@@ -10,12 +10,27 @@ describe 'check_file', :os => :solaris do
10
10
  it { should eq 'test -f /etc/passwd' }
11
11
  end
12
12
 
13
- describe 'check_mounted', :os => :debian do
13
+ describe 'check_mounted', :os => :solaris do
14
14
  subject { commands.check_mounted('/') }
15
15
  it { should eq "mount | grep -w 'on /'" }
16
16
  end
17
17
 
18
- describe 'check_resolvable', :os => :debian do
18
+ describe 'check_reachable', :os => :solaris do
19
+ context "connect with name from /etc/services to localhost" do
20
+ subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
21
+ it { should eq "nc -vvvvzt localhost ssh -w 1" }
22
+ end
23
+ context "connect with ip and port 11111 and timeout of 5" do
24
+ subject { commands.check_reachable('127.0.0.1', '11111', 'udp', 5) }
25
+ it { should eq "nc -vvvvzu 127.0.0.1 11111 -w 5" }
26
+ end
27
+ context "do a ping" do
28
+ subject { commands.check_reachable('127.0.0.1', nil, 'icmp', 1) }
29
+ it { should eq "ping -n 127.0.0.1 -w 1 -c 2" }
30
+ end
31
+ end
32
+
33
+ describe 'check_resolvable', :os => :solaris do
19
34
  context "resolve localhost by hosts" do
20
35
  subject { commands.check_resolvable('localhost', 'hosts') }
21
36
  it { should eq "grep -w localhost /etc/hosts" }
@@ -12,6 +12,9 @@ describe 'Serverspec matchers of Solaris family', :os => :solaris do
12
12
  it_behaves_like 'support be_mounted.with matcher', '/'
13
13
  it_behaves_like 'support be_mounted.only_with matcher', '/'
14
14
 
15
+ it_behaves_like 'support be_reachable matcher', '127.0.0.1:11111', '1.1.1.1:ssh'
16
+ it_behaves_like 'support be_reachable.with matcher', '127.0.0.1:11111', '1.1.1.1:ssh'
17
+
15
18
  it_behaves_like 'support be_resolvable matcher', 'localhost'
16
19
  it_behaves_like 'support be_resolvable.by matcher', 'localhost', 'hosts'
17
20
  it_behaves_like 'support be_resolvable.by matcher', 'localhost', 'dns'
@@ -94,6 +94,35 @@ shared_examples_for 'support be_listening matcher' do |valid_port|
94
94
  end
95
95
  end
96
96
 
97
+ shared_examples_for 'support be_reachable matcher' do |valid_host|
98
+ describe 'be_reachable' do
99
+ context valid_host do
100
+ it { should be_reachable }
101
+ end
102
+
103
+ describe 'invalid-host' do
104
+ it { should_not be_reachable }
105
+ end
106
+ end
107
+ end
108
+
109
+ shared_examples_for 'support be_reachable.with matcher' do |valid_host|
110
+ describe 'be_reachable.with' do
111
+ context valid_host do
112
+ it { should be_reachable.with(:proto => "icmp", :timeout=> 1) }
113
+ end
114
+ context valid_host do
115
+ it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) }
116
+ end
117
+ context valid_host do
118
+ it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) }
119
+ end
120
+ context 'invalid-host' do
121
+ it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) }
122
+ end
123
+ end
124
+ end
125
+
97
126
  shared_examples_for 'support be_mounted matcher' do |valid_mount|
98
127
  describe 'be_mounted' do
99
128
  describe valid_mount do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.21
4
+ version: 0.2.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-04 00:00:00.000000000 Z
12
+ date: 2013-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
@@ -145,6 +145,7 @@ files:
145
145
  - lib/serverspec/matchers/be_mounted.rb
146
146
  - lib/serverspec/matchers/be_owned_by.rb
147
147
  - lib/serverspec/matchers/be_permissive.rb
148
+ - lib/serverspec/matchers/be_reachable.rb
148
149
  - lib/serverspec/matchers/be_readable.rb
149
150
  - lib/serverspec/matchers/be_resolvable.rb
150
151
  - lib/serverspec/matchers/be_running.rb