From 5371dbbd92b1a0bf58e2a47954e90a43168e0a5d Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Tue, 28 Jul 2020 08:41:54 +1200 Subject: [PATCH] Add volume resize functional test for replication Change-Id: Id08df79f064ddf9a31247853fb19625e695f7bd0 --- trove_tempest_plugin/tests/base.py | 77 ++++++++++--------- .../tests/scenario/base_replication.py | 20 +++++ 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/trove_tempest_plugin/tests/base.py b/trove_tempest_plugin/tests/base.py index c0791f1..633cdef 100644 --- a/trove_tempest_plugin/tests/base.py +++ b/trove_tempest_plugin/tests/base.py @@ -255,12 +255,22 @@ class BaseTroveTest(test.BaseTestCase): """ name = name or cls.get_resource_name("instance") + # Flavor, volume, datastore are not needed for creating replica. + if replica_of: + body = { + "instance": { + "name": name, + "nics": [{"net-id": cls.private_network}], + "access": {"is_public": True}, + "replica_of": replica_of, + } + } + # Get datastore version. Get from API if the default ds version is not # configured. - if not datastore_version: + elif not datastore_version: default_versions = CONF.database.default_datastore_versions datastore_version = default_versions.get(cls.datastore) - if not datastore_version: res = cls.client.list_resources("datastores") for d in res['datastores']: @@ -270,41 +280,38 @@ class BaseTroveTest(test.BaseTestCase): else: datastore_version = d['versions'][0]['name'] break + if not datastore_version: + message = ('Failed to get available datastore version.') + raise exceptions.TempestException(message) - if not datastore_version: - message = ('Failed to get available datastore version.') - raise exceptions.TempestException(message) - - body = { - "instance": { - "name": name, - "datastore": { - "type": cls.datastore, - "version": datastore_version - }, - "flavorRef": CONF.database.flavor_id, - "volume": { - "size": 1, - "type": CONF.database.volume_type - }, - "nics": [{"net-id": cls.private_network}], - "databases": [{"name": database}], - "users": [ - { - "name": username, - "password": password, - "databases": [{"name": database}] - } - ], - "access": {"is_public": True} + if not replica_of: + body = { + "instance": { + "name": name, + "datastore": { + "type": cls.datastore, + "version": datastore_version + }, + "flavorRef": CONF.database.flavor_id, + "volume": { + "size": 1, + "type": CONF.database.volume_type + }, + "nics": [{"net-id": cls.private_network}], + "databases": [{"name": database}], + "users": [ + { + "name": username, + "password": password, + "databases": [{"name": database}] + } + ], + "access": {"is_public": True} + } } - } - if backup_id: - body['instance'].update({'restorePoint': {'backupRef': backup_id}}) - if replica_of: - body['instance']['replica_of'] = replica_of - body['instance'].pop('databases', None) - body['instance'].pop('users', None) + if backup_id: + body['instance'].update( + {'restorePoint': {'backupRef': backup_id}}) res = cls.client.create_resource("instances", body) cls.addClassResourceCleanup(cls.wait_for_instance_status, diff --git a/trove_tempest_plugin/tests/scenario/base_replication.py b/trove_tempest_plugin/tests/scenario/base_replication.py index 618cd2f..85ad5b3 100644 --- a/trove_tempest_plugin/tests/scenario/base_replication.py +++ b/trove_tempest_plugin/tests/scenario/base_replication.py @@ -167,6 +167,26 @@ class TestReplicationBase(trove_base.BaseTroveTest): self.verify_data_replication(replica2_ip, constants.DB_USER, constants.DB_PASS, constants.DB_NAME) + # Volume resize to primary + LOG.info(f"Resizing volume for primary {self.instance_id} to 2G") + req_body = { + "resize": { + "volume": {"size": 2} + } + } + self.client.create_resource(f"instances/{self.instance_id}/action", + req_body, expected_status_code=202, + need_response=False) + self.wait_for_instance_status(self.instance_id) + self.wait_for_instance_status(replica1_id) + self.wait_for_instance_status(replica2_id) + + # Verify the volumes of all the replicas are also resized to 2G + replica1 = self.client.get_resource('instances', replica1_id) + self.assertEqual(2, replica1['instance']['volume'].get('size', 0)) + replica2 = self.client.get_resource('instances', replica2_id) + self.assertEqual(2, replica2['instance']['volume'].get('size', 0)) + # Promote replica1 to primary LOG.info(f"Promoting replica1 {replica1_id} to primary") promote_primary = {