From 86a870cc5043ccebbae54e16d4bb4c3cfb44ee4b Mon Sep 17 00:00:00 2001 From: Andrew Bogott Date: Fri, 6 Jan 2023 14:46:25 -0600 Subject: [PATCH] Establish consistency on db_info.addresses between taskmanager and instance We had two different workflows here using the same variable but expecting it to have a totally different format. The taskmanager dns code was populating that variable with nova api output; the database list code populated it manually with a custom-format structure. This seems to have survived a long time because these are both edge cases: the dns workflow was only traversed with dns integration is switched on (unusual) and the database list only relied on IP addresses when hostnames weren't present. This patch picks a winner (the custom structure used by the database listing code) and modifies the dns workflow to live with that same format. This is spackle over a whole lot of bitrot, but should get both use cases working properly. Story: #2010077 Task: #45568 Change-Id: I5832733dd312db24d2d8047658fdd1af9f4e700a --- trove/instance/models.py | 14 +++++++------- trove/taskmanager/models.py | 5 ++--- trove/tests/unittests/instance/test_service.py | 6 +++++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/trove/instance/models.py b/trove/instance/models.py index 36084f2211..565d014575 100644 --- a/trove/instance/models.py +++ b/trove/instance/models.py @@ -141,14 +141,14 @@ def load_simple_instance_server_status(context, db_info): def load_simple_instance_addresses(context, db_info): """Get addresses of the instance from Neutron.""" - if 'BUILDING' == db_info.task_status.action and not db_info.cluster_id: - db_info.addresses = [] - return - addresses = [] user_ports = [] - client = clients.create_neutron_client(context, db_info.region_id) - ports = neutron.get_instance_ports(client, db_info.compute_instance_id) + try: + client = clients.create_neutron_client(context, db_info.region_id) + ports = neutron.get_instance_ports(client, db_info.compute_instance_id) + except nova_exceptions.NotFound: + db_info.addresses = [] + return for port in ports: if port['network_id'] not in CONF.management_networks: LOG.debug('Found user port %s for instance %s', port['id'], @@ -249,7 +249,7 @@ class SimpleInstance(object): ips = self.get_visible_ip_addresses() if ips: # FIXME - return ips[0] + return ips[0]['address'] @property def flavor_id(self): diff --git a/trove/taskmanager/models.py b/trove/taskmanager/models.py index d29762592d..5b91797867 100755 --- a/trove/taskmanager/models.py +++ b/trove/taskmanager/models.py @@ -64,6 +64,7 @@ from trove.instance.models import FreshInstance from trove.instance.models import Instance from trove.instance.models import InstanceServiceStatus from trove.instance.models import InstanceStatus +from trove.instance.models import load_simple_instance_addresses from trove.instance import service_status as srvstatus from trove.instance.tasks import InstanceTasks from trove.module import models as module_models @@ -1154,9 +1155,7 @@ class FreshInstanceTasks(FreshInstance, NotifyMixin, ConfigurationMixin): utils.poll_until(get_server, ip_is_available, sleep_time=1, time_out=CONF.dns_time_out) - server = self.nova_client.servers.get( - self.db_info.compute_instance_id) - self.db_info.addresses = server.addresses + load_simple_instance_addresses(self.context, self.db_info) LOG.debug("Creating dns entry...") ip = self.dns_ip_address if not ip: diff --git a/trove/tests/unittests/instance/test_service.py b/trove/tests/unittests/instance/test_service.py index 807cb161ad..971bad1a37 100644 --- a/trove/tests/unittests/instance/test_service.py +++ b/trove/tests/unittests/instance/test_service.py @@ -135,11 +135,13 @@ class TestInstanceController(trove_testtools.TestCase): mock.MagicMock(), body, mock.ANY ) + @mock.patch('trove.instance.models.load_simple_instance_addresses') @mock.patch.object(clients, 'create_nova_client', return_value=mock.MagicMock()) @mock.patch('trove.rpc.get_client') def test_update_datastore_version(self, mock_get_rpc_client, - mock_create_nova_client): + mock_create_nova_client, + mock_load_addresses): # Create an instance in db. instance = ins_models.DBInstance.create( name=self.random_name('instance'), @@ -177,6 +179,8 @@ class TestInstanceController(trove_testtools.TestCase): instance_id=instance.id, datastore_version_id=new_ds_version.id) + mock_load_addresses.assert_called_once() + @mock.patch('trove.instance.models.load_server_group_info') @mock.patch('trove.instance.models.load_guest_info') @mock.patch('trove.instance.models.load_simple_instance_addresses')