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
This commit is contained in:
Andrew Bogott 2023-01-06 14:46:25 -06:00 committed by Andrew Bogott
parent 6822a76ad9
commit 86a870cc50
3 changed files with 14 additions and 11 deletions

View File

@ -141,14 +141,14 @@ def load_simple_instance_server_status(context, db_info):
def load_simple_instance_addresses(context, db_info): def load_simple_instance_addresses(context, db_info):
"""Get addresses of the instance from Neutron.""" """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 = [] addresses = []
user_ports = [] user_ports = []
client = clients.create_neutron_client(context, db_info.region_id) try:
ports = neutron.get_instance_ports(client, db_info.compute_instance_id) 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: for port in ports:
if port['network_id'] not in CONF.management_networks: if port['network_id'] not in CONF.management_networks:
LOG.debug('Found user port %s for instance %s', port['id'], LOG.debug('Found user port %s for instance %s', port['id'],
@ -249,7 +249,7 @@ class SimpleInstance(object):
ips = self.get_visible_ip_addresses() ips = self.get_visible_ip_addresses()
if ips: if ips:
# FIXME # FIXME
return ips[0] return ips[0]['address']
@property @property
def flavor_id(self): def flavor_id(self):

View File

@ -64,6 +64,7 @@ from trove.instance.models import FreshInstance
from trove.instance.models import Instance from trove.instance.models import Instance
from trove.instance.models import InstanceServiceStatus from trove.instance.models import InstanceServiceStatus
from trove.instance.models import InstanceStatus 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 import service_status as srvstatus
from trove.instance.tasks import InstanceTasks from trove.instance.tasks import InstanceTasks
from trove.module import models as module_models 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, utils.poll_until(get_server, ip_is_available,
sleep_time=1, time_out=CONF.dns_time_out) sleep_time=1, time_out=CONF.dns_time_out)
server = self.nova_client.servers.get( load_simple_instance_addresses(self.context, self.db_info)
self.db_info.compute_instance_id)
self.db_info.addresses = server.addresses
LOG.debug("Creating dns entry...") LOG.debug("Creating dns entry...")
ip = self.dns_ip_address ip = self.dns_ip_address
if not ip: if not ip:

View File

@ -135,11 +135,13 @@ class TestInstanceController(trove_testtools.TestCase):
mock.MagicMock(), body, mock.ANY mock.MagicMock(), body, mock.ANY
) )
@mock.patch('trove.instance.models.load_simple_instance_addresses')
@mock.patch.object(clients, 'create_nova_client', @mock.patch.object(clients, 'create_nova_client',
return_value=mock.MagicMock()) return_value=mock.MagicMock())
@mock.patch('trove.rpc.get_client') @mock.patch('trove.rpc.get_client')
def test_update_datastore_version(self, mock_get_rpc_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. # Create an instance in db.
instance = ins_models.DBInstance.create( instance = ins_models.DBInstance.create(
name=self.random_name('instance'), name=self.random_name('instance'),
@ -177,6 +179,8 @@ class TestInstanceController(trove_testtools.TestCase):
instance_id=instance.id, instance_id=instance.id,
datastore_version_id=new_ds_version.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_server_group_info')
@mock.patch('trove.instance.models.load_guest_info') @mock.patch('trove.instance.models.load_guest_info')
@mock.patch('trove.instance.models.load_simple_instance_addresses') @mock.patch('trove.instance.models.load_simple_instance_addresses')