diff --git a/tests_e2e/orchestrator/lib/agent_test_suite.py b/tests_e2e/orchestrator/lib/agent_test_suite.py index 022bfe830..799ea441b 100644 --- a/tests_e2e/orchestrator/lib/agent_test_suite.py +++ b/tests_e2e/orchestrator/lib/agent_test_suite.py @@ -149,6 +149,8 @@ def __init__(self, metadata: TestSuiteMetadata) -> None: self._test_suites: List[AgentTestSuite] # Test suites to execute in the environment + self._test_args: Dict[str, str] # Additional arguments pass to the test suite + self._cloud: str # Azure cloud where test VMs are located self._subscription_id: str # Azure subscription where test VMs are located self._location: str # Azure location (region) where test VMs are located @@ -209,6 +211,7 @@ def _initialize(self, environment: Environment, variables: Dict[str, Any], lisa_ self._environment_name = variables["c_env_name"] self._test_suites = variables["c_test_suites"] + self._test_args = self._get_test_args(variables["test_args"]) self._cloud = variables["cloud"] self._subscription_id = variables["subscription_id"] @@ -812,12 +815,15 @@ def _create_test_context(self,) -> AgentTestContext: subscription=self._subscription_id, resource_group=self._resource_group_name, name=self._vm_name) - return AgentVmTestContext( + vm_test_context = AgentVmTestContext( working_directory=self._working_directory, vm=vm, ip_address=self._vm_ip_address, username=self._user, identity_file=self._identity_file) + for key in self._test_args: + setattr(vm_test_context, key, self._test_args[key]) + return vm_test_context else: log.info("Creating test context for scale set") if self._create_scale_set: @@ -836,11 +842,27 @@ def _create_test_context(self,) -> AgentTestContext: if self._create_scale_set: self._test_nodes = [_TestNode(name=i.instance_name, ip_address=i.ip_address) for i in scale_set.get_instances_ip_address()] - return AgentVmssTestContext( + vmss_test_context = AgentVmssTestContext( working_directory=self._working_directory, vmss=scale_set, username=self._user, identity_file=self._identity_file) + for key in self._test_args: + setattr(vmss_test_context, key, self._test_args[key]) + return vmss_test_context + + @staticmethod + def _get_test_args(arg_str) -> Dict[str, str]: + """ + Returns the arguments to be passed to the test classes + """ + test_args: Dict[str, str] = {} + if arg_str == "": + return test_args + for arg in arg_str.split(','): + key, value = map(str.strip, arg.split('=')) + test_args[key] = value + return test_args @staticmethod def _mark_log_as_failed(): diff --git a/tests_e2e/orchestrator/runbook.yml b/tests_e2e/orchestrator/runbook.yml index 722ceba61..9365e4616 100644 --- a/tests_e2e/orchestrator/runbook.yml +++ b/tests_e2e/orchestrator/runbook.yml @@ -55,6 +55,12 @@ variable: - recover_network_interface # + # Additional arguments pass to the test suites + # + - name: test_args + value: "" + is_case_visible: true + # Parameters used to create test VMs # - name: subscription_id diff --git a/tests_e2e/pipeline/pipeline.yml b/tests_e2e/pipeline/pipeline.yml index 35d3fe4c1..8a7971456 100644 --- a/tests_e2e/pipeline/pipeline.yml +++ b/tests_e2e/pipeline/pipeline.yml @@ -19,6 +19,11 @@ parameters: type: string default: "-" + - name: test_args + displayName: Test Args (additional arguments pass to the test suites. Comma-separated list of key=value pairs) + type: string + default: "-" + - name: image displayName: Image (image/image set name, URN, or VHD) type: string @@ -121,6 +126,7 @@ jobs: KEEP_ENVIRONMENT: ${{ parameters.keep_environment }} LOCATION: ${{ parameters.location }} TEST_SUITES: ${{ parameters.test_suites }} + TEST_ARGS: ${{ parameters.test_args }} VM_SIZE: ${{ parameters.vm_size }} - bash: $(Build.SourcesDirectory)/tests_e2e/pipeline/scripts/collect_artifacts.sh diff --git a/tests_e2e/pipeline/scripts/execute_tests.sh b/tests_e2e/pipeline/scripts/execute_tests.sh index 9c185b333..d2d2f874c 100755 --- a/tests_e2e/pipeline/scripts/execute_tests.sh +++ b/tests_e2e/pipeline/scripts/execute_tests.sh @@ -54,6 +54,9 @@ if [[ $TEST_SUITES == "-" ]]; then else TEST_SUITES="-v test_suites:\"$TEST_SUITES\"" fi +if [[ $TEST_ARGS == "-" ]]; then + TEST_ARGS="" +fi if [[ $IMAGE == "-" ]]; then IMAGE="" fi @@ -92,4 +95,5 @@ docker run --rm \ -v location:\"$LOCATION\" \ -v vm_size:\"$VM_SIZE\" \ -v allow_ssh:\"$IP_ADDRESS\" \ + -v test_args:\"$TEST_ARGS\" \ $TEST_SUITES" diff --git a/tests_e2e/tests/agent_publish/agent_publish.py b/tests_e2e/tests/agent_publish/agent_publish.py index 0cf51c331..83c3f7160 100644 --- a/tests_e2e/tests/agent_publish/agent_publish.py +++ b/tests_e2e/tests/agent_publish/agent_publish.py @@ -18,10 +18,13 @@ # import uuid from datetime import datetime -from typing import Any, Dict, List + +from assertpy import fail from tests_e2e.tests.lib.agent_test import AgentVmTest from tests_e2e.tests.lib.agent_test_context import AgentVmTestContext +from tests_e2e.tests.lib.agent_update_helpers import request_rsm_update +from tests_e2e.tests.lib.retry import retry_if_false from tests_e2e.tests.lib.vm_extension_identifier import VmExtensionIds, VmExtensionIdentifier from tests_e2e.tests.lib.logging import log from tests_e2e.tests.lib.ssh_client import SshClient @@ -36,40 +39,126 @@ class AgentPublishTest(AgentVmTest): def __init__(self, context: AgentVmTestContext): super().__init__(context) self._ssh_client: SshClient = self._context.create_ssh_client() + self._published_version = self._get_published_version() def run(self): """ we run the scenario in the following steps: 1. Print the current agent version before the update 2. Prepare the agent for the update - 3. Check for agent update from the log - 4. Print the agent version after the update - 5. Ensure CSE is working + 3. Check for agent update from the log and waagent version + 4. Ensure CSE is working """ self._get_agent_info() - self._prepare_agent() - self._check_update() - self._get_agent_info() + + log.info("Testing rsm update flow....") + self._prepare_agent_for_rsm_update() + self._check_update_from_log() + self._verify_current_agent_version() + self._check_cse() + + log.info("Testing self update flow....") + self._prepare_agent_for_self_update() + self._check_update_from_log() + self._verify_current_agent_version() + self._check_cse() def get_ignore_errors_before_timestamp(self) -> datetime: timestamp = self._ssh_client.run_command("agent_publish-get_agent_log_record_timestamp.py") return datetime.strptime(timestamp.strip(), u'%Y-%m-%d %H:%M:%S.%f') + def _get_published_version(self): + """ + Gets version from test_args if provided, else use the release version from source code version.py + """ + if hasattr(self._context, "published_version"): + return self._context.published_version + + version = self._ssh_client.run_command("pypy3 -c 'from azurelinuxagent.common.version import AGENT_VERSION; print(AGENT_VERSION)'").rstrip() + return version + def _get_agent_info(self) -> None: stdout: str = self._ssh_client.run_command("waagent-version", use_sudo=True) log.info('Agent info \n%s', stdout) - def _prepare_agent(self) -> None: + def _verify_agent_reported_supported_feature_flag(self): + """ + RSM update rely on supported feature flag that agent sends to CRP.So, checking if GA reports feature flag from reported status + """ + log.info( + "Executing verify_versioning_supported_feature.py remote script to verify agent reported supported feature flag, so that CRP can send RSM update request") + self._run_remote_test(self._ssh_client, "agent_update-verify_versioning_supported_feature.py", use_sudo=True) + log.info("Successfully verified that Agent reported VersioningGovernance supported feature flag") + + def _check_rsm_gs(self, requested_version: str) -> None: + # This checks if RSM GS available to the agent after we send the rsm update request + log.info( + 'Executing wait_for_rsm_gs.py remote script to verify latest GS contain requested version after rsm update requested') + self._run_remote_test(self._ssh_client, f"agent_update-wait_for_rsm_gs.py --version {requested_version}", + use_sudo=True) + log.info('Verified latest GS contain requested version after rsm update requested') + + def _prepare_agent_for_rsm_update(self) -> None: + """ + This method prepares the agent for the RSM update + """ + # First we update the agent to latest version like prod + # Next send RSM update request for new published test version + log.info( + 'Updating agent config flags to allow and download test versions') + output: str = self._ssh_client.run_command( + "update-waagent-conf AutoUpdate.Enabled=y AutoUpdate.UpdateToLatestVersion=y", use_sudo=True) + log.info('Successfully updated agent update config \n %s', output) + + self._verify_agent_reported_supported_feature_flag() + arch_type = self._ssh_client.get_architecture() + request_rsm_update(self._published_version, self._context.vm, arch_type) + self._check_rsm_gs(self._published_version) + + output: str = self._ssh_client.run_command( + "update-waagent-conf Debug.EnableGAVersioning=y AutoUpdate.GAFamily=Test", use_sudo=True) + log.info('Successfully enabled rsm updates \n %s', output) + + def _prepare_agent_for_self_update(self) -> None: + """ + This method prepares the agent for the self update + """ log.info("Modifying agent update related config flags and renaming the log file") - self._run_remote_test(self._ssh_client, "sh -c 'agent-service stop && mv /var/log/waagent.log /var/log/waagent.$(date --iso-8601=seconds).log && update-waagent-conf AutoUpdate.UpdateToLatestVersion=y AutoUpdate.GAFamily=Test AutoUpdate.Enabled=y Extensions.Enabled=y'", use_sudo=True) - log.info('Renamed log file and updated agent-update DownloadNewAgents GAFamily config flags') + setup_script = ("agent-service stop && mv /var/log/waagent.log /var/log/waagent.$(date --iso-8601=seconds).log && " + "rm -rf /var/lib/waagent/WALinuxAgent-* && " + "update-waagent-conf AutoUpdate.UpdateToLatestVersion=y AutoUpdate.GAFamily=Test AutoUpdate.Enabled=y Extensions.Enabled=y Debug.EnableGAVersioning=n") + self._run_remote_test(self._ssh_client, f"sh -c '{setup_script}'", use_sudo=True) + log.info('Renamed log file and updated self-update config flags') - def _check_update(self) -> None: + def _check_update_from_log(self) -> None: log.info("Verifying for agent update status") - self._run_remote_test(self._ssh_client, "agent_publish-check_update.py") + self._run_remote_test(self._ssh_client, f"agent_publish-check_update.py --published-version {self._published_version}") log.info('Successfully checked the agent update') + def _verify_current_agent_version(self) -> None: + """ + Verify current agent version running on published version + """ + + def _check_agent_version(version: str) -> bool: + waagent_version: str = self._ssh_client.run_command("waagent-version", use_sudo=True) + expected_version = f"Goal state agent: {version}" + if expected_version in waagent_version: + return True + else: + return False + + waagent_version: str = "" + log.info("Verifying agent updated to published version: {0}".format(self._published_version)) + success: bool = retry_if_false(lambda: _check_agent_version(self._published_version)) + if not success: + fail("Guest agent didn't update to published version {0} but found \n {1}. \n ".format( + self._published_version, waagent_version)) + waagent_version: str = self._ssh_client.run_command("waagent-version", use_sudo=True) + log.info( + f"Successfully verified agent updated to published version. Current agent version running:\n {waagent_version}") + def _check_cse(self) -> None: custom_script_2_1 = VirtualMachineExtensionClient( self._context.vm, @@ -86,20 +175,6 @@ def _check_cse(self) -> None: ) custom_script_2_1.assert_instance_view(expected_version="2.1", expected_message=message) - def get_ignore_error_rules(self) -> List[Dict[str, Any]]: - ignore_rules = [ - # - # This is expected as latest version can be the less than test version - # - # WARNING ExtHandler ExtHandler Agent WALinuxAgent-9.9.9.9 is permanently blacklisted - # - { - 'message': r"Agent WALinuxAgent-9.9.9.9 is permanently blacklisted" - } - - ] - return ignore_rules - if __name__ == "__main__": AgentPublishTest.run_from_command_line() diff --git a/tests_e2e/tests/agent_update/rsm_update.py b/tests_e2e/tests/agent_update/rsm_update.py index 86ff7b5e9..ad2222d11 100644 --- a/tests_e2e/tests/agent_update/rsm_update.py +++ b/tests_e2e/tests/agent_update/rsm_update.py @@ -23,22 +23,16 @@ # The test verifies agent update for rsm workflow. This test covers three scenarios downgrade, upgrade and no update. # For each scenario, we initiate the rsm request with target version and then verify agent updated to that target version. # -import json import re from typing import List, Dict, Any -import requests from assertpy import assert_that, fail -from azure.identity import DefaultAzureCredential -from azure.mgmt.compute.models import VirtualMachine -from msrestazure.azure_cloud import Cloud from tests_e2e.tests.lib.agent_test import AgentVmTest from tests_e2e.tests.lib.agent_test_context import AgentVmTestContext -from tests_e2e.tests.lib.azure_clouds import AZURE_CLOUDS +from tests_e2e.tests.lib.agent_update_helpers import request_rsm_update from tests_e2e.tests.lib.logging import log from tests_e2e.tests.lib.retry import retry_if_false -from tests_e2e.tests.lib.virtual_machine_client import VirtualMachineClient class RsmUpdateBvt(AgentVmTest): @@ -71,6 +65,7 @@ def get_ignore_error_rules(self) -> List[Dict[str, Any]]: return ignore_rules def run(self) -> None: + arch_type = self._ssh_client.get_architecture() # retrieve the installed agent version in the vm before run the scenario self._retrieve_installed_agent_version() # Allow agent to send supported feature flag @@ -81,7 +76,7 @@ def run(self) -> None: log.info("Current agent version running on the vm before update is \n%s", stdout) self._downgrade_version: str = "2.3.15.0" log.info("Attempting downgrade version %s", self._downgrade_version) - self._request_rsm_update(self._downgrade_version) + request_rsm_update(self._downgrade_version, self._context.vm, arch_type) self._check_rsm_gs(self._downgrade_version) self._prepare_agent() # Verify downgrade scenario @@ -94,7 +89,7 @@ def run(self) -> None: log.info("Current agent version running on the vm before update is \n%s", stdout) upgrade_version: str = "2.3.15.1" log.info("Attempting upgrade version %s", upgrade_version) - self._request_rsm_update(upgrade_version) + request_rsm_update(upgrade_version, self._context.vm, arch_type) self._check_rsm_gs(upgrade_version) self._verify_guest_agent_update(upgrade_version) self._verify_agent_reported_update_status(upgrade_version) @@ -105,7 +100,7 @@ def run(self) -> None: log.info("Current agent version running on the vm before update is \n%s", stdout) current_version: str = "2.3.15.1" log.info("Attempting update version same as current version %s", current_version) - self._request_rsm_update(current_version) + request_rsm_update(current_version, self._context.vm, arch_type) self._check_rsm_gs(current_version) self._verify_guest_agent_update(current_version) self._verify_agent_reported_update_status(current_version) @@ -117,7 +112,7 @@ def run(self) -> None: log.info("Current agent version running on the vm before update is \n%s", stdout) version: str = "1.5.0.0" log.info("Attempting requested version %s", version) - self._request_rsm_update(version) + request_rsm_update(version, self._context.vm, arch_type) self._check_rsm_gs(version) self._verify_no_guest_agent_update(version) self._verify_agent_reported_update_status(version) @@ -146,64 +141,6 @@ def _prepare_agent(self) -> None: "update-waagent-conf AutoUpdate.UpdateToLatestVersion=y Debug.EnableGAVersioning=y AutoUpdate.GAFamily=Test", use_sudo=True) log.info('Successfully updated agent update config \n %s', output) - @staticmethod - def _verify_agent_update_flag_enabled(vm: VirtualMachineClient) -> bool: - result: VirtualMachine = vm.get_model() - flag: bool = result.os_profile.linux_configuration.enable_vm_agent_platform_updates - if flag is None: - return False - return flag - - def _enable_agent_update_flag(self, vm: VirtualMachineClient) -> None: - osprofile = { - "location": self._context.vm.location, # location is required field - "properties": { - "osProfile": { - "linuxConfiguration": { - "enableVMAgentPlatformUpdates": True - } - } - } - } - log.info("updating the vm with osProfile property:\n%s", osprofile) - vm.update(osprofile) - - def _request_rsm_update(self, requested_version: str) -> None: - """ - This method is to simulate the rsm request. - First we ensure the PlatformUpdates enabled in the vm and then make a request using rest api - """ - if not self._verify_agent_update_flag_enabled(self._context.vm): - # enable the flag - log.info("Attempting vm update to set the enableVMAgentPlatformUpdates flag") - self._enable_agent_update_flag(self._context.vm) - log.info("Updated the enableVMAgentPlatformUpdates flag to True") - else: - log.info("Already enableVMAgentPlatformUpdates flag set to True") - - cloud: Cloud = AZURE_CLOUDS[self._context.vm.cloud] - credential: DefaultAzureCredential = DefaultAzureCredential(authority=cloud.endpoints.active_directory) - token = credential.get_token(cloud.endpoints.resource_manager + "/.default") - headers = {'Authorization': 'Bearer ' + token.token, 'Content-Type': 'application/json'} - # Later this api call will be replaced by azure-python-sdk wrapper - base_url = cloud.endpoints.resource_manager - url = base_url + "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}/" \ - "UpgradeVMAgent?api-version=2022-08-01".format(self._context.vm.subscription, - self._context.vm.resource_group, - self._context.vm.name) - data = { - "target": "Microsoft.OSTCLinuxAgent.Test", - "targetVersion": requested_version - } - - log.info("Attempting rsm upgrade post request to endpoint: {0} with data: {1}".format(url, data)) - response = requests.post(url, data=json.dumps(data), headers=headers, timeout=300) - if response.status_code == 202: - log.info("RSM upgrade request accepted") - else: - raise Exception("Error occurred while making RSM upgrade request. Status code : {0} and msg: {1}".format( - response.status_code, response.content)) - def _verify_guest_agent_update(self, requested_version: str) -> None: """ Verify current agent version running on rsm requested version diff --git a/tests_e2e/tests/lib/agent_test.py b/tests_e2e/tests/lib/agent_test.py index 0021a8d74..e4f73d725 100644 --- a/tests_e2e/tests/lib/agent_test.py +++ b/tests_e2e/tests/lib/agent_test.py @@ -73,6 +73,8 @@ def run_from_command_line(cls): """ Convenience method to execute the test when it is being invoked directly from the command line (as opposed as being invoked from a test framework or library.) + + TODO: Need to implement for reading test specific arguments from command line """ try: if issubclass(cls, AgentVmTest): diff --git a/tests_e2e/tests/lib/agent_update_helpers.py b/tests_e2e/tests/lib/agent_update_helpers.py new file mode 100644 index 000000000..d48d47bf4 --- /dev/null +++ b/tests_e2e/tests/lib/agent_update_helpers.py @@ -0,0 +1,93 @@ +# +# Copyright 2018 Microsoft Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json + +import requests +from azure.identity import DefaultAzureCredential +from msrestazure.azure_cloud import Cloud +from azure.mgmt.compute.models import VirtualMachine + +from tests_e2e.tests.lib.azure_clouds import AZURE_CLOUDS +from tests_e2e.tests.lib.logging import log +from tests_e2e.tests.lib.virtual_machine_client import VirtualMachineClient + +# Helper methods for agent update/publish tests + + +def verify_agent_update_flag_enabled(vm: VirtualMachineClient) -> bool: + result: VirtualMachine = vm.get_model() + flag: bool = result.os_profile.linux_configuration.enable_vm_agent_platform_updates + if flag is None: + return False + return flag + + +def enable_agent_update_flag(vm: VirtualMachineClient) -> None: + osprofile = { + "location": vm.location, # location is required field + "properties": { + "osProfile": { + "linuxConfiguration": { + "enableVMAgentPlatformUpdates": True + } + } + } + } + log.info("updating the vm with osProfile property:\n%s", osprofile) + vm.update(osprofile) + + +def request_rsm_update(requested_version: str, vm: VirtualMachineClient, arch_type) -> None: + """ + This method is to simulate the rsm request. + First we ensure the PlatformUpdates enabled in the vm and then make a request using rest api + """ + if not verify_agent_update_flag_enabled(vm): + # enable the flag + log.info("Attempting vm update to set the enableVMAgentPlatformUpdates flag") + enable_agent_update_flag(vm) + log.info("Updated the enableVMAgentPlatformUpdates flag to True") + else: + log.info("Already enableVMAgentPlatformUpdates flag set to True") + + cloud: Cloud = AZURE_CLOUDS[vm.cloud] + credential: DefaultAzureCredential = DefaultAzureCredential(authority=cloud.endpoints.active_directory) + token = credential.get_token(cloud.endpoints.resource_manager + "/.default") + headers = {'Authorization': 'Bearer ' + token.token, 'Content-Type': 'application/json'} + # Later this api call will be replaced by azure-python-sdk wrapper + base_url = cloud.endpoints.resource_manager + url = base_url + "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}/" \ + "UpgradeVMAgent?api-version=2022-08-01".format(vm.subscription, + vm.resource_group, + vm.name) + if arch_type == "aarch64": + data = { + "target": "Microsoft.OSTCLinuxAgent.ARM64Test", + "targetVersion": requested_version + } + else: + data = { + "target": "Microsoft.OSTCLinuxAgent.Test", + "targetVersion": requested_version, + } + + log.info("Attempting rsm upgrade post request to endpoint: {0} with data: {1}".format(url, data)) + response = requests.post(url, data=json.dumps(data), headers=headers, timeout=300) + if response.status_code == 202: + log.info("RSM upgrade request accepted") + else: + raise Exception("Error occurred while making RSM upgrade request. Status code : {0} and msg: {1}".format( + response.status_code, response.content)) \ No newline at end of file diff --git a/tests_e2e/tests/scripts/agent_publish-check_update.py b/tests_e2e/tests/scripts/agent_publish-check_update.py index 38ae00a90..ab5eb7356 100755 --- a/tests_e2e/tests/scripts/agent_publish-check_update.py +++ b/tests_e2e/tests/scripts/agent_publish-check_update.py @@ -1,5 +1,5 @@ #!/usr/bin/env pypy3 - +import argparse # Microsoft Azure Linux Agent # # Copyright 2018 Microsoft Corporation @@ -53,6 +53,13 @@ """ _UPDATE_PATTERN_03 = re.compile(r'(.*Agent) update found, exiting current process to (\S*) to the new Agent version (\S*)') +""" +Current Agent 2.8.9.9 completed all update checks, exiting current process to upgrade to the new Agent version 2.10.0.7 +('2.8.9.9', 'upgrade', '2.10.0.7') +""" +_UPDATE_PATTERN_04 = re.compile(r'Current Agent (\S*) completed all update checks, exiting current process to (\S*) to the new Agent version (\S*)') + + """ > Agent WALinuxAgent-2.2.47 is running as the goal state agent ('2.2.47',) @@ -60,7 +67,7 @@ _RUNNING_PATTERN_00 = re.compile(r'.*Agent\sWALinuxAgent-(\S*)\sis running as the goal state agent') -def verify_agent_update_from_log(): +def verify_agent_update_from_log(published_version: str) -> bool: exit_code = 0 detected_update = False @@ -73,16 +80,17 @@ def verify_agent_update_from_log(): if 'TelemetryData' in record.text: continue - for p in [_UPDATE_PATTERN_00, _UPDATE_PATTERN_01, _UPDATE_PATTERN_02, _UPDATE_PATTERN_03]: - update_match = re.match(p, record.text) + for p in [_UPDATE_PATTERN_00, _UPDATE_PATTERN_01, _UPDATE_PATTERN_02, _UPDATE_PATTERN_03, _UPDATE_PATTERN_04]: + update_match = re.match(p, record.message) if update_match: - detected_update = True update_version = update_match.groups()[2] - log.info('found the agent update log: %s', record.text) - break + if update_version == published_version: + detected_update = True + log.info('found the agent update log: %s', record.text) + break if detected_update: - running_match = re.match(_RUNNING_PATTERN_00, record.text) + running_match = re.match(_RUNNING_PATTERN_00, record.message) if running_match and update_version == running_match.groups()[0]: update_successful = True log.info('found the agent started new version log: %s', record.text) @@ -95,7 +103,7 @@ def verify_agent_update_from_log(): log.warning('update was not successful') exit_code = 1 else: - log.warning('update was not detected') + log.warning('update was not detected for version: %s', published_version) exit_code = 1 return exit_code == 0 @@ -103,7 +111,10 @@ def verify_agent_update_from_log(): # This method will trace agent update messages in the agent log and determine if the update was successful or not. def main(): - found: bool = retry_if_false(verify_agent_update_from_log) + parser = argparse.ArgumentParser() + parser.add_argument('-p', '--published-version', required=True) + args = parser.parse_args() + found: bool = retry_if_false(lambda: verify_agent_update_from_log(args.published_version)) if not found: fail('update was not found in the logs')