diff --git a/tests_e2e/orchestrator/lib/agent_test_suite.py b/tests_e2e/orchestrator/lib/agent_test_suite.py index b499e3afa..b93ae3fac 100644 --- a/tests_e2e/orchestrator/lib/agent_test_suite.py +++ b/tests_e2e/orchestrator/lib/agent_test_suite.py @@ -731,14 +731,14 @@ def _execute_test_suite(self, suite: TestSuiteInfo, test_context: AgentTestConte log.info("\t%s", r) log.info("") - except: # pylint: disable=bare-except + except Exception as e: suite_success = False self._report_test_result( suite_full_name, suite_name, TestStatus.FAILED, suite_start_time, - message=f"Unhandled exception while executing test suite {suite_name}.", + message=f"Unhandled exception while executing test suite {suite_name}: {e}", add_exception_stack_trace=True) finally: if not suite_success: diff --git a/tests_e2e/tests/lib/ssh_client.py b/tests_e2e/tests/lib/ssh_client.py index ae7600c11..b0efb3a86 100644 --- a/tests_e2e/tests/lib/ssh_client.py +++ b/tests_e2e/tests/lib/ssh_client.py @@ -65,6 +65,9 @@ def generate_ssh_key(private_key_file: Path): def get_architecture(self): return self.run_command("uname -m").rstrip() + def get_distro(self): + return self.run_command("get_distro.py").rstrip() + def copy_to_node(self, local_path: Path, remote_path: Path, recursive: bool = False, attempts: int = ATTEMPTS, attempt_delay: int = ATTEMPT_DELAY) -> None: """ File copy to a remote node diff --git a/tests_e2e/tests/no_outbound_connections/check_no_outbound_connections.py b/tests_e2e/tests/no_outbound_connections/check_no_outbound_connections.py index f97346469..a1145385d 100755 --- a/tests_e2e/tests/no_outbound_connections/check_no_outbound_connections.py +++ b/tests_e2e/tests/no_outbound_connections/check_no_outbound_connections.py @@ -20,17 +20,25 @@ from typing import Any, Dict, List from tests_e2e.tests.lib.agent_test import AgentVmTest +from tests_e2e.tests.lib.agent_test_context import AgentTestContext from tests_e2e.tests.lib.logging import log from tests_e2e.tests.lib.shell import CommandError from tests_e2e.tests.lib.ssh_client import SshClient -from azurelinuxagent.common.version import DISTRO_NAME, DISTRO_VERSION - - class CheckNoOutboundConnections(AgentVmTest): """ Verifies that there is no outbound connectivity on the test VM. """ + def __init__(self, context: AgentTestContext): + super().__init__(context) + self.__distro: str = None + + @property + def distro(self) -> str: + if self.__distro is None: + raise Exception("The distro has not been initialized") + return self.__distro + def run(self): # This script is executed on the test VM. It tries to connect to a well-known DNS server (DNS is on port 53). script: str = """ @@ -46,6 +54,13 @@ def run(self): exit(1) """ ssh_client: SshClient = self._context.create_ssh_client() + try: + self.__distro = ssh_client.get_distro() + log.info("Distro: %s", self.distro) + except Exception as e: + log.warning("Could not determine the distro (setting to UNKNOWN): %s", e) + self.__distro = "UNKNOWN" + try: log.info("Verifying that there is no outbound connectivity on the test VM") ssh_client.run_command("pypy3 -c '{0}'".format(script.replace('"', '\"'))) @@ -69,7 +84,7 @@ def get_ignore_error_rules(self) -> List[Dict[str, Any]]: # { 'message': r"The permanent firewall rules for Azure Fabric are not setup correctly.*The following rules are missing: \['ACCEPT DNS'\]", - 'if': lambda r: DISTRO_NAME == 'redhat' and DISTRO_VERSION == '8.2' + 'if': lambda _: self.distro == 'redhat_82' } ]