mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-19 11:56:13 +01:00
behave: Print server logs when a scenario fails
This commit is contained in:
parent
01036341d4
commit
237d0d30f6
@ -1,5 +1,7 @@
|
||||
import os
|
||||
|
||||
from behave.model_core import Status
|
||||
|
||||
from steps import common
|
||||
from steps import osc
|
||||
from steps import podman
|
||||
@ -14,10 +16,18 @@ def after_step(context, step):
|
||||
|
||||
|
||||
def before_scenario(context, scenario):
|
||||
pass
|
||||
# truncate the logs before running any commands
|
||||
proc = context.podman.container.exec(["bash", "-c", "find /srv/www/obs/api/log/ /srv/obs/log/ -name '*.log' -exec truncate --size=0 {} \\;"])
|
||||
|
||||
|
||||
def after_scenario(context, scenario):
|
||||
if scenario.status == Status.failed:
|
||||
# the scenario has failed, dump server logs
|
||||
print("===== BEGIN: server logs ======")
|
||||
proc = context.podman.container.exec(["bash", "-c", "tail -n +1 /srv/www/obs/api/log/*.log /srv/obs/log/*.log"])
|
||||
print(proc.stdout)
|
||||
print("===== END: server logs ======")
|
||||
|
||||
if "destructive" in scenario.tags:
|
||||
# start a new container after a destructive test
|
||||
# we must use an existing podman instance defined in `before_all` due to context attribute life-cycle:
|
||||
|
@ -175,6 +175,10 @@ class Container:
|
||||
self.wait_on_systemd()
|
||||
self.port = self.get_port()
|
||||
|
||||
def exec(self, args, check=True):
|
||||
args = ["exec", self.container_id] + args
|
||||
return self._run(args, check=check)
|
||||
|
||||
def kill(self):
|
||||
if not self.container_id:
|
||||
return
|
||||
@ -189,12 +193,7 @@ class Container:
|
||||
self.start()
|
||||
|
||||
def wait_on_systemd(self):
|
||||
args = [
|
||||
"exec",
|
||||
self.container_id,
|
||||
"/usr/bin/systemctl", "is-system-running", "--wait"
|
||||
]
|
||||
self._run(args, check=False)
|
||||
self.exec(["/usr/bin/systemctl", "is-system-running", "--wait"], check=False)
|
||||
|
||||
def get_port(self):
|
||||
args = ["port", self.container_id]
|
||||
|
Loading…
Reference in New Issue
Block a user