serverspec 0.7.7 → 0.7.8
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.
- checksums.yaml +4 -4
- data/lib/serverspec/backend/ssh.rb +14 -4
- data/lib/serverspec/commands/base.rb +4 -0
- data/lib/serverspec/commands/linux.rb +11 -0
- data/lib/serverspec/configuration.rb +1 -1
- data/lib/serverspec/type/interface.rb +4 -0
- data/lib/serverspec/version.rb +1 -1
- data/spec/backend/ssh/build_command_spec.rb +39 -2
- data/spec/debian/interface_spec.rb +10 -0
- data/spec/gentoo/interface_spec.rb +10 -0
- data/spec/redhat/interface_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81dfca1b27052f6fde88b707a39a88b9aa6b2f2d
|
4
|
+
data.tar.gz: 89eb5ad29b3113ef22451c013a5160797551f74b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44674d6f99cacae928100c6abcb4101107721eb33ba53eea3b27c05d3d2889ed4cf37c3ceb383c4af163599b35f2e1bb4254b36a09fdc62d178e3a072100dce8
|
7
|
+
data.tar.gz: bd01d518d19c6f06a32c454aac243e9a70b562526e0da8102a992f3dbb95bae4119d00dc7659cf9b6e179c922f9dc8f1aaf6f862c8ec666d068b70a0439a85ab
|
@@ -19,9 +19,9 @@ module Serverspec
|
|
19
19
|
def build_command(cmd)
|
20
20
|
cmd = super(cmd)
|
21
21
|
if RSpec.configuration.ssh.options[:user] != 'root'
|
22
|
-
cmd = "sudo #{cmd}"
|
23
|
-
cmd.gsub!(/(\&\&\s*!?\(?\s*)/, "\\
|
24
|
-
cmd.gsub!(/(\|\|\s*!?\(?\s*)/, "\\
|
22
|
+
cmd = "#{sudo} #{cmd}"
|
23
|
+
cmd.gsub!(/(\&\&\s*!?\(?\s*)/, "\\1#{sudo} ")
|
24
|
+
cmd.gsub!(/(\|\|\s*!?\(?\s*)/, "\\1#{sudo} ")
|
25
25
|
end
|
26
26
|
cmd
|
27
27
|
end
|
@@ -31,7 +31,7 @@ module Serverspec
|
|
31
31
|
user = RSpec.configuration.ssh.options[:user]
|
32
32
|
pre_command = Serverspec.configuration.pre_command
|
33
33
|
if pre_command && user != 'root'
|
34
|
-
cmd = "sudo #{cmd}"
|
34
|
+
cmd = "#{sudo} #{cmd}"
|
35
35
|
end
|
36
36
|
cmd
|
37
37
|
end
|
@@ -75,6 +75,16 @@ module Serverspec
|
|
75
75
|
ssh.loop
|
76
76
|
{ :stdout => stdout_data, :stderr => stderr_data, :exit_status => exit_status, :exit_signal => exit_signal }
|
77
77
|
end
|
78
|
+
|
79
|
+
def sudo
|
80
|
+
sudo_path = Serverspec.configuration.sudo_path || RSpec.configuration.sudo_path
|
81
|
+
if sudo_path
|
82
|
+
"#{sudo_path}/sudo"
|
83
|
+
else
|
84
|
+
'sudo'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
78
88
|
end
|
79
89
|
end
|
80
90
|
end
|
@@ -32,6 +32,17 @@ module Serverspec
|
|
32
32
|
def get_interface_speed_of(name)
|
33
33
|
"ethtool #{name} | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\\/s/,\"\\\\1\",\"\")}'"
|
34
34
|
end
|
35
|
+
|
36
|
+
def check_ipv4_address(interface, ip_address)
|
37
|
+
ip_address = ip_address.dup
|
38
|
+
if ip_address =~ /\/\d+$/
|
39
|
+
ip_address << " "
|
40
|
+
else
|
41
|
+
ip_address << "/"
|
42
|
+
end
|
43
|
+
ip_address.gsub!(".", "\\.")
|
44
|
+
"ip addr show #{interface} | grep 'inet #{ip_address}'"
|
45
|
+
end
|
35
46
|
end
|
36
47
|
end
|
37
48
|
end
|
data/lib/serverspec/version.rb
CHANGED
@@ -8,8 +8,9 @@ ssh = double
|
|
8
8
|
describe 'build command with sudo' do
|
9
9
|
before :each do
|
10
10
|
RSpec.configure do |c|
|
11
|
-
ssh.stub(:options) { { :user => 'foo'
|
11
|
+
ssh.stub(:options) { { :user => 'foo' } }
|
12
12
|
c.ssh = ssh
|
13
|
+
c.sudo_path = nil
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -20,7 +21,7 @@ describe 'build command with sudo' do
|
|
20
21
|
|
21
22
|
context 'command pattern 2' do
|
22
23
|
subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
|
23
|
-
|
24
|
+
it { should eq 'sudo test ! -f /etc/selinux/config || (sudo getenforce | grep -i -- disabled && sudo grep -i -- ^SELINUX=disabled$ /etc/selinux/config)' }
|
24
25
|
end
|
25
26
|
|
26
27
|
context 'command pattern 3' do
|
@@ -28,3 +29,39 @@ describe 'build command with sudo' do
|
|
28
29
|
it { should eq "sudo dpkg -s apache2 && ! sudo dpkg -s apache2 | grep -E '^Status: .+ not-installed$'" }
|
29
30
|
end
|
30
31
|
end
|
32
|
+
|
33
|
+
# Alternate path for sudo command:
|
34
|
+
sudo_path = '/usr/local/bin'
|
35
|
+
|
36
|
+
describe 'build command with sudo on alternate path' do
|
37
|
+
before :each do
|
38
|
+
RSpec.configure do |c|
|
39
|
+
ssh.stub(:options) { { :user => 'foo' } }
|
40
|
+
c.ssh = ssh
|
41
|
+
c.sudo_path = "#{sudo_path}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
context 'command pattern 1a' do
|
47
|
+
subject { backend.build_command('test -f /etc/passwd') }
|
48
|
+
it { should eq "#{sudo_path}/sudo test -f /etc/passwd" }
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'command pattern 2a' do
|
52
|
+
subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
|
53
|
+
it { should eq "#{sudo_path}/sudo test ! -f /etc/selinux/config || (#{sudo_path}/sudo getenforce | grep -i -- disabled && #{sudo_path}/sudo grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'command pattern 3a' do
|
57
|
+
subject { backend.build_command("dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'") }
|
58
|
+
it { should eq "#{sudo_path}/sudo dpkg -s apache2 && ! #{sudo_path}/sudo dpkg -s apache2 | grep -E '^Status: .+ not-installed$'" }
|
59
|
+
end
|
60
|
+
|
61
|
+
after :each do
|
62
|
+
RSpec.configure do |c|
|
63
|
+
c.sudo_path = nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -8,6 +8,16 @@ describe interface('eth0') do
|
|
8
8
|
its(:command) { should eq "ethtool eth0 | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\/s/,\"\\\\1\",\"\")}'" }
|
9
9
|
end
|
10
10
|
|
11
|
+
describe interface('eth0') do
|
12
|
+
it { should have_ipv4_address("192.168.10.10") }
|
13
|
+
its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/'" }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe interface('eth0') do
|
17
|
+
it { should have_ipv4_address("192.168.10.10/24") }
|
18
|
+
its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/24 '" }
|
19
|
+
end
|
20
|
+
|
11
21
|
describe interface('invalid-interface') do
|
12
22
|
let(:stdout) { '1000' }
|
13
23
|
its(:speed) { should_not eq 100 }
|
@@ -8,6 +8,16 @@ describe interface('eth0') do
|
|
8
8
|
its(:command) { should eq "ethtool eth0 | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\/s/,\"\\\\1\",\"\")}'" }
|
9
9
|
end
|
10
10
|
|
11
|
+
describe interface('eth0') do
|
12
|
+
it { should have_ipv4_address("192.168.10.10") }
|
13
|
+
its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/'" }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe interface('eth0') do
|
17
|
+
it { should have_ipv4_address("192.168.10.10/24") }
|
18
|
+
its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/24 '" }
|
19
|
+
end
|
20
|
+
|
11
21
|
describe interface('invalid-interface') do
|
12
22
|
let(:stdout) { '1000' }
|
13
23
|
its(:speed) { should_not eq 100 }
|
@@ -8,6 +8,16 @@ describe interface('eth0') do
|
|
8
8
|
its(:command) { should eq "ethtool eth0 | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\/s/,\"\\\\1\",\"\")}'" }
|
9
9
|
end
|
10
10
|
|
11
|
+
describe interface('eth0') do
|
12
|
+
it { should have_ipv4_address("192.168.10.10") }
|
13
|
+
its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/'" }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe interface('eth0') do
|
17
|
+
it { should have_ipv4_address("192.168.10.10/24") }
|
18
|
+
its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/24 '" }
|
19
|
+
end
|
20
|
+
|
11
21
|
describe interface('invalid-interface') do
|
12
22
|
let(:stdout) { '1000' }
|
13
23
|
its(:speed) { should_not eq 100 }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gosuke Miyashita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|