diff --git a/orm/services/image_manager/ims/persistency/sql_alchemy/db_models.py b/orm/services/image_manager/ims/persistency/sql_alchemy/db_models.py index 9e704d2b..d579a095 100755 --- a/orm/services/image_manager/ims/persistency/sql_alchemy/db_models.py +++ b/orm/services/image_manager/ims/persistency/sql_alchemy/db_models.py @@ -100,11 +100,12 @@ class Image(Base, IMSBaseModel): def __json__(self): properties = {} - # don't send tags to rds server - # tags = {} + tags = [] for prop in self.properties: properties[prop.key_name] = prop.key_value + for item in self.tags: + tags.append(item['tag']) return dict( id=self.id, @@ -122,6 +123,7 @@ class Image(Base, IMSBaseModel): created_at=self.created_at, updated_at=self.updated_at, properties=properties, + tags=tags, regions=self.get_regions_json(), customers=[customer.__json__() for customer in self.customers] ) diff --git a/orm/services/resource_distributor/rds/services/yaml_image_builder.py b/orm/services/resource_distributor/rds/services/yaml_image_builder.py index 4888252c..6546a0af 100755 --- a/orm/services/resource_distributor/rds/services/yaml_image_builder.py +++ b/orm/services/resource_distributor/rds/services/yaml_image_builder.py @@ -28,12 +28,17 @@ def _properties(alldata, region): disk_format=alldata['disk_format'], min_disk=alldata['min_disk'], id=str(uuid.UUID(alldata['id'])), + tags=alldata['tags'], protected=protected, copy_from=alldata["url"], owner=alldata["owner"], is_public=public, tenants=str(tenants) ) + + if region['action'] != 'create': + properties['deactivate'] = {1: False, 0: True}[alldata['enabled']] + if alldata['properties']: properties['extra_properties'] = alldata['properties'] diff --git a/orm/tests/unit/rds/services/test_image_yaml.py b/orm/tests/unit/rds/services/test_image_yaml.py index 951eefcf..fd3e544a 100755 --- a/orm/tests/unit/rds/services/test_image_yaml.py +++ b/orm/tests/unit/rds/services/test_image_yaml.py @@ -9,11 +9,7 @@ json_input = { 'url': 'https://mirrors.it.att.com/images/image-name', 'disk_format': 'raw', 'min_ram': 0, 'enabled': 1, 'visibility': 'public', 'owner': 'unknown', - 'image_tags': [{ - 'image_internal_id': 1, 'tag': 'abcd-efgh-ijkl-4567' - }, { - 'image_internal_id': 1, 'tag': 'abcd-efgh-ijkl-4567' - }], + 'tags': ["abcd-efgh-ijkl-4567", "mnop-qrst-uvwx-0987"], 'regions': [{ 'action': 'delete', 'image_internal_id': 1, 'type': 'single', 'name': 'North' @@ -29,7 +25,7 @@ json_input = { 'customers': [{ 'customer_id': 'abcd-efgh-ijkl-4567', 'image_id': 1 }, { - 'customer_id': 'abcd-efgh-ijkl-4567', 'image_id': 1 + 'customer_id': 'opqr-stuv-wxyz-8901', 'image_id': 1 }], 'container_format': 'bare', 'min_disk': 2, 'id': '12345678901234567890123456789012' @@ -46,10 +42,12 @@ yaml_output = { 'container_format': 'bare', 'disk_format': 'raw', 'is_public': True, 'copy_from': 'https://mirrors.it.att.com/images/image-name', + 'deactivate': False, 'min_disk': 2, 'min_ram': 0, 'name': 'Ubuntu', 'owner': 'unknown', 'protected': True, 'id': '12345678-9012-3456-7890-123456789012', - 'tenants': ['abcd-efgh-ijkl-4567', 'abcd-efgh-ijkl-4567'], + 'tenants': ['abcd-efgh-ijkl-4567', 'opqr-stuv-wxyz-8901'], + 'tags': ['abcd-efgh-ijkl-4567', 'mnop-qrst-uvwx-0987'], 'extra_properties': { 'key_name': 'Key1', 'key_value': 'Key1.value', 'image_internal_id': 1 diff --git a/ranger-tempest-plugin/ranger_tempest_plugin/tests/api/ims_base.py b/ranger-tempest-plugin/ranger_tempest_plugin/tests/api/ims_base.py index a2eddfdb..5be4a138 100755 --- a/ranger-tempest-plugin/ranger_tempest_plugin/tests/api/ims_base.py +++ b/ranger-tempest-plugin/ranger_tempest_plugin/tests/api/ims_base.py @@ -70,6 +70,9 @@ class ImsBaseOrmTest(base.BaseOrmTest): post_body["regions"] = [region] if set_region else [] # create image with visibililty = "public" or "private" post_body["visibility"] = "private" if set_private else "public" + # set image tags + post_body["tags"] = ["tag1", "tag2"] + # add tenant for the image only if set_private if set_private: if single_tenant: diff --git a/ranger-tempest-plugin/ranger_tempest_plugin/tests/api/test_images.py b/ranger-tempest-plugin/ranger_tempest_plugin/tests/api/test_images.py index 3ee652e9..fe5abe62 100755 --- a/ranger-tempest-plugin/ranger_tempest_plugin/tests/api/test_images.py +++ b/ranger-tempest-plugin/ranger_tempest_plugin/tests/api/test_images.py @@ -181,7 +181,8 @@ class TestTempestIms(ims_base.ImsBaseOrmTest): @decorators.idempotent_id('bac99348-6b13-4b30-958b-3c039b27eda3') def test_update_image_tenant(self): # replace current tenant in self.private_image with alt tenant - self.client.update_customer(self.private_image['id'], self.alt_tenant_id) + self.client.update_customer(self.private_image['id'], + self.alt_tenant_id) self._wait_for_image_status_on_dcp(self.private_image['id'], 'Success') # check that image tenants array contains only alt tenant @@ -210,21 +211,22 @@ class TestTempestIms(ims_base.ImsBaseOrmTest): @decorators.idempotent_id('01160918-e217-401d-a6a0-e7992ab76e41') def test_update_image(self): region = {} - post_body = self._get_image_params(set_region=False, - set_enabled=False) + post_body = self._get_image_params(set_region=False) image = self._data_setup(post_body) test_image_id = image['id'] - # setup region and change 'enabled' and 'customer' properties + # setup region and change 'enabled', 'customers' properties region["name"] = self.region_id region["type"] = "single" region["checksum"] = "7297321c2fa6424417a548c85edd6e98" region["virtual_size"] = "None" region["size"] = "38797312" post_body["regions"] = [region] - - post_body["enabled"] = True + post_body["enabled"] = False post_body["customers"] = [self.alt_tenant_id] + # empty tags list + post_body["tags"] = [] + _, body = self.client.update_image(test_image_id, para=None, **post_body) self._wait_for_image_status_on_dcp(test_image_id, 'Success') @@ -233,7 +235,8 @@ class TestTempestIms(ims_base.ImsBaseOrmTest): image = body["image"] self.assertEqual(image["regions"][0]["name"], CONF.identity.region) self.assertIn(self.alt_tenant_id, image['customers']) - self.assertTrue(image['enabled']) + self.assertFalse(image['enabled']) + self.assertFalse(image['tags']) @decorators.idempotent_id('23e2e7e2-5b19-4c66-b35c-7c686a986627') def test_delete_image(self):