Skip to content

Commit

Permalink
environment.py: get apparmor logs from host in a function
Browse files Browse the repository at this point in the history
  • Loading branch information
panlinux committed Mar 26, 2024
1 parent 919400d commit 36d595d
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import pycloudlib # type: ignore # noqa: F401
from behave.model import Feature, Scenario
from behave.model_core import Status
from behave.runner import Context

import features.cloud as cloud
Expand Down Expand Up @@ -464,9 +465,23 @@ def after_scenario(context, scenario):
logging.error(str(e))
logging.warning("Failed to collect coverage")

def _get_apparmor_logs_from_host():
# get apparmor DENIED messages from the host
with open("/var/log/syslog", "r") as syslog_fd:
syslog_messages = syslog_fd.readlines()
apparmor_denied = [
msg.strip()
for msg in syslog_messages
if ("DENIED" in msg and "ubuntu_pro_" in msg)
]
return apparmor_denied

def after_step(context, step):
"""Collect test artifacts in the event of failure."""
apparmor_logs = _get_apparmor_logs_from_host()
if apparmor_logs:
# naughty
step.status = Status.failed
if step.status == "failed":
logging.warning("STEP FAILED. Collecting logs.")
inner_dir = os.path.join(
Expand Down Expand Up @@ -499,18 +514,10 @@ def after_step(context, step):
)
)

# get apparmor DENIED messages from the host
# XXX
with open("/var/log/syslog", "r") as syslog_fd:
syslog_messages = syslog_fd.readlines()
apparmor_denied = [
msg.strip()
for msg in syslog_messages
if ("DENIED" in msg and "ubuntu_pro_" in msg)
]
logging.warning("XXX apparmor DENIED from host begin")
logging.warning("\n".join(apparmor_denied))
logging.warning("XXX apparmor DENIED from host end")
if apparmor_logs:
logging.warning("XXX apparmor DENIED from host begin")
logging.warning("\n".join(apparmor_logs))
logging.warning("XXX apparmor DENIED from host end")

if hasattr(context, "machines") and SUT in context.machines:
try:
Expand Down

0 comments on commit 36d595d

Please sign in to comment.