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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eac29c488fa7b1d1346c1110303f0d9a99d17a46
4
- data.tar.gz: e904dba7761bac6160e428dd54d9d3e8f7d61e63
3
+ metadata.gz: 81dfca1b27052f6fde88b707a39a88b9aa6b2f2d
4
+ data.tar.gz: 89eb5ad29b3113ef22451c013a5160797551f74b
5
5
  SHA512:
6
- metadata.gz: d11501b36ff63604cf5e2508df4d64bdc5729ad277232f82f69f942ad24c843bbb0cef562a577962d5bb3b589c88dea15ad939eec9ad0de9cd80b48af378b09d
7
- data.tar.gz: 7936003b36cb17bf752cfd6e359dfce04141599f9db85c9c1357498b899a138e6375c1ac82275847f127119f1445fd1eeacef6aa2719d1469c1e9162831aed1d
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*)/, "\\1sudo ")
24
- cmd.gsub!(/(\|\|\s*!?\(?\s*)/, "\\1sudo ")
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
@@ -248,6 +248,10 @@ module Serverspec
248
248
  def check_kernel_module_loaded(name)
249
249
  raise NotImplementedError.new
250
250
  end
251
+
252
+ def check_ipv4_address(interface, ip_address)
253
+ raise NotImplementedError.new
254
+ end
251
255
  end
252
256
  end
253
257
  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
@@ -1,7 +1,7 @@
1
1
  module Serverspec
2
2
  module Configuration
3
3
  class << self
4
- VALID_OPTIONS_KEYS = [:path, :pre_command, :stdout, :stderr].freeze
4
+ VALID_OPTIONS_KEYS = [:path, :pre_command, :stdout, :stderr, :sudo_path].freeze
5
5
  attr_accessor(*VALID_OPTIONS_KEYS)
6
6
 
7
7
  def defaults
@@ -7,6 +7,10 @@ module Serverspec
7
7
  val = val.to_i if val.match(/^\d+$/)
8
8
  val
9
9
  end
10
+
11
+ def has_ipv4_address?(ip_address)
12
+ backend.check_ipv4_address(@name, ip_address)
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.7.7"
2
+ VERSION = "0.7.8"
3
3
  end
@@ -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
- it { should eq 'sudo test ! -f /etc/selinux/config || (sudo getenforce | grep -i -- disabled && sudo grep -i -- ^SELINUX=disabled$ /etc/selinux/config)' }
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.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-10 00:00:00.000000000 Z
11
+ date: 2013-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh