Check ownerid and visibility on image cleanup 91/65791/5 v0.35.1
authorAnil Belur <abelur@linuxfoundation.org>
Sat, 17 Oct 2020 03:16:50 +0000 (13:16 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Tue, 20 Oct 2020 00:07:52 +0000 (10:07 +1000)
Recently update on the cloud provider caused the builder-cron-openstack
job to break, which exposed a bug in our cleanup scripts.

Check the visibility and ownerid of the image before attempting to
remove and image.

Issue: RELENG-3239
Change-Id: I38098c45fe73e872f3ca96960f704f168d9c4596
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
lftools/openstack/image.py
releasenotes/notes/Handle-image-ownership-in-cleanup-e598855680b02a50.yaml [new file with mode: 0644]

index b37597a..cd35cd7 100644 (file)
@@ -74,9 +74,21 @@ def cleanup(os_cloud, days=0, hide_public=False, ci_managed=True, clouds=None):
 
     def _remove_images_from_cloud(images, cloud):
         print("Removing {} images from {}.".format(len(images), cloud.cloud_config.name))
+        project_info = cloud._get_project_info()
         for image in images:
+
             if image.is_protected:
-                print("WARNING: Image {} is protected. Cannot remove...".format(image.name))
+                log.warning("Image {} is protected. Cannot remove...".format(image.name))
+                continue
+
+            if image.visibility == "shared":
+                log.warning("Image {} is shared. Cannot remove...".format(image.name))
+                continue
+
+            if project_info["id"] != image.owner:
+                log.warning(
+                    "Image {} not owned by project {}. Cannot remove...".format(image.name, cloud.cloud_config.name)
+                )
                 continue
 
             try:
diff --git a/releasenotes/notes/Handle-image-ownership-in-cleanup-e598855680b02a50.yaml b/releasenotes/notes/Handle-image-ownership-in-cleanup-e598855680b02a50.yaml
new file mode 100644 (file)
index 0000000..e0c2283
--- /dev/null
@@ -0,0 +1,10 @@
+---
+fixes:
+  - |
+    Check image owner and visibility on image cleanup
+
+    Recently update on the cloud provider has caused the builder-cron-openstack
+    job to fail, and exposed a bug in our cleanup scripts.
+
+    Check the visibility and ownerid of the image before attempting to remove
+    and image.