From 8f4d3414f55fbd7c73a01d33dca95d75f5d389f7 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Mon, 22 Apr 2024 11:52:32 +0100 Subject: [PATCH] Only run when docker running and on ubuntu on runners. --- .github/workflows/code_test_and_deploy.yml | 13 +++++---- tests/ssh_test_utils.py | 32 +++++++++++++++++----- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.github/workflows/code_test_and_deploy.yml b/.github/workflows/code_test_and_deploy.yml index 7431a905..2abfa972 100644 --- a/.github/workflows/code_test_and_deploy.yml +++ b/.github/workflows/code_test_and_deploy.yml @@ -45,13 +45,14 @@ jobs: run: | python -m pip install --upgrade pip pip install .[dev] - - name: Shutdown Ubuntu MySQL (SUDO) # free up port 3306 for ssh tests: https://github.com/orgs/community/discussions/25550 - run: | - if [ "$RUNNER_OS" == "Linux" ]; then - sudo service mysql stop - fi - name: Test - run: pytest -k test_combinations_ssh_transfer + run: | + if [ "$RUNNER_OS" == "Linux" ]; then + sudo service mysql stop # free up port 3306 for ssh tests: https://github.com/orgs/community/discussions/25550 + pytest + else + pytest -k "not test_combinations_ssh_transfer and not test_ssh_setup" + fi build_sdist_wheels: name: Build source distribution diff --git a/tests/ssh_test_utils.py b/tests/ssh_test_utils.py index 81cb53ee..5db0bbdd 100644 --- a/tests/ssh_test_utils.py +++ b/tests/ssh_test_utils.py @@ -1,3 +1,7 @@ +""" + +""" + import builtins import copy import os @@ -93,8 +97,8 @@ def setup_ssh_connection(project, setup_ssh_key_pair=True): def setup_project_and_container_for_ssh(project): """""" - assert is_docker_installed(), ( - "docker not installed, " + assert docker_is_running(), ( + "docker is not running, " "this should be checked at the top of test script" ) @@ -171,16 +175,31 @@ def recursive_search_central(project): def get_test_ssh(): """""" - docker_installed = is_docker_installed() + docker_installed = docker_is_running() if not docker_installed: - warnings.warn("SSH tests are not run as docker is not installed.") + warnings.warn( + "SSH tests are not run as docker either not installed or running." + ) return docker_installed +def docker_is_running(): + """""" + if not is_docker_installed(): + return False + + is_running = check_sys_command_returns_0("docker stats --no-stream") + return is_running + + def is_docker_installed(): """""" - check_install = ( - lambda command: subprocess.run( + return check_sys_command_returns_0("docker -v") + + +def check_sys_command_returns_0(command): + return ( + subprocess.run( command, shell=True, stdout=subprocess.DEVNULL, @@ -188,4 +207,3 @@ def is_docker_installed(): ).returncode == 0 ) - return check_install("docker -v")