-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07c6ec3
commit cc8c86c
Showing
1 changed file
with
37 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,56 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import getopt | ||
import winrm | ||
import logging | ||
|
||
def setup_logging(): | ||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | ||
|
||
def print_usage(): | ||
print(f"Usage: {sys.argv[0]} -i <VM_IPAddress> -a <buildJDKWin_arguments>") | ||
def usage(): | ||
print("Usage: %s -i <VM_IPAddress> -a <buildJDKWin_arguments>" % sys.argv[0]) | ||
print(" Use '-b' to run a build or '-t' to run a test") | ||
sys.exit(1) | ||
|
||
def run_command_over_winrm(vm_ip, command_args, mode): | ||
command_base = "Start-Process powershell.exe -Verb runAs; cd C:/tmp; bash C:/vagrant/pbTestScripts/" | ||
command = command_base + ("buildJDKWin.sh " if mode == 1 else "testJDKWin.sh ") + command_args | ||
|
||
logging.info(f"Executing command: {command} on VM: {vm_ip}") | ||
|
||
try: | ||
session = winrm.Session(vm_ip, auth=('vagrant', 'vagrant')) | ||
result = session.run_ps(command) | ||
|
||
stdout = result.std_out.decode().strip() | ||
stderr = result.std_err.decode().strip() | ||
def run_winrm(vmIP, buildArgs, mode): | ||
cmd_str = "Start-Process powershell.exe -Verb runAs; cd C:/tmp; sh C:/vagrant/pbTestScripts/" | ||
print(f"Mode: {mode}") | ||
if mode == 1: | ||
cmd_str += "buildJDKWin.sh " | ||
else: | ||
cmd_str += "testJDKWin.sh " | ||
cmd_str += buildArgs | ||
print(f"Running: {cmd_str}") | ||
|
||
if stdout: | ||
logging.info(f"Command Output: {stdout}") | ||
if stderr: | ||
logging.error(f"Command Error: {stderr}") | ||
session = winrm.Session(vmIP, auth=('vagrant', 'vagrant')) | ||
result = session.run_ps(cmd_str) | ||
|
||
return result.status_code | ||
except Exception as e: | ||
logging.error(f"Failed to execute command: {str(e)}") | ||
sys.exit(1) | ||
# Print the output and error from the command execution | ||
print(f"STDOUT: {result.std_out.decode('utf-8')}") | ||
print(f"STDERR: {result.std_err.decode('utf-8')}") | ||
|
||
def main(argv): | ||
setup_logging() | ||
|
||
mode = 1 # Default mode is build | ||
command_args = "" | ||
vm_ip_address = "" | ||
|
||
# mode refers to whether it's running a build or a test | ||
mode = 1 | ||
print("Running python script") | ||
inputArgs = "" | ||
ipAddress = "" | ||
try: | ||
opts, _ = getopt.getopt(argv, "ha:i:bt") | ||
opts, args = getopt.getopt(argv, "ha:i:bt") | ||
except getopt.GetoptError as error: | ||
logging.error(f"Argument parsing error: {str(error)}") | ||
print_usage() | ||
|
||
for option, value in opts: | ||
if option == '-a': | ||
command_args = value | ||
elif option == '-i': | ||
vm_ip_address = value | ||
elif option == '-h': | ||
print_usage() | ||
elif option == '-b': | ||
print(str(error)) | ||
usage() | ||
|
||
for current_option, current_value in opts: | ||
if current_option == '-a': | ||
inputArgs = current_value | ||
elif current_option == '-i': | ||
ipAddress = current_value | ||
elif current_option == '-h': | ||
usage() | ||
elif current_option == '-b': | ||
mode = 1 | ||
elif option == '-t': | ||
elif current_option == '-t': | ||
mode = 2 | ||
|
||
if not vm_ip_address or not command_args: | ||
logging.error("VM IP address and command arguments are required.") | ||
print_usage() | ||
|
||
logging.info(f"Command Arguments: {command_args}") | ||
logging.info(f"VM IP Address: {vm_ip_address}") | ||
run_command_over_winrm(vm_ip_address, command_args, mode) | ||
print(f"This is what is in the 'inputArgs' var: {inputArgs}") | ||
print(f"This is what is in the 'ipAddress' var: {ipAddress}") | ||
run_winrm(ipAddress, inputArgs, mode) | ||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) |