serverspec 0.11.5 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -5
- data/lib/serverspec.rb +2 -36
- data/lib/serverspec/helper.rb +2 -32
- data/lib/serverspec/helper/backend.rb +11 -0
- data/lib/serverspec/helper/os.rb +25 -0
- data/lib/serverspec/setup.rb +3 -3
- data/lib/serverspec/version.rb +1 -1
- data/serverspec.gemspec +1 -0
- data/spec/aix/command_spec.rb +1 -1
- data/spec/aix/cron_spec.rb +1 -1
- data/spec/aix/default_gateway_spec.rb +1 -1
- data/spec/aix/file_spec.rb +1 -1
- data/spec/aix/group_spec.rb +1 -1
- data/spec/aix/host_spec.rb +1 -1
- data/spec/aix/package_spec.rb +1 -1
- data/spec/aix/php_config_spec.rb +1 -1
- data/spec/aix/port_spec.rb +1 -1
- data/spec/aix/routing_table_spec.rb +1 -1
- data/spec/aix/service_spec.rb +1 -1
- data/spec/aix/user_spec.rb +1 -1
- data/spec/backend/cmd/configuration_spec.rb +2 -2
- data/spec/backend/exec/build_command_spec.rb +1 -1
- data/spec/backend/exec/configuration_spec.rb +2 -3
- data/spec/backend/powershell/script_helper_spec.rb +4 -4
- data/spec/backend/ssh/build_command_spec.rb +1 -1
- data/spec/backend/ssh/configuration_spec.rb +2 -3
- data/spec/backend/winrm/configuration_spec.rb +2 -2
- data/spec/darwin/command_spec.rb +1 -1
- data/spec/darwin/cron_spec.rb +1 -1
- data/spec/darwin/default_gateway_spec.rb +1 -1
- data/spec/darwin/file_spec.rb +1 -1
- data/spec/darwin/group_spec.rb +1 -1
- data/spec/darwin/host_spec.rb +1 -1
- data/spec/darwin/mail_alias_spec.rb +1 -1
- data/spec/darwin/package_spec.rb +1 -1
- data/spec/darwin/php_config_spec.rb +1 -1
- data/spec/darwin/port_spec.rb +1 -1
- data/spec/darwin/routing_table_spec.rb +1 -1
- data/spec/darwin/service_spec.rb +1 -1
- data/spec/darwin/user_spec.rb +1 -1
- data/spec/debian/cgroup_spec.rb +1 -1
- data/spec/debian/command_spec.rb +1 -1
- data/spec/debian/cron_spec.rb +1 -1
- data/spec/debian/default_gateway_spec.rb +1 -1
- data/spec/debian/file_spec.rb +1 -1
- data/spec/debian/group_spec.rb +1 -1
- data/spec/debian/host_spec.rb +1 -1
- data/spec/debian/interface_spec.rb +1 -1
- data/spec/debian/iptables_spec.rb +1 -1
- data/spec/debian/kernel_module_spec.rb +1 -1
- data/spec/debian/linux_kernel_parameter_spec.rb +1 -1
- data/spec/debian/lxc_spec.rb +1 -1
- data/spec/debian/mail_alias_spec.rb +1 -1
- data/spec/debian/package_spec.rb +1 -1
- data/spec/debian/php_config_spec.rb +1 -1
- data/spec/debian/port_spec.rb +1 -1
- data/spec/debian/routing_table_spec.rb +1 -1
- data/spec/debian/selinux_spec.rb +1 -1
- data/spec/debian/service_spec.rb +1 -1
- data/spec/debian/user_spec.rb +1 -1
- data/spec/debian/zfs_spec.rb +1 -1
- data/spec/freebsd/command_spec.rb +1 -1
- data/spec/freebsd/cron_spec.rb +1 -1
- data/spec/freebsd/default_gateway_spec.rb +1 -1
- data/spec/freebsd/file_spec.rb +1 -1
- data/spec/freebsd/group_spec.rb +1 -1
- data/spec/freebsd/host_spec.rb +1 -1
- data/spec/freebsd/package_spec.rb +1 -1
- data/spec/freebsd/php_config_spec.rb +1 -1
- data/spec/freebsd/port_spec.rb +1 -1
- data/spec/freebsd/routing_table_spec.rb +1 -1
- data/spec/freebsd/service_spec.rb +1 -1
- data/spec/freebsd/user_spec.rb +1 -1
- data/spec/gentoo/cgroup_spec.rb +1 -1
- data/spec/gentoo/command_spec.rb +1 -1
- data/spec/gentoo/cron_spec.rb +1 -1
- data/spec/gentoo/default_gateway_spec.rb +1 -1
- data/spec/gentoo/file_spec.rb +1 -1
- data/spec/gentoo/group_spec.rb +1 -1
- data/spec/gentoo/host_spec.rb +1 -1
- data/spec/gentoo/interface_spec.rb +1 -1
- data/spec/gentoo/iptables_spec.rb +1 -1
- data/spec/gentoo/kernel_module_spec.rb +1 -1
- data/spec/gentoo/linux_kernel_parameter_spec.rb +1 -1
- data/spec/gentoo/lxc_spec.rb +1 -1
- data/spec/gentoo/mail_alias_spec.rb +1 -1
- data/spec/gentoo/package_spec.rb +1 -1
- data/spec/gentoo/php_config_spec.rb +1 -1
- data/spec/gentoo/port_spec.rb +1 -1
- data/spec/gentoo/routing_table_spec.rb +1 -1
- data/spec/gentoo/selinux_spec.rb +1 -1
- data/spec/gentoo/service_spec.rb +1 -1
- data/spec/gentoo/user_spec.rb +1 -1
- data/spec/gentoo/zfs_spec.rb +1 -1
- data/spec/plamo/cgroup_spec.rb +1 -1
- data/spec/plamo/command_spec.rb +1 -1
- data/spec/plamo/cron_spec.rb +1 -1
- data/spec/plamo/default_gateway_spec.rb +1 -1
- data/spec/plamo/file_spec.rb +1 -1
- data/spec/plamo/group_spec.rb +1 -1
- data/spec/plamo/host_spec.rb +1 -1
- data/spec/plamo/interface_spec.rb +1 -1
- data/spec/plamo/iptables_spec.rb +1 -1
- data/spec/plamo/kernel_module_spec.rb +1 -1
- data/spec/plamo/linux_kernel_parameter_spec.rb +1 -1
- data/spec/plamo/lxc_spec.rb +1 -1
- data/spec/plamo/mail_alias_spec.rb +1 -1
- data/spec/plamo/package_spec.rb +1 -1
- data/spec/plamo/php_config_spec.rb +1 -1
- data/spec/plamo/port_spec.rb +1 -1
- data/spec/plamo/routing_table_spec.rb +1 -1
- data/spec/plamo/selinux_spec.rb +1 -1
- data/spec/plamo/service_spec.rb +1 -1
- data/spec/plamo/user_spec.rb +1 -1
- data/spec/plamo/zfs_spec.rb +1 -1
- data/spec/redhat/cgroup_spec.rb +1 -1
- data/spec/redhat/command_spec.rb +1 -1
- data/spec/redhat/cron_spec.rb +1 -1
- data/spec/redhat/default_gateway_spec.rb +1 -1
- data/spec/redhat/file_spec.rb +1 -1
- data/spec/redhat/group_spec.rb +1 -1
- data/spec/redhat/host_spec.rb +1 -1
- data/spec/redhat/interface_spec.rb +1 -1
- data/spec/redhat/iptables_spec.rb +1 -1
- data/spec/redhat/kernel_module_spec.rb +1 -1
- data/spec/redhat/linux_kernel_parameter_spec.rb +1 -1
- data/spec/redhat/lxc_spec.rb +1 -1
- data/spec/redhat/mail_alias_spec.rb +1 -1
- data/spec/redhat/package_spec.rb +1 -1
- data/spec/redhat/php_config_spec.rb +1 -1
- data/spec/redhat/port_spec.rb +1 -1
- data/spec/redhat/routing_table_spec.rb +1 -1
- data/spec/redhat/selinux_spec.rb +1 -1
- data/spec/redhat/service_spec.rb +1 -1
- data/spec/redhat/user_spec.rb +1 -1
- data/spec/redhat/yumrepo_spec.rb +1 -1
- data/spec/redhat/zfs_spec.rb +1 -1
- data/spec/smartos/mail_alias_spec.rb +1 -1
- data/spec/solaris/command_spec.rb +1 -1
- data/spec/solaris/cron_spec.rb +1 -1
- data/spec/solaris/default_gateway_spec.rb +1 -1
- data/spec/solaris/file_spec.rb +1 -1
- data/spec/solaris/group_spec.rb +1 -1
- data/spec/solaris/host_spec.rb +1 -1
- data/spec/solaris/ipfilter_spec.rb +1 -1
- data/spec/solaris/ipnat_spec.rb +1 -1
- data/spec/solaris/mail_alias_spec.rb +1 -1
- data/spec/solaris/package_spec.rb +1 -1
- data/spec/solaris/php_config_spec.rb +1 -1
- data/spec/solaris/port_spec.rb +1 -1
- data/spec/solaris/routing_table_spec.rb +1 -1
- data/spec/solaris/service_spec.rb +1 -1
- data/spec/solaris/svcprop_spec.rb +1 -1
- data/spec/solaris/user_spec.rb +1 -1
- data/spec/solaris/zfs_spec.rb +1 -1
- data/spec/solaris10/file_spec.rb +1 -1
- data/spec/solaris10/group_spec.rb +1 -1
- data/spec/solaris10/mail_alias_spec.rb +1 -1
- data/spec/solaris10/package_spec.rb +1 -1
- data/spec/solaris10/php_config_spec.rb +1 -1
- data/spec/solaris10/user_spec.rb +1 -1
- data/spec/solaris11/command_spec.rb +1 -1
- data/spec/solaris11/cron_spec.rb +1 -1
- data/spec/solaris11/default_gateway_spec.rb +1 -1
- data/spec/solaris11/file_spec.rb +1 -1
- data/spec/solaris11/group_spec.rb +1 -1
- data/spec/solaris11/host_spec.rb +1 -1
- data/spec/solaris11/ipfilter_spec.rb +1 -1
- data/spec/solaris11/ipnat_spec.rb +1 -1
- data/spec/solaris11/mail_alias_spec.rb +1 -1
- data/spec/solaris11/package_spec.rb +1 -1
- data/spec/solaris11/php_config_spec.rb +1 -1
- data/spec/solaris11/port_spec.rb +1 -1
- data/spec/solaris11/routing_table_spec.rb +1 -1
- data/spec/solaris11/service_spec.rb +1 -1
- data/spec/solaris11/svcprop_spec.rb +1 -1
- data/spec/solaris11/user_spec.rb +1 -1
- data/spec/solaris11/zfs_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -6
- data/spec/windows/command_spec.rb +2 -2
- data/spec/windows/file_spec.rb +2 -2
- data/spec/windows/group_spec.rb +2 -2
- data/spec/windows/port_spec.rb +2 -2
- data/spec/windows/service_spec.rb +2 -2
- data/spec/windows/user_spec.rb +2 -2
- data/spec/windows/windows_registry_key_spec.rb +2 -2
- metadata +18 -45
- data/lib/serverspec/attributes.rb +0 -17
- data/lib/serverspec/backend.rb +0 -7
- data/lib/serverspec/backend/base.rb +0 -31
- data/lib/serverspec/backend/cmd.rb +0 -39
- data/lib/serverspec/backend/exec.rb +0 -218
- data/lib/serverspec/backend/powershell/command.rb +0 -40
- data/lib/serverspec/backend/powershell/script_helper.rb +0 -85
- data/lib/serverspec/backend/powershell/support/check_file_access_rules.ps1 +0 -8
- data/lib/serverspec/backend/powershell/support/crop_text.ps1 +0 -11
- data/lib/serverspec/backend/powershell/support/find_group.ps1 +0 -8
- data/lib/serverspec/backend/powershell/support/find_installed_application.ps1 +0 -7
- data/lib/serverspec/backend/powershell/support/find_service.ps1 +0 -5
- data/lib/serverspec/backend/powershell/support/find_user.ps1 +0 -8
- data/lib/serverspec/backend/powershell/support/find_usergroup.ps1 +0 -9
- data/lib/serverspec/backend/powershell/support/is_port_listening.ps1 +0 -13
- data/lib/serverspec/backend/ssh.rb +0 -93
- data/lib/serverspec/backend/winrm.rb +0 -26
- data/lib/serverspec/configuration.rb +0 -12
- data/lib/serverspec/helper/aix.rb +0 -9
- data/lib/serverspec/helper/attributes.rb +0 -16
- data/lib/serverspec/helper/base.rb +0 -9
- data/lib/serverspec/helper/cmd.rb +0 -15
- data/lib/serverspec/helper/configuration.rb +0 -37
- data/lib/serverspec/helper/darwin.rb +0 -9
- data/lib/serverspec/helper/debian.rb +0 -9
- data/lib/serverspec/helper/detect_os.rb +0 -19
- data/lib/serverspec/helper/exec.rb +0 -14
- data/lib/serverspec/helper/freebsd.rb +0 -9
- data/lib/serverspec/helper/gentoo.rb +0 -9
- data/lib/serverspec/helper/plamo.rb +0 -9
- data/lib/serverspec/helper/properties.rb +0 -14
- data/lib/serverspec/helper/puppet.rb +0 -9
- data/lib/serverspec/helper/redhat.rb +0 -9
- data/lib/serverspec/helper/smartos.rb +0 -10
- data/lib/serverspec/helper/solaris.rb +0 -9
- data/lib/serverspec/helper/solaris10.rb +0 -9
- data/lib/serverspec/helper/solaris11.rb +0 -9
- data/lib/serverspec/helper/ssh.rb +0 -15
- data/lib/serverspec/helper/windows.rb +0 -9
- data/lib/serverspec/helper/winrm.rb +0 -15
- data/lib/serverspec/properties.rb +0 -17
- data/spec/helpers/properties_spec.rb +0 -11
data/spec/spec_helper.rb
CHANGED
@@ -2,14 +2,14 @@ require 'serverspec'
|
|
2
2
|
require 'pathname'
|
3
3
|
require 'rspec/mocks/standalone'
|
4
4
|
|
5
|
-
include
|
5
|
+
include SpecInfra::Helper::Exec
|
6
6
|
|
7
7
|
PROJECT_ROOT = (Pathname.new(File.dirname(__FILE__)) + '..').expand_path
|
8
8
|
|
9
9
|
Dir[PROJECT_ROOT.join("spec/support/**/*.rb")].each { |file| require(file) }
|
10
10
|
|
11
11
|
|
12
|
-
module
|
12
|
+
module SpecInfra
|
13
13
|
module Backend
|
14
14
|
module TestCommandRunner
|
15
15
|
def do_run cmd
|
@@ -19,15 +19,15 @@ module Serverspec
|
|
19
19
|
|
20
20
|
if cmd =~ /invalid/
|
21
21
|
{
|
22
|
-
:stdout => ::
|
23
|
-
:stderr => ::
|
22
|
+
:stdout => ::SpecInfra.configuration.stdout,
|
23
|
+
:stderr => ::SpecInfra.configuration.stderr,
|
24
24
|
:exit_status => 1,
|
25
25
|
:exit_signal => nil
|
26
26
|
}
|
27
27
|
else
|
28
28
|
{
|
29
|
-
:stdout => ::
|
30
|
-
:stderr => ::
|
29
|
+
:stdout => ::SpecInfra.configuration.stdout,
|
30
|
+
:stderr => ::SpecInfra.configuration.stderr,
|
31
31
|
:exit_status => 0,
|
32
32
|
:exit_signal => nil
|
33
33
|
}
|
@@ -45,7 +45,9 @@ module Serverspec
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
+
end
|
48
49
|
|
50
|
+
module Serverspec
|
49
51
|
module Type
|
50
52
|
class Base
|
51
53
|
def set_command(command)
|
data/spec/windows/file_spec.rb
CHANGED
data/spec/windows/group_spec.rb
CHANGED
data/spec/windows/port_spec.rb
CHANGED
data/spec/windows/user_spec.rb
CHANGED
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.
|
4
|
+
version: 0.12.0
|
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-11-
|
11
|
+
date: 2013-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: specinfra
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.2
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,23 +112,6 @@ files:
|
|
98
112
|
- WINDOWS_SUPPORT.md
|
99
113
|
- bin/serverspec-init
|
100
114
|
- lib/serverspec.rb
|
101
|
-
- lib/serverspec/attributes.rb
|
102
|
-
- lib/serverspec/backend.rb
|
103
|
-
- lib/serverspec/backend/base.rb
|
104
|
-
- lib/serverspec/backend/cmd.rb
|
105
|
-
- lib/serverspec/backend/exec.rb
|
106
|
-
- lib/serverspec/backend/powershell/command.rb
|
107
|
-
- lib/serverspec/backend/powershell/script_helper.rb
|
108
|
-
- lib/serverspec/backend/powershell/support/check_file_access_rules.ps1
|
109
|
-
- lib/serverspec/backend/powershell/support/crop_text.ps1
|
110
|
-
- lib/serverspec/backend/powershell/support/find_group.ps1
|
111
|
-
- lib/serverspec/backend/powershell/support/find_installed_application.ps1
|
112
|
-
- lib/serverspec/backend/powershell/support/find_service.ps1
|
113
|
-
- lib/serverspec/backend/powershell/support/find_user.ps1
|
114
|
-
- lib/serverspec/backend/powershell/support/find_usergroup.ps1
|
115
|
-
- lib/serverspec/backend/powershell/support/is_port_listening.ps1
|
116
|
-
- lib/serverspec/backend/ssh.rb
|
117
|
-
- lib/serverspec/backend/winrm.rb
|
118
115
|
- lib/serverspec/commands/aix.rb
|
119
116
|
- lib/serverspec/commands/base.rb
|
120
117
|
- lib/serverspec/commands/darwin.rb
|
@@ -129,31 +126,10 @@ files:
|
|
129
126
|
- lib/serverspec/commands/solaris10.rb
|
130
127
|
- lib/serverspec/commands/solaris11.rb
|
131
128
|
- lib/serverspec/commands/windows.rb
|
132
|
-
- lib/serverspec/configuration.rb
|
133
129
|
- lib/serverspec/helper.rb
|
134
|
-
- lib/serverspec/helper/
|
135
|
-
- lib/serverspec/helper/
|
136
|
-
- lib/serverspec/helper/base.rb
|
137
|
-
- lib/serverspec/helper/cmd.rb
|
138
|
-
- lib/serverspec/helper/configuration.rb
|
139
|
-
- lib/serverspec/helper/darwin.rb
|
140
|
-
- lib/serverspec/helper/debian.rb
|
141
|
-
- lib/serverspec/helper/detect_os.rb
|
142
|
-
- lib/serverspec/helper/exec.rb
|
143
|
-
- lib/serverspec/helper/freebsd.rb
|
144
|
-
- lib/serverspec/helper/gentoo.rb
|
145
|
-
- lib/serverspec/helper/plamo.rb
|
146
|
-
- lib/serverspec/helper/properties.rb
|
147
|
-
- lib/serverspec/helper/puppet.rb
|
148
|
-
- lib/serverspec/helper/redhat.rb
|
149
|
-
- lib/serverspec/helper/smartos.rb
|
150
|
-
- lib/serverspec/helper/solaris.rb
|
151
|
-
- lib/serverspec/helper/solaris10.rb
|
152
|
-
- lib/serverspec/helper/solaris11.rb
|
153
|
-
- lib/serverspec/helper/ssh.rb
|
130
|
+
- lib/serverspec/helper/backend.rb
|
131
|
+
- lib/serverspec/helper/os.rb
|
154
132
|
- lib/serverspec/helper/type.rb
|
155
|
-
- lib/serverspec/helper/windows.rb
|
156
|
-
- lib/serverspec/helper/winrm.rb
|
157
133
|
- lib/serverspec/matchers.rb
|
158
134
|
- lib/serverspec/matchers/be_enabled.rb
|
159
135
|
- lib/serverspec/matchers/be_executable.rb
|
@@ -174,7 +150,6 @@ files:
|
|
174
150
|
- lib/serverspec/matchers/return_exit_status.rb
|
175
151
|
- lib/serverspec/matchers/return_stderr.rb
|
176
152
|
- lib/serverspec/matchers/return_stdout.rb
|
177
|
-
- lib/serverspec/properties.rb
|
178
153
|
- lib/serverspec/setup.rb
|
179
154
|
- lib/serverspec/subject.rb
|
180
155
|
- lib/serverspec/type/base.rb
|
@@ -291,7 +266,6 @@ files:
|
|
291
266
|
- spec/gentoo/service_spec.rb
|
292
267
|
- spec/gentoo/user_spec.rb
|
293
268
|
- spec/gentoo/zfs_spec.rb
|
294
|
-
- spec/helpers/properties_spec.rb
|
295
269
|
- spec/plamo/cgroup_spec.rb
|
296
270
|
- spec/plamo/command_spec.rb
|
297
271
|
- spec/plamo/cron_spec.rb
|
@@ -496,7 +470,6 @@ test_files:
|
|
496
470
|
- spec/gentoo/service_spec.rb
|
497
471
|
- spec/gentoo/user_spec.rb
|
498
472
|
- spec/gentoo/zfs_spec.rb
|
499
|
-
- spec/helpers/properties_spec.rb
|
500
473
|
- spec/plamo/cgroup_spec.rb
|
501
474
|
- spec/plamo/command_spec.rb
|
502
475
|
- spec/plamo/cron_spec.rb
|
data/lib/serverspec/backend.rb
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
require 'serverspec/backend/base'
|
2
|
-
require 'serverspec/backend/ssh'
|
3
|
-
require 'serverspec/backend/exec'
|
4
|
-
require 'serverspec/backend/powershell/script_helper'
|
5
|
-
require 'serverspec/backend/powershell/command'
|
6
|
-
require 'serverspec/backend/cmd'
|
7
|
-
require 'serverspec/backend/winrm'
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
|
-
module Serverspec
|
4
|
-
module Backend
|
5
|
-
class Base
|
6
|
-
include Singleton
|
7
|
-
|
8
|
-
def set_commands(c)
|
9
|
-
@commands = c
|
10
|
-
end
|
11
|
-
|
12
|
-
def set_example(e)
|
13
|
-
@example = e
|
14
|
-
end
|
15
|
-
|
16
|
-
def commands
|
17
|
-
@commands
|
18
|
-
end
|
19
|
-
|
20
|
-
def check_zero(cmd, *args)
|
21
|
-
ret = run_command(commands.send(cmd, *args))
|
22
|
-
ret[:exit_status] == 0
|
23
|
-
end
|
24
|
-
|
25
|
-
# Default action is to call check_zero with args
|
26
|
-
def method_missing(meth, *args, &block)
|
27
|
-
check_zero(meth, *args)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
|
3
|
-
module Serverspec
|
4
|
-
module Backend
|
5
|
-
class Cmd < Base
|
6
|
-
include PowerShell::ScriptHelper
|
7
|
-
|
8
|
-
def run_command(cmd, opts={})
|
9
|
-
script = create_script(cmd)
|
10
|
-
result = execute_script %Q{powershell -encodedCommand #{encode_script(script)}}
|
11
|
-
|
12
|
-
if @example
|
13
|
-
@example.metadata[:command] = script
|
14
|
-
@example.metadata[:stdout] = result[:stdout] + result[:stderr]
|
15
|
-
end
|
16
|
-
{ :stdout => result[:stdout], :stderr => result[:stderr],
|
17
|
-
:exit_status => result[:status], :exit_signal => nil }
|
18
|
-
end
|
19
|
-
|
20
|
-
def execute_script script
|
21
|
-
if Open3.respond_to? :capture3
|
22
|
-
stdout, stderr, status = Open3.capture3(script)
|
23
|
-
# powershell still exits with 0 even if there are syntax errors, although it spits the error out into stderr
|
24
|
-
# so we have to resort to return an error exit code if there is anything in the standard error
|
25
|
-
status = 1 if status == 0 and !stderr.empty?
|
26
|
-
{ :stdout => stdout, :stderr => stderr, :status => status }
|
27
|
-
else
|
28
|
-
stdout = `#{script} 2>&1`
|
29
|
-
{ :stdout => stdout, :stderr => nil, :status => $? }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def check_os
|
34
|
-
# Dirty hack for specs
|
35
|
-
'Windows'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,218 +0,0 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
|
-
module Serverspec
|
4
|
-
module Backend
|
5
|
-
class Exec < Base
|
6
|
-
|
7
|
-
def run_command(cmd, opts={})
|
8
|
-
cmd = build_command(cmd)
|
9
|
-
cmd = add_pre_command(cmd)
|
10
|
-
stdout = run_with_no_ruby_environment do
|
11
|
-
`#{build_command(cmd)} 2>&1`
|
12
|
-
end
|
13
|
-
# In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8
|
14
|
-
#stdout, stderr, status = Open3.capture3(cmd)
|
15
|
-
|
16
|
-
if @example
|
17
|
-
@example.metadata[:command] = cmd
|
18
|
-
@example.metadata[:stdout] = stdout
|
19
|
-
end
|
20
|
-
|
21
|
-
{ :stdout => stdout, :stderr => nil,
|
22
|
-
:exit_status => $?.exitstatus, :exit_signal => nil }
|
23
|
-
end
|
24
|
-
|
25
|
-
def run_with_no_ruby_environment
|
26
|
-
keys = %w[BUNDLER_EDITOR BUNDLE_BIN_PATH BUNDLE_GEMFILE
|
27
|
-
RUBYOPT GEM_HOME GEM_PATH GEM_CACHE]
|
28
|
-
|
29
|
-
keys.each { |key| ENV["_SERVERSPEC_#{key}"] = ENV[key] ; ENV.delete(key) }
|
30
|
-
yield
|
31
|
-
ensure
|
32
|
-
keys.each { |key| ENV[key] = ENV.delete("_SERVERSPEC_#{key}") }
|
33
|
-
end
|
34
|
-
|
35
|
-
def build_command(cmd)
|
36
|
-
path = Serverspec.configuration.path || RSpec.configuration.path
|
37
|
-
if path
|
38
|
-
cmd = "env PATH=#{path}:$PATH #{cmd}"
|
39
|
-
cmd.gsub!(/(\&\&\s*!?\(?\s*)/, "\\1env PATH=#{path}:$PATH ")
|
40
|
-
cmd.gsub!(/(\|\|\s*!?\(?\s*)/, "\\1env PATH=#{path}:$PATH ")
|
41
|
-
end
|
42
|
-
cmd
|
43
|
-
end
|
44
|
-
|
45
|
-
def add_pre_command(cmd)
|
46
|
-
path = Serverspec.configuration.path || RSpec.configuration.path
|
47
|
-
if Serverspec.configuration.pre_command
|
48
|
-
cmd = "#{Serverspec.configuration.pre_command} && #{cmd}"
|
49
|
-
cmd = "env PATH=#{path}:$PATH #{cmd}" if path
|
50
|
-
end
|
51
|
-
cmd
|
52
|
-
end
|
53
|
-
|
54
|
-
def check_running(process)
|
55
|
-
ret = run_command(commands.check_running(process))
|
56
|
-
|
57
|
-
# In Ubuntu, some services are under upstart and "service foo status" returns
|
58
|
-
# exit status 0 even though they are stopped.
|
59
|
-
# So return false if stdout contains "stopped/waiting".
|
60
|
-
return false if ret[:stdout] =~ /stopped\/waiting/
|
61
|
-
|
62
|
-
# If the service is not registered, check by ps command
|
63
|
-
if ret[:exit_status] == 1
|
64
|
-
ret = run_command(commands.check_process(process))
|
65
|
-
end
|
66
|
-
|
67
|
-
ret[:exit_status] == 0
|
68
|
-
end
|
69
|
-
|
70
|
-
def check_monitored_by_monit(process)
|
71
|
-
ret = run_command(commands.check_monitored_by_monit(process))
|
72
|
-
return false unless ret[:stdout] != nil && ret[:exit_status] == 0
|
73
|
-
|
74
|
-
retlines = ret[:stdout].split(/[\r\n]+/).map(&:strip)
|
75
|
-
proc_index = retlines.index("Process '#{process}'")
|
76
|
-
return false unless proc_index
|
77
|
-
|
78
|
-
retlines[proc_index+2].match(/\Amonitoring status\s+monitored\Z/i) != nil
|
79
|
-
end
|
80
|
-
|
81
|
-
def check_readable(file, by_whom)
|
82
|
-
mode = sprintf('%04s',run_command(commands.get_mode(file))[:stdout].strip)
|
83
|
-
mode = mode.split('')
|
84
|
-
mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
|
85
|
-
case by_whom
|
86
|
-
when nil
|
87
|
-
mode_octal & 0444 != 0
|
88
|
-
when 'owner'
|
89
|
-
mode_octal & 0400 != 0
|
90
|
-
when 'group'
|
91
|
-
mode_octal & 0040 != 0
|
92
|
-
when 'others'
|
93
|
-
mode_octal & 0004 != 0
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def check_writable(file, by_whom)
|
98
|
-
mode = sprintf('%04s',run_command(commands.get_mode(file))[:stdout].strip)
|
99
|
-
mode = mode.split('')
|
100
|
-
mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
|
101
|
-
case by_whom
|
102
|
-
when nil
|
103
|
-
mode_octal & 0222 != 0
|
104
|
-
when 'owner'
|
105
|
-
mode_octal & 0200 != 0
|
106
|
-
when 'group'
|
107
|
-
mode_octal & 0020 != 0
|
108
|
-
when 'others'
|
109
|
-
mode_octal & 0002 != 0
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def check_executable(file, by_whom)
|
114
|
-
mode = sprintf('%04s',run_command(commands.get_mode(file))[:stdout].strip)
|
115
|
-
mode = mode.split('')
|
116
|
-
mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
|
117
|
-
case by_whom
|
118
|
-
when nil
|
119
|
-
mode_octal & 0111 != 0
|
120
|
-
when 'owner'
|
121
|
-
mode_octal & 0100 != 0
|
122
|
-
when 'group'
|
123
|
-
mode_octal & 0010 != 0
|
124
|
-
when 'others'
|
125
|
-
mode_octal & 0001 != 0
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def check_mounted(path, expected_attr, only_with)
|
130
|
-
ret = run_command(commands.check_mounted(path))
|
131
|
-
if expected_attr.nil? || ret[:exit_status] != 0
|
132
|
-
return ret[:exit_status] == 0
|
133
|
-
end
|
134
|
-
|
135
|
-
mount = ret[:stdout].scan(/\S+/)
|
136
|
-
actual_attr = { :device => mount[0], :type => mount[4] }
|
137
|
-
mount[5].gsub(/\(|\)/, '').split(',').each do |option|
|
138
|
-
name, val = option.split('=')
|
139
|
-
if val.nil?
|
140
|
-
actual_attr[name.to_sym] = true
|
141
|
-
else
|
142
|
-
val = val.to_i if val.match(/^\d+$/)
|
143
|
-
actual_attr[name.to_sym] = val
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
if ! expected_attr[:options].nil?
|
148
|
-
expected_attr.merge!(expected_attr[:options])
|
149
|
-
expected_attr.delete(:options)
|
150
|
-
end
|
151
|
-
|
152
|
-
if only_with
|
153
|
-
actual_attr == expected_attr
|
154
|
-
else
|
155
|
-
expected_attr.each do |key, val|
|
156
|
-
return false if actual_attr[key] != val
|
157
|
-
end
|
158
|
-
true
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def check_routing_table(expected_attr)
|
163
|
-
return false if ! expected_attr[:destination]
|
164
|
-
ret = run_command(commands.check_routing_table(expected_attr[:destination]))
|
165
|
-
return false if ret[:exit_status] != 0
|
166
|
-
|
167
|
-
ret[:stdout] =~ /^(\S+)(?: via (\S+))? dev (\S+).+\r\n(?:default via (\S+))?/
|
168
|
-
actual_attr = {
|
169
|
-
:destination => $1,
|
170
|
-
:gateway => $2 ? $2 : $4,
|
171
|
-
:interface => expected_attr[:interface] ? $3 : nil
|
172
|
-
}
|
173
|
-
|
174
|
-
expected_attr.each do |key, val|
|
175
|
-
return false if actual_attr[key] != val
|
176
|
-
end
|
177
|
-
true
|
178
|
-
end
|
179
|
-
|
180
|
-
def check_os
|
181
|
-
return RSpec.configuration.os if RSpec.configuration.os
|
182
|
-
if run_command('ls /etc/redhat-release')[:exit_status] == 0
|
183
|
-
line = run_command('cat /etc/redhat-release')[:stdout]
|
184
|
-
if line =~ /release (\d[\d.]*)/
|
185
|
-
release = $1
|
186
|
-
end
|
187
|
-
{ :family => 'RedHat', :release => release }
|
188
|
-
elsif run_command('ls /etc/system-release')[:exit_status] == 0
|
189
|
-
{ :family => 'RedHat', :release => nil } # Amazon Linux
|
190
|
-
elsif run_command('ls /etc/debian_version')[:exit_status] == 0
|
191
|
-
{ :family => 'Debian', :release => nil }
|
192
|
-
elsif run_command('ls /etc/gentoo-release')[:exit_status] == 0
|
193
|
-
{ :family => 'Gentoo', :release => nil }
|
194
|
-
elsif run_command('ls /usr/lib/setup/Plamo-*')[:exit_status] == 0
|
195
|
-
{ :family => 'Plamo', :release => nil }
|
196
|
-
elsif run_command('uname -s')[:stdout] =~ /AIX/i
|
197
|
-
{ :family => 'AIX', :release => nil }
|
198
|
-
elsif (os = run_command('uname -sr')[:stdout]) && os =~ /SunOS/i
|
199
|
-
if os =~ /5.10/
|
200
|
-
{ :family => 'Solaris10', :release => nil }
|
201
|
-
elsif run_command('grep -q "Oracle Solaris 11" /etc/release')[:exit_status] == 0
|
202
|
-
{ :family => 'Solaris11', :release => nil }
|
203
|
-
elsif run_command('grep -q SmartOS /etc/release')[:exit_status] == 0
|
204
|
-
{ :family => 'SmartOS', :release => nil }
|
205
|
-
else
|
206
|
-
{ :family => 'Solaris', :release => nil }
|
207
|
-
end
|
208
|
-
elsif run_command('uname -s')[:stdout] =~ /Darwin/i
|
209
|
-
{ :family => 'Darwin', :release => nil }
|
210
|
-
elsif run_command('uname -s')[:stdout] =~ /FreeBSD/i
|
211
|
-
{ :family => 'FreeBSD', :release => nil }
|
212
|
-
else
|
213
|
-
{ :family => 'Base', :release => nil }
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|