Browse Source

Merge "Cleanup unused code"

tags/22.0.0.0rc1
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
c92b902f43
4 changed files with 12 additions and 73 deletions
  1. +1
    -2
      nova/compute/manager.py
  2. +3
    -29
      nova/network/neutron.py
  3. +5
    -5
      nova/tests/unit/compute/test_compute.py
  4. +3
    -37
      nova/tests/unit/network/test_neutron.py

+ 1
- 2
nova/compute/manager.py View File

@@ -7621,11 +7621,10 @@ class ComputeManager(manager.Manager):
instance,
requested_networks,
bind_host_id=bind_host_id,
attach=True,
)

if len(network_info) != 1:
LOG.error('allocate_port_for_instance returned %(ports)s '
LOG.error('allocate_for_instance returned %(ports)s '
'ports', {'ports': len(network_info)})
# TODO(elod.illes): an instance.interface_attach.error notification
# should be sent here


+ 3
- 29
nova/network/neutron.py View File

@@ -687,9 +687,8 @@ class API(base.Base):
# under user's zone.
self._reset_port_dns_name(network, port_id, neutron)

# TODO(gibi): remove unused attach flag
def _validate_requested_port_ids(self, context, instance, neutron,
requested_networks, attach=False):
requested_networks):
"""Processes and validates requested networks for allocation.

Iterates over the list of NetworkRequest objects, validating the
@@ -704,9 +703,6 @@ class API(base.Base):
:type neutron: neutronclient.v2_0.client.Client
:param requested_networks: List of user-requested networks and/or ports
:type requested_networks: nova.objects.NetworkRequestList
:param attach: Boolean indicating if a port is being attached to an
existing running instance. Should be False during server create.
:type attach: bool
:returns: tuple of:
- ports: dict mapping of port id to port dict
- ordered_networks: list of nova.objects.NetworkRequest objects
@@ -902,9 +898,6 @@ class API(base.Base):
return {}

# if this function is directly called without a requested_network param
# or if it is indirectly called through allocate_port_for_instance()
# with None params=(network_id=None, requested_ip=None, port_id=None,
# pci_request_id=None):
if (not requested_networks or
requested_networks.is_single_unspecified or
requested_networks.auto_allocate):
@@ -995,11 +988,10 @@ class API(base.Base):

return requests_and_created_ports

# TODO(gibi): remove the unused attach flag
def allocate_for_instance(self, context, instance,
requested_networks,
security_groups=None, bind_host_id=None,
attach=False, resource_provider_mapping=None):
resource_provider_mapping=None):
"""Allocate network resources for the instance.

:param context: The request context.
@@ -1008,8 +1000,6 @@ class API(base.Base):
:param security_groups: None or security groups to allocate for
instance.
:param bind_host_id: the host ID to attach to the ports being created.
:param attach: Boolean indicating if a port is being attached to an
existing running instance. Should be False during server create.
:param resource_provider_mapping: a dict keyed by ids of the entities
(for example Neutron port) requesting resources for this instance
mapped to a list of resource provider UUIDs that are fulfilling
@@ -1043,8 +1033,7 @@ class API(base.Base):
# See bug 1849657.
requested_ports_dict, ordered_networks = (
self._validate_requested_port_ids(
context, instance, admin_client, requested_networks,
attach=attach))
context, instance, admin_client, requested_networks))

nets = self._validate_requested_network_ids(
context, instance, neutron, requested_networks, ordered_networks)
@@ -1687,21 +1676,6 @@ class API(base.Base):
update_instance_cache_with_nw_info(self, context, instance,
network_model.NetworkInfo([]))

# TODO(gibi): remove this unused function
def allocate_port_for_instance(self, context, instance, port_id,
network_id=None, requested_ip=None,
bind_host_id=None, tag=None):
"""Allocate a port for the instance."""
requested_networks = objects.NetworkRequestList(
objects=[objects.NetworkRequest(network_id=network_id,
address=requested_ip,
port_id=port_id,
pci_request_id=None,
tag=tag)])
return self.allocate_for_instance(context, instance,
requested_networks=requested_networks,
bind_host_id=bind_host_id, attach=True)

def deallocate_port_for_instance(self, context, instance, port_id):
"""Remove a specified port from the instance.



+ 5
- 5
nova/tests/unit/compute/test_compute.py View File

@@ -10288,7 +10288,7 @@ class ComputeAPITestCase(BaseTestCase):
mock_allocate.assert_called_once_with(
self.context, instance,
test.MatchType(objects.NetworkRequestList),
bind_host_id='fake-mini', attach=True)
bind_host_id='fake-mini')
network_requests = mock_allocate.mock_calls[0][1][2]
self.assertEqual(1, len(network_requests.objects))
network_request = network_requests[0]
@@ -10351,7 +10351,7 @@ class ComputeAPITestCase(BaseTestCase):
mock_allocate.assert_called_once_with(
self.context, instance,
test.MatchType(objects.NetworkRequestList),
bind_host_id='fake-mini', attach=True)
bind_host_id='fake-mini')
network_requests = mock_allocate.mock_calls[0][1][2]
self.assertEqual(1, len(network_requests.objects))
network_request = network_requests[0]
@@ -10404,7 +10404,7 @@ class ComputeAPITestCase(BaseTestCase):
mock_allocate.assert_called_once_with(
self.context, instance,
test.MatchType(objects.NetworkRequestList),
bind_host_id='fake-mini', attach=True)
bind_host_id='fake-mini')
network_requests = mock_allocate.mock_calls[0][1][2]
self.assertEqual(1, len(network_requests.objects))
network_request = network_requests[0]
@@ -10472,7 +10472,7 @@ class ComputeAPITestCase(BaseTestCase):
mock_allocate.assert_called_once_with(
self.context, instance,
test.MatchType(objects.NetworkRequestList),
bind_host_id='fake-host', attach=True)
bind_host_id='fake-host')
network_requests = mock_allocate.mock_calls[0][1][2]
self.assertEqual(1, len(network_requests.objects))
network_request = network_requests[0]
@@ -10549,7 +10549,7 @@ class ComputeAPITestCase(BaseTestCase):
mock_allocate.assert_called_once_with(
self.context, instance,
test.MatchType(objects.NetworkRequestList),
bind_host_id='fake-host', attach=True)
bind_host_id='fake-host')
network_requests = mock_allocate.mock_calls[0][1][2]
self.assertEqual(1, len(network_requests.objects))
network_request = network_requests[0]


+ 3
- 37
nova/tests/unit/network/test_neutron.py View File

@@ -5100,38 +5100,6 @@ class TestAPI(TestAPIBase):
mock.ANY,
mock.ANY)

@mock.patch('nova.network.neutron.API._validate_requested_port_ids')
@mock.patch('nova.network.neutron.API._get_available_networks')
@mock.patch('nova.network.neutron.get_client')
def test_allocate_port_for_instance_no_networks(self,
mock_getclient,
mock_avail_nets,
mock_validate_port_ids):
"""Tests that if no networks are requested and no networks are
available, we fail with InterfaceAttachFailedNoNetwork.
"""
instance = fake_instance.fake_instance_obj(self.context,
project_id=uuids.my_tenant)
mock_validate_port_ids.return_value = ({}, [])
mock_avail_nets.return_value = []
api = neutronapi.API()
ex = self.assertRaises(exception.InterfaceAttachFailedNoNetwork,
api.allocate_port_for_instance,
self.context, instance, port_id=None)
self.assertEqual(
"No specific network was requested and none are available for "
"project '%s'." % uuids.my_tenant, six.text_type(ex))

@mock.patch.object(neutronapi.API, 'allocate_for_instance')
def test_allocate_port_for_instance_with_tag(self, mock_allocate):
instance = fake_instance.fake_instance_obj(self.context)
api = neutronapi.API()
api.allocate_port_for_instance(self.context, instance, None,
network_id=None, requested_ip=None,
bind_host_id=None, tag='foo')
req_nets_in_call = mock_allocate.call_args[1]['requested_networks']
self.assertEqual('foo', req_nets_in_call.objects[0].tag)

@mock.patch('nova.network.neutron.LOG')
@mock.patch('nova.network.neutron.API._delete_ports')
@mock.patch('nova.network.neutron.API._unbind_ports')
@@ -6877,7 +6845,7 @@ class TestAllocateForInstance(test.NoDBTestCase):
self.assertEqual(result[1], {"id": uuids.preexist})

mock_validate_ports.assert_called_once_with(
self.context, self.instance, "admin", None, attach=False)
self.context, self.instance, "admin", None)

def test_ensure_no_port_binding_failure_raises(self):
port = {
@@ -6926,8 +6894,7 @@ class TestAllocateForInstance(test.NoDBTestCase):
self.assertEqual(requested_networks[0], ordered_networks[0])
self.assertEqual('net-2', ordered_networks[1].network_id)

def _assert_validate_requested_port_ids_raises(self, exception, extras,
attach=False):
def _assert_validate_requested_port_ids_raises(self, exception, extras):
api = neutronapi.API()
mock_client = mock.Mock()
requested_networks = objects.NetworkRequestList(objects=[
@@ -6941,8 +6908,7 @@ class TestAllocateForInstance(test.NoDBTestCase):
mock_client.show_port.return_value = {"port": port}

self.assertRaises(exception, api._validate_requested_port_ids,
self.context, self.instance, mock_client, requested_networks,
attach=attach)
self.context, self.instance, mock_client, requested_networks)

def test_validate_requested_port_ids_raise_not_usable(self):
self._assert_validate_requested_port_ids_raises(


Loading…
Cancel
Save