Merge "Refactor network API 'get_instance_nw_info'"
This commit is contained in:
commit
e9bfc2deda
|
@ -369,16 +369,10 @@ class API(base_api.NetworkAPI):
|
|||
@wrap_check_policy
|
||||
def get_instance_nw_info(self, context, instance, **kwargs):
|
||||
"""Returns all network info related to an instance."""
|
||||
result = self._get_instance_nw_info(context, instance)
|
||||
# NOTE(comstud): Don't update API cell with new info_cache every
|
||||
# time we pull network info for an instance. The periodic healing
|
||||
# of info_cache causes too many cells messages. Healing the API
|
||||
# will happen separately.
|
||||
base_api.update_instance_cache_with_nw_info(self, context, instance,
|
||||
result, update_cells=False)
|
||||
return result
|
||||
return super(API, self).get_instance_nw_info(context, instance,
|
||||
**kwargs)
|
||||
|
||||
def _get_instance_nw_info(self, context, instance):
|
||||
def _get_instance_nw_info(self, context, instance, **kwargs):
|
||||
"""Returns all network info related to an instance."""
|
||||
flavor = instance.get_flavor()
|
||||
args = {'instance_id': instance.uuid,
|
||||
|
|
|
@ -238,6 +238,19 @@ class NetworkAPI(base.Base):
|
|||
|
||||
def get_instance_nw_info(self, context, instance, **kwargs):
|
||||
"""Returns all network info related to an instance."""
|
||||
with lockutils.lock('refresh_cache-%s' % instance.uuid):
|
||||
result = self._get_instance_nw_info(context, instance, **kwargs)
|
||||
# NOTE(comstud): Don't update API cell with new info_cache every
|
||||
# time we pull network info for an instance. The periodic healing
|
||||
# of info_cache causes too many cells messages. Healing the API
|
||||
# will happen separately.
|
||||
update_instance_cache_with_nw_info(self, context, instance,
|
||||
nw_info=result,
|
||||
update_cells=False)
|
||||
return result
|
||||
|
||||
def _get_instance_nw_info(self, context, instance, **kwargs):
|
||||
"""Template method, so a subclass can implement for neutron/network."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def create_pci_requests_for_sriov_ports(self, context,
|
||||
|
|
|
@ -854,29 +854,9 @@ class API(base_api.NetworkAPI):
|
|||
{'port_id': port_id, 'reason': exc})
|
||||
raise exception.NovaException(message=msg)
|
||||
|
||||
def get_instance_nw_info(self, context, instance, networks=None,
|
||||
port_ids=None, use_slave=False,
|
||||
admin_client=None,
|
||||
preexisting_port_ids=None):
|
||||
"""Return network information for specified instance
|
||||
and update cache.
|
||||
"""
|
||||
# NOTE(geekinutah): It would be nice if use_slave had us call
|
||||
# special APIs that pummeled slaves instead of
|
||||
# the master. For now we just ignore this arg.
|
||||
with lockutils.lock('refresh_cache-%s' % instance.uuid):
|
||||
result = self._get_instance_nw_info(context, instance, networks,
|
||||
port_ids, admin_client,
|
||||
preexisting_port_ids)
|
||||
base_api.update_instance_cache_with_nw_info(self, context,
|
||||
instance,
|
||||
nw_info=result,
|
||||
update_cells=False)
|
||||
return result
|
||||
|
||||
def _get_instance_nw_info(self, context, instance, networks=None,
|
||||
port_ids=None, admin_client=None,
|
||||
preexisting_port_ids=None):
|
||||
preexisting_port_ids=None, **kwargs):
|
||||
# NOTE(danms): This is an inner method intended to be called
|
||||
# by other code that updates instance nwinfo. It *must* be
|
||||
# called with the refresh_cache-%(instance_uuid) lock held!
|
||||
|
|
|
@ -535,6 +535,20 @@ class ApiTestCase(test.TestCase):
|
|||
self.context, instance,
|
||||
{'source_compute': None, 'dest_compute': 'fake_compute_source'})
|
||||
|
||||
@mock.patch('oslo_concurrency.lockutils.lock')
|
||||
@mock.patch.object(api.API, '_get_instance_nw_info')
|
||||
@mock.patch('nova.network.base_api.update_instance_cache_with_nw_info')
|
||||
def test_get_instance_nw_info(self, mock_update, mock_get, mock_lock):
|
||||
fake_result = mock.sentinel.get_nw_info_result
|
||||
mock_get.return_value = fake_result
|
||||
instance = fake_instance.fake_instance_obj(self.context)
|
||||
result = self.network_api.get_instance_nw_info(self.context, instance)
|
||||
mock_get.assert_called_once_with(self.context, instance)
|
||||
mock_update.assert_called_once_with(self.network_api, self.context,
|
||||
instance, nw_info=fake_result,
|
||||
update_cells=False)
|
||||
self.assertEqual(fake_result, result)
|
||||
|
||||
|
||||
@mock.patch('nova.network.api.API')
|
||||
@mock.patch('nova.db.instance_info_cache_update', return_value=fake_info_cache)
|
||||
|
|
|
@ -2820,6 +2820,20 @@ class TestNeutronv2WithMock(test.TestCase):
|
|||
api.get_instance_nw_info, 'context', instance)
|
||||
mock_lock.assert_called_once_with('refresh_cache-%s' % instance.uuid)
|
||||
|
||||
@mock.patch('oslo_concurrency.lockutils.lock')
|
||||
@mock.patch.object(neutronapi.API, '_get_instance_nw_info')
|
||||
@mock.patch('nova.network.base_api.update_instance_cache_with_nw_info')
|
||||
def test_get_instance_nw_info(self, mock_update, mock_get, mock_lock):
|
||||
fake_result = mock.sentinel.get_nw_info_result
|
||||
mock_get.return_value = fake_result
|
||||
instance = fake_instance.fake_instance_obj(self.context)
|
||||
result = self.api.get_instance_nw_info(self.context, instance)
|
||||
mock_get.assert_called_once_with(self.context, instance)
|
||||
mock_update.assert_called_once_with(self.api, self.context, instance,
|
||||
nw_info=fake_result,
|
||||
update_cells=False)
|
||||
self.assertEqual(fake_result, result)
|
||||
|
||||
def _test_validate_networks_fixed_ip_no_dup(self, nets, requested_networks,
|
||||
ids, list_port_values):
|
||||
|
||||
|
|
Loading…
Reference in New Issue