Module: Windows::Exec
Constant Summary collapse
- ABS_CMD =
'c:\\\\windows\\\\system32\\\\cmd.exe'
- CMD =
'cmd.exe'
Instance Attribute Summary
Attributes included from Beaker::CommandFactory
Instance Method Summary collapse
-
#append_commands(_command = '', user_ac = '', _opts = {}) ⇒ String
Gets the specific append commands as needed for this host.
-
#cygwin_installed? ⇒ Boolean
Determine if cygwin is actually installed on the SUT.
- #echo(msg, abs = true) ⇒ Object
- #get_ip ⇒ Object
-
#mkdir_p(dir) ⇒ Boolean
Create the provided directory structure on the host.
-
#mv(orig, dest, rm = true) ⇒ Object
Move the origin to destination.
- #path ⇒ Object
-
#ping(target, attempts = 5) ⇒ Boolean
Attempt to ping the provided target hostname.
-
#prepend_commands(_command = '', user_pc = nil, opts = {}) ⇒ String
Gets the specific prepend commands as needed for this host.
- #reboot ⇒ Object
-
#selinux_enabled? ⇒ Boolean
Checks if selinux is enabled selinux is not available on Windows.
-
#ssh_permit_user_environment ⇒ Result
private
Sets the PermitUserEnvironment setting & restarts the SSH service.
-
#ssh_service_restart ⇒ Result
Restarts the SSH service.
- #touch(file, abs = true) ⇒ Object
Methods included from Beaker::CommandFactory
Instance Method Details
#append_commands(_command = '', user_ac = '', _opts = {}) ⇒ String
Gets the specific append commands as needed for this host
111 112 113 |
# File 'lib/beaker/host/windows/exec.rb', line 111 def append_commands(_command = '', user_ac = '', _opts = {}) user_ac end |
#cygwin_installed? ⇒ Boolean
Determine if cygwin is actually installed on the SUT. Differs from is_cygwin?, which is just a type check for a Windows::Host.
151 152 153 154 155 156 |
# File 'lib/beaker/host/windows/exec.rb', line 151 def cygwin_installed? output = exec(Beaker::Command.new('cygcheck --check-setup cygwin'), :accept_all_exit_codes => true).stdout return true if output.include?('cygwin') && output.include?('OK') false end |
#echo(msg, abs = true) ⇒ Object
14 15 16 |
# File 'lib/beaker/host/windows/exec.rb', line 14 def echo(msg, abs = true) (abs ? ABS_CMD : CMD) + " /c echo #{msg}" end |
#get_ip ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/beaker/host/windows/exec.rb', line 26 def get_ip # when querying for an IP this way the return value can be formatted like: # IPAddress= # IPAddress={"129.168.0.1"} # IPAddress={"192.168.0.1","2001:db8:aaaa:bbbb:cccc:dddd:eeee:0001"} ips = execute("wmic nicconfig where ipenabled=true GET IPAddress /format:list") ip = '' ips.each_line do |line| matches = line.split('=') next if matches.length <= 1 matches = matches[1].match(/^{"(.*?)"/) next if matches.nil? || matches.captures.nil? || matches.captures.empty? ip = matches.captures[0] if matches && matches.captures break if ip != '' end ip end |
#mkdir_p(dir) ⇒ Boolean
Create the provided directory structure on the host
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/beaker/host/windows/exec.rb', line 126 def mkdir_p(dir) # single or double quotes will disable ~ expansion, so only quote if we have to str = dir.to_s cmd = if str.start_with?('~') && !str.include?(' ') "mkdir -p #{str}" else "mkdir -p \"#{str}\"" end result = exec(Beaker::Command.new(cmd), :acceptable_exit_codes => [0, 1]) result.exit_code == 0 end |
#mv(orig, dest, rm = true) ⇒ Object
Move the origin to destination. The destination is removed prior to moving.
142 143 144 145 |
# File 'lib/beaker/host/windows/exec.rb', line 142 def mv orig, dest, rm = true rm_rf dest unless !rm execute("mv \"#{orig}\" \"#{dest}\"") end |
#path ⇒ Object
22 23 24 |
# File 'lib/beaker/host/windows/exec.rb', line 22 def path 'c:/windows/system32;c:/windows' end |
#ping(target, attempts = 5) ⇒ Boolean
Attempt to ping the provided target hostname
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/beaker/host/windows/exec.rb', line 53 def ping target, attempts = 5 try = 0 while try < attempts result = exec(Beaker::Command.new("ping -n 1 #{target}"), :accept_all_exit_codes => true) return true if result.exit_code == 0 try += 1 end result.exit_code == 0 end |
#prepend_commands(_command = '', user_pc = nil, opts = {}) ⇒ String
Gets the specific prepend commands as needed for this host
98 99 100 101 102 |
# File 'lib/beaker/host/windows/exec.rb', line 98 def prepend_commands(_command = '', user_pc = nil, opts = {}) cygwin_prefix = (self.is_cygwin? and opts[:cmd_exe]) ? 'cmd.exe /c' : '' spacing = user_pc && !cygwin_prefix.empty? ? ' ' : '' "#{cygwin_prefix}#{spacing}#{user_pc}" end |
#reboot ⇒ Object
4 5 6 7 8 9 |
# File 'lib/beaker/host/windows/exec.rb', line 4 def reboot exec(Beaker::Command.new('shutdown /f /r /t 0 /d p:4:1 /c "Beaker::Host reboot command issued"'), :reset_connection => true) # rebooting on windows is sloooooow # give it some breathing room before attempting a reconnect sleep(40) end |
#selinux_enabled? ⇒ Boolean
Checks if selinux is enabled selinux is not available on Windows
119 120 121 |
# File 'lib/beaker/host/windows/exec.rb', line 119 def selinux_enabled? false end |
#ssh_permit_user_environment ⇒ Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the PermitUserEnvironment setting & restarts the SSH service
85 86 87 88 |
# File 'lib/beaker/host/windows/exec.rb', line 85 def ssh_permit_user_environment exec(Beaker::Command.new("echo '\nPermitUserEnvironment yes' >> /etc/sshd_config")) ssh_service_restart end |
#ssh_service_restart ⇒ Result
Restarts the SSH service.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/beaker/host/windows/exec.rb', line 67 def ssh_service_restart command_result = nil # we get periodic failures to restart the service, so looping these with re-attempts repeat_fibonacci_style_for(5) do 0 == exec(Beaker::Command.new("cygrunsrv -E sshd"), :acceptable_exit_codes => [0, 1]).exit_code end repeat_fibonacci_style_for(5) do command_result = exec(Beaker::Command.new("cygrunsrv -S sshd"), :acceptable_exit_codes => [0, 1]) 0 == command_result.exit_code end command_result end |