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
|
import os
|
||||||
|
|
||||||
|
from behave.model_core import Status
|
||||||
|
|
||||||
from steps import common
|
from steps import common
|
||||||
from steps import osc
|
from steps import osc
|
||||||
from steps import podman
|
from steps import podman
|
||||||
@ -14,10 +16,18 @@ def after_step(context, step):
|
|||||||
|
|
||||||
|
|
||||||
def before_scenario(context, scenario):
|
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):
|
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:
|
if "destructive" in scenario.tags:
|
||||||
# start a new container after a destructive test
|
# 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:
|
# 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.wait_on_systemd()
|
||||||
self.port = self.get_port()
|
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):
|
def kill(self):
|
||||||
if not self.container_id:
|
if not self.container_id:
|
||||||
return
|
return
|
||||||
@ -189,12 +193,7 @@ class Container:
|
|||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def wait_on_systemd(self):
|
def wait_on_systemd(self):
|
||||||
args = [
|
self.exec(["/usr/bin/systemctl", "is-system-running", "--wait"], check=False)
|
||||||
"exec",
|
|
||||||
self.container_id,
|
|
||||||
"/usr/bin/systemctl", "is-system-running", "--wait"
|
|
||||||
]
|
|
||||||
self._run(args, check=False)
|
|
||||||
|
|
||||||
def get_port(self):
|
def get_port(self):
|
||||||
args = ["port", self.container_id]
|
args = ["port", self.container_id]
|
||||||
|
Loading…
Reference in New Issue
Block a user