1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 22:56:15 +01:00

behave: Properly support @destructive tests

This commit is contained in:
Daniel Mach 2022-12-09 15:09:44 +01:00
parent 1839e834c6
commit 44eac57595
2 changed files with 13 additions and 7 deletions

View File

@ -20,8 +20,9 @@ def before_scenario(context, scenario):
def after_scenario(context, scenario): def after_scenario(context, scenario):
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
context.podman.kill() # we must use an existing podman instance defined in `before_all` due to context attribute life-cycle:
context.podman = podman.Podman(context) # https://behave.readthedocs.io/en/stable/context_attributes.html
context.podman.restart()
context.osc.clear() context.osc.clear()
common.check_exit_code(context) common.check_exit_code(context)

View File

@ -8,9 +8,7 @@ class Podman:
self.context = context self.context = context
debug(context, "Podman.__init__()") debug(context, "Podman.__init__()")
self.container_id = None self.container_id = None
self.run() self.start()
self.wait_on_systemd()
self.port = self.get_port()
def __del__(self): def __del__(self):
try: try:
@ -33,8 +31,8 @@ class Podman:
debug(self.context, "> stderr:", proc.stderr) debug(self.context, "> stderr:", proc.stderr)
return proc return proc
def run(self): def start(self):
debug(self.context, "Podman.run()") debug(self.context, "Podman.start()")
args = [ args = [
"run", "run",
"--name", "obs-server-behave", "--name", "obs-server-behave",
@ -50,6 +48,8 @@ class Podman:
proc = self._run(args) proc = self._run(args)
lines = proc.stdout.strip().splitlines() lines = proc.stdout.strip().splitlines()
self.container_id = lines[-1] self.container_id = lines[-1]
self.wait_on_systemd()
self.port = self.get_port()
def kill(self): def kill(self):
if not self.container_id: if not self.container_id:
@ -59,6 +59,11 @@ class Podman:
self._run(args) self._run(args)
self.container_id = None self.container_id = None
def restart(self):
debug(self.context, "Podman.restart()")
self.kill()
self.start()
def wait_on_systemd(self): def wait_on_systemd(self):
args = [ args = [
"exec", "exec",