Skip to content

Commit

Permalink
improved logging (Azure#2893)
Browse files Browse the repository at this point in the history
  • Loading branch information
nagworld9 committed Aug 30, 2023
1 parent 9630724 commit 9bdf245
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
8 changes: 4 additions & 4 deletions tests_e2e/tests/agent_publish/agent_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def _get_agent_info(self) -> None:

def _prepare_agent(self) -> None:
log.info("Modifying agent update related config flags")
output = self._ssh_client.run_command("update-waagent-conf Debug.DownloadNewAgents=y AutoUpdate.GAFamily=Test", use_sudo=True)
log.info('Updated agent-update related config flags \n%s', output)
self._run_remote_test("update-waagent-conf Debug.DownloadNewAgents=y AutoUpdate.GAFamily=Test", use_sudo=True)
log.info('Updated agent-update DownloadNewAgents GAFamily config flags')

def _check_update(self) -> None:
log.info("Verifying for agent update status")
output = self._ssh_client.run_command("agent_publish-check_update.py")
log.info('Checked the agent update \n%s', output)
self._run_remote_test("agent_publish-check_update.py")
log.info('Successfully checked the agent update')

def _check_cse(self) -> None:
custom_script_2_1 = VirtualMachineExtensionClient(
Expand Down
33 changes: 16 additions & 17 deletions tests_e2e/tests/scripts/agent_publish-check_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
# limitations under the License.
#
import re
import sys
import logging

from assertpy import fail

from tests_e2e.tests.lib.agent_log import AgentLog
from tests_e2e.tests.lib.logging import log
from tests_e2e.tests.lib.remote_test import run_remote_test
from tests_e2e.tests.lib.retry import retry_if_false


Expand Down Expand Up @@ -65,9 +67,9 @@ def verify_agent_update_from_log():
update_successful = False
update_version = ''

log = AgentLog()
agentlog = AgentLog()

for record in log.read():
for record in agentlog.read():
if 'TelemetryData' in record.text:
continue

Expand All @@ -76,37 +78,34 @@ def verify_agent_update_from_log():
if update_match:
detected_update = True
update_version = update_match.groups()[2]
logging.info('found the agent update log: %s', record.text)
log.info('found the agent update log: %s', record.text)
break

if detected_update:
running_match = re.match(_RUNNING_PATTERN_00, record.text)
if running_match and update_version == running_match.groups()[0]:
update_successful = True
logging.info('found the agent started new version log: %s', record.text)
log.info('found the agent started new version log: %s', record.text)

if detected_update:
logging.info('update was detected: %s', update_version)
log.info('update was detected: %s', update_version)
if update_successful:
logging.info('update was successful')
log.info('update was successful')
else:
logging.warning('update was not successful')
log.warning('update was not successful')
exit_code = 1
else:
logging.warning('update was not detected')
log.warning('update was not detected')
exit_code = 1

return exit_code == 0


# This method will trace agent update messages in the agent log and determine if the update was successful or not.
try:
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.DEBUG, stream=sys.stdout)
def main():
found: bool = retry_if_false(verify_agent_update_from_log)
if not found:
raise Exception('update was not found in the logs')
except Exception as e:
logging.error(e)
sys.exit(1)
fail('update was not found in the logs')


sys.exit(0)
run_remote_test(main)

0 comments on commit 9bdf245

Please sign in to comment.