Skip to content

Commit

Permalink
Log collector scenario should not pick up runs before service restart (
Browse files Browse the repository at this point in the history
…#3228)

* Log collector scenario fix (#24)

* test

* test

* Rename agent log:

* Use runcommand instead of remote test
  • Loading branch information
maddieford authored Sep 23, 2024
1 parent 31adf25 commit 2e93b78
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tests_e2e/tests/log_collector/log_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

from assertpy import fail

import tests_e2e.tests.lib.logging
from azurelinuxagent.common.utils.shellutil import CommandError
from tests_e2e.tests.lib.agent_test import AgentVmTest
from tests_e2e.tests.lib.logging import log


class LogCollector(AgentVmTest):
Expand All @@ -32,15 +32,24 @@ class LogCollector(AgentVmTest):
"""
def run(self):
ssh_client = self._context.create_ssh_client()
ssh_client.run_command("update-waagent-conf Logs.Collect=y Debug.EnableCgroupV2ResourceLimiting=y Debug.LogCollectorInitialDelay=60", use_sudo=True)

# Rename the agent log file so that the test does not pick up any incomplete log collector runs that started
# before the config is updated
# Enable Cgroup v2 resource limiting and reduce log collector iniital delay via config
log.info("Renaming agent log file and modifying log collector conf flags")
setup_script = ("agent-service stop && mv /var/log/waagent.log /var/log/waagent.$(date --iso-8601=seconds).log && "
"update-waagent-conf Logs.Collect=y Debug.EnableCgroupV2ResourceLimiting=y Debug.LogCollectorInitialDelay=60")
ssh_client.run_command(f"sh -c '{setup_script}'", use_sudo=True)
log.info('Renamed log file and updated log collector config flags')

# Wait for log collector to finish uploading logs
for _ in range(3):
time.sleep(90)
try:
ssh_client.run_command("grep 'Successfully uploaded logs' /var/log/waagent.log")
break
except CommandError:
tests_e2e.tests.lib.logging.log.info("The Agent has not finished log collection, will check again after a short delay")
log.info("The Agent has not finished log collection, will check again after a short delay")
else:
raise Exception("Timeout while waiting for the Agent to finish log collection")

Expand Down Expand Up @@ -70,7 +79,7 @@ def run(self):
# Check that all expected logs exist and are in the correct order
indent = lambda lines: "\n".join([f" {ln}" for ln in lines])
if len(lc_logs) == len(expected) and all([re.match(expected[i], lc_logs[i]) is not None for i in range(len(expected))]):
tests_e2e.tests.lib.logging.log.info("The log collector run completed as expected.\nLog messages:\n%s", indent(lc_logs))
log.info("The log collector run completed as expected.\nLog messages:\n%s", indent(lc_logs))
else:
fail(f"The log collector run did not complete as expected.\nExpected:\n{indent(expected)}\nActual:\n{indent(lc_logs)}")

Expand Down

0 comments on commit 2e93b78

Please sign in to comment.