Ignore acl_log lines printed before a test SG logging starts

Instead of taking the last N lines printed that include "acl_log", print
only those "acl_log" lines with ID greater than the value obtained before
the test started.

Change-Id: I31d74e72678c21dac0850daea761fca1f9f736ac
This commit is contained in:
Eduardo Olivares 2024-12-23 09:55:21 +01:00
parent a575b79451
commit 901b1cd6b6

View File

@ -203,36 +203,37 @@ class BaseSecGroupLoggingTest(
def _get_logs_and_counts(self, hypervisor_ssh, start_track):
# create dictionary to track values of a hypervisor if it doesn't exist
self._hypervisors_counts.setdefault(hypervisor_ssh.host, dict())
# tracks A value, before test traffic sent to be logged
if start_track:
# tracks A value, before test traffic sent to be logged
_track_value = int(hypervisor_ssh.exec_command(
"sudo grep acl_log {} | tail -n1 | cut -d '|' -f 2"
.format(self.SG_LOG_FILE), timeout=120))
self._hypervisors_counts[hypervisor_ssh.host]['A'] = _track_value
LOG.debug("Start log count value A on '%s' is %d",
hypervisor_ssh.host, _track_value)
# tracks B value, after test traffic sent to be logged
# (extracts logs from file right away, to avoid race conditions).
else:
cmds_output = hypervisor_ssh.exec_command(
("B=$(sudo grep acl_log {0} | tail -n1 | cut -d '|' -f 2 | "
"sed 's/^0*//') && echo $B && "
"sudo grep acl_log {0} | tail -n $(($B-{1}))").format(
self.SG_LOG_FILE,
self._hypervisors_counts[hypervisor_ssh.host]['A']),
# tracks B value, after test traffic sent to be logged
# (extracts logs from file right away, to avoid race conditions).
cmd_outputs = hypervisor_ssh.exec_command(
"sudo grep acl_log {0}".format(self.SG_LOG_FILE),
timeout=120).splitlines()
# save B in instance, and log in tempest the B value
_track_value = int(cmds_output[0])
self._hypervisors_counts[hypervisor_ssh.host]['B'] = _track_value
b = self._hypervisors_counts[hypervisor_ssh.host]['B'] = int(
cmd_outputs[-1].split("|")[1])
LOG.debug("End log count value B on '%s' is %d",
hypervisor_ssh.host, _track_value)
# parse and save logs retrieved, per hypervisor tracked counts
hypervisor_ssh.host, b)
# extract logs with ID greater than A and lower or equal than B
# i.e. the logs that were printed during this test
a = self._hypervisors_counts[hypervisor_ssh.host]['A']
new_logs = [output for output in cmd_outputs
if a < int(output.split("|")[1]) <= b]
self._hypervisors_counts[hypervisor_ssh.host][
'tested_logs'] = "\n".join(cmds_output[1:])
'tested_logs'] = "\n".join(new_logs)
# log in tempest the retrieved entries amount
_test_logs_amount = \
self._hypervisors_counts[hypervisor_ssh.host]['B'] - \
self._hypervisors_counts[hypervisor_ssh.host]['A']
_test_logs_amount = b - a
mess = "Unexpected num of lines with {} < acl_log_ID <= {}".format(
a, b)
mess += "\n" + "\n".join(cmd_outputs)
self.assertEqual(_test_logs_amount, len(new_logs), mess)
self._hypervisors_counts[hypervisor_ssh.host][
'test_logs_amount'] = _test_logs_amount
LOG.debug(