Merge "Update dhcp_opts on both create and update"
This commit is contained in:
@@ -166,7 +166,7 @@ class API(base_api.NetworkAPI):
|
||||
return nets
|
||||
|
||||
def _create_port(self, port_client, instance, network_id, port_req_body,
|
||||
fixed_ip=None, security_group_ids=None, dhcp_opts=None):
|
||||
fixed_ip=None, security_group_ids=None):
|
||||
"""Attempts to create a port for the instance on the given network.
|
||||
|
||||
:param port_client: The client to use to create the port.
|
||||
@@ -177,7 +177,6 @@ class API(base_api.NetworkAPI):
|
||||
:param fixed_ip: Optional fixed IP to use from the given network.
|
||||
:param security_group_ids: Optional list of security group IDs to
|
||||
apply to the port.
|
||||
:param dhcp_opts: Optional DHCP options.
|
||||
:returns: ID of the created port.
|
||||
:raises PortLimitExceeded: If neutron fails with an OverQuota error.
|
||||
:raises NoMoreFixedIps: If neutron fails with
|
||||
@@ -193,8 +192,6 @@ class API(base_api.NetworkAPI):
|
||||
port_req_body['port']['tenant_id'] = instance.project_id
|
||||
if security_group_ids:
|
||||
port_req_body['port']['security_groups'] = security_group_ids
|
||||
if dhcp_opts is not None:
|
||||
port_req_body['port']['extra_dhcp_opts'] = dhcp_opts
|
||||
port = port_client.create_port(port_req_body)
|
||||
port_id = port['port']['id']
|
||||
if (port['port'].get('binding:vif_type') ==
|
||||
@@ -635,12 +632,14 @@ 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 not request.port_id:
|
||||
created_port_id = self._create_port(
|
||||
port_client, instance, request.network_id,
|
||||
port_req_body, request.address,
|
||||
security_group_ids, dhcp_opts)
|
||||
security_group_ids)
|
||||
created_port_ids.append(created_port_id)
|
||||
ports_in_requested_order.append(created_port_id)
|
||||
else:
|
||||
|
||||
@@ -559,6 +559,8 @@ class TestNeutronv2Base(test.TestCase):
|
||||
neutron=self.moxed_client)
|
||||
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 request.port_id:
|
||||
port = ports[request.port_id]
|
||||
self.moxed_client.update_port(request.port_id,
|
||||
@@ -580,8 +582,6 @@ class TestNeutronv2Base(test.TestCase):
|
||||
port_req_body['port']['binding:host_id'] = (
|
||||
self.instance.get('host'))
|
||||
res_port = {'port': {'id': 'fake'}}
|
||||
if has_extra_dhcp_opts:
|
||||
port_req_body['port']['extra_dhcp_opts'] = dhcp_options
|
||||
if kwargs.get('_break') == 'mac' + request.network_id:
|
||||
self.mox.ReplayAll()
|
||||
return api
|
||||
@@ -4226,6 +4226,20 @@ class TestNeutronv2ExtraDhcpOpts(TestNeutronv2Base):
|
||||
|
||||
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 TestAllocateForInstanceHelpers(test.NoDBTestCase):
|
||||
def test_populate_mac_address_skip_if_none(self):
|
||||
@@ -4483,13 +4497,13 @@ class TestNeutronPortSecurity(test.NoDBTestCase):
|
||||
u'net1', {'port':
|
||||
{'device_owner': u'compute:nova',
|
||||
'device_id': uuids.instance}},
|
||||
None, [], None),
|
||||
None, []),
|
||||
mock.call(
|
||||
mock.ANY, instance,
|
||||
u'net2', {'port':
|
||||
{'device_owner': u'compute:nova',
|
||||
'device_id': uuids.instance}},
|
||||
None, [], None)])
|
||||
None, [])])
|
||||
|
||||
@mock.patch.object(neutronapi.API, 'get_instance_nw_info')
|
||||
@mock.patch.object(neutronapi.API, '_update_port_dns_name')
|
||||
@@ -4544,15 +4558,13 @@ class TestNeutronPortSecurity(test.NoDBTestCase):
|
||||
u'net1', {'port':
|
||||
{'device_owner': u'compute:nova',
|
||||
'device_id': uuids.instance}},
|
||||
None, ['default-uuid', 'secgrp-uuid1', 'secgrp-uuid2'],
|
||||
None),
|
||||
None, ['default-uuid', 'secgrp-uuid1', 'secgrp-uuid2']),
|
||||
mock.call(
|
||||
mock.ANY, instance,
|
||||
u'net2', {'port':
|
||||
{'device_owner': u'compute:nova',
|
||||
'device_id': uuids.instance}},
|
||||
None, ['default-uuid', 'secgrp-uuid1', 'secgrp-uuid2'],
|
||||
None)])
|
||||
None, ['default-uuid', 'secgrp-uuid1', 'secgrp-uuid2'])])
|
||||
|
||||
@mock.patch.object(neutronapi.API, 'get_instance_nw_info')
|
||||
@mock.patch.object(neutronapi.API, '_update_port_dns_name')
|
||||
@@ -4605,13 +4617,13 @@ class TestNeutronPortSecurity(test.NoDBTestCase):
|
||||
u'net1', {'port':
|
||||
{'device_owner': u'compute:nova',
|
||||
'device_id': uuids.instance}},
|
||||
None, [], None),
|
||||
None, []),
|
||||
mock.call(
|
||||
mock.ANY, instance,
|
||||
u'net2', {'port':
|
||||
{'device_owner': u'compute:nova',
|
||||
'device_id': uuids.instance}},
|
||||
None, [], None)])
|
||||
None, [])])
|
||||
|
||||
@mock.patch.object(neutronapi.API, 'get_instance_nw_info')
|
||||
@mock.patch.object(neutronapi.API, '_update_port_dns_name')
|
||||
|
||||
Reference in New Issue
Block a user