serverspec 2.0.0.beta2 → 2.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -6
- data/Rakefile +2 -27
- data/lib/serverspec/helper.rb +0 -1
- data/lib/serverspec/helper/os.rb +2 -0
- data/lib/serverspec/helper/type.rb +1 -1
- data/lib/serverspec/setup.rb +11 -12
- data/lib/serverspec/type/base.rb +2 -1
- data/lib/serverspec/type/cgroup.rb +1 -1
- data/lib/serverspec/type/command.rb +1 -1
- data/lib/serverspec/type/cron.rb +1 -1
- data/lib/serverspec/type/default_gateway.rb +2 -2
- data/lib/serverspec/type/file.rb +22 -22
- data/lib/serverspec/type/group.rb +2 -2
- data/lib/serverspec/type/host.rb +3 -3
- data/lib/serverspec/type/iis_app_pool.rb +2 -2
- data/lib/serverspec/type/iis_website.rb +5 -5
- data/lib/serverspec/type/interface.rb +2 -2
- data/lib/serverspec/type/ipfilter.rb +1 -1
- data/lib/serverspec/type/ipnat.rb +1 -1
- data/lib/serverspec/type/iptables.rb +1 -1
- data/lib/serverspec/type/kernel_module.rb +1 -1
- data/lib/serverspec/type/linux_kernel_parameter.rb +1 -1
- data/lib/serverspec/type/lxc.rb +2 -2
- data/lib/serverspec/type/mail_alias.rb +1 -1
- data/lib/serverspec/type/package.rb +4 -4
- data/lib/serverspec/type/php_config.rb +1 -1
- data/lib/serverspec/type/port.rb +2 -2
- data/lib/serverspec/type/process.rb +2 -2
- data/lib/serverspec/type/routing_table.rb +1 -1
- data/lib/serverspec/type/selinux.rb +3 -3
- data/lib/serverspec/type/service.rb +7 -8
- data/lib/serverspec/type/user.rb +6 -6
- data/lib/serverspec/type/windows_feature.rb +1 -1
- data/lib/serverspec/type/windows_hot_fix.rb +1 -1
- data/lib/serverspec/type/windows_registry_key.rb +4 -4
- data/lib/serverspec/type/windows_scheduled_task.rb +9 -0
- data/lib/serverspec/type/yumrepo.rb +2 -2
- data/lib/serverspec/type/zfs.rb +2 -2
- data/lib/serverspec/version.rb +1 -1
- data/spec/spec_helper.rb +2 -33
- data/spec/type/cgroup_spec.rb +13 -0
- data/spec/type/command_spec.rb +64 -0
- data/spec/type/cron_spec.rb +19 -0
- data/spec/type/default_gateway_spec.rb +14 -0
- data/spec/type/file_spec.rb +392 -0
- data/spec/type/group_spec.rb +19 -0
- data/spec/type/host_spec.rb +56 -0
- data/spec/type/interface_spec.rb +21 -0
- data/spec/type/iptables_spec.rb +19 -0
- data/spec/type/kernel_module_spec.rb +11 -0
- data/spec/type/linux_kernel_parameter_spec.rb +33 -0
- data/spec/type/lxc_spec.rb +20 -0
- data/spec/type/mail_alias_spec.rb +11 -0
- data/spec/type/package_spec.rb +104 -0
- data/spec/type/php_config_spec.rb +33 -0
- data/spec/type/port_spec.rb +27 -0
- data/spec/type/process_spec.rb +35 -0
- data/spec/type/routing_table_spec.rb +118 -0
- data/spec/type/selinux_spec.rb +15 -0
- data/spec/type/service_spec.rb +94 -0
- data/spec/type/user_spec.rb +51 -0
- data/spec/type/yumrepo_spec.rb +25 -0
- data/spec/type/zfs_spec.rb +15 -0
- metadata +49 -3
- data/lib/serverspec/helper/backend.rb +0 -11
@@ -2,14 +2,14 @@ module Serverspec
|
|
2
2
|
module Type
|
3
3
|
class Interface < Base
|
4
4
|
def speed
|
5
|
-
ret =
|
5
|
+
ret = @runner.run_command(commands.get_interface_speed_of(@name))
|
6
6
|
val = ret.stdout.strip
|
7
7
|
val = val.to_i if val.match(/^\d+$/)
|
8
8
|
val
|
9
9
|
end
|
10
10
|
|
11
11
|
def has_ipv4_address?(ip_address)
|
12
|
-
|
12
|
+
@runner.check_ipv4_address(@name, ip_address)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/serverspec/type/lxc.rb
CHANGED
@@ -2,11 +2,11 @@ module Serverspec
|
|
2
2
|
module Type
|
3
3
|
class Lxc < Base
|
4
4
|
def exists?
|
5
|
-
|
5
|
+
@runner.check_container(@name)
|
6
6
|
end
|
7
7
|
|
8
8
|
def running?
|
9
|
-
|
9
|
+
@runner.check_container_running(@name)
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_s
|
@@ -3,20 +3,20 @@ module Serverspec
|
|
3
3
|
class Package < Base
|
4
4
|
def installed?(provider, version)
|
5
5
|
if provider.nil?
|
6
|
-
|
6
|
+
@runner.check_installed(@name, version)
|
7
7
|
else
|
8
8
|
check_method = "check_installed_by_#{provider}".to_sym
|
9
9
|
|
10
|
-
unless
|
10
|
+
unless @runner.respond_to?(check_method) || commands.respond_to?(check_method)
|
11
11
|
raise ArgumentError.new("`be_installed` matcher doesn't support #{provider}")
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
@runner.send(check_method, @name, version)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
def version
|
19
|
-
ret =
|
19
|
+
ret = @runner.run_command(commands.get_package_version(@name)).stdout.strip
|
20
20
|
if ret.empty?
|
21
21
|
nil
|
22
22
|
else
|
@@ -2,7 +2,7 @@ module Serverspec
|
|
2
2
|
module Type
|
3
3
|
class PhpConfig < Base
|
4
4
|
def value
|
5
|
-
ret =
|
5
|
+
ret = @runner.run_command("php -r 'echo get_cfg_var( \"#{@name}\" );'")
|
6
6
|
val = ret.stdout
|
7
7
|
val = val.to_i if val.match(/^\d+$/)
|
8
8
|
val
|
data/lib/serverspec/type/port.rb
CHANGED
@@ -8,9 +8,9 @@ module Serverspec
|
|
8
8
|
raise ArgumentError.new("`be_listening` matcher doesn't support #{protocol}")
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
@runner.check_listening_with_protocol(@name, protocol)
|
12
12
|
else
|
13
|
-
|
13
|
+
@runner.check_listening(@name)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -2,7 +2,7 @@ module Serverspec
|
|
2
2
|
module Type
|
3
3
|
class Process < Base
|
4
4
|
def running?
|
5
|
-
pid =
|
5
|
+
pid = @runner.run_command(commands.get_process(@name, :format => "pid=")).stdout
|
6
6
|
not pid.empty?
|
7
7
|
end
|
8
8
|
|
@@ -19,7 +19,7 @@ module Serverspec
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_column(keyword)
|
22
|
-
ret =
|
22
|
+
ret = @runner.get_process(@name, :format => "#{keyword}=")
|
23
23
|
val = ret.stdout.strip
|
24
24
|
val = val.to_i if val.match(/^\d+$/)
|
25
25
|
val
|
@@ -2,15 +2,15 @@ module Serverspec
|
|
2
2
|
module Type
|
3
3
|
class Selinux < Base
|
4
4
|
def disabled?
|
5
|
-
|
5
|
+
@runner.check_selinux('disabled')
|
6
6
|
end
|
7
7
|
|
8
8
|
def enforcing?
|
9
|
-
|
9
|
+
@runner.check_selinux('enforcing')
|
10
10
|
end
|
11
11
|
|
12
12
|
def permissive?
|
13
|
-
|
13
|
+
@runner.check_selinux('permissive')
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_s
|
@@ -2,15 +2,15 @@ module Serverspec
|
|
2
2
|
module Type
|
3
3
|
class Service < Base
|
4
4
|
def enabled?(level=3)
|
5
|
-
|
5
|
+
@runner.check_enabled(@name, level)
|
6
6
|
end
|
7
7
|
|
8
8
|
def installed?(name, version)
|
9
|
-
|
9
|
+
@runner.check_service_installed(@name)
|
10
10
|
end
|
11
11
|
|
12
12
|
def has_start_mode?(mode)
|
13
|
-
|
13
|
+
@runner.check_service_start_mode(@name, mode)
|
14
14
|
end
|
15
15
|
|
16
16
|
def running?(under)
|
@@ -21,9 +21,9 @@ module Serverspec
|
|
21
21
|
raise ArgumentError.new("`be_running` matcher doesn't support #{under}")
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
@runner.send(check_method, @name)
|
25
25
|
else
|
26
|
-
|
26
|
+
@runner.check_running(@name)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -32,12 +32,11 @@ module Serverspec
|
|
32
32
|
unless monitor && commands.respond_to?(check_method)
|
33
33
|
raise ArgumentError.new("`be_monitored_by` matcher doesn't support #{monitor}")
|
34
34
|
end
|
35
|
-
|
36
|
-
backend.send(check_method, @name)
|
35
|
+
res = @runner.send(check_method, @name)
|
37
36
|
end
|
38
37
|
|
39
38
|
def has_property?(property)
|
40
|
-
|
39
|
+
@runner.check_svcprops(@name, property)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
data/lib/serverspec/type/user.rb
CHANGED
@@ -2,27 +2,27 @@ module Serverspec
|
|
2
2
|
module Type
|
3
3
|
class User < Base
|
4
4
|
def exists?
|
5
|
-
|
5
|
+
@runner.check_user(@name)
|
6
6
|
end
|
7
7
|
|
8
8
|
def belongs_to_group?(group)
|
9
|
-
|
9
|
+
@runner.check_belonging_group(@name, group)
|
10
10
|
end
|
11
11
|
|
12
12
|
def has_uid?(uid)
|
13
|
-
|
13
|
+
@runner.check_uid(@name, uid)
|
14
14
|
end
|
15
15
|
|
16
16
|
def has_home_directory?(path)
|
17
|
-
|
17
|
+
@runner.check_home_directory(@name, path)
|
18
18
|
end
|
19
19
|
|
20
20
|
def has_login_shell?(shell)
|
21
|
-
|
21
|
+
@runner.check_login_shell(@name, shell)
|
22
22
|
end
|
23
23
|
|
24
24
|
def has_authorized_key?(key)
|
25
|
-
|
25
|
+
@runner.check_authorized_key(@name, key)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -2,19 +2,19 @@ module Serverspec
|
|
2
2
|
module Type
|
3
3
|
class WindowsRegistryKey < Base
|
4
4
|
def exists?
|
5
|
-
|
5
|
+
@runner.check_registry_key(@name)
|
6
6
|
end
|
7
7
|
|
8
8
|
def has_property?(property_name, property_type = :type_string)
|
9
|
-
|
9
|
+
@runner.check_registry_key(@name, {:name => property_name, :type => property_type})
|
10
10
|
end
|
11
11
|
|
12
12
|
def has_value?(value)
|
13
|
-
|
13
|
+
@runner.check_registry_key(@name, {:name => '', :type => :type_string, :value => value})
|
14
14
|
end
|
15
15
|
|
16
16
|
def has_property_value?(property_name, property_type, value)
|
17
|
-
|
17
|
+
@runner.check_registry_key(@name, {:name => property_name, :type => property_type, :value => value})
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/serverspec/type/zfs.rb
CHANGED
data/lib/serverspec/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -6,47 +6,16 @@ include Specinfra::Helper::Exec
|
|
6
6
|
|
7
7
|
PROJECT_ROOT = (Pathname.new(File.dirname(__FILE__)) + '..').expand_path
|
8
8
|
|
9
|
-
Dir[PROJECT_ROOT.join("spec/support/**/*.rb")].each { |file| require(file) }
|
10
|
-
|
11
|
-
|
12
9
|
module Specinfra
|
13
10
|
module Backend
|
14
|
-
|
15
|
-
def
|
16
|
-
if @example
|
17
|
-
@example.metadata[:subject].set_command(cmd)
|
18
|
-
end
|
19
|
-
|
11
|
+
class Exec < Base
|
12
|
+
def run_command cmd
|
20
13
|
CommandResult.new({
|
21
14
|
:stdout => ::Specinfra.configuration.stdout,
|
22
15
|
:stderr => ::Specinfra.configuration.stderr,
|
23
16
|
:exit_status => cmd =~ /invalid/ ? 1 : 0,
|
24
17
|
:exit_signal => nil,
|
25
18
|
})
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
[Exec, Ssh, Cmd, WinRM].each do |clz|
|
30
|
-
clz.class_eval do
|
31
|
-
include TestCommandRunner
|
32
|
-
def run_command(cmd)
|
33
|
-
cmd = build_command(cmd.to_s)
|
34
|
-
cmd = add_pre_command(cmd)
|
35
|
-
do_run cmd
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module Serverspec
|
43
|
-
module Type
|
44
|
-
class Base
|
45
|
-
def set_command(command)
|
46
|
-
@command = command
|
47
|
-
end
|
48
|
-
def command
|
49
|
-
@command
|
50
19
|
end
|
51
20
|
end
|
52
21
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Specinfra::Helper::RedHat
|
4
|
+
|
5
|
+
describe cgroup('group1') do
|
6
|
+
let(:stdout) { "1\r\n" }
|
7
|
+
its('cpuset.cpus') { should eq 1 }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe cgroup('group1') do
|
11
|
+
let(:stdout) { "1\r\n" }
|
12
|
+
its('cpuset.cpus') { should_not eq 0 }
|
13
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Specinfra::Helper::RedHat
|
4
|
+
|
5
|
+
=begin
|
6
|
+
describe command('cat /etc/resolv.conf') do
|
7
|
+
let(:stdout) { "nameserver 127.0.0.1\r\n" }
|
8
|
+
it { should return_stdout("nameserver 127.0.0.1") }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'complete matching of stdout' do
|
12
|
+
context command('cat /etc/resolv.conf') do
|
13
|
+
let(:stdout) { "foocontent-should-be-includedbar\r\n" }
|
14
|
+
it { should_not return_stdout('content-should-be-included') }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'regexp matching of stdout' do
|
19
|
+
context command('cat /etc/resolv.conf') do
|
20
|
+
let(:stdout) { "nameserver 127.0.0.1\r\n" }
|
21
|
+
it { should return_stdout(/127\.0\.0\.1/) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe command('cat /etc/resolv.conf') do
|
26
|
+
let(:stderr) { "No such file or directory\r\n" }
|
27
|
+
it { should return_stderr("No such file or directory") }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'complete matching of stderr' do
|
31
|
+
context command('cat /etc/resolv.conf') do
|
32
|
+
let(:stderr) { "No such file or directory\r\n" }
|
33
|
+
it { should_not return_stderr('file') }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'regexp matching of stderr' do
|
38
|
+
context command('cat /etc/resolv.conf') do
|
39
|
+
let(:stderr) { "No such file or directory\r\n" }
|
40
|
+
it { should return_stderr(/file/) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe command('cat /etc/resolv.conf') do
|
45
|
+
it { should return_exit_status 0 }
|
46
|
+
end
|
47
|
+
=end
|
48
|
+
|
49
|
+
describe command('ls -al /') do
|
50
|
+
let(:stdout) { <<EOF
|
51
|
+
total 88
|
52
|
+
drwxr-xr-x 23 root root 4096 Oct 10 17:19 .
|
53
|
+
drwxr-xr-x 23 root root 4096 Oct 10 17:19 ..
|
54
|
+
drwxr-xr-x 2 root root 4096 Sep 11 16:43 bin
|
55
|
+
drwxr-xr-x 3 root root 4096 Sep 23 18:14 boot
|
56
|
+
drwxr-xr-x 14 root root 4260 Oct 14 16:14 dev
|
57
|
+
drwxr-xr-x 104 root root 4096 Oct 14 17:34 etc
|
58
|
+
drwxr-xr-x 8 root root 4096 Oct 1 15:09 home
|
59
|
+
EOF
|
60
|
+
}
|
61
|
+
|
62
|
+
its(:stdout) { should match /bin/ }
|
63
|
+
its(:stdout) { should eq stdout }
|
64
|
+
end
|