charmed-kubernetes / pytest-operator

Apache License 2.0
7 stars 13 forks source link

Fix model cleanup failure due to dead machine #44

Closed Cynerva closed 2 years ago

Cynerva commented 2 years ago

Fixes this exception coming from _cleanup_model:

Traceback (most recent call last):
  File "/opt/github-runner/_work/layer-calico/layer-calico/.tox/integration/lib/python3.8/site-packages/pytest_asyncio/plugin.py", line 362, in finalizer
    loop.run_until_complete(async_finalizer())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/opt/github-runner/_work/layer-calico/layer-calico/.tox/integration/lib/python3.8/site-packages/pytest_asyncio/plugin.py", line 354, in async_finalizer
    await gen_obj.__anext__()
  File "/opt/github-runner/_work/layer-calico/layer-calico/.tox/integration/lib/python3.8/site-packages/pytest_operator/plugin.py", line 153, in ops_test
    await ops_test._cleanup_model()
  File "/opt/github-runner/_work/layer-calico/layer-calico/.tox/integration/lib/python3.8/site-packages/pytest_operator/plugin.py", line 282, in _cleanup_model
    log.info(f"Destroying machine {machine.id}")
  File "/opt/github-runner/_work/layer-calico/layer-calico/.tox/integration/lib/python3.8/site-packages/juju/model.py", line 278, in __getattr__
    return self.safe_data[name]
  File "/opt/github-runner/_work/layer-calico/layer-calico/.tox/integration/lib/python3.8/site-packages/juju/model.py", line 371, in safe_data
    raise DeadEntityException(
juju.exceptions.DeadEntityException: Entity machine:2 is dead - its attributes can no longer be accessed. Use the .previous() method on this object to get a copy of the object at its previous state.

This occurred because the test prior to this had just cleaned up an application that was on machine 2. The machine is already dead, no need to destroy it again.

Cynerva commented 2 years ago

https://github.com/charmed-kubernetes/pytest-operator/pull/45 should fix the test failure seen here. Once that PR has been merged, I'll rebase this one on top.