From 589e4ec45a3d24eeb40d16b0bfca573152b099f8 Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Sat, 21 Nov 2020 20:53:01 +1300 Subject: [PATCH] Support datastore version number for configuration Story: 2008358 Task: 41263 Change-Id: I529a07d50c0659af0c9821a8570f7548e8521805 --- .../samples/config-group-create-request.json | 3 +- .../samples/config-group-create-response.json | 3 +- .../samples/config-group-show-response.json | 5 +- .../samples/config-groups-list-response.json | 7 +- trove/configuration/views.py | 8 +- .../unittests/configuration/test_service.py | 83 +++++++++++++++++++ trove/tests/unittests/trove_testtools.py | 8 ++ 7 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 trove/tests/unittests/configuration/test_service.py diff --git a/api-ref/source/samples/config-group-create-request.json b/api-ref/source/samples/config-group-create-request.json index 51472330c3..f19c4a98f7 100644 --- a/api-ref/source/samples/config-group-create-request.json +++ b/api-ref/source/samples/config-group-create-request.json @@ -3,7 +3,8 @@ "name": "group1", "datastore": { "type": "mysql", - "version": "5.7.29" + "version": "mysql-5.7", + "version_number": "5.7.29" }, "values": { "connect_timeout": 200 diff --git a/api-ref/source/samples/config-group-create-response.json b/api-ref/source/samples/config-group-create-response.json index 825ea1aba1..1bbb3e5b8a 100644 --- a/api-ref/source/samples/config-group-create-response.json +++ b/api-ref/source/samples/config-group-create-response.json @@ -4,7 +4,8 @@ "updated": "2020-06-16T10:40:50", "datastore_name": "mysql", "datastore_version_id": "cf91aa9a-2192-4ec4-b7ce-5cac3b1e7dbe", - "datastore_version_name": "5.7.29", + "datastore_version_name": "mysql-5.7", + "datastore_version_number": "5.7.29", "description": null, "id": "9dcfca0b-d181-4b36-bbf0-09bc47b103ab", "instance_count": 0, diff --git a/api-ref/source/samples/config-group-show-response.json b/api-ref/source/samples/config-group-show-response.json index a5ee26b415..88791e4bff 100644 --- a/api-ref/source/samples/config-group-show-response.json +++ b/api-ref/source/samples/config-group-show-response.json @@ -1,16 +1,17 @@ { "configuration": { "datastore_name": "mysql", + "datastore_version_id": "b9f97132-467b-4f8e-b12d-947cfc223ac3", + "datastore_version_name": "mysql-5.7", + "datastore_version_number": "5.7.29", "updated": "2015-11-22T19:07:20", "values": { "connect_timeout": 17 }, "name": "group1", "created": "2015-11-20T20:51:24", - "datastore_version_name": "5.6", "instance_count": 1, "id": "1c8a4fdd-690c-4e6e-b2e1-148b8d738770", - "datastore_version_id": "b9f97132-467b-4f8e-b12d-947cfc223ac3", "description": null } } diff --git a/api-ref/source/samples/config-groups-list-response.json b/api-ref/source/samples/config-groups-list-response.json index 5bdaa990d8..bcedcb167c 100644 --- a/api-ref/source/samples/config-groups-list-response.json +++ b/api-ref/source/samples/config-groups-list-response.json @@ -1,13 +1,14 @@ { "configurations": [ { - "datastore_name": "mysql", "updated": "2015-07-01T16:38:27", + "datastore_version_id": "2dc7faa0-efff-4c2b-8cff-bcd949c518a5", + "datastore_name": "mysql", + "datastore_version_name": "mysql-5.7", + "datastore_version_number": "5.7.29", "name": "group1", "created": "2015-07-01T16:38:27", - "datastore_version_name": "5.6", "id": "2aa51628-5c42-4086-8682-137caffd2ba6", - "datastore_version_id": "2dc7faa0-efff-4c2b-8cff-bcd949c518a5", "description": null } ] diff --git a/trove/configuration/views.py b/trove/configuration/views.py index d9b09c19a9..3984a72943 100644 --- a/trove/configuration/views.py +++ b/trove/configuration/views.py @@ -99,12 +99,14 @@ class DetailedConfigurationView(object): "created": self.configuration.created, "updated": self.configuration.updated, "instance_count": - getattr(self.configuration, "instance_count", 0), + getattr(self.configuration, "instance_count", 0), "datastore_name": self.configuration.datastore.name, "datastore_version_id": - self.configuration.datastore_version_id, + self.configuration.datastore_version_id, "datastore_version_name": - self.configuration.datastore_version.name + self.configuration.datastore_version.name, + "datastore_version_number": + self.configuration.datastore_version.version } return {"configuration": configuration_dict} diff --git a/trove/tests/unittests/configuration/test_service.py b/trove/tests/unittests/configuration/test_service.py new file mode 100644 index 0000000000..55bd905c05 --- /dev/null +++ b/trove/tests/unittests/configuration/test_service.py @@ -0,0 +1,83 @@ +# Copyright 2020 Catalyst Cloud +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from unittest import mock + +from trove.common import cfg +from trove.common import wsgi +from trove.configuration import models as config_models +from trove.configuration import service +from trove.datastore import models as ds_models +from trove.tests.unittests import trove_testtools +from trove.tests.unittests.util import util + +CONF = cfg.CONF + + +class TestConfigurationsController(trove_testtools.TestCase): + @classmethod + def setUpClass(cls): + util.init_db() + + cls.ds_name = cls.random_name( + 'datastore', prefix='TestConfigurationsController') + ds_models.update_datastore(name=cls.ds_name, default_version=None) + cls.ds = ds_models.Datastore.load(cls.ds_name) + + ds_version_name = cls.random_name( + 'version', prefix='TestConfigurationsController') + ds_models.update_datastore_version( + cls.ds_name, ds_version_name, 'mysql', '', + ['trove'], '', 1, version='5.7.29') + cls.ds_version = ds_models.DatastoreVersion.load( + cls.ds, ds_version_name, version='5.7.29') + + cls.tenant_id = cls.random_uuid() + cls.config = config_models.Configuration.create( + cls.random_name('configuration'), + '', cls.tenant_id, None, + cls.ds_version.id) + cls.config_id = cls.config.id + + cls.controller = service.ConfigurationsController() + + super(TestConfigurationsController, cls).setUpClass() + + @classmethod + def tearDownClass(cls): + util.cleanup_db() + + super(TestConfigurationsController, cls).tearDownClass() + + def test_show(self): + req_mock = mock.MagicMock( + environ={ + wsgi.CONTEXT_KEY: mock.MagicMock(project_id=self.tenant_id) + } + ) + result = self.controller.show(req_mock, self.tenant_id, + self.config_id) + data = result.data(None).get('configuration') + + expected = { + "id": self.config_id, + "name": self.config.name, + "description": '', + "instance_count": 0, + "datastore_name": self.ds_name, + "datastore_version_id": self.ds_version.id, + "datastore_version_name": self.ds_version.name, + "datastore_version_number": self.ds_version.version + } + + self.assertDictContains(data, expected) diff --git a/trove/tests/unittests/trove_testtools.py b/trove/tests/unittests/trove_testtools.py index 57ada51afe..34e67b8904 100644 --- a/trove/tests/unittests/trove_testtools.py +++ b/trove/tests/unittests/trove_testtools.py @@ -122,3 +122,11 @@ class TestCase(testtools.TestCase): @classmethod def random_uuid(cls): return str(uuid.uuid4()) + + def assertDictContains(self, parent, child): + """Checks whether child dict is a subset of parent. + + assertDictContainsSubset() in standard Python 2.7 has been deprecated + since Python 3.2 + """ + self.assertEqual(parent, dict(parent, **child))