From b5fa6078765b69b1404b2c6f4b92f0733c16cad7 Mon Sep 17 00:00:00 2001 From: Noopur Date: Fri, 28 Feb 2025 18:33:11 +0530 Subject: [PATCH] E2E Testing: Register collaborators before exporting workspace (#1410) * E2E Testing: Register collaborators irrespective of TLS/nonTLS Signed-off-by: noopur * Skip docker cleanup if not running Signed-off-by: noopur * Show msg as an info not warning Signed-off-by: noopur --------- Signed-off-by: noopur --- tests/end_to_end/conftest.py | 11 +++++++---- tests/end_to_end/utils/docker_helper.py | 10 ++++++++++ tests/end_to_end/utils/federation_helper.py | 22 --------------------- tests/end_to_end/utils/tr_workspace.py | 12 +++++------ 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/tests/end_to_end/conftest.py b/tests/end_to_end/conftest.py index b56afccce1..a5e0fcc1b7 100644 --- a/tests/end_to_end/conftest.py +++ b/tests/end_to_end/conftest.py @@ -193,7 +193,10 @@ def pytest_sessionfinish(session, exitstatus): shutil.rmtree(cache_dir, ignore_errors=False) log.debug(f"Cleared .pytest_cache directory at {cache_dir}") - # Cleanup docker containers related to aggregator and collaborators, if any. - dh.cleanup_docker_containers(list_of_containers=["aggregator", "collaborator*"]) - # Cleanup docker network created for openfl, if any. - dh.remove_docker_network(["openfl"]) + if dh.is_docker_running(): + # Cleanup docker containers related to aggregator and collaborators, if any. + dh.cleanup_docker_containers(list_of_containers=["aggregator", "collaborator*"]) + # Cleanup docker network created for openfl, if any. + dh.remove_docker_network(["openfl"]) + else: + log.info("Docker is not running or not accessible. Skipping Docker cleanup steps.") diff --git a/tests/end_to_end/utils/docker_helper.py b/tests/end_to_end/utils/docker_helper.py index d5f4feaa5c..66ddbba438 100644 --- a/tests/end_to_end/utils/docker_helper.py +++ b/tests/end_to_end/utils/docker_helper.py @@ -233,3 +233,13 @@ def build_docker_image(image_name, dockerfile_path): ) except Exception as e: raise ex.DockerException(f"Error building docker image: {e}") + + +def is_docker_running(): + try: + subprocess.run(["docker", "info"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return True + except subprocess.CalledProcessError: + return False + except FileNotFoundError: + return False diff --git a/tests/end_to_end/utils/federation_helper.py b/tests/end_to_end/utils/federation_helper.py index cac8e5b9a2..a587d1369d 100644 --- a/tests/end_to_end/utils/federation_helper.py +++ b/tests/end_to_end/utils/federation_helper.py @@ -192,28 +192,6 @@ def import_pki_for_collaborators(collaborators, local_bind_path): except Exception as e: raise e - # Copy the cols.yaml file from aggregator to all the collaborators - # File cols.yaml is updated after PKI setup - try: - results = [ - executor.submit( - copy_file_between_participants, - local_src_path=os.path.join(local_agg_ws_path, "plan"), - local_dest_path=constants.COL_PLAN_PATH.format( - local_bind_path, collaborator.name - ), - file_name="cols.yaml", - run_with_sudo=True, - ) - for collaborator in collaborators - ] - if not all([f.result() for f in results]): - raise Exception( - "Failed to copy cols.yaml file from aggregator to one or more collaborators" - ) - except Exception as e: - raise e - return True diff --git a/tests/end_to_end/utils/tr_workspace.py b/tests/end_to_end/utils/tr_workspace.py index 43e7d48b3c..f98017c62e 100644 --- a/tests/end_to_end/utils/tr_workspace.py +++ b/tests/end_to_end/utils/tr_workspace.py @@ -100,11 +100,11 @@ def create_tr_workspace(request, eval_scope=False): workspace_path, local_bind_path, agg_domain_name, model_owner, plan_path, agg_workspace_path = common_workspace_creation(request, eval_scope) model_name = request.config.model_name # Certify the workspace in case of TLS - # Register the collaborators in case of non-TLS if request.config.use_tls: model_owner.certify_workspace() - else: - model_owner.register_collaborators(plan_path, request.config.num_collaborators) + + # Register the collaborators. It will also update plan/cols.yaml file with the collaborator names. + model_owner.register_collaborators(plan_path, request.config.num_collaborators) # Create the objects for aggregator and collaborators # Workspace path for aggregator is uniform in case of docker or task_runner @@ -188,11 +188,11 @@ def create_tr_dws_workspace(request, eval_scope=False): image_name = constants.DFLT_DOCKERIZE_IMAGE_NAME # Certify the workspace in case of TLS - # Register the collaborators in case of non-TLS if request.config.use_tls: model_owner.certify_workspace() - else: - model_owner.register_collaborators(plan_path, request.config.num_collaborators) + + # Register the collaborators. It will also update plan/cols.yaml file with the collaborator names. + model_owner.register_collaborators(plan_path, request.config.num_collaborators) # Create the objects for aggregator and collaborators # Workspace path for aggregator is uniform in case of docker or task_runner