beaker 2.10.0 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/HISTORY.md +292 -4
- data/acceptance/tests/base/host.rb +1 -0
- data/lib/beaker/answers/version30.rb +10 -10
- data/lib/beaker/cli.rb +10 -8
- data/lib/beaker/command.rb +1 -1
- data/lib/beaker/dsl/helpers/facter_helpers.rb +10 -1
- data/lib/beaker/dsl/helpers/hiera_helpers.rb +0 -11
- data/lib/beaker/dsl/helpers/host_helpers.rb +12 -3
- data/lib/beaker/dsl/helpers/puppet_helpers.rb +11 -3
- data/lib/beaker/dsl/helpers/tk_helpers.rb +0 -12
- data/lib/beaker/dsl/helpers/web_helpers.rb +0 -12
- data/lib/beaker/dsl/install_utils/module_utils.rb +9 -6
- data/lib/beaker/dsl/install_utils/pe_utils.rb +60 -8
- data/lib/beaker/dsl/install_utils/puppet_utils.rb +15 -2
- data/lib/beaker/host.rb +11 -145
- data/lib/beaker/host/mac.rb +3 -7
- data/lib/beaker/host/mac/pkg.rb +43 -0
- data/lib/beaker/host/pswindows.rb +1 -1
- data/lib/beaker/host/pswindows/exec.rb +83 -2
- data/lib/beaker/host/pswindows/pkg.rb +9 -6
- data/lib/beaker/host/unix/exec.rb +105 -0
- data/lib/beaker/host/unix/pkg.rb +22 -9
- data/lib/beaker/host/windows.rb +2 -1
- data/lib/beaker/host/windows/exec.rb +1 -1
- data/lib/beaker/host/windows/pkg.rb +4 -7
- data/lib/beaker/host_prebuilt_steps.rb +14 -14
- data/lib/beaker/hypervisor/aws_sdk.rb +198 -114
- data/lib/beaker/hypervisor/openstack.rb +48 -25
- data/lib/beaker/shared/host_manager.rb +11 -2
- data/lib/beaker/ssh_connection.rb +26 -0
- data/lib/beaker/version.rb +1 -1
- data/spec/beaker/answers_spec.rb +56 -0
- data/spec/beaker/cli_spec.rb +16 -12
- data/spec/beaker/command_spec.rb +3 -0
- data/spec/beaker/dsl/install_utils/module_utils_spec.rb +2 -2
- data/spec/beaker/dsl/install_utils/pe_utils_spec.rb +71 -3
- data/spec/beaker/dsl/install_utils/puppet_utils_spec.rb +4 -1
- data/spec/beaker/host/unix/pkg_spec.rb +10 -10
- data/spec/beaker/host_prebuilt_steps_spec.rb +3 -1
- data/spec/beaker/host_spec.rb +8 -2
- data/spec/beaker/hypervisor/vagrant_spec.rb +1 -0
- metadata +3 -2
data/lib/beaker/host/mac.rb
CHANGED
@@ -3,19 +3,15 @@
|
|
3
3
|
end
|
4
4
|
|
5
5
|
module Mac
|
6
|
-
|
6
|
+
class Host < Unix::Host
|
7
7
|
|
8
|
-
[ '
|
9
|
-
require "beaker/host/unix/#{lib}"
|
10
|
-
end
|
11
|
-
[ 'user', 'group' ].each do |lib|
|
8
|
+
[ 'user', 'group', 'pkg' ].each do |lib|
|
12
9
|
require "beaker/host/mac/#{lib}"
|
13
10
|
end
|
14
11
|
|
15
12
|
include Mac::User
|
16
13
|
include Mac::Group
|
17
|
-
include
|
18
|
-
include Unix::Exec
|
14
|
+
include Mac::Pkg
|
19
15
|
|
20
16
|
def self.pe_defaults
|
21
17
|
h = Beaker::Options::OptionsHash.new
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Mac::Pkg
|
2
|
+
include Beaker::CommandFactory
|
3
|
+
|
4
|
+
def check_for_package(name)
|
5
|
+
raise "Package #{name} cannot be queried on #{self}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def install_package(name, cmdline_args = '', version = nil)
|
9
|
+
raise "Package #{name} cannot be installed on #{self}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def uninstall_package(name, cmdline_args = '')
|
13
|
+
raise "Package #{name} cannot be installed on #{self}"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Upgrade an installed package to the latest available version
|
17
|
+
#
|
18
|
+
# @param [String] name The name of the package to update
|
19
|
+
# @param [String] cmdline_args Additional command line arguments for
|
20
|
+
# the package manager
|
21
|
+
def upgrade_package(name, cmdline_args = '')
|
22
|
+
raise "Package #{name} cannot be upgraded on #{self}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Deploy configuration generated by the packaging tooling to this host.
|
26
|
+
#
|
27
|
+
# This method calls one of #deploy_apt_repo, #deploy_yum_repo, or
|
28
|
+
# #deploy_zyp_repo depending on the platform of this Host.
|
29
|
+
#
|
30
|
+
# @note See {Beaker::DSL::Helpers::HostHelpers#deploy_package_repo} for info on
|
31
|
+
# params
|
32
|
+
def deploy_package_repo(path, name, version)
|
33
|
+
raise "Package repo cannot be deployed on #{self}; the platform is not supported"
|
34
|
+
end
|
35
|
+
|
36
|
+
#Examine the host system to determine the architecture
|
37
|
+
#@return [Boolean] true if x86_64, false otherwise
|
38
|
+
def determine_if_x86_64
|
39
|
+
result = exec(Beaker::Command.new("uname -a | grep x86_64"), :expect_all_exit_codes => true)
|
40
|
+
result.exit_code == 0
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module PSWindows::Exec
|
2
2
|
include Beaker::CommandFactory
|
3
|
+
include Beaker::DSL::Wrappers
|
3
4
|
|
4
5
|
def reboot
|
5
6
|
exec(Beaker::Command.new("shutdown /r /t 0"), :expect_connection_failure => true)
|
@@ -25,13 +26,93 @@ module PSWindows::Exec
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def get_ip
|
28
|
-
ip = execute("for /f \"tokens=14\" %f in ('ipconfig ^| find \"IP Address\"') do @echo %f").strip
|
29
|
+
ip = execute("for /f \"tokens=14\" %f in ('ipconfig ^| find \"IP Address\"') do @echo %f", :accept_all_exit_codes => true).strip
|
29
30
|
if ip == ''
|
30
|
-
ip = execute("for /f \"tokens=14\" %f in ('ipconfig ^| find \"IPv4 Address\"') do @echo %f").strip
|
31
|
+
ip = execute("for /f \"tokens=14\" %f in ('ipconfig ^| find \"IPv4 Address\"') do @echo %f", :accept_all_exit_codes => true).strip
|
31
32
|
end
|
32
33
|
if ip == ''
|
33
34
|
ip = execute("for /f \"tokens=14\" %f in ('ipconfig ^| find \"IPv6 Address\"') do @echo %f").strip
|
34
35
|
end
|
35
36
|
ip
|
36
37
|
end
|
38
|
+
|
39
|
+
# Create the provided directory structure on the host
|
40
|
+
# @param [String] dir The directory structure to create on the host
|
41
|
+
# @return [Boolean] True, if directory construction succeeded, otherwise False
|
42
|
+
def mkdir_p dir
|
43
|
+
windows_dirstring = dir.gsub('/','\\')
|
44
|
+
cmd = "if not exist #{windows_dirstring} (md #{windows_dirstring})"
|
45
|
+
result = exec(Beaker::Command.new(cmd), :acceptable_exit_codes => [0, 1])
|
46
|
+
result.exit_code == 0
|
47
|
+
end
|
48
|
+
|
49
|
+
#Add the provided key/val to the current ssh environment
|
50
|
+
#@param [String] key The key to add the value to
|
51
|
+
#@param [String] val The value for the key
|
52
|
+
#@example
|
53
|
+
# host.add_env_var('PATH', '/usr/bin:PATH')
|
54
|
+
def add_env_var key, val
|
55
|
+
key = key.to_s.upcase
|
56
|
+
#see if the key/value pair already exists
|
57
|
+
cur_val = subbed_val = get_env_var(key, true)
|
58
|
+
subbed_val = cur_val.gsub(/#{Regexp.escape(val.gsub(/'|"/, ''))}/, '')
|
59
|
+
if cur_val.empty?
|
60
|
+
exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', '#{val}', 'Machine')"))
|
61
|
+
self.close #refresh the state
|
62
|
+
elsif subbed_val == cur_val #not present, add it
|
63
|
+
exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', '#{val};#{cur_val}', 'Machine')"))
|
64
|
+
self.close #refresh the state
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#Delete the provided key/val from the current ssh environment
|
69
|
+
#@param [String] key The key to delete the value from
|
70
|
+
#@param [String] val The value to delete for the key
|
71
|
+
#@example
|
72
|
+
# host.delete_env_var('PATH', '/usr/bin:PATH')
|
73
|
+
def delete_env_var key, val
|
74
|
+
key = key.to_s.upcase
|
75
|
+
#get the current value of the key
|
76
|
+
cur_val = subbed_val = get_env_var(key, true)
|
77
|
+
subbed_val = (cur_val.split(';') - [val.gsub(/'|"/, '')]).join(';')
|
78
|
+
if subbed_val != cur_val
|
79
|
+
#remove the current key value
|
80
|
+
self.clear_env_var(key)
|
81
|
+
#set to the truncated value
|
82
|
+
self.add_env_var(key, subbed_val)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
#Return the value of a specific env var
|
87
|
+
#@param [String] key The key to look for
|
88
|
+
#@param [Boolean] clean Remove the 'KEY=' and only return the value of the env var
|
89
|
+
#@example
|
90
|
+
# host.get_env_var('path')
|
91
|
+
def get_env_var key, clean = false
|
92
|
+
self.close #refresh the state
|
93
|
+
key = key.to_s.upcase
|
94
|
+
val = exec(Beaker::Command.new("set #{key}"), :accept_all_exit_codes => true).stdout.chomp
|
95
|
+
if val.empty?
|
96
|
+
return ''
|
97
|
+
else
|
98
|
+
if clean
|
99
|
+
val.gsub(/#{key}=/,'')
|
100
|
+
else
|
101
|
+
val
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
#Delete the environment variable from the current ssh environment
|
107
|
+
#@param [String] key The key to delete
|
108
|
+
#@example
|
109
|
+
# host.clear_env_var('PATH')
|
110
|
+
def clear_env_var key
|
111
|
+
key = key.to_s.upcase
|
112
|
+
exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', $null, 'Machine')"))
|
113
|
+
exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', $null, 'User')"))
|
114
|
+
exec(powershell("[Environment]::SetEnvironmentVariable('#{key}', $null, 'Process')"))
|
115
|
+
self.close #refresh the state
|
116
|
+
end
|
117
|
+
|
37
118
|
end
|
@@ -2,7 +2,7 @@ module PSWindows::Pkg
|
|
2
2
|
include Beaker::CommandFactory
|
3
3
|
|
4
4
|
def check_for_command(name)
|
5
|
-
result = exec(Beaker::Command.new("where #{name}"), :
|
5
|
+
result = exec(Beaker::Command.new("where #{name}"), :accept_all_exit_codes => true)
|
6
6
|
result.exit_code == 0
|
7
7
|
end
|
8
8
|
|
@@ -24,14 +24,18 @@ module PSWindows::Pkg
|
|
24
24
|
0
|
25
25
|
end
|
26
26
|
|
27
|
+
#Examine the host system to determine the architecture, overrides default host determine_if_x86_64 so that wmic is used
|
28
|
+
#@return [Boolean] true if x86_64, false otherwise
|
29
|
+
def determine_if_x86_64
|
30
|
+
(identify_windows_architecture =~ /64/) == 0
|
31
|
+
end
|
32
|
+
|
27
33
|
private
|
28
34
|
|
29
35
|
# @api private
|
30
36
|
def identify_windows_architecture
|
31
37
|
arch = nil
|
32
|
-
execute("wmic os get osarchitecture",
|
33
|
-
:acceptable_exit_codes => (0...127)) do |result|
|
34
|
-
|
38
|
+
execute("wmic os get osarchitecture", :accept_all_exit_codes => true) do |result|
|
35
39
|
arch = if result.exit_code == 0
|
36
40
|
result.stdout =~ /64/ ? '64' : '32'
|
37
41
|
else
|
@@ -44,8 +48,7 @@ module PSWindows::Pkg
|
|
44
48
|
# @api private
|
45
49
|
def identify_windows_architecture_from_os_name_for_win2003
|
46
50
|
arch = nil
|
47
|
-
execute("wmic os get name",
|
48
|
-
:acceptable_exit_codes => (0...127)) do |result|
|
51
|
+
execute("wmic os get name", :accept_all_exit_codes => true) do |result|
|
49
52
|
arch = result.stdout =~ /64/ ? '64' : '32'
|
50
53
|
end
|
51
54
|
arch
|
@@ -28,4 +28,109 @@ module Unix::Exec
|
|
28
28
|
execute("ip a|awk '/global/{print$2}' | cut -d/ -f1 | head -1").strip
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
# Create the provided directory structure on the host
|
33
|
+
# @param [String] dir The directory structure to create on the host
|
34
|
+
# @return [Boolean] True, if directory construction succeeded, otherwise False
|
35
|
+
def mkdir_p dir
|
36
|
+
cmd = "mkdir -p #{dir}"
|
37
|
+
result = exec(Beaker::Command.new(cmd), :acceptable_exit_codes => [0, 1])
|
38
|
+
result.exit_code == 0
|
39
|
+
end
|
40
|
+
|
41
|
+
# Recursively remove the path provided
|
42
|
+
# @param [String] path The path to remove
|
43
|
+
def rm_rf path
|
44
|
+
exec(Beaker::Command.new("rm -rf #{path}"))
|
45
|
+
end
|
46
|
+
|
47
|
+
# Converts the provided environment file to a new shell script in /etc/profile.d, then sources that file.
|
48
|
+
# This is for sles based hosts.
|
49
|
+
# @param [String] env_file The ssh environment file to read from
|
50
|
+
def mirror_env_to_profile_d env_file
|
51
|
+
if self[:platform] =~ /sles-/
|
52
|
+
@logger.debug("mirroring environment to /etc/profile.d on sles platform host")
|
53
|
+
cur_env = exec(Beaker::Command.new("cat #{env_file}")).stdout
|
54
|
+
shell_env = ''
|
55
|
+
cur_env.each_line do |env_line|
|
56
|
+
shell_env << "export #{env_line}"
|
57
|
+
end
|
58
|
+
#here doc it over
|
59
|
+
exec(Beaker::Command.new("cat << EOF > #{self[:profile_d_env_file]}\n#{shell_env}EOF"))
|
60
|
+
#set permissions
|
61
|
+
exec(Beaker::Command.new("chmod +x #{self[:profile_d_env_file]}"))
|
62
|
+
#keep it current
|
63
|
+
exec(Beaker::Command.new("source #{self[:profile_d_env_file]}"))
|
64
|
+
else
|
65
|
+
#noop
|
66
|
+
@logger.debug("will not mirror environment to /etc/profile.d on non-sles platform host")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
#Add the provided key/val to the current ssh environment
|
71
|
+
#@param [String] key The key to add the value to
|
72
|
+
#@param [String] val The value for the key
|
73
|
+
#@example
|
74
|
+
# host.add_env_var('PATH', '/usr/bin:PATH')
|
75
|
+
def add_env_var key, val
|
76
|
+
key = key.to_s.upcase
|
77
|
+
env_file = self[:ssh_env_file]
|
78
|
+
escaped_val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;')
|
79
|
+
#see if the key/value pair already exists
|
80
|
+
if exec(Beaker::Command.new("grep #{key}=.*#{escaped_val} #{env_file}"), :accept_all_exit_codes => true ).exit_code == 0
|
81
|
+
return #nothing to do here, key value pair already exists
|
82
|
+
#see if the key already exists
|
83
|
+
elsif exec(Beaker::Command.new("grep #{key} #{env_file}"), :accept_all_exit_codes => true ).exit_code == 0
|
84
|
+
exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=/#{key}=#{escaped_val}:/", env_file))
|
85
|
+
else
|
86
|
+
exec(Beaker::Command.new("echo \"#{key}=#{val}\" >> #{env_file}"))
|
87
|
+
end
|
88
|
+
#update the profile.d to current state
|
89
|
+
#match it to the contents of ssh_env_file
|
90
|
+
mirror_env_to_profile_d(env_file)
|
91
|
+
end
|
92
|
+
|
93
|
+
#Delete the provided key/val from the current ssh environment
|
94
|
+
#@param [String] key The key to delete the value from
|
95
|
+
#@param [String] val The value to delete for the key
|
96
|
+
#@example
|
97
|
+
# host.delete_env_var('PATH', '/usr/bin:PATH')
|
98
|
+
def delete_env_var key, val
|
99
|
+
key = key.to_s.upcase
|
100
|
+
env_file = self[:ssh_env_file]
|
101
|
+
val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;')
|
102
|
+
#if the key only has that single value remove the entire line
|
103
|
+
exec(Beaker::SedCommand.new(self['platform'], "/#{key}=#{val}$/d", env_file))
|
104
|
+
#value in middle of list
|
105
|
+
exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=\\(.*\\)[;:]#{val}/#{key}=\\1/", env_file))
|
106
|
+
#value in start of list
|
107
|
+
exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=#{val}[;:]/#{key}=/", env_file))
|
108
|
+
#update the profile.d to current state
|
109
|
+
#match it to the contents of ssh_env_file
|
110
|
+
mirror_env_to_profile_d(env_file)
|
111
|
+
end
|
112
|
+
|
113
|
+
#Return the value of a specific env var
|
114
|
+
#@param [String] key The key to look for
|
115
|
+
#@example
|
116
|
+
# host.get_env_var('path')
|
117
|
+
def get_env_var key
|
118
|
+
key = key.to_s.upcase
|
119
|
+
exec(Beaker::Command.new("env | grep #{key}"), :accept_all_exit_codes => true).stdout.chomp
|
120
|
+
end
|
121
|
+
|
122
|
+
#Delete the environment variable from the current ssh environment
|
123
|
+
#@param [String] key The key to delete
|
124
|
+
#@example
|
125
|
+
# host.clear_env_var('PATH')
|
126
|
+
def clear_env_var key
|
127
|
+
key = key.to_s.upcase
|
128
|
+
env_file = self[:ssh_env_file]
|
129
|
+
#remove entire line
|
130
|
+
exec(Beaker::SedCommand.new(self['platform'], "/#{key}=.*$/d", env_file))
|
131
|
+
#update the profile.d to current state
|
132
|
+
#match it to the contents of ssh_env_file
|
133
|
+
mirror_env_to_profile_d(env_file)
|
134
|
+
end
|
135
|
+
|
31
136
|
end
|
data/lib/beaker/host/unix/pkg.rb
CHANGED
@@ -8,7 +8,7 @@ module Unix::Pkg
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def check_for_command(name)
|
11
|
-
result = exec(Beaker::Command.new("which #{name}"), :
|
11
|
+
result = exec(Beaker::Command.new("which #{name}"), :accept_all_exit_codes => true)
|
12
12
|
case self['platform']
|
13
13
|
when /solaris-10/
|
14
14
|
result.stdout =~ %r|/.*/#{name}|
|
@@ -20,25 +20,25 @@ module Unix::Pkg
|
|
20
20
|
def check_for_package(name)
|
21
21
|
case self['platform']
|
22
22
|
when /sles-10/
|
23
|
-
result = exec(Beaker::Command.new("zypper se -i --match-exact #{name}"), :
|
23
|
+
result = exec(Beaker::Command.new("zypper se -i --match-exact #{name}"), :accept_all_exit_codes => true)
|
24
24
|
result.stdout =~ /No packages found/ ? (return false) : (return result.exit_code == 0)
|
25
25
|
when /sles-/
|
26
|
-
result = exec(Beaker::Command.new("zypper se -i --match-exact #{name}"), :
|
26
|
+
result = exec(Beaker::Command.new("zypper se -i --match-exact #{name}"), :accept_all_exit_codes => true)
|
27
27
|
when /el-4/
|
28
28
|
@logger.debug("Package query not supported on rhel4")
|
29
29
|
return false
|
30
30
|
when /fedora|centos|eos|el-/
|
31
|
-
result = exec(Beaker::Command.new("rpm -q #{name}"), :
|
31
|
+
result = exec(Beaker::Command.new("rpm -q #{name}"), :accept_all_exit_codes => true)
|
32
32
|
when /ubuntu|debian|cumulus/
|
33
|
-
result = exec(Beaker::Command.new("dpkg -s #{name}"), :
|
33
|
+
result = exec(Beaker::Command.new("dpkg -s #{name}"), :accept_all_exit_codes => true)
|
34
34
|
when /solaris-11/
|
35
|
-
result = exec(Beaker::Command.new("pkg info #{name}"), :
|
35
|
+
result = exec(Beaker::Command.new("pkg info #{name}"), :accept_all_exit_codes => true)
|
36
36
|
when /solaris-10/
|
37
|
-
result = exec(Beaker::Command.new("pkginfo #{name}"), :
|
37
|
+
result = exec(Beaker::Command.new("pkginfo #{name}"), :accept_all_exit_codes => true)
|
38
38
|
when /freebsd-9/
|
39
|
-
result = exec(Beaker::Command.new("pkg_info #{name}"), :
|
39
|
+
result = exec(Beaker::Command.new("pkg_info #{name}"), :accept_all_exit_codes => true)
|
40
40
|
when /freebsd-10/
|
41
|
-
result = exec(Beaker::Command.new("pkg info #{name}"), :
|
41
|
+
result = exec(Beaker::Command.new("pkg info #{name}"), :accept_all_exit_codes => true)
|
42
42
|
else
|
43
43
|
raise "Package #{name} cannot be queried on #{self}"
|
44
44
|
end
|
@@ -211,4 +211,17 @@ module Unix::Pkg
|
|
211
211
|
raise "Package repo cannot be deployed on #{self}; the platform is not supported"
|
212
212
|
end
|
213
213
|
end
|
214
|
+
|
215
|
+
#Examine the host system to determine the architecture
|
216
|
+
#@return [Boolean] true if x86_64, false otherwise
|
217
|
+
def determine_if_x86_64
|
218
|
+
if self[:platform] =~ /solaris/
|
219
|
+
result = exec(Beaker::Command.new("uname -a | grep x86_64"), :accept_all_exit_codes => true)
|
220
|
+
result.exit_code == 0
|
221
|
+
else
|
222
|
+
result = exec(Beaker::Command.new("arch | grep x86_64"), :accept_all_exit_codes => true)
|
223
|
+
result.exit_code == 0
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
214
227
|
end
|
data/lib/beaker/host/windows.rb
CHANGED
@@ -2,7 +2,7 @@ module Windows::Exec
|
|
2
2
|
include Beaker::CommandFactory
|
3
3
|
|
4
4
|
def reboot
|
5
|
-
exec(Beaker::Command.new(
|
5
|
+
exec(Beaker::Command.new('shutdown /r /t 0 /d p:4:1 /c "Beaker::Host reboot command issued"'), :expect_connection_failure => true)
|
6
6
|
end
|
7
7
|
|
8
8
|
ABS_CMD = 'c:\\\\windows\\\\system32\\\\cmd.exe'
|
@@ -2,12 +2,12 @@ module Windows::Pkg
|
|
2
2
|
include Beaker::CommandFactory
|
3
3
|
|
4
4
|
def check_for_command(name)
|
5
|
-
result = exec(Beaker::Command.new("which #{name}"), :
|
5
|
+
result = exec(Beaker::Command.new("which #{name}"), :accept_all_exit_codes => true)
|
6
6
|
result.exit_code == 0
|
7
7
|
end
|
8
8
|
|
9
9
|
def check_for_package(name)
|
10
|
-
result = exec(Beaker::Command.new("cygcheck #{name}"), :
|
10
|
+
result = exec(Beaker::Command.new("cygcheck #{name}"), :accept_all_exit_codes => true)
|
11
11
|
result.exit_code == 0
|
12
12
|
end
|
13
13
|
|
@@ -46,9 +46,7 @@ module Windows::Pkg
|
|
46
46
|
# @api private
|
47
47
|
def identify_windows_architecture
|
48
48
|
arch = nil
|
49
|
-
execute("echo '' | wmic os get osarchitecture",
|
50
|
-
:acceptable_exit_codes => (0...127)) do |result|
|
51
|
-
|
49
|
+
execute("echo '' | wmic os get osarchitecture", :accept_all_exit_codes => true) do |result|
|
52
50
|
arch = if result.exit_code == 0
|
53
51
|
result.stdout =~ /64/ ? '64' : '32'
|
54
52
|
else
|
@@ -61,8 +59,7 @@ module Windows::Pkg
|
|
61
59
|
# @api private
|
62
60
|
def identify_windows_architecture_from_os_name_for_win2003
|
63
61
|
arch = nil
|
64
|
-
execute("echo '' | wmic os get name | grep x64",
|
65
|
-
:acceptable_exit_codes => (0...127)) do |result|
|
62
|
+
execute("echo '' | wmic os get name | grep x64", :accept_all_exit_codes => true) do |result|
|
66
63
|
arch = result.exit_code == 0 ? '64' : '32'
|
67
64
|
end
|
68
65
|
arch
|
@@ -19,7 +19,7 @@ module Beaker
|
|
19
19
|
SLES10_PACKAGES = ['curl']
|
20
20
|
SLES_PACKAGES = ['curl', 'ntp']
|
21
21
|
DEBIAN_PACKAGES = ['curl', 'ntpdate', 'lsb-release']
|
22
|
-
CUMULUS_PACKAGES = ['
|
22
|
+
CUMULUS_PACKAGES = ['curl', 'ntpdate']
|
23
23
|
ETC_HOSTS_PATH = "/etc/hosts"
|
24
24
|
ETC_HOSTS_PATH_SOLARIS = "/etc/inet/hosts"
|
25
25
|
ROOT_KEYS_SCRIPT = "https://raw.githubusercontent.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys"
|
@@ -55,7 +55,7 @@ module Beaker
|
|
55
55
|
try = 0
|
56
56
|
until try >= TRIES do
|
57
57
|
try += 1
|
58
|
-
if host.exec(Command.new(ntp_command), :
|
58
|
+
if host.exec(Command.new(ntp_command), :accept_all_exit_codes => true).exit_code == 0
|
59
59
|
success=true
|
60
60
|
break
|
61
61
|
end
|
@@ -139,9 +139,9 @@ module Beaker
|
|
139
139
|
logger.notify "Sync root authorized_keys from github on #{host.name}"
|
140
140
|
# Allow all exit code, as this operation is unlikely to cause problems if it fails.
|
141
141
|
if host['platform'] =~ /solaris|eos/
|
142
|
-
host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "bash"), :
|
142
|
+
host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "bash"), :accept_all_exit_codes => true)
|
143
143
|
else
|
144
|
-
host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "env PATH=/usr/gnu/bin:$PATH bash"), :
|
144
|
+
host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "env PATH=/usr/gnu/bin:$PATH bash"), :accept_all_exit_codes => true)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
rescue => e
|
@@ -359,7 +359,7 @@ module Beaker
|
|
359
359
|
host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin yes/PermitRootLogin Yes/g' /etc/sshd_config"))
|
360
360
|
elsif host['platform'] =~ /freebsd/
|
361
361
|
host.exec(Command.new("sudo sed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), {:pty => true} )
|
362
|
-
elsif host.
|
362
|
+
elsif not host.is_powershell?
|
363
363
|
host.exec(Command.new("sudo su -c \"sed -ri 's/^#?PermitRootLogin no|^#?PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config\""), {:pty => true})
|
364
364
|
else
|
365
365
|
logger.warn("Attempting to enable root login non-supported platform: #{host.name}: #{host['platform']}")
|
@@ -368,7 +368,7 @@ module Beaker
|
|
368
368
|
if host['platform'] =~ /debian|ubuntu|cumulus/
|
369
369
|
host.exec(Command.new("sudo su -c \"service ssh restart\""), {:pty => true})
|
370
370
|
elsif host['platform'] =~ /centos-7|el-7|redhat-7/
|
371
|
-
host.exec(Command.new("sudo -E systemctl restart sshd.service"), {:
|
371
|
+
host.exec(Command.new("sudo -E systemctl restart sshd.service"), {:pty => true})
|
372
372
|
elsif host['platform'] =~ /centos|el-|redhat|fedora|eos/
|
373
373
|
host.exec(Command.new("sudo -E /sbin/service sshd reload"), {:pty => true})
|
374
374
|
elsif host['platform'] =~ /freebsd/
|
@@ -461,10 +461,10 @@ module Beaker
|
|
461
461
|
# @param [String] val The string to 'echo' on the host
|
462
462
|
def echo_on_host host, val
|
463
463
|
#val = val.gsub(/"/, "\"").gsub(/\(/, "\(")
|
464
|
-
if host.
|
465
|
-
host.exec(Command.new("echo \"#{val}\"")).stdout.chomp
|
466
|
-
else
|
464
|
+
if host.is_powershell?
|
467
465
|
host.exec(Command.new("echo #{val}")).stdout.chomp
|
466
|
+
else
|
467
|
+
host.exec(Command.new("echo \"#{val}\"")).stdout.chomp
|
468
468
|
end
|
469
469
|
end
|
470
470
|
|
@@ -488,7 +488,7 @@ module Beaker
|
|
488
488
|
|
489
489
|
env.each_key do |key|
|
490
490
|
separator = host['pathseparator']
|
491
|
-
if key == 'PATH' && host.
|
491
|
+
if key == 'PATH' && (not host.is_powershell?)
|
492
492
|
separator = ':'
|
493
493
|
end
|
494
494
|
env[key] = env[key].join(separator)
|
@@ -548,7 +548,7 @@ module Beaker
|
|
548
548
|
host.exec(Command.new("sudo /etc/rc.d/sshd restart"))
|
549
549
|
end
|
550
550
|
|
551
|
-
if
|
551
|
+
if not host.is_powershell?
|
552
552
|
#ensure that ~/.ssh/environment exists
|
553
553
|
host.exec(Command.new("mkdir -p #{Pathname.new(host[:ssh_env_file]).dirname}"))
|
554
554
|
host.exec(Command.new("chmod 0600 #{Pathname.new(host[:ssh_env_file]).dirname}"))
|
@@ -565,10 +565,10 @@ module Beaker
|
|
565
565
|
host.close
|
566
566
|
|
567
567
|
# print out the working env
|
568
|
-
if host.
|
569
|
-
host.exec(Command.new("cat #{host[:ssh_env_file]}"))
|
570
|
-
else
|
568
|
+
if host.is_powershell?
|
571
569
|
host.exec(Command.new("SET"))
|
570
|
+
else
|
571
|
+
host.exec(Command.new("cat #{host[:ssh_env_file]}"))
|
572
572
|
end
|
573
573
|
|
574
574
|
end
|