Merge "Remove unused vpn param from allocate_for_instance"

This commit is contained in:
Zuul 2020-09-08 10:24:44 +00:00 committed by Gerrit Code Review
commit a837a0ba25
5 changed files with 28 additions and 40 deletions

View File

@ -1722,8 +1722,7 @@ class ComputeManager(manager.Manager):
raise exception.InstanceExists(name=instance.name)
def _allocate_network_async(self, context, instance, requested_networks,
security_groups, is_vpn,
resource_provider_mapping):
security_groups, resource_provider_mapping):
"""Method used to allocate networks in the background.
Broken out for testing.
@ -1744,7 +1743,7 @@ class ComputeManager(manager.Manager):
for attempt in range(1, attempts + 1):
try:
nwinfo = self.network_api.allocate_for_instance(
context, instance, vpn=is_vpn,
context, instance,
requested_networks=requested_networks,
security_groups=security_groups,
bind_host_id=bind_host_id,
@ -1807,11 +1806,9 @@ class ComputeManager(manager.Manager):
instance.task_state = task_states.NETWORKING
instance.save(expected_task_state=[None])
is_vpn = False
return network_model.NetworkInfoAsyncWrapper(
self._allocate_network_async, context, instance,
requested_networks, security_groups, is_vpn,
resource_provider_mapping)
requested_networks, security_groups, resource_provider_mapping)
def _default_root_device_name(self, instance, image_meta, root_bdm):
"""Gets a default root device name from the driver.

View File

@ -1006,7 +1006,7 @@ class API(base.Base):
return requests_and_created_ports
def allocate_for_instance(self, context, instance, vpn,
def allocate_for_instance(self, context, instance,
requested_networks,
security_groups=None, bind_host_id=None,
attach=False, resource_provider_mapping=None):
@ -1014,7 +1014,6 @@ class API(base.Base):
:param context: The request context.
:param instance: nova.objects.instance.Instance object.
:param vpn: A boolean, ignored by this driver.
:param requested_networks: objects.NetworkRequestList object.
:param security_groups: None or security groups to allocate for
instance.
@ -1708,7 +1707,7 @@ class API(base.Base):
port_id=port_id,
pci_request_id=None,
tag=tag)])
return self.allocate_for_instance(context, instance, vpn=False,
return self.allocate_for_instance(context, instance,
requested_networks=requested_networks,
bind_host_id=bind_host_id, attach=True)

View File

@ -639,7 +639,7 @@ class TestSecurityGroupsV21(test.TestCase):
neutron = neutron_api.API()
with mock.patch.object(nova.db.api, 'instance_get_by_uuid',
return_value=db_inst):
neutron.allocate_for_instance(_context, instance, False, None,
neutron.allocate_for_instance(_context, instance, None,
security_groups=[sg['id']])
req = fakes.HTTPRequest.blank(

View File

@ -624,7 +624,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
instance = fake_instance.fake_instance_obj(
self.context, expected_attrs=['system_metadata'])
is_vpn = 'fake-is-vpn'
req_networks = objects.NetworkRequestList(
objects=[objects.NetworkRequest(network_id='fake')])
sec_groups = 'fake-sec-groups'
@ -640,7 +639,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
res = self.compute._allocate_network_async(self.context, instance,
req_networks,
sec_groups,
is_vpn,
rp_mapping)
self.assertEqual(7, mock_sleep.call_count)
@ -655,7 +653,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
self.flags(network_allocate_retries=0)
instance = {}
is_vpn = 'fake-is-vpn'
req_networks = objects.NetworkRequestList(
objects=[objects.NetworkRequest(network_id='fake')])
sec_groups = 'fake-sec-groups'
@ -667,10 +664,10 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
self.assertRaises(test.TestingException,
self.compute._allocate_network_async,
self.context, instance, req_networks,
sec_groups, is_vpn, rp_mapping)
sec_groups, rp_mapping)
mock_allocate.assert_called_once_with(
self.context, instance, vpn=is_vpn,
self.context, instance,
requested_networks=req_networks,
security_groups=sec_groups,
bind_host_id=instance.get('host'),
@ -684,7 +681,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
instance = fake_instance.fake_instance_obj(
self.context, expected_attrs=['system_metadata'])
is_vpn = 'fake-is-vpn'
req_networks = objects.NetworkRequestList(
objects=[objects.NetworkRequest(network_id='fake')])
sec_groups = 'fake-sec-groups'
@ -698,7 +694,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
res = self.compute._allocate_network_async(self.context, instance,
req_networks,
sec_groups,
is_vpn,
rp_mapping)
self.assertEqual(final_result, res)
self.assertEqual(1, sleep.call_count)
@ -710,8 +705,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
objects=[objects.NetworkRequest(network_id='none')])
nwinfo = self.compute._allocate_network_async(
self.context, mock.sentinel.instance, req_networks,
security_groups=['default'], is_vpn=False,
resource_provider_mapping={})
security_groups=['default'], resource_provider_mapping={})
self.assertEqual(0, len(nwinfo))
@mock.patch('nova.compute.manager.ComputeManager.'

View File

@ -614,11 +614,11 @@ class TestAPIBase(test.TestCase):
nw_info = None
if exception:
self.assertRaises(exception, self.api.allocate_for_instance,
ctxt, self.instance, False,
ctxt, self.instance,
requested_networks, bind_host_id=bind_host_id)
else:
nw_info = self.api.allocate_for_instance(
ctxt, self.instance, False, requested_networks,
ctxt, self.instance, requested_networks,
bind_host_id=bind_host_id)
mock_get_client.assert_has_calls([
@ -1277,7 +1277,7 @@ class TestAPI(TestAPIBase):
mocked_client.list_networks.return_value = {
'networks': model.NetworkInfo([])}
nwinfo = self.api.allocate_for_instance(self.context, self.instance,
False, None)
None)
self.assertEqual(0, len(nwinfo))
mock_get_client.assert_has_calls([
mock.call(self.context),
@ -1343,7 +1343,7 @@ class TestAPI(TestAPIBase):
self.assertRaises(exception.PortInUse,
self.api.allocate_for_instance,
self.context, self.instance, False,
self.context, self.instance,
requested_networks=requested_networks)
mock_unbind.assert_called_once_with(self.context, [],
mocked_client, mock.ANY)
@ -1388,7 +1388,7 @@ class TestAPI(TestAPIBase):
"fail to create port")
self.assertRaises(NEUTRON_CLIENT_EXCEPTION,
self.api.allocate_for_instance,
self.context, self.instance, False,
self.context, self.instance,
requested_networks=requested_networks)
mock_get_client.assert_has_calls([
mock.call(self.context),
@ -1412,7 +1412,7 @@ class TestAPI(TestAPIBase):
objects=[objects.NetworkRequest()])
self.assertRaises(test.TestingException,
self.api.allocate_for_instance, self.context,
self.instance, False, requested_networks)
self.instance, requested_networks)
mock_get_client.assert_has_calls([
mock.call(self.context),
mock.call(self.context, admin=True)])
@ -1474,7 +1474,7 @@ class TestAPI(TestAPIBase):
{'networks': self.nets8}]
self.assertRaises(exception.ExternalNetworkAttachForbidden,
self.api.allocate_for_instance, self.context,
self.instance, False, None)
self.instance, None)
mock_get_client.assert_has_calls([
mock.call(self.context),
mock.call(self.context, admin=True)])
@ -1501,7 +1501,7 @@ class TestAPI(TestAPIBase):
self.assertRaises(
exception.NetworkAmbiguous,
self.api.allocate_for_instance,
self.context, self.instance, False, None)
self.context, self.instance, None)
mock_get_client.assert_has_calls([
mock.call(self.context),
mock.call(self.context, admin=True)])
@ -5092,7 +5092,7 @@ class TestAPI(TestAPIBase):
mock_avail_nets.return_value = [{'id': 'net-1',
'subnets': ['subnet1']}]
self.api.allocate_for_instance(mock.sentinel.ctx, mock_inst, False,
self.api.allocate_for_instance(mock.sentinel.ctx, mock_inst,
requested_networks=nw_req)
mock_unbind.assert_called_once_with(mock.sentinel.ctx,
@ -5328,7 +5328,7 @@ class TestAPI(TestAPIBase):
self.assertRaises(exception.PortBindingFailed,
self.api.allocate_for_instance,
mock.sentinel.ctx,
mock_inst, False, None)
mock_inst, None)
mock_nc.delete_port.assert_called_once_with(uuids.portid_1)
@mock.patch('nova.network.neutron.API._show_port')
@ -5349,7 +5349,7 @@ class TestAPI(TestAPIBase):
self.assertRaises(exception.PortBindingFailed,
self.api.allocate_for_instance,
mock.sentinel.ctx, mock_inst, False,
mock.sentinel.ctx, mock_inst,
requested_networks=nw_req)
@mock.patch('nova.objects.virtual_interface.VirtualInterface.create')
@ -5383,7 +5383,7 @@ class TestAPI(TestAPIBase):
with mock.patch.object(self.api, 'get_instance_nw_info'):
self.api.allocate_for_instance(
mock.sentinel.ctx, mock_inst, False,
mock.sentinel.ctx, mock_inst,
requested_networks=nw_req,
resource_provider_mapping={uuids.portid_1: [uuids.rp1]})
@ -6843,8 +6843,7 @@ class TestAllocateForInstance(test.NoDBTestCase):
self.instance.project_id = ""
self.assertRaises(exception.InvalidInput,
api.allocate_for_instance, self.context, self.instance,
False, None)
api.allocate_for_instance, self.context, self.instance, None)
@mock.patch.object(neutronapi.API, 'get_instance_nw_info')
@mock.patch.object(neutronapi.API, '_update_ports_for_instance')
@ -6871,8 +6870,7 @@ class TestAllocateForInstance(test.NoDBTestCase):
{"id": uuids.created}, {"id": uuids.preexist}, {"id": "foo"}
]
result = api.allocate_for_instance(self.context, self.instance,
False, None)
result = api.allocate_for_instance(self.context, self.instance, None)
self.assertEqual(len(result), 2)
self.assertEqual(result[0], {"id": uuids.created})
@ -7431,7 +7429,7 @@ class TestNeutronPortSecurity(test.NoDBTestCase):
api = neutronapi.API()
mock_create_port.return_value = {'id': 'foo', 'mac_address': 'bar'}
api.allocate_for_instance(
'context', instance, False, requested_networks=onets,
'context', instance, requested_networks=onets,
security_groups=secgroups)
mock_process_security_groups.assert_called_once_with(
@ -7484,7 +7482,7 @@ class TestNeutronPortSecurity(test.NoDBTestCase):
api = neutronapi.API()
mock_create_port.return_value = {'id': 'foo', 'mac_address': 'bar'}
api.allocate_for_instance(
'context', instance, False, requested_networks=onets,
'context', instance, requested_networks=onets,
security_groups=secgroups)
mock_create_port.assert_has_calls([
@ -7535,7 +7533,7 @@ class TestNeutronPortSecurity(test.NoDBTestCase):
api = neutronapi.API()
mock_create_port.return_value = {'id': 'foo', 'mac_address': 'bar'}
api.allocate_for_instance(
'context', instance, False, requested_networks=onets,
'context', instance, requested_networks=onets,
security_groups=secgroups)
mock_process_security_groups.assert_called_once_with(
@ -7589,7 +7587,7 @@ class TestNeutronPortSecurity(test.NoDBTestCase):
self.assertRaises(
exception.SecurityGroupCannotBeApplied,
api.allocate_for_instance,
'context', instance, False, requested_networks=onets,
'context', instance, requested_networks=onets,
security_groups=secgroups)
mock_process_security_groups.assert_called_once_with(
@ -7782,7 +7780,7 @@ class TestAPIAutoAllocateNetwork(test.NoDBTestCase):
requested_networks = objects.NetworkRequestList(objects=[net_req])
nw_info = self.api.allocate_for_instance(
self.context, instance, False, requested_networks)
self.context, instance, requested_networks)
self.assertEqual(1, len(nw_info))
self.assertEqual(uuids.port_id, nw_info[0]['id'])
# assert that we filtered available networks on admin_state_up=True