← Back to team overview

cloud-certification-team team mailing list archive

[Merge] lp:~jeffmarcom/cloud-testing/glance_delete_image_tests into lp:cloud-testing/cloudbox

 

Jeff Marcom has proposed merging lp:~jeffmarcom/cloud-testing/glance_delete_image_tests into lp:cloud-testing/cloudbox.

Requested reviews:
  Cloud Certification (cloud-certification-team)

For more details, see:
https://code.launchpad.net/~jeffmarcom/cloud-testing/glance_delete_image_tests/+merge/174801

This is a simple remove image test for openstack glance. This merge proposal includes both a local (cli) and remote (api) job.
-- 
https://code.launchpad.net/~jeffmarcom/cloud-testing/glance_delete_image_tests/+merge/174801
Your team Cloud Certification is requested to review the proposed merge of lp:~jeffmarcom/cloud-testing/glance_delete_image_tests into lp:cloud-testing/cloudbox.
=== modified file 'cloudbox/openstack/api.py'
--- cloudbox/openstack/api.py	2013-06-20 19:51:19 +0000
+++ cloudbox/openstack/api.py	2013-07-15 15:52:42 +0000
@@ -57,6 +57,7 @@
         "view_usage": ["os-simple-tenant-usage", "GET"]},
     "Image": {
         "add_image": ["v2/images", "POST"],
+        "delete_image": ["v2/images", "DELETE"],
         "upload_image": ["v2/images", "PUT"],
         "list_images": ["v2/images", "GET"]},
 

=== modified file 'cloudbox/openstack/component/image.py'
--- cloudbox/openstack/component/image.py	2013-06-04 21:40:47 +0000
+++ cloudbox/openstack/component/image.py	2013-07-15 15:52:42 +0000
@@ -38,7 +38,12 @@
     from within glance.
     """
 
-    def __init__(self, image_name, image_file, container_format, disk_format):
+    def __init__(
+            self,
+            image_name,
+            image_file="",
+            container_format="",
+            disk_format=""):
 
         self.image_name = image_name
         self.image_file = image_file
@@ -76,6 +81,15 @@
         return openstack_cli("glance").execute(
             "image-create", params.replace("\n", ""))
 
+    def remove(self):
+
+        params = "{}".format(self.image_name)
+
+        logging.debug("Attempting to remove: %s" % self.image_name)
+
+        return openstack_cli("glance").execute(
+            "image-delete", params.replace("\n", ""))
+
 
 class ImageAPI(object):
     """This class provides image information as well as
@@ -86,9 +100,9 @@
             self,
             image_owner,
             image_name,
-            image_file,
-            container_format,
-            disk_format):
+            image_file="",
+            container_format="",
+            disk_format=""):
 
         self.image_name = image_name
         self.image_file = image_file
@@ -153,7 +167,7 @@
         # Check image detail status via info schema
         try:
             image_status = image_detail["status"]
-        except IndexError as status_failure:
+        except KeyError as status_failure:
             image_status = "failed"
             print("Error while adding image", file=sys.stderr)
             print(status_failure, file=sys.stderr)
@@ -163,3 +177,27 @@
 
         logging.error("Image add failed")
         return 1, image_detail
+
+    def list(self):
+        return openstack_api("glance").request("list_images")["images"]
+
+    def remove(self):
+        # Retieve ID for image
+        images = self.list()
+        id = ""
+        for image in images:
+            try:
+                if self.image_name == image["name"]:
+                    id = image["id"]
+            except KeyError:
+                logging.error("Failed finding image id")
+                logging.debug(image)
+                return 1
+
+        if id == "":
+            logging.error("Failed finding image:%s", self.image_name)
+            return 1
+
+        api_obj = openstack_api("glance")
+        api_obj.page_tac = "/" + id
+        return api_obj.request("delete_image")

=== added file 'extras/whitelists/folsom_cleanup_local.whitelist'
--- extras/whitelists/folsom_cleanup_local.whitelist	1970-01-01 00:00:00 +0000
+++ extras/whitelists/folsom_cleanup_local.whitelist	2013-07-15 15:52:42 +0000
@@ -0,0 +1,16 @@
+environment
+module
+package
+uname
+lsb
+dpkg
+__info__
+lspci_attachment
+modprobe_attachment
+modules_attachment
+__networking__
+networking/detect
+__folsom_remote__
+openstack/service_info
+__folsom_local_glance__
+glance/remove_image/local

=== added file 'extras/whitelists/folsom_cleanup_remote.whitelist'
--- extras/whitelists/folsom_cleanup_remote.whitelist	1970-01-01 00:00:00 +0000
+++ extras/whitelists/folsom_cleanup_remote.whitelist	2013-07-15 15:52:42 +0000
@@ -0,0 +1,15 @@
+environment
+module
+package
+uname
+lsb
+dpkg
+__info__
+lspci_attachment
+modprobe_attachment
+modules_attachment
+__networking__
+networking/detect
+__folsom_remote__
+openstack/service_info
+glance/remove_image/remote

=== modified file 'jobs/folsom_local_glance.txt.in'
--- jobs/folsom_local_glance.txt.in	2013-05-27 23:36:22 +0000
+++ jobs/folsom_local_glance.txt.in	2013-07-15 15:52:42 +0000
@@ -4,3 +4,8 @@
 _description:
  Adds an image to the deployed openstack environment via glance command line tool
 
+plugin: shell
+name: glance/remove_image/local
+command: glance_cli_test image --delete
+_description:
+ Removes an image from the deployed openstack environment via glance command line tool

=== modified file 'jobs/folsom_remote.txt.in'
--- jobs/folsom_remote.txt.in	2013-06-18 18:49:37 +0000
+++ jobs/folsom_remote.txt.in	2013-07-15 15:52:42 +0000
@@ -47,6 +47,12 @@
  Adds an image to the deployed openstack environment via glance api
 
 plugin: shell
+name: glance/remove_image/remote
+command: glance_api_test image --delete
+_description:
+ Removes an image from the deployed openstack environment via glance api
+
+plugin: shell
 name: nova/add_flavor_tiny/remote
 command: nova_api_test flavor --add --type tiny
 _description:

=== modified file 'scripts/glance_api_test'
--- scripts/glance_api_test	2013-06-04 21:40:47 +0000
+++ scripts/glance_api_test	2013-07-15 15:52:42 +0000
@@ -38,6 +38,9 @@
     container_format = openstack_config.Image["container_format"]
     disk_format = openstack_config.Image["disk_format"]
 
+    if args.name != "":
+        image_name = args.name
+
     test = ImageAPI(
         image_owner,
         image_name,
@@ -59,6 +62,22 @@
 
         exit_code, output = test.add()
 
+    if args.delete:
+        print("Attempting to remove:", image_name)
+
+        test.remove()
+        image_list = test.list()
+
+        images = []
+        for item in image_list:
+            try:
+                images.append(item["name"])
+            except KeyError:
+                print("Failed finding image name\n", item)
+
+        if image_name not in images:
+            exit_code = 0
+
     sys.exit(exit_code)
 
 
@@ -74,6 +93,10 @@
     image_test_parser.add_argument(
         '--add', action="store_true")
     image_test_parser.add_argument(
+        '--delete', action="store_true")
+    image_test_parser.add_argument(
+        '--name', default="", type=str, action="store")
+    image_test_parser.add_argument(
         '--debug', action="store_true")
 
     image_test_parser.set_defaults(func=image_test)

=== modified file 'scripts/glance_cli_test'
--- scripts/glance_cli_test	2013-06-04 21:40:47 +0000
+++ scripts/glance_cli_test	2013-07-15 15:52:42 +0000
@@ -37,6 +37,9 @@
     container_format = openstack_config.Image["container_format"]
     disk_format = openstack_config.Image["disk_format"]
 
+    if args.name != "":
+        image_name = args.name
+
     test = ImageCLI(image_name, image_file, container_format, disk_format)
 
     if args.add:
@@ -50,6 +53,13 @@
 
         exit_code, output = test.add()
 
+    if args.delete:
+        print("Attempting to remove:", image_name)
+
+        exit_code, output = test.remove()
+
+        print(output)
+
     sys.exit(exit_code)
 
 
@@ -65,6 +75,10 @@
     image_test_parser.add_argument(
         '--add', action="store_true")
     image_test_parser.add_argument(
+        '--delete', action="store_true")
+    image_test_parser.add_argument(
+        '--name', default="", type=str, action="store")
+    image_test_parser.add_argument(
         '--debug', action="store_true")
 
     image_test_parser.set_defaults(func=image_test)


Follow ups