teemtee / tmt

Test Management Tool
MIT License
84 stars 125 forks source link

Unable to clean up guest provisioned by `beaker` plugin #1989

Open psss opened 1 year ago

psss commented 1 year ago

Using separate steps to provision and finish a plan with guest provisioned using the beaker plugin results in a traceback.

tmt run provision -h beaker
tmt run --last login
tmt run --last finish

The following traceback is generated:

Traceback (most recent call last):
  File "/usr/bin/tmt", line 62, in <module>
    tmt.cli.main()
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1689, in invoke
    return _process_result(rv)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1626, in _process_result
    value = ctx.invoke(self._result_callback, value, **ctx.params)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/tmt/cli.py", line 357, in finito
    click_context.obj.run.go()
  File "/usr/lib/python3.11/site-packages/tmt/base.py", line 2707, in go
    plan.go()
  File "/usr/lib/python3.11/site-packages/tmt/base.py", line 1675, in go
    self.finish.go()
  File "/usr/lib/python3.11/site-packages/tmt/steps/finish/__init__.py", line 136, in go
    guest.remove()
  File "/usr/lib/python3.11/site-packages/tmt/steps/provision/mrack.py", line 504, in remove
    self.api.delete()
    ^^^^^^^^
  File "/usr/lib/python3.11/site-packages/tmt/steps/provision/mrack.py", line 373, in api
    self._api = BeakerAPI(self)
                ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/tmt/steps/provision/mrack.py", line 219, in update_wrapper
    return asyncio.run(func(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/tmt/steps/provision/mrack.py", line 277, in __init__
    global_context = mrack.context.global_context
                     ^^^^^^^^^^^^^
AttributeError: type object 'Any' has no attribute 'context'

It seems that after wake() up the context is not well prepared. @Tiboris, could you please have a look?

sbertramrh commented 1 year ago

I think this might be the similar problem I ran into. I ran a test to end before finish and then trying tmt clean -v resulted in this error:

[sbertram@sbertram beaker]$ tmt clean -v
clean
guests
    Stopping guests in run '/var/tmp/tmt/run-033' plan '/qcom-builder/gen3/plan'.
        finish

Traceback (most recent call last):
  File "/home/sbertram/.local/bin/tmt", line 14, in <module>
    tmt.cli.main()
  File "/home/sbertram/.local/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/sbertram/.local/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/sbertram/.local/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sbertram/.local/lib/python3.8/site-packages/click/core.py", line 1635, in invoke
    rv = super().invoke(ctx)
  File "/home/sbertram/.local/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sbertram/.local/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/sbertram/.local/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/sbertram/.local/lib/python3.8/site-packages/tmt/cli.py", line 1513, in clean
    if not clean_obj.guests():
  File "/home/sbertram/.local/lib/python3.8/site-packages/tmt/base.py", line 3450, in guests
    if not self._stop_running_guests(run):
  File "/home/sbertram/.local/lib/python3.8/site-packages/tmt/base.py", line 3422, in _stop_running_guests
    plan.finish.go()
  File "/home/sbertram/.local/lib/python3.8/site-packages/tmt/steps/finish/__init__.py", line 178, in go
    guest.remove()
  File "/home/sbertram/.local/lib/python3.8/site-packages/tmt/steps/provision/mrack.py", line 531, in remove
    self.api.delete()
  File "/home/sbertram/.local/lib/python3.8/site-packages/tmt/steps/provision/mrack.py", line 401, in api
    self._api = BeakerAPI(self)
  File "/home/sbertram/.local/lib/python3.8/site-packages/tmt/steps/provision/mrack.py", line 221, in update_wrapper
    return asyncio.run(func(*args, **kwargs))
  File "/usr/lib64/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib64/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/sbertram/.local/lib/python3.8/site-packages/tmt/steps/provision/mrack.py", line 305, in __init__
    global_context = mrack.context.global_context
AttributeError: '_SpecialForm' object has no attribute 'context'

This is with tmt 1.26 and mrack 1.15.1.

The workaround was to do each separately and then the problems went away.

[sbertram@sbertram beaker]$ tmt clean runs -v
clean
runs
    Removing workdir '/var/tmp/tmt/run-001'.
    Removing workdir '/var/tmp/tmt/run-002'.
    Removing workdir '/var/tmp/tmt/run-003'.
    Removing workdir '/var/tmp/tmt/run-004'.
    Removing workdir '/var/tmp/tmt/run-005'.
    Removing workdir '/var/tmp/tmt/run-006'.
    Removing workdir '/var/tmp/tmt/run-007'.
    Removing workdir '/var/tmp/tmt/run-008'.
    Removing workdir '/var/tmp/tmt/run-009'.
    Removing workdir '/var/tmp/tmt/run-010'.
    Removing workdir '/var/tmp/tmt/run-011'.
    Removing workdir '/var/tmp/tmt/run-012'.
    Removing workdir '/var/tmp/tmt/run-013'.
    Removing workdir '/var/tmp/tmt/run-014'.
    Removing workdir '/var/tmp/tmt/run-015'.
    Removing workdir '/var/tmp/tmt/run-016'.
    Removing workdir '/var/tmp/tmt/run-017'.
    Removing workdir '/var/tmp/tmt/run-018'.
    Removing workdir '/var/tmp/tmt/run-019'.
    Removing workdir '/var/tmp/tmt/run-020'.
    Removing workdir '/var/tmp/tmt/run-021'.
    Removing workdir '/var/tmp/tmt/run-022'.
    Removing workdir '/var/tmp/tmt/run-023'.
    Removing workdir '/var/tmp/tmt/run-024'.
    Removing workdir '/var/tmp/tmt/run-026'.
    Removing workdir '/var/tmp/tmt/run-027'.
    Removing workdir '/var/tmp/tmt/run-028'.
    Removing workdir '/var/tmp/tmt/run-029'.
    Removing workdir '/var/tmp/tmt/run-030'.
    Removing workdir '/var/tmp/tmt/run-031'.
    Removing workdir '/var/tmp/tmt/run-032'.
    Removing workdir '/var/tmp/tmt/run-033'.
    Removing workdir '/var/tmp/tmt/run-034'.
    Removing workdir '/var/tmp/tmt/run-037'.
    Removing workdir '/var/tmp/tmt/run-038'.
    Removing workdir '/var/tmp/tmt/run-039'.
    Removing workdir '/var/tmp/tmt/run-040'.
    Removing workdir '/var/tmp/tmt/run-041'.
    Removing workdir '/var/tmp/tmt/run-042'.
[sbertram@sbertram beaker]$ tmt clean images -v
clean
images
    testcloud
        warn: Directory '/var/tmp/tmt/testcloud/images' does not exist.
[sbertram@sbertram beaker]$ tmt clean image -v
clean
images
    testcloud
        warn: Directory '/var/tmp/tmt/testcloud/images' does not exist.
[sbertram@sbertram beaker]$ tmt clean guest -v
clean
guests
[sbertram@sbertram beaker]$ tmt clean -v
clean
guests
runs
images
    testcloud
        warn: Directory '/var/tmp/tmt/testcloud/images' does not exist.
psss commented 1 year ago

@dav-pascual, could you please have a look?

dav-pascual commented 1 year ago

@dav-pascual, could you please have a look?

@psss Sure! I will take a look after I am back from vacation (starting tmr, until the end of august)

happz commented 2 months ago

@dav-pascual hello, do you still plan to dedicate some of your time to work on this issue?

psss commented 1 month ago

@dav-pascual, any update on this one?

dav-pascual commented 1 month ago

I'll investigate this issue shortly! (beggining of oct), sorry for the delay :)

psss commented 3 weeks ago

@dav-pascual, thanks! Assigning to you then. Will you be able to finish this by the end of October to make it into 1.38?

thrix commented 4 days ago

@dav-pascual howdy, any luck?