diff --git a/Tests/iaas/cleanup.py b/Tests/iaas/cleanup.py index 7097ff69b..13f58a51f 100755 --- a/Tests/iaas/cleanup.py +++ b/Tests/iaas/cleanup.py @@ -50,6 +50,20 @@ def disconnect_routers(self): for port in ports: self.conn.network.remove_interface_from_router(router.id, port_id=port["id"]) + def cleanup_images(self): + logger.debug("clean up images") + images = list(self.conn.image.images()) + for image in images: + if not self.prefix or not image.name or not image.name.startswith(self.prefix): + continue + if image.visibility != "private": + continue + logger.info(image.name) + try: + self.conn.image.delete_image(image) + except Exception as e: + logger.warning(f"Failed to delete image {image.name}: {e}") + def cleanup_routers(self): logger.debug("clean up routers") routers = list(self.conn.network.routers()) @@ -194,6 +208,7 @@ def cleanup(self): self.cleanup_security_groups() self.cleanup_floating_ips() self.cleanup_routers() + self.cleanup_images() def main(argv): diff --git a/Tests/iaas/openstack_test.py b/Tests/iaas/openstack_test.py index 940d2218b..61dcfbd2a 100755 --- a/Tests/iaas/openstack_test.py +++ b/Tests/iaas/openstack_test.py @@ -37,7 +37,7 @@ from scs_0104_standard_images.standard_images import \ SCS_0104_IMAGE_SPECS, compute_scs_0104_source, compute_scs_0104_image, \ compute_image_lookup_ex, compute_scs_0104_source_ex, compute_scs_0104_source_capi, \ - compute_scs_0104_image_ubuntu_latest + compute_scs_0104_image_ubuntu_latest, compute_scs_0104_custom_image_upload from scs_0114_volume_types.volume_types import \ compute_volume_type_lookup, compute_scs_0114_syntax_check, compute_scs_0114_aspect_type from scs_0115_security_groups.security_groups import \ @@ -163,6 +163,7 @@ def make_container(subject, cloud): c.add_function('scs_0104_image_debian_12', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 12'])) c.add_function('scs_0104_image_debian_11', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 11'])) c.add_function('scs_0104_image_debian_10', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 10'])) + c.add_function('scs_0104_custom_image_upload', lambda c: compute_scs_0104_custom_image_upload(c.conn, PREFIX)) # scs_0114_volume_types c.add_function('volume_types', lambda c: c.conn.list_volume_types()) c.add_function('volume_type_lookup', lambda c: compute_volume_type_lookup(c.volume_types)) diff --git a/Tests/iaas/scs_0104_standard_images/standard_images.py b/Tests/iaas/scs_0104_standard_images/standard_images.py index 5f50aa881..1ea86dbe8 100644 --- a/Tests/iaas/scs_0104_standard_images/standard_images.py +++ b/Tests/iaas/scs_0104_standard_images/standard_images.py @@ -1,5 +1,6 @@ from collections import defaultdict from datetime import date +import io import logging import re @@ -171,3 +172,100 @@ def compute_scs_0104_image_ubuntu_latest(image_lookup_ex, os_distro='ubuntu'): logger.error(f"Missing generic {os_distro} image with os_version in {acceptable!r}") return False return True + + +def compute_scs_0104_custom_image_upload(conn, prefix="_scs-"): + """ + Test custom image upload via Glance per SCS-0104 and validate image listing, + filtering, schemas, and details retrieval per SCS-0128 baseline requirements. + """ + image_name = f"{prefix}scs0104-upload-test" + payload = b"\x00" * 1024 # 1 KB valid raw zero-block passing format inspection + test_image = None + errors = 0 + + try: + logger.info(f"Creating image record {image_name}...") + test_image = conn.image.create_image( + name=image_name, + data=io.BytesIO(payload), + disk_format="raw", + container_format="bare", + visibility="private", + wait=True, + ) + + if not test_image or not test_image.id: + logger.error("Failed to create and upload custom image") + return False + + image_id = test_image.id + logger.info(f"Custom image uploaded with ID: {image_id}") + + # 1. Validate image details retrieval + retrieved = conn.image.get_image(image_id) + if not retrieved or retrieved.name != image_name or retrieved.status != "active": + logger.error(f"Image detail retrieval failed: expected active {image_name}, got {retrieved}") + errors += 1 + + # 2. Validate schemas (covering tempest get_images_schema & get_image_schema) + try: + images_schema = conn.image.get_images_schema() + if not images_schema or "name" not in str(images_schema): + logger.error("Invalid images schema response") + errors += 1 + except Exception as e: + logger.error(f"Failed to fetch images schema: {e}") + errors += 1 + + try: + image_schema = conn.image.get_image_schema() + if not image_schema or "name" not in str(image_schema): + logger.error("Invalid image schema response") + errors += 1 + except Exception as e: + logger.error(f"Failed to fetch image schema: {e}") + errors += 1 + + # 3. Validate listing with parameter filtering (covering tempest list_images_param_*) + # Filter by visibility + priv_images = list(conn.image.images(visibility="private")) + if not any(img.id == image_id for img in priv_images): + logger.error(f"Image {image_id} not found when listing with visibility=private") + errors += 1 + + # Filter by status + active_images = list(conn.image.images(status="active")) + if not any(img.id == image_id for img in active_images): + logger.error(f"Image {image_id} not found when listing with status=active") + errors += 1 + + # Filter by disk_format and container_format + format_images = list(conn.image.images(disk_format="raw", container_format="bare")) + if not any(img.id == image_id for img in format_images): + logger.error(f"Image {image_id} not found with disk_format=raw and container_format=bare") + errors += 1 + + # Verify limit parameter on Glance REST endpoint + try: + resp = conn.image.get("/images", params={"limit": 1}).json() + page_images = resp.get("images", []) + if len(page_images) > 1: + logger.error(f"Glance limit=1 returned {len(page_images)} images on first page") + errors += 1 + except Exception as e: + logger.error(f"Failed to test limit parameter query: {e}") + errors += 1 + + except Exception as e: + logger.error(f"Error during SCS-0104 custom image upload test: {e}", exc_info=True) + return False + finally: + if test_image and test_image.id: + logger.info(f"Cleaning up custom test image {test_image.id}...") + try: + conn.image.delete_image(test_image.id, ignore_missing=True) + except Exception as e: + logger.warning(f"Failed to delete test image {test_image.id}: {e}") + + return errors == 0 diff --git a/Tests/iaas/scs_0128_e2e_testing/tempest-tests-non-admin.lst b/Tests/iaas/scs_0128_e2e_testing/tempest-tests-non-admin.lst index 1755e4320..041ca6d03 100644 --- a/Tests/iaas/scs_0128_e2e_testing/tempest-tests-non-admin.lst +++ b/Tests/iaas/scs_0128_e2e_testing/tempest-tests-non-admin.lst @@ -106,16 +106,6 @@ tempest.api.identity.v3.test_users.IdentityV3UsersTest.test_user_update_own_pass tempest.api.image.v2.test_images.BasicOperationsImagesTest.test_delete_image[id-f848bb94-1c6e-45a4-8726-39e3a5b23535,smoke] tempest.api.image.v2.test_images.BasicOperationsImagesTest.test_register_upload_get_image_file[id-139b765e-7f3d-4b3d-8b37-3ca3876ee318,smoke] tempest.api.image.v2.test_images.BasicOperationsImagesTest.test_update_image[id-f66891a7-a35c-41a8-b590-a065c2a1caa6,smoke] -tempest.api.image.v2.test_images.ListUserImagesTest.test_get_image_schema[id-622b925c-479f-4736-860d-adeaf13bc371] -tempest.api.image.v2.test_images.ListUserImagesTest.test_get_images_schema[id-25c8d7b2-df21-460f-87ac-93130bcdc684] -tempest.api.image.v2.test_images.ListUserImagesTest.test_list_images_param_container_format[id-9959ca1d-1aa7-4b7a-a1ea-0fff0499b37e] -tempest.api.image.v2.test_images.ListUserImagesTest.test_list_images_param_disk_format[id-4a4735a7-f22f-49b6-b0d9-66e1ef7453eb] -tempest.api.image.v2.test_images.ListUserImagesTest.test_list_images_param_limit[id-e914a891-3cc8-4b40-ad32-e0a39ffbddbb] -tempest.api.image.v2.test_images.ListUserImagesTest.test_list_images_param_min_max_size[id-4ad8c157-971a-4ba8-aa84-ed61154b1e7f] -tempest.api.image.v2.test_images.ListUserImagesTest.test_list_images_param_size[id-cf1b9a48-8340-480e-af7b-fe7e17690876] -tempest.api.image.v2.test_images.ListUserImagesTest.test_list_images_param_status[id-7fc9e369-0f58-4d05-9aa5-0969e2d59d15] -tempest.api.image.v2.test_images.ListUserImagesTest.test_list_images_param_visibility[id-7a95bb92-d99e-4b12-9718-7bc6ab73e6d2] -tempest.api.image.v2.test_images.ListUserImagesTest.test_list_no_params[id-1e341d7a-90a9-494c-b143-2cdf2aeb6aee] tempest.api.image.v2.test_images_negative.ImagesNegativeTest.test_delete_image_null_id[id-32248db1-ab88-4821-9604-c7c369f1f88c,negative] tempest.api.image.v2.test_images_negative.ImagesNegativeTest.test_delete_non_existing_image[id-6fe40f1c-57bd-4918-89cc-8500f850f3de,negative] tempest.api.image.v2.test_images_negative.ImagesNegativeTest.test_get_delete_deleted_image[id-e57fc127-7ba0-4693-92d7-1d8a05ebcba9,negative]