From c75399776979845b7f428a0b7ae4e4fdca992b8f Mon Sep 17 00:00:00 2001 From: Joerg Schultze-Lutter <76180229+joergschultzelutter@users.noreply.github.com> Date: Mon, 8 Aug 2022 10:45:16 +0200 Subject: [PATCH] Client-triggered forced update of pip packages --- src/client.py | 18 ++++++++++++++++-- src/server.py | 11 +++++++++-- src/utils.py | 16 +++++++++++++++- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/client.py b/src/client.py index 08b8875..9c985af 100644 --- a/src/client.py +++ b/src/client.py @@ -48,7 +48,12 @@ class RemoteFrameworkClient: - def __init__(self, remote_connect_string: str, debug=False): + def __init__( + self, + remote_connect_string: str, + always_upgrade_server_packages: bool, + debug: bool = False, + ): """ Constructor for RemoteFrameworkClient @@ -56,6 +61,10 @@ def __init__(self, remote_connect_string: str, debug=False): ========== remote_connect_string : 'str' connect string, containing host, port, user and pass + always_upgrade_server_packages: 'bool' + Always upgrade pip packages on the server even if they are already installed. This is + exquivalent to the server's "always-upgrade-packages" option but allows you to control + the upgrade through a client call debug: 'bool' run in debug mode. Enables extra logging and instructs the remote server not to cleanup the workspace after test execution @@ -66,6 +75,7 @@ def __init__(self, remote_connect_string: str, debug=False): self._debug = debug self._remote_connect_string = remote_connect_string + self._always_upgrade_server_packages = always_upgrade_server_packages self._dependencies = {} self._pip_dependencies = {} self._suites = {} @@ -122,6 +132,7 @@ def execute_run( self._suites, self._dependencies, self._pip_dependencies, + self._always_upgrade_server_packages, robot_arg_dict, self._debug, ) @@ -347,6 +358,7 @@ def _process_robot_file(self, source): robot_output_file, robot_log_file, robot_report_file, + robot_always_upgrade_server_packages, ) = get_command_line_params_client() # Set debug level @@ -427,7 +439,9 @@ def _process_robot_file(self, source): # Default branch for executing actual tests rfs = RemoteFrameworkClient( - remote_connect_string=remote_connect_string, debug=robot_debug + remote_connect_string=remote_connect_string, + always_upgrade_server_packages=robot_always_upgrade_server_packages, + debug=robot_debug, ) result = rfs.execute_run( suite_list=robot_input_dir, diff --git a/src/server.py b/src/server.py index 8f45cd0..5478b76 100644 --- a/src/server.py +++ b/src/server.py @@ -109,6 +109,7 @@ def execute_robot_run( test_suites: dict, dependencies: dict, pip_dependencies: dict, + always_upgrade_server_packages: bool, robot_args: dict, debug=False, ): @@ -123,6 +124,10 @@ def execute_robot_run( Dictionary of files the test suites are dependent on pip_dependencies: 'list' List of pip packages that the user explicitly asked us to install + always_upgrade_server_packages: 'bool' + Always upgrade pip packages on the server even if they are already installed. This is + exquivalent to the server's "always-upgrade-packages" option but allows you to control + the upgrade through a client call robot_args: 'dict' Dictionary of arguments to pass to robot.run() debug: 'bool' @@ -169,8 +174,10 @@ def execute_robot_run( # Check if the package (excluding the version info!) is already installed # If not, collect the entries with potential version info # (but don't install the pip packages yet) - if (pip_package not in installed_pips) or ( - robot_always_upgrade_packages + if ( + (pip_package not in installed_pips) + or (robot_always_upgrade_packages) + or (always_upgrade_server_packages) ): if pip_dependency not in pips_to_be_installed: pips_to_be_installed.append(pip_dependency) diff --git a/src/utils.py b/src/utils.py index 7c3e2d1..04e7582 100644 --- a/src/utils.py +++ b/src/utils.py @@ -200,7 +200,9 @@ def get_command_line_params_server(): dest="robot_always_upgrade_packages", action="store_true", help="If your Robot Framework suite depends on external pip packages, always upgrade these packages" - " even if they are already installed", + " on the XMLRPC server even if they are already installed. Similar to the client argument" + " 'always-upgrade-server-packages' but forces the upgrade for each test (regardless of the client" + " settings)." ) parser.add_argument( @@ -416,6 +418,16 @@ def get_command_line_params_client(): help="Robot Framework report file name. Default value: remote_report.html", ) + parser.add_argument( + "--always-upgrade-server-packages", + dest="robot_always_upgrade_server_packages", + action="store_true", + help="If your Robot Framework suite depends on external pip packages, always upgrade these packages" + " on the remote XMLRPC server even if they are already installed. This is the equivalent to the" + " server's 'always-upgrade-packages' option which allows you to control a forced update through" + " the client.", + ) + parser.add_argument( "--debug", dest="robot_debug", @@ -445,6 +457,7 @@ def get_command_line_params_client(): robot_output_file = args.robot_output_file robot_log_file = args.robot_log_file robot_report_file = args.robot_report_file + robot_always_upgrade_server_packages = args.robot_always_upgrade_server_packages # populate defaults in case the user has not specified a value # obviously, argparse's 'extend' option does not permit defaults @@ -471,6 +484,7 @@ def get_command_line_params_client(): robot_output_file, robot_log_file, robot_report_file, + robot_always_upgrade_server_packages, )