← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/lpbuildbot-worker:ephemeral-cleanup-crash into lpbuildbot-worker:main

 

Tom Wardill has proposed merging ~twom/lpbuildbot-worker:ephemeral-cleanup-crash into lpbuildbot-worker:main.

Commit message:
Fix crash on deleting ephemeral container

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~twom/lpbuildbot-worker/+git/lpbuildbot-worker/+merge/392288

Newer versions of pylxd don't like calling .delete() on an ephemeral container that has already had .stop() and therefore already been removed.
Fix that by checking if we only need to stop.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/lpbuildbot-worker:ephemeral-cleanup-crash into lpbuildbot-worker:main.
diff --git a/lp-setup-lxd-cleanup b/lp-setup-lxd-cleanup
index 72ca33e..b719902 100755
--- a/lp-setup-lxd-cleanup
+++ b/lp-setup-lxd-cleanup
@@ -16,8 +16,10 @@ def clean_up_containers(client, base_name):
                 if container.status == "Running":
                     print("Stopping container {}".format(container.name))
                     container.stop(wait=True)
-                print("Removing {}".format(container.name))
-                container.delete(wait=True)
+                if not container.ephemeral:
+                    # ephemeral containers are deleted on stop
+                    print("Removing {}".format(container.name))
+                    container.delete(wait=True)
         except LXDAPIException as e:
             if e.response.status_code != 404:
                 raise e