Skip to content

Commit

Permalink
enable RSM e2e tests (#3030)
Browse files Browse the repository at this point in the history
* enable RSM tests

* merge conflicts
  • Loading branch information
nagworld9 authored Feb 7, 2024
1 parent 475c7f3 commit d8565ac
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 40 deletions.
2 changes: 1 addition & 1 deletion tests_e2e/test_suites/agent_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Self-update: If vm not enrolled into RSM, it will validate agent uses self-update to update to latest version published
name: "AgentUpdate"
tests:
# - "agent_update/rsm_update.py" TODO: will enable this test once we have a new test version published
- "agent_update/rsm_update.py"
- "agent_update/self_update.py"
images:
- "random(endorsed, 10)"
Expand Down
76 changes: 45 additions & 31 deletions tests_e2e/tests/agent_update/rsm_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(self) -> None:
log.info("*******Verifying the Agent Downgrade scenario*******")
stdout: str = self._ssh_client.run_command("waagent-version", use_sudo=True)
log.info("Current agent version running on the vm before update is \n%s", stdout)
self._downgrade_version: str = "1.5.0.0"
self._downgrade_version: str = "2.3.15.0"
log.info("Attempting downgrade version %s", self._downgrade_version)
self._request_rsm_update(self._downgrade_version)
self._check_rsm_gs(self._downgrade_version)
Expand All @@ -88,33 +88,31 @@ def run(self) -> None:
self._verify_guest_agent_update(self._downgrade_version)
self._verify_agent_reported_update_status(self._downgrade_version)


# Verify upgrade scenario
log.info("*******Verifying the Agent Upgrade scenario*******")
stdout: str = self._ssh_client.run_command("waagent-version", use_sudo=True)
log.info("Current agent version running on the vm before update is \n%s", stdout)
upgrade_version: str = "1.5.1.0"
upgrade_version: str = "2.3.15.1"
log.info("Attempting upgrade version %s", upgrade_version)
self._request_rsm_update(upgrade_version)
self._check_rsm_gs(upgrade_version)
self._verify_guest_agent_update(upgrade_version)
self._verify_agent_reported_update_status(upgrade_version)

# verify no version update. There is bug in CRP and will enable once it's fixed
# verify no version update.
log.info("*******Verifying the no version update scenario*******")
stdout: str = self._ssh_client.run_command("waagent-version", use_sudo=True)
log.info("Current agent version running on the vm before update is \n%s", stdout)
version: str = "1.5.1.0"
log.info("Attempting update version same as current version %s", upgrade_version)
self._request_rsm_update(version)
self._check_rsm_gs(version)
self._verify_guest_agent_update(version)
self._verify_agent_reported_update_status(version)
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)
self._check_rsm_gs(current_version)
self._verify_guest_agent_update(current_version)
self._verify_agent_reported_update_status(current_version)

# verify requested version below daemon version
# All the daemons set to 2.2.53, so requesting version below daemon version
log.info("*******Verifying requested version below daemon version scenario*******")
# changing daemon version to 1.5.0.1 from 1.0.0.0 as there is no pkg below than 1.0.0.0 available in PIR, Otherwise we will get pkg not found error
self._prepare_agent("1.5.0.1", update_config=False)
stdout: str = self._ssh_client.run_command("waagent-version", use_sudo=True)
log.info("Current agent version running on the vm before update is \n%s", stdout)
version: str = "1.5.0.0"
Expand All @@ -126,23 +124,27 @@ def run(self) -> None:

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(
'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(self, daemon_version="1.0.0.0", update_config=True) -> None:
def _prepare_agent(self) -> None:
"""
This method is to ensure agent is ready for accepting rsm updates. As part of that we update following flags
1) Changing daemon version since daemon has a hard check on agent version in order to update agent. It doesn't allow versions which are less than daemon version.
2) Updating GAFamily type "Test" and GAUpdates flag to process agent updates on test versions.
"""
log.info('Executing modify_agent_version remote script to update agent installed version to lower than requested version')
self._run_remote_test(self._ssh_client, f"agent_update-modify_agent_version {daemon_version}", use_sudo=True)
log.info('Successfully updated agent installed version')
if update_config:
log.info('Executing update-waagent-conf remote script to update agent update config flags to allow and download test versions')
self._run_remote_test(self._ssh_client, "update-waagent-conf Debug.EnableGAVersioning=y AutoUpdate.GAFamily=Test", use_sudo=True)
log.info('Successfully updated agent update config')
log.info(
'Executing modify_agent_version remote script to update agent installed version to lower than requested version')
output: str = self._ssh_client.run_command("agent_update-modify_agent_version 2.2.53", use_sudo=True)
log.info('Successfully updated agent installed version \n%s', output)
log.info(
'Executing update-waagent-conf remote script to update agent update config flags to allow and download test versions')
output: str = self._ssh_client.run_command(
"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:
Expand Down Expand Up @@ -186,7 +188,9 @@ def _request_rsm_update(self, requested_version: str) -> None:
# 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)
"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
Expand All @@ -197,12 +201,14 @@ def _request_rsm_update(self, requested_version: str) -> None:
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))
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
"""

def _check_agent_version(requested_version: str) -> bool:
waagent_version: str = self._ssh_client.run_command("waagent-version", use_sudo=True)
expected_version = f"Goal state agent: {requested_version}"
Expand All @@ -216,25 +222,29 @@ def _check_agent_version(requested_version: str) -> bool:
success: bool = retry_if_false(lambda: _check_agent_version(requested_version))
if not success:
fail("Guest agent didn't update to requested version {0} but found \n {1}. \n "
"To debug verify if CRP has upgrade operation around that time and also check if agent log has any errors ".format(requested_version, waagent_version))
"To debug verify if CRP has upgrade operation around that time and also check if agent log has any errors ".format(
requested_version, waagent_version))
waagent_version: str = self._ssh_client.run_command("waagent-version", use_sudo=True)
log.info(f"Successfully verified agent updated to requested version. Current agent version running:\n {waagent_version}")
log.info(
f"Successfully verified agent updated to requested version. Current agent version running:\n {waagent_version}")

def _verify_no_guest_agent_update(self, version: str) -> None:
"""
verify current agent version is not updated to requested version
"""
log.info("Verifying no update happened to agent")
current_agent: str = self._ssh_client.run_command("waagent-version", use_sudo=True)
assert_that(current_agent).does_not_contain(version).described_as(f"Agent version changed.\n Current agent {current_agent}")
assert_that(current_agent).does_not_contain(version).described_as(
f"Agent version changed.\n Current agent {current_agent}")
log.info("Verified agent was not updated to requested version")

def _verify_agent_reported_supported_feature_flag(self):
"""
RSM update rely on supported flag that agent sends to CRP.So, checking if GA reports feature flag from the agent log
"""

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")
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")

Expand All @@ -243,8 +253,11 @@ def _verify_agent_reported_update_status(self, version: str):
Verify if the agent reported update status to CRP after update performed
"""

log.info("Executing verify_agent_reported_update_status.py remote script to verify agent reported update status for version {0}".format(version))
self._run_remote_test(self._ssh_client, f"agent_update-verify_agent_reported_update_status.py --version {version}", use_sudo=True)
log.info(
"Executing verify_agent_reported_update_status.py remote script to verify agent reported update status for version {0}".format(
version))
self._run_remote_test(self._ssh_client,
f"agent_update-verify_agent_reported_update_status.py --version {version}", use_sudo=True)
log.info("Successfully Agent reported update status for version {0}".format(version))

def _retrieve_installed_agent_version(self):
Expand All @@ -258,7 +271,8 @@ def _retrieve_installed_agent_version(self):
if match:
self._installed_agent_version = match.groups()[0]
else:
log.warning("Unable to retrieve installed agent version and set to default value {0}".format(self._installed_agent_version))
log.warning("Unable to retrieve installed agent version and set to default value {0}".format(
self._installed_agent_version))


if __name__ == "__main__":
Expand Down
4 changes: 1 addition & 3 deletions tests_e2e/tests/scripts/agent_update-modify_agent_version
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ echo "Agent's Python: $PYTHON"
# some distros return .pyc byte file instead source file .py. So, I retrieve parent directory first.
version_file_dir=$($PYTHON -c 'import azurelinuxagent.common.version as v; import os; print(os.path.dirname(v.__file__))')
version_file_full_path="$version_file_dir/version.py"
sed -E -i "s/AGENT_VERSION\s+=\s+'[0-9.]+'/AGENT_VERSION = '$version'/" $version_file_full_path
echo "Restarting service..."
agent-service restart
sed -E -i "s/^AGENT_VERSION\s+=\s+'[0-9.]+'/AGENT_VERSION = '$version'/" $version_file_full_path
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def check_agent_reported_update_status(expected_version: str) -> bool:
with open(file, 'r') as f:
data = json.load(f)
log.info("Agent status file is %s and it's content %s", file, data)
status = data["__status__"]
guest_agent_status = status["aggregateStatus"]["guestAgentStatus"]
guest_agent_status = data["aggregateStatus"]["guestAgentStatus"]
if "updateStatus" in guest_agent_status.keys():
if guest_agent_status["updateStatus"]["expectedVersion"] == expected_version:
log.info("we found the expected version %s in agent status file", expected_version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def check_agent_supports_versioning() -> bool:
with open(file, 'r') as f:
data = json.load(f)
log.info("Agent status file is %s and it's content %s", file, data)
status = data["__status__"]
supported_features = status["supportedFeatures"]
supported_features = data["supportedFeatures"]
for supported_feature in supported_features:
if supported_feature["Key"] == "VersioningGovernance":
return True
Expand Down
2 changes: 1 addition & 1 deletion tests_e2e/tests/scripts/agent_update-wait_for_rsm_gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_requested_version(gs: GoalState) -> str:
raise Exception(
u"No manifest links found for agent family Test, skipping agent update verification")
manifest = agent_family_manifests[0]
if manifest.is_requested_version_specified and manifest.version is not None:
if manifest.version is not None:
return str(manifest.version)
return ""

Expand Down

0 comments on commit d8565ac

Please sign in to comment.