Merge "Remove "dhcp_options_for_instance""

This commit is contained in:
Jenkins 2017-08-29 05:39:56 +00:00 committed by Gerrit Code Review
commit 0e52b3fe68
10 changed files with 21 additions and 122 deletions

View File

@ -1359,7 +1359,7 @@ class ComputeManager(manager.Manager):
raise exception.InstanceExists(name=instance.name)
def _allocate_network_async(self, context, instance, requested_networks,
macs, security_groups, is_vpn, dhcp_options):
macs, security_groups, is_vpn):
"""Method used to allocate networks in the background.
Broken out for testing.
@ -1384,7 +1384,6 @@ class ComputeManager(manager.Manager):
requested_networks=requested_networks,
macs=macs,
security_groups=security_groups,
dhcp_options=dhcp_options,
bind_host_id=bind_host_id)
LOG.debug('Instance network_info: |%s|', nwinfo,
instance=instance)
@ -1430,14 +1429,13 @@ class ComputeManager(manager.Manager):
security_groups = []
macs = self.driver.macs_for_instance(instance)
dhcp_options = self.driver.dhcp_options_for_instance(instance)
network_info = self._allocate_network(context, instance,
requested_networks, macs, security_groups, dhcp_options)
requested_networks, macs, security_groups)
return network_info
def _allocate_network(self, context, instance, requested_networks, macs,
security_groups, dhcp_options):
security_groups):
"""Start network allocation asynchronously. Return an instance
of NetworkInfoAsyncWrapper that can be used to retrieve the
allocated networks when the operation has finished.
@ -1453,8 +1451,7 @@ class ComputeManager(manager.Manager):
is_vpn = False
return network_model.NetworkInfoAsyncWrapper(
self._allocate_network_async, context, instance,
requested_networks, macs, security_groups, is_vpn,
dhcp_options)
requested_networks, macs, security_groups, is_vpn)
def _default_root_device_name(self, instance, image_meta, root_bdm):
try:

View File

@ -215,7 +215,6 @@ class API(base_api.NetworkAPI):
def allocate_for_instance(self, context, instance, vpn,
requested_networks, macs=None,
security_groups=None,
dhcp_options=None,
bind_host_id=None):
"""Allocates all network structures for an instance.
@ -229,11 +228,6 @@ class API(base_api.NetworkAPI):
with requested_networks which is user supplied).
:param security_groups: None or security groups to allocate for
instance.
:param dhcp_options: None or a set of key/value pairs that should
determine the DHCP BOOTP response, eg. for PXE booting an instance
configured with the baremetal hypervisor. It is expected that these
are already formatted for the neutron v2 api.
See nova/virt/driver.py:dhcp_options_for_instance for an example.
:param bind_host_id: ignored by this driver.
:returns: network info as from get_instance_nw_info() below
"""
@ -250,7 +244,6 @@ class API(base_api.NetworkAPI):
args['host'] = instance.host
args['rxtx_factor'] = flavor['rxtx_factor']
args['macs'] = macs
args['dhcp_options'] = dhcp_options
# Check to see if we're asked to 'auto' allocate networks because if
# so we need to just null out the requested_networks value so the

View File

@ -185,8 +185,7 @@ class NetworkAPI(base.Base):
def allocate_for_instance(self, context, instance, vpn,
requested_networks, macs=None,
security_groups=None,
dhcp_options=None, bind_host_id=None):
security_groups=None, bind_host_id=None):
"""Allocates all network structures for an instance.
:param context: The request context.
@ -199,11 +198,6 @@ class NetworkAPI(base.Base):
with requested_networks which is user supplied).
:param security_groups: None or security groups to allocate for
instance.
:param dhcp_options: None or a set of key/value pairs that should
determine the DHCP BOOTP response, eg. for PXE booting an instance
configured with the baremetal hypervisor. It is expected that these
are already formatted for the neutron v2 api.
See nova/virt/driver.py:dhcp_options_for_instance for an example.
:param bind_host_id: the host ID to attach to the ports being created.
:returns: network info as from get_instance_nw_info() below
"""

View File

@ -794,8 +794,7 @@ class API(base_api.NetworkAPI):
def allocate_for_instance(self, context, instance, vpn,
requested_networks, macs=None,
security_groups=None,
dhcp_options=None, bind_host_id=None):
security_groups=None, bind_host_id=None):
"""Allocate network resources for the instance.
:param context: The request context.
@ -812,11 +811,6 @@ class API(base_api.NetworkAPI):
MAC addresses).
:param security_groups: None or security groups to allocate for
instance.
:param dhcp_options: None or a set of key/value pairs that should
determine the DHCP BOOTP response, eg. for PXE booting an instance
configured with the baremetal hypervisor. It is expected that these
are already formatted for the neutron v2 api.
See nova/virt/driver.py:dhcp_options_for_instance for an example.
:param bind_host_id: the host ID to attach to the ports being created.
:returns: network info as from get_instance_nw_info()
"""
@ -866,7 +860,7 @@ class API(base_api.NetworkAPI):
created_port_ids = self._update_ports_for_instance(
context, instance,
neutron, admin_client, requests_and_created_ports, nets,
bind_host_id, dhcp_options, available_macs)
bind_host_id, available_macs)
#
# Perform a full update of the network_info_cache,
@ -891,12 +885,12 @@ class API(base_api.NetworkAPI):
def _update_ports_for_instance(self, context, instance, neutron,
admin_client, requests_and_created_ports, nets,
bind_host_id, dhcp_opts, available_macs):
bind_host_id, available_macs):
"""Update ports from network_requests.
Updates the pre-existing ports and the ones created in
``_create_ports_for_instance`` with ``device_id``, ``device_owner``,
optionally ``mac_address`` and ``dhcp_opts``, and, depending on the
optionally ``mac_address`` and, depending on the
loaded extensions, ``rxtx_factor``, ``binding:host_id``, ``dns_name``.
:param context: The request context.
@ -906,8 +900,6 @@ class API(base_api.NetworkAPI):
:param requests_and_created_ports: [(NetworkRequest, created_port_id)]
:param nets: a dict of network_id to networks returned from neutron
:param bind_host_id: a string for port['binding:host_id']
:param dhcp_opts: a list dicts that contain dhcp option name and value
e.g. [{'opt_name': 'tftp-server', 'opt_value': '1.2.3.4'}]
:param available_macs: a list of available mac addresses
"""
@ -944,8 +936,6 @@ class API(base_api.NetworkAPI):
request.pci_request_id, port_req_body)
self._populate_mac_address(
instance, port_req_body, available_macs)
if dhcp_opts is not None:
port_req_body['port']['extra_dhcp_opts'] = dhcp_opts
if created_port_id:
port_id = created_port_id

View File

@ -149,6 +149,7 @@ class NetworkAPI(object):
def allocate_for_instance(self, ctxt, instance_id, project_id, host,
rxtx_factor, vpn, requested_networks, macs=None,
dhcp_options=None):
# NOTE(mriedem): dhcp_options should be removed in version 2.0
version = '1.13'
if not self.client.can_send_version(version):
version = '1.9'

View File

@ -4285,7 +4285,7 @@ class ComputeTestCase(BaseTestCase,
security_groups = None if CONF.use_neutron else []
mock_allocate.assert_called_once_with(self.context, instance,
vpn=False, requested_networks=None, macs=macs,
security_groups=security_groups, dhcp_options=None,
security_groups=security_groups,
bind_host_id=self.compute.host)
mock_mac.assert_called_once_with(test.MatchType(instance_obj.Instance))

View File

@ -421,7 +421,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
macs = 'fake-macs'
sec_groups = 'fake-sec-groups'
final_result = 'meow'
dhcp_options = None
expected_sleep_times = [1, 2, 4, 8, 16, 30, 30, 30]
@ -432,8 +431,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
req_networks,
macs,
sec_groups,
is_vpn,
dhcp_options)
is_vpn)
mock_sleep.has_calls(expected_sleep_times)
self.assertEqual(final_result, res)
@ -451,7 +449,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
objects=[objects.NetworkRequest(network_id='fake')])
macs = 'fake-macs'
sec_groups = 'fake-sec-groups'
dhcp_options = None
with mock.patch.object(
self.compute.network_api, 'allocate_for_instance',
@ -459,13 +456,12 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
self.assertRaises(test.TestingException,
self.compute._allocate_network_async,
self.context, instance, req_networks, macs,
sec_groups, is_vpn, dhcp_options)
sec_groups, is_vpn)
mock_allocate.assert_called_once_with(
self.context, instance, vpn=is_vpn,
requested_networks=req_networks, macs=macs,
security_groups=sec_groups,
dhcp_options=dhcp_options,
bind_host_id=instance.get('host'))
@mock.patch.object(manager.ComputeManager, '_instance_update')
@ -481,7 +477,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
objects=[objects.NetworkRequest(network_id='fake')])
macs = 'fake-macs'
sec_groups = 'fake-sec-groups'
dhcp_options = None
final_result = 'zhangtralon'
with mock.patch.object(self.compute.network_api,
@ -492,8 +487,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
req_networks,
macs,
sec_groups,
is_vpn,
dhcp_options)
is_vpn)
self.assertEqual(final_result, res)
self.assertEqual(1, sleep.call_count)
@ -504,7 +498,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
objects=[objects.NetworkRequest(network_id='none')])
nwinfo = self.compute._allocate_network_async(
self.context, mock.sentinel.instance, req_networks, macs=None,
security_groups=['default'], is_vpn=False, dhcp_options=None)
security_groups=['default'], is_vpn=False)
self.assertEqual(0, len(nwinfo))
@mock.patch('nova.compute.manager.ComputeManager.'
@ -5202,7 +5196,7 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
instance, self.requested_networks, self.security_groups)
mock_allocate.assert_called_once_with(self.context, instance,
self.requested_networks, None, self.security_groups, None)
self.requested_networks, None, self.security_groups)
self.assertTrue(hasattr(nw_info_obj, 'wait'), "wait must be there")
@mock.patch.object(manager.ComputeManager, '_allocate_network')
@ -5216,7 +5210,7 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
instance, self.requested_networks, self.security_groups)
mock_allocate.assert_called_once_with(self.context, instance,
self.requested_networks, None, self.security_groups, None)
self.requested_networks, None, self.security_groups)
self.assertTrue(hasattr(nw_info_obj, 'wait'), "wait must be there")
@mock.patch.object(manager.ComputeManager, '_allocate_network')

View File

@ -136,7 +136,7 @@ class ApiTestCase(test.TestCase):
"allocate_for_instance") as mock_alloc:
kwargs = dict(zip(['host', 'instance_id', 'project_id',
'requested_networks', 'rxtx_factor', 'vpn',
'macs', 'dhcp_options'],
'macs'],
itertools.repeat(mock.ANY)))
mock_alloc.return_value = []
flavor = flavors.get_default_flavor()

View File

@ -458,11 +458,6 @@ class TestNeutronv2Base(test.TestCase):
bind_host_id = kwargs.get('bind_host_id') or None
has_extra_dhcp_opts = False
dhcp_options = kwargs.get('dhcp_options')
if dhcp_options is not None:
has_extra_dhcp_opts = True
has_dns_extension = False
if kwargs.get('dns_extension'):
has_dns_extension = True
@ -543,8 +538,6 @@ class TestNeutronv2Base(test.TestCase):
if macs:
port_req_body['port']['mac_address'] = macs.pop()
if has_extra_dhcp_opts:
port_req_body['port']['extra_dhcp_opts'] = dhcp_options
if not request.port_id:
port_id = uuids.fake
@ -775,8 +768,7 @@ class TestNeutronv2Base(test.TestCase):
mock_vif.side_effect = _new_vif
requested_networks = kwargs.get("requested_networks", None)
allowed_keys = ["macs", "security_groups",
"dhcp_options", "bind_host_id"]
allowed_keys = ["macs", "security_groups", "bind_host_id"]
afi_kwargs = {}
for key in kwargs.keys():
if key in allowed_keys:
@ -4707,7 +4699,7 @@ class TestNeutronv2WithMock(test.TestCase):
self.api._update_ports_for_instance,
self.context, instance, ntrn, ntrn,
requests_and_created_ports, nets, bind_host_id=None,
dhcp_opts=None, available_macs=None)
available_macs=None)
# assert the calls
mock_update_port.assert_has_calls([
mock.call(ntrn, instance, uuids.preexisting_port_id, mock.ANY),
@ -5113,40 +5105,6 @@ class TestNeutronv2Portbinding(TestNeutronv2Base):
self.context, 'id')
class TestNeutronv2ExtraDhcpOpts(TestNeutronv2Base):
def setUp(self):
super(TestNeutronv2ExtraDhcpOpts, self).setUp()
neutronapi.get_client(mox.IgnoreArg()).MultipleTimes().AndReturn(
self.moxed_client)
def test_allocate_for_instance_1_with_extra_dhcp_opts_turned_off(self):
self._allocate_for_instance(1, extra_dhcp_opts=False)
def test_allocate_for_instance_extradhcpopts(self):
dhcp_opts = [{'opt_name': 'bootfile-name',
'opt_value': 'pxelinux.0'},
{'opt_name': 'tftp-server',
'opt_value': '123.123.123.123'},
{'opt_name': 'server-ip-address',
'opt_value': '123.123.123.456'}]
self._allocate_for_instance(1, dhcp_options=dhcp_opts)
def test_allocate_for_instance_extradhcpopts_update(self):
dhcp_opts = [{'opt_name': 'bootfile-name',
'opt_value': 'pxelinux.0'},
{'opt_name': 'tftp-server',
'opt_value': '123.123.123.123'},
{'opt_name': 'server-ip-address',
'opt_value': '123.123.123.456'}]
requested_networks = objects.NetworkRequestList(
objects=[objects.NetworkRequest(port_id=uuids.portid_1)])
self._allocate_for_instance(net_idx=1,
requested_networks=requested_networks,
dhcp_options=dhcp_opts)
class TestAllocateForInstance(test.NoDBTestCase):
def setUp(self):
super(TestAllocateForInstance, self).setUp()
@ -5535,7 +5493,6 @@ class TestAllocateForInstance(test.NoDBTestCase):
net2 = {"id": uuids.net2}
nets = {uuids.net1: net1, uuids.net2: net2}
bind_host_id = "bind_host_id"
dhcp_opts = [{'opt_name': 'tftp-server', 'opt_value': '1.2.3.4'}]
available_macs = ["mac1", "mac2"]
mock_neutron.list_extensions.return_value = {"extensions": [
@ -5548,7 +5505,7 @@ class TestAllocateForInstance(test.NoDBTestCase):
created_port_ids = api._update_ports_for_instance(
self.context, self.instance,
mock_neutron, mock_admin, requests_and_created_ports, nets,
bind_host_id, dhcp_opts, available_macs)
bind_host_id, available_macs)
# TODO(johngarbutt) need to build on this test so we can replace
# all the mox based tests
@ -5562,7 +5519,6 @@ class TestAllocateForInstance(test.NoDBTestCase):
'device_owner': 'compute:test_az',
'mac_address': 'mac1',
neutronapi.BINDING_HOST_ID: bind_host_id,
'extra_dhcp_opts': dhcp_opts,
'device_id': self.instance.uuid}})

View File

@ -1291,32 +1291,6 @@ class ComputeDriver(object):
"""
return None
def dhcp_options_for_instance(self, instance):
"""Get DHCP options for this instance.
Some hypervisors (such as bare metal) require that instances boot from
the network, and manage their own TFTP service. This requires passing
the appropriate options out to the DHCP service. Most hypervisors can
use the default implementation which returns None.
This is called during spawn_instance by the compute manager.
Note that the format of the return value is specific to the Neutron
client API.
:return: None, or a set of DHCP options, eg:
| [{'opt_name': 'bootfile-name',
| 'opt_value': '/tftpboot/path/to/config'},
| {'opt_name': 'server-ip-address',
| 'opt_value': '1.2.3.4'},
| {'opt_name': 'tftp-server',
| 'opt_value': '1.2.3.4'}
| ]
"""
return None
def manage_image_cache(self, context, all_instances):
"""Manage the driver's local image cache.