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')