Skip to content

Commit

Permalink
Evaluate distro remotely [no_outbound_connections test suite]
Browse files Browse the repository at this point in the history
  • Loading branch information
narrieta@microsoft committed Feb 4, 2025
1 parent c0d0207 commit bcf58ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests_e2e/orchestrator/lib/agent_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions tests_e2e/tests/lib/ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand All @@ -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('"', '\"')))
Expand All @@ -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'
}
]

Expand Down

0 comments on commit bcf58ad

Please sign in to comment.