From d2034477b25f45669f0022ef6c70070016e16418 Mon Sep 17 00:00:00 2001 From: Norberto Arrieta Date: Thu, 24 Oct 2024 09:43:18 -0700 Subject: [PATCH 1/2] Refactor script to check network connectivity [Agent Persist Firewall test] (#3249) Co-authored-by: narrieta@microsoft --- .../agent_persist_firewall-access_wireserver | 82 ++++++++----------- 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/tests_e2e/tests/scripts/agent_persist_firewall-access_wireserver b/tests_e2e/tests/scripts/agent_persist_firewall-access_wireserver index 425d6ba61..3fb007a6e 100755 --- a/tests_e2e/tests/scripts/agent_persist_firewall-access_wireserver +++ b/tests_e2e/tests/scripts/agent_persist_firewall-access_wireserver @@ -29,65 +29,53 @@ echo "$(date --utc +%FT%T.%3NZ): Running as user: $USER" function check_online { - ping 8.8.8.8 -c 1 -i .2 -t 30 > /dev/null 2>&1 && echo 0 || echo 1 -} - -function ping_localhost -{ - ping 127.0.0.1 -c 1 -i .2 -t 30 > /dev/null 2>&1 && echo 0 || echo 1 -} - -function socket_connection -{ - python3 /home/"$TEST_USER"/bin/agent_persist_firewall-check_connectivity.py 2>&1 && echo 0 || echo 1 -} - -# Check more, sleep less -MAX_CHECKS=10 -# Initial starting value for checks -CHECKS=0 -IS_ONLINE=$(check_online) - -echo "Checking network connectivity..." -echo "Running ping to 8.8.8.8 option" -# Loop while we're not online. -while [ "$IS_ONLINE" -eq 1 ]; do - - CHECKS=$((CHECKS + 1)) - if [ $CHECKS -gt $MAX_CHECKS ]; then - break - fi - - echo "$(date --utc +%FT%T.%3NZ): Network still not accessible" - # We're offline. Sleep for a bit, then check again - sleep 1; - IS_ONLINE=$(check_online) - -done + echo "Checking network connectivity..." + + echo "Running ping to 8.8.8.8 option" + checks=0 + while true; do + if ping 8.8.8.8 -c 1 -i .2 -t 30; then + echo "Network is accessible" + return 0 + fi + checks=$((checks + 1)) + if [ $checks -gt 10 ]; then + break + fi + + echo "$(date --utc +%FT%T.%3NZ): Network still not accessible" + # We're offline. Sleep for a bit, then check again + sleep 1; + done + + echo "Checking other options to see if network is accessible..." -# logging other options output to compare and evaluate which option is more stable when ping to 8.8.8.8 failed -if [ "$IS_ONLINE" -eq 1 ]; then - echo "Checking other options to see if network is accessible" echo "Running ping to localhost option" - PING_LOCAL=$(ping_localhost) - if [ "$PING_LOCAL" -eq 1 ]; then - echo "Ping to localhost failed" - else + if ping 127.0.0.1 -c 1 -i .2 -t 30; then echo "Ping to localhost succeeded" + return 0 fi + echo "Ping to localhost failed" + echo "Running socket connection to wireserver:53 option" - IS_ONLINE=$(socket_connection) -fi -if [ "$IS_ONLINE" -eq 1 ]; then + if python3 /home/"$TEST_USER"/bin/agent_persist_firewall-check_connectivity.py; then + echo "Socket connection succeeded" + return 0 + fi + echo "Socket connection failed" + + echo "Unable to connect to network, giving up" + return 1 +} + +if ! check_online; then # We will never be able to get online. Kill script. echo "Unable to connect to network, exiting now" - echo "ExitCode: 1" exit 1 fi echo "Finally online, Time: $(date --utc +%FT%T.%3NZ)" echo "Trying to contact Wireserver as $USER to see if accessible" - echo "" echo "Firewall configuration before accessing Wireserver:" if sudo which iptables > /dev/null ; then From facc242ef0a354ca0be53f78809ed5a9c9ba93c3 Mon Sep 17 00:00:00 2001 From: maddieford <93676569+maddieford@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:37:17 -0700 Subject: [PATCH 2/2] Agent_ext_workflow scenario fix (#3245) * Ignore extra ext operations for test case * Fix expected ops in install scenarios * Improve comment * Improve comments --- .../agent_ext_workflow/extension_workflow.py | 54 ++++++++++--------- ..._ext_workflow-assert_operation_sequence.py | 10 +++- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/tests_e2e/tests/agent_ext_workflow/extension_workflow.py b/tests_e2e/tests/agent_ext_workflow/extension_workflow.py index 3f25c6a6b..c52620c3f 100644 --- a/tests_e2e/tests/agent_ext_workflow/extension_workflow.py +++ b/tests_e2e/tests/agent_ext_workflow/extension_workflow.py @@ -304,15 +304,25 @@ def run(self): log.info("") log.info("*******Verifying the extension update with install scenario*******") - # Record the time we start the test - start_time = self._ssh_client.run_command("date '+%Y-%m-%dT%TZ'").rstrip() - # Version 1.2.0 of the test extension has the same functionalities as 1.1.5 with # "updateMode": "UpdateWithInstall" in HandlerManifest.json to test update case new_version_update_mode_with_install = "1.2.0" old_version = "1.1.5" - # Create DcrTestExtension with version 1.1 and 1.2 + # Install test extension v1.1.5 on the VM and assert instance view before updating the start_time, since + # the previous test case removed v1.1.5 from the VM. + dcr_ext = ExtensionWorkflow.GuestAgentDcrTestExtension( + extension=dcr_test_ext_client, + ssh_client=self._ssh_client, + version=old_version + ) + dcr_ext.modify_ext_settings_and_enable() + dcr_ext.assert_instance_view() + + # Record the time we start the update with install scenario test + start_time = self._ssh_client.run_command("date '+%Y-%m-%dT%TZ'").rstrip() + + # Create DcrTestExtension with version 1.2 dcr_test_ext_id_1_2 = VmExtensionIdentifier( VmExtensionIds.GuestAgentDcrTestExtension.publisher, VmExtensionIds.GuestAgentDcrTestExtension.type, @@ -323,15 +333,6 @@ def run(self): dcr_test_ext_id_1_2, resource_name="GuestAgentDcrTestExt" ) - dcr_ext = ExtensionWorkflow.GuestAgentDcrTestExtension( - extension=dcr_test_ext_client, - ssh_client=self._ssh_client, - version=old_version - ) - - # Install test extension v1.1.5 on the VM and assert instance view - dcr_ext.modify_ext_settings_and_enable() - dcr_ext.assert_instance_view() # Update extension object & version to new version dcr_ext.update_ext_version(dcr_test_ext_client_1_2, new_version_update_mode_with_install) @@ -371,14 +372,24 @@ def run(self): log.info("") log.info("*******Verifying the extension update without install scenario*******") - # Record the time we start the test - start_time = self._ssh_client.run_command("date '+%Y-%m-%dT%TZ'").rstrip() - # Version 1.3.0 of the test extension has the same functionalities as 1.1.5 with # "updateMode": "UpdateWithoutInstall" in HandlerManifest.json to test update case new_version_update_mode_without_install = "1.3.0" - # Create DcrTestExtension with version 1.1 and 1.3 + # Install test extension v1.1.5 on the VM and assert instance view before updating the start_time, since + # the previous test case removed v1.1.5 from the VM. + dcr_ext = ExtensionWorkflow.GuestAgentDcrTestExtension( + extension=dcr_test_ext_client, + ssh_client=self._ssh_client, + version=old_version + ) + dcr_ext.modify_ext_settings_and_enable() + dcr_ext.assert_instance_view() + + # Record the time we start the update without scenario test + start_time = self._ssh_client.run_command("date '+%Y-%m-%dT%TZ'").rstrip() + + # Create DcrTestExtension with version 1.3 dcr_test_ext_id_1_3 = VmExtensionIdentifier( VmExtensionIds.GuestAgentDcrTestExtension.publisher, VmExtensionIds.GuestAgentDcrTestExtension.type, @@ -388,15 +399,6 @@ def run(self): dcr_test_ext_id_1_3, resource_name="GuestAgentDcrTestExt" ) - dcr_ext = ExtensionWorkflow.GuestAgentDcrTestExtension( - extension=dcr_test_ext_client, - ssh_client=self._ssh_client, - version=old_version - ) - - # Install test extension v1.1.5 on the VM and assert instance view - dcr_ext.modify_ext_settings_and_enable() - dcr_ext.assert_instance_view() # Update extension object & version to new version dcr_ext.update_ext_version(dcr_test_ext_client_1_3, new_version_update_mode_without_install) diff --git a/tests_e2e/tests/scripts/agent_ext_workflow-assert_operation_sequence.py b/tests_e2e/tests/scripts/agent_ext_workflow-assert_operation_sequence.py index d01d27799..4817da30f 100755 --- a/tests_e2e/tests/scripts/agent_ext_workflow-assert_operation_sequence.py +++ b/tests_e2e/tests/scripts/agent_ext_workflow-assert_operation_sequence.py @@ -58,9 +58,8 @@ def parse_ops_log(ops_version: str, input_ops: List[str], start_time: str): ops = [] with open(ops_file_name, 'r') as ops_log: - # we get the last len(input_ops) from the log file and ensure they match with the input_ops # Example of a line in the log file - `Date:2019-07-30T21:54:03Z; Operation:install; SeqNo:0` - content = ops_log.readlines()[-len(input_ops):] + content = ops_log.readlines() for op_log in content: data = op_log.split(DELIMITER) date = datetime.strptime(data[0].split("Date:")[1], "%Y-%m-%dT%H:%M:%SZ") @@ -72,6 +71,13 @@ def parse_ops_log(ops_version: str, input_ops: List[str], start_time: str): continue ops.append({'date': date, 'op': op, 'seq_no': seq_no}) + + # Only parse the expected number of operations after the test case starts. There may be additional + # operations on the extension if the agent processes a goal state with additional extensions added by policy + # or otherwise (ConfigurationforLinux, for example) + if len(ops) == len(input_ops): + break + return ops