Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the ignore rule in agent update test #2915

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions tests_e2e/orchestrator/lib/agent_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,19 @@ def _execute(self, environment: Environment, variables: Dict[str, Any]):
test_suite_success = False
raise

# initialize and save test classes at once to avoid multiple initialization and also keep the context of the test class around
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code would be simpler and clearer if you move the call to self._check_agent_log() into execute_test_suite().

As test are executed, we can collect the ignore rules into an array and then just pass them as argument to check_agent_log()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me work on it

load_tests = {}
for suite in self.context.test_suites: # pylint: disable=E1133
for test in suite.tests:
if test.name not in load_tests:
load_tests[test.name] = test.test_class(self.context)

for suite in self.context.test_suites: # pylint: disable=E1133
log.info("Executing test suite %s", suite.name)
self.context.lisa_log.info("Executing Test Suite %s", suite.name)
test_suite_success = self._execute_test_suite(suite) and test_suite_success
test_suite_success = self._execute_test_suite(suite, load_tests) and test_suite_success

test_suite_success = self._check_agent_log() and test_suite_success
test_suite_success = self._check_agent_log(load_tests) and test_suite_success

finally:
collect = self.context.collect_logs
Expand All @@ -493,7 +500,7 @@ def _execute(self, environment: Environment, variables: Dict[str, Any]):
if not success:
self._mark_log_as_failed()

def _execute_test_suite(self, suite: TestSuiteInfo) -> bool:
def _execute_test_suite(self, suite: TestSuiteInfo, load_tests: Dict[str, Any]) -> bool:
"""
Executes the given test suite and returns True if all the tests in the suite succeeded.
"""
Expand Down Expand Up @@ -523,8 +530,7 @@ def _execute_test_suite(self, suite: TestSuiteInfo) -> bool:
test_success: bool = True

try:
test.test_class(self.context).run()

load_tests[test.name].run()
summary.append(f"[Passed] {test.name}")
log.info("******** [Passed] %s", test.name)
self.context.lisa_log.info("[Passed] %s", test_full_name)
Expand Down Expand Up @@ -609,7 +615,7 @@ def _execute_test_suite(self, suite: TestSuiteInfo) -> bool:

return suite_success

def _check_agent_log(self) -> bool:
def _check_agent_log(self, load_tests: Dict[str, Any]) -> bool:
"""
Checks the agent log for errors; returns true on success (no errors int the log)
"""
Expand All @@ -628,7 +634,7 @@ def _check_agent_log(self) -> bool:
# E1133: Non-iterable value self.context.test_suites is used in an iterating context (not-an-iterable)
for suite in self.context.test_suites: # pylint: disable=E1133
for test in suite.tests:
ignore_error_rules.extend(test.test_class(self.context).get_ignore_error_rules())
ignore_error_rules.extend(load_tests[test.name].get_ignore_error_rules())

if len(ignore_error_rules) > 0:
new = []
Expand Down
19 changes: 17 additions & 2 deletions tests_e2e/tests/agent_update/rsm_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# 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
Expand All @@ -49,16 +50,17 @@ def __init__(self, context: AgentTestContext):
ip_address=self._context.vm_ip_address,
username=self._context.username,
private_key_file=self._context.private_key_file)
self._installed_agent_version = "9.9.9.9"

def get_ignore_error_rules(self) -> List[Dict[str, Any]]:
ignore_rules = [
#
# This is expected as we validate the downgrade scenario
#
# WARNING ExtHandler ExtHandler Agent WALinuxAgent-9.9.9.9 is permanently blacklisted
#
# Note: Version varies depending on the pipeline branch the test is running on
{
'message': r"Agent WALinuxAgent-9.9.9.9 is permanently blacklisted"
'message': rf"Agent WALinuxAgent-{self._installed_agent_version} is permanently blacklisted"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why using the version of the installed agent? shouldn't it be the version that your test uses for the downgrade?

Copy link
Contributor Author

@nagworld9 nagworld9 Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we blacklist the current version which is running not the downloaded version. we use different versions for downgrade and upgrade sceanrio

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but 9.9.9.9 was blacklisted only because it was > than the version you were upgrading/downgrading to, right? shouldn't this rule be added conditionally, only if installed version > your test version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, let me add that

},
# We don't allow downgrades below then daemon version
# 2023-07-11T02:28:21.249836Z WARNING ExtHandler ExtHandler [AgentUpdateError] The Agent received a request to downgrade to version 1.4.0.0, but downgrading to a version less than the Agent installed on the image (1.4.0.1) is not supported. Skipping downgrade.
Expand All @@ -71,6 +73,8 @@ def get_ignore_error_rules(self) -> List[Dict[str, Any]]:
return ignore_rules

def run(self) -> None:
# retrieve the installed agent version in the vm before run the scenario
self._retrieve_installed_agent_version()
# Allow agent to send supported feature flag
self._verify_agent_reported_supported_feature_flag()

Expand Down Expand Up @@ -241,6 +245,17 @@ def _verify_agent_reported_update_status(self, version: str):
self._ssh_client.run_command(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):
"""
Retrieve the installed agent version
"""
log.info("Retrieving installed agent version")
stdout: str = self._ssh_client.run_command("waagent-version", use_sudo=True)
log.info("Retrieved installed agent version \n {0}".format(stdout))
match = re.search(r'.*Goal state agent: (\S*)', stdout)
if match:
Copy link
Member

@narrieta narrieta Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no match should be an error instead of defaulting to 9.9.9.9, shouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even we raise an error, we still check ignore rules. Need default value either case but that won't change behavior and makes if condition false, so rule won't apply.

But I'll raise error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or at least a warning, rather than silently default to 9.9.9.9

self._installed_agent_version = match.groups()[0]


if __name__ == "__main__":
RsmUpdateBvt.run_from_command_line()
Loading