From 84c23a4781e8f49773134af4f81a7d8813689349 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Tue, 22 Sep 2020 10:56:10 -0700 Subject: [PATCH] Associate tenants as memeber list to shared image Change-Id: I297c9a9ec77a64b07b3ad6a8c59121c7381bfd97 --- orm/orm_client/ormcli/imscli.py | 5 ++-- .../image_manager/ims/logic/image_logic.py | 21 +++++++-------- .../ims/persistency/wsme/models.py | 26 ++++++++----------- .../rds/services/yaml_image_builder.py | 4 +-- .../controllers/v1/orm/images/test_images.py | 2 +- orm/tests/unit/ims/logic/test_image_logic.py | 8 +++--- orm/tests/unit/ims/test_models.py | 8 +++--- .../unit/rds/services/test_image_yaml.py | 5 ++-- tools/zuul/playbooks/docker-image-build.yaml | 3 +++ 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/orm/orm_client/ormcli/imscli.py b/orm/orm_client/ormcli/imscli.py index f2f15409..0aa03a53 100644 --- a/orm/orm_client/ormcli/imscli.py +++ b/orm/orm_client/ormcli/imscli.py @@ -91,13 +91,14 @@ def add_to_parser(service_sub): parser_get_image.add_argument('imageid', type=str, help=h2) h1, h2 = '[<"X-RANGER-Client" header>]', \ - '[--visibility ] ' \ + '[--visibility ] ' \ '[--region ] [--customer ]' parser_list_images = subparsers.add_parser('list_images', help='%s %s' % (h1, h2)) parser_list_images.add_argument('client', **cli_common.ORM_CLIENT_KWARGS) parser_list_images.add_argument('--visibility', type=str, - choices=['public', 'private']) + choices=['public', 'private', + 'community', 'shared']) parser_list_images.add_argument('--region', type=str, help='region name') parser_list_images.add_argument('--customer', type=str, help='customer id') diff --git a/orm/services/image_manager/ims/logic/image_logic.py b/orm/services/image_manager/ims/logic/image_logic.py index 54c8d15a..cef84eb1 100755 --- a/orm/services/image_manager/ims/logic/image_logic.py +++ b/orm/services/image_manager/ims/logic/image_logic.py @@ -324,8 +324,9 @@ def add_customers(image_uuid, customers, transaction_id): raise ErrorStatus(404, 'image with id: {0} not found'.format( image_uuid)) - if sql_image.visibility == "public": - raise ErrorStatus(400, 'Cannot add Customers to public Image') + if sql_image.visibility != "shared": + raise ErrorStatus(400, + 'Customer can only be added to shared image.') existing_region_names = sql_image.get_existing_region_names() @@ -362,8 +363,8 @@ def replace_customers(image_uuid, customers, transaction_id): if not sql_image: raise ErrorStatus(404, 'image {0} not found'.format(image_uuid)) - if sql_image.visibility == "public": - raise ValueError('Cannot add Customers to public Image') + if sql_image.visibility != "shared": + raise ValueError('Customer can only be replaced with shared Image') existing_region_names = sql_image.get_existing_region_names() sql_image.remove_all_customers() @@ -400,15 +401,11 @@ def delete_customer(image_uuid, customer_id, transaction_id): sql_image = image_rec.get_image_by_id(image_uuid) if not sql_image: raise ErrorStatus(404, 'image {0} not found'.format(image_uuid)) - # if trying to delete the only one Customer then return value error - if sql_image.visibility == "public": - raise ValueError( - "Image {} is public, no customers".format(image_uuid)) - if len(sql_image.customers) == 1 and \ - sql_image.customers[0].customer_id == customer_id: - raise ValueError('Private Image must have at least one Customer - ' - 'You are trying to delete the only one Customer') + if sql_image.visibility != "shared": + raise ValueError( + "Customer can only be deleted from shared image {}".format( + image_uuid)) existing_region_names = sql_image.get_existing_region_names() sql_image.remove_customer(customer_id) diff --git a/orm/services/image_manager/ims/persistency/wsme/models.py b/orm/services/image_manager/ims/persistency/wsme/models.py index 0987e988..b3c1a81d 100755 --- a/orm/services/image_manager/ims/persistency/wsme/models.py +++ b/orm/services/image_manager/ims/persistency/wsme/models.py @@ -220,24 +220,20 @@ class Image(Model): def validate_model(self, context=None): if self.name.strip() == '': - raise ErrorStatus(400, "Image name is required.") + raise ErrorStatus(400, 'Image name is required.') if self.url.strip() == '': - raise ErrorStatus(400, "Image location URL is required.") + raise ErrorStatus(400, 'Image location URL is required.') # Validate visibility - if self.visibility == 'public' and self.customers: + if self.visibility not in ["private", "public", "community", "shared"]: raise ErrorStatus(400, - 'Visibility is public but some customers were' - ' specified!') - elif self.visibility == 'private' and not self.customers: + 'Image visibility can only be public, private,' + ' community, or shared') + elif self.customers and self.visibility != "shared": raise ErrorStatus(400, - 'Visibility is private but no customers were' - ' specified!') - elif self.visibility not in ["private", "public"]: - raise ErrorStatus( - 400, - "Image visibility can only be 'public' or 'private'") + 'Customers can only be specified with shared' + ' image!') # Validate disk format valid_disk_formats = ('ami', 'ari', 'aki', 'vhd', 'vmdk', 'raw', @@ -262,15 +258,15 @@ class Image(Model): if int(self.min_ram) not in list(range(0, self.min_ram + 1, 1024)): raise ErrorStatus( - 400, "mininum RAM value must be a multiple of 1024") + 400, 'mininum RAM value must be a multiple of 1024') if context == "update": for region in self.regions: if region.type == "group": raise ErrorStatus( 400, - "region {} type is invalid for update, \'group\' can" - " be only in create".format(region.name)) + 'region {} type is invalid for update, \'group\' can' + ' be only in create'.format(region.name)) def to_db_model(self): image = db_models.Image() 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 70ea7e7d..f9d30d0c 100755 --- a/orm/services/resource_distributor/rds/services/yaml_image_builder.py +++ b/orm/services/resource_distributor/rds/services/yaml_image_builder.py @@ -18,7 +18,6 @@ def create_full_yaml(title, resources, description, outputs): def _properties(alldata, region): - public = alldata['visibility'] protected = {0: False, 1: True}[alldata['protected']] members = [member['customer_id'] for member in alldata['customers']] properties = dict( @@ -32,7 +31,8 @@ def _properties(alldata, region): protected=protected, location=alldata["url"], owner=alldata["owner"], - visibility=alldata['visibility'] + visibility=alldata['visibility'], + members=members ) if region['action'] != 'create': diff --git a/orm/tests/unit/ims/controllers/v1/orm/images/test_images.py b/orm/tests/unit/ims/controllers/v1/orm/images/test_images.py index 70692e1c..6af0425a 100755 --- a/orm/tests/unit/ims/controllers/v1/orm/images/test_images.py +++ b/orm/tests/unit/ims/controllers/v1/orm/images/test_images.py @@ -325,7 +325,7 @@ image_json = \ { "name": "abcde1e236", "url": "https://mirrors.it.att.com/images/image-name", - "visibility": "private", + "visibility": "shared", "disk-format": "raw", "container-format": "bare", "min-disk": 1, diff --git a/orm/tests/unit/ims/logic/test_image_logic.py b/orm/tests/unit/ims/logic/test_image_logic.py index c388fee4..dbbc38e4 100755 --- a/orm/tests/unit/ims/logic/test_image_logic.py +++ b/orm/tests/unit/ims/logic/test_image_logic.py @@ -64,7 +64,7 @@ class RdsResponse(object): resolved_regions = [{'type': 'single', 'name': 'rdm1'}] -visibility = "private" +visibility = "shared" regions = [] image_status_dict = {'regions': [{ @@ -572,7 +572,7 @@ class TestAddCustomers(FunctionalTest): self.assertRaises(image_logic.ErrorStatus, image_logic.add_customers, 'uuid', mock.MagicMock(), 'transaction') - visibility = 'private' + visibility = 'shared' @mock.patch.object(image_logic, 'get_image_by_uuid', return_value=ImageWrapperTest( @@ -604,7 +604,7 @@ class TestReplaceCustomers(FunctionalTest): mock_send_to_rds_if_needed, mock_get_image_by_uuid): global visibility - visibility = 'private' + visibility = 'shared' rds_proxy, mock_data_manager = get_data_manager_mock() mock_di.resolver.unpack.return_value = mock_data_manager customers_wrapper = models.CustomerWrapper(['customer']) @@ -646,7 +646,7 @@ class TestReplaceCustomers(FunctionalTest): image_logic.replace_customers, 'uuid', mock.MagicMock(), 'transaction') - visibility = 'private' + visibility = 'shared' @mock.patch.object(image_logic, 'get_image_by_uuid', return_value=ImageWrapperTest( diff --git a/orm/tests/unit/ims/test_models.py b/orm/tests/unit/ims/test_models.py index 5e8f0c9a..734c2923 100644 --- a/orm/tests/unit/ims/test_models.py +++ b/orm/tests/unit/ims/test_models.py @@ -14,7 +14,8 @@ class TestModels(FunctionalTest): def setUp(self): FunctionalTest.setUp(self) - models.get_regions_of_group = mock.MagicMock(return_value=GROUP_REGIONS) + models.get_regions_of_group = mock.MagicMock( + return_value=GROUP_REGIONS) models.set_utils_conf = mock.MagicMock() def test_handle_group_success(self): @@ -37,7 +38,7 @@ class TestWsmeModels(FunctionalTest): image_wrapper.image.name = 'name' image_wrapper.image.url = 'http://aic.att.com' - image_wrapper.image.visibility = 'private' + image_wrapper.image.visibility = 'shared' image_wrapper.image.disk_format = 'raw' image_wrapper.image.container_format = 'bare' image_wrapper.image.min_ram = 1024 @@ -53,6 +54,7 @@ def get_image_model(): :return: new customer object """ - image = models.Image(id='a', regions=[models.Region(name='r1', type='group')]) + image = models.Image(id='a', + regions=[models.Region(name='r1', type='group')]) return image diff --git a/orm/tests/unit/rds/services/test_image_yaml.py b/orm/tests/unit/rds/services/test_image_yaml.py index ff70c344..408a44df 100755 --- a/orm/tests/unit/rds/services/test_image_yaml.py +++ b/orm/tests/unit/rds/services/test_image_yaml.py @@ -8,7 +8,7 @@ json_input = { 'status': 'complete', 'name': 'Ubuntu', 'internal_id': 1, 'url': 'https://mirrors.it.att.com/images/image-name', 'disk_format': 'raw', 'min_ram': 0, 'enabled': 1, - 'visibility': 'public', 'owner': 'unknown', + 'visibility': 'shared', 'owner': 'unknown', 'tags': ["abcd-efgh-ijkl-4567", "mnop-qrst-uvwx-0987"], 'regions': [{ 'action': 'delete', 'image_internal_id': 1, @@ -43,13 +43,14 @@ yaml_output = { 'glance_image': { 'properties': { 'container_format': 'bare', 'disk_format': 'raw', - 'visibility': 'public', + 'visibility': 'shared', 'location': 'https://mirrors.it.att.com/images/image-name', 'active': True, 'min_disk': 2, 'min_ram': 0, 'name': 'Ubuntu', 'owner': 'unknown', 'protected': True, 'id': '12345678-9012-3456-7890-123456789012', 'tags': ['abcd-efgh-ijkl-4567', 'mnop-qrst-uvwx-0987'], + 'members': ['abcd-efgh-ijkl-4567', 'opqr-stuv-wxyz-8901'], 'extra_properties': { 'key_name': 'Key1', 'key_value': 'Key1.value', 'image_internal_id': 1 diff --git a/tools/zuul/playbooks/docker-image-build.yaml b/tools/zuul/playbooks/docker-image-build.yaml index 673874ab..b845a266 100644 --- a/tools/zuul/playbooks/docker-image-build.yaml +++ b/tools/zuul/playbooks/docker-image-build.yaml @@ -28,6 +28,9 @@ - name: Publish images block: + - pip: + name: docker + version: 2.7.0 - docker_login: username: "{{ ranger_quay_io_credentials.username }}" password: "{{ ranger_quay_io_credentials.password }}"