Merge "Implement `get_port_type_virtual_and_parents
` method"
This commit is contained in:
commit
8828ec8dc9
@ -970,3 +970,39 @@ def sync_ha_chassis_group(context, network_id, nb_idl, sb_idl, txn):
|
|||||||
# Return the existing register UUID or the HA chassis group creation
|
# Return the existing register UUID or the HA chassis group creation
|
||||||
# command (see ovsdbapp ``HAChassisGroupAddChassisCommand`` class).
|
# command (see ovsdbapp ``HAChassisGroupAddChassisCommand`` class).
|
||||||
return ha_ch_grp.uuid if ha_ch_grp else hcg_cmd
|
return ha_ch_grp.uuid if ha_ch_grp else hcg_cmd
|
||||||
|
|
||||||
|
|
||||||
|
def get_port_type_virtual_and_parents(subnets, fixed_ips, network_id, port_id,
|
||||||
|
nb_idl):
|
||||||
|
"""Returns if a port is type virtual and its corresponding parents.
|
||||||
|
|
||||||
|
:param subnets: (list of dict) subnet dictionaries
|
||||||
|
:param fixed_ips: (list of dict) fixed IPs of several subnets (usually
|
||||||
|
belonging to a network but not mandatory)
|
||||||
|
:param network_id: (string) network ID
|
||||||
|
:param port_id: (string) port ID
|
||||||
|
:param nb_idl: (``OvsdbNbOvnIdl``) OVN Northbound IDL
|
||||||
|
:return: (tuple, three strings) (1) the virtual type ('' if not virtual),
|
||||||
|
(2) the virtual IP address and (3) the virtual parents
|
||||||
|
"""
|
||||||
|
port_type, virtual_ip, virtual_parents = '', None, None
|
||||||
|
if not subnets:
|
||||||
|
return port_type, virtual_ip, virtual_parents
|
||||||
|
|
||||||
|
subnets_by_id = {subnet['id'] for subnet in subnets}
|
||||||
|
for fixed_ip in fixed_ips:
|
||||||
|
if fixed_ip.get('subnet_id') not in subnets_by_id:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Check if the port being created is a virtual port
|
||||||
|
parents = get_virtual_port_parents(
|
||||||
|
nb_idl, fixed_ip['ip_address'], network_id, port_id)
|
||||||
|
if not parents:
|
||||||
|
continue
|
||||||
|
|
||||||
|
port_type = constants.LSP_TYPE_VIRTUAL
|
||||||
|
virtual_ip = fixed_ip['ip_address']
|
||||||
|
virtual_parents = ','.join(parents)
|
||||||
|
break
|
||||||
|
|
||||||
|
return port_type, virtual_ip, virtual_parents
|
||||||
|
@ -310,11 +310,20 @@ class OVNClient(object):
|
|||||||
address4_scope_id, address6_scope_id = (
|
address4_scope_id, address6_scope_id = (
|
||||||
utils.get_subnets_address_scopes(context, subnets, ip_subnets,
|
utils.get_subnets_address_scopes(context, subnets, ip_subnets,
|
||||||
self._plugin))
|
self._plugin))
|
||||||
|
p_type, virtual_ip, virtual_parents = (
|
||||||
|
utils.get_port_type_virtual_and_parents(
|
||||||
|
subnets, ip_subnets, port['network_id'], port['id'],
|
||||||
|
self._nb_idl))
|
||||||
|
if p_type:
|
||||||
|
port_type = ovn_const.LSP_TYPE_VIRTUAL
|
||||||
|
options[ovn_const.LSP_OPTIONS_VIRTUAL_IP_KEY] = virtual_ip
|
||||||
|
options[ovn_const.LSP_OPTIONS_VIRTUAL_PARENTS_KEY] = (
|
||||||
|
virtual_parents)
|
||||||
|
|
||||||
if subnets:
|
if subnets:
|
||||||
for ip in ip_subnets:
|
for ip in ip_subnets:
|
||||||
ip_addr = ip['ip_address']
|
ip_addr = ip['ip_address']
|
||||||
address += ' ' + ip_addr
|
address += ' ' + ip_addr
|
||||||
subnet = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subnet = [
|
subnet = [
|
||||||
@ -330,18 +339,6 @@ class OVNClient(object):
|
|||||||
cidrs += ' {}/{}'.format(ip['ip_address'],
|
cidrs += ' {}/{}'.format(ip['ip_address'],
|
||||||
subnet['cidr'].split('/')[1])
|
subnet['cidr'].split('/')[1])
|
||||||
|
|
||||||
# Check if the port being created is a virtual port
|
|
||||||
parents = utils.get_virtual_port_parents(
|
|
||||||
self._nb_idl, ip_addr, port['network_id'], port['id'])
|
|
||||||
if not parents:
|
|
||||||
continue
|
|
||||||
|
|
||||||
port_type = ovn_const.LSP_TYPE_VIRTUAL
|
|
||||||
options[ovn_const.LSP_OPTIONS_VIRTUAL_IP_KEY] = ip_addr
|
|
||||||
options[ovn_const.LSP_OPTIONS_VIRTUAL_PARENTS_KEY] = (
|
|
||||||
','.join(parents))
|
|
||||||
break
|
|
||||||
|
|
||||||
# Metadata port.
|
# Metadata port.
|
||||||
if port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED:
|
if port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED:
|
||||||
port_type = ovn_const.LSP_TYPE_LOCALPORT
|
port_type = ovn_const.LSP_TYPE_LOCALPORT
|
||||||
|
@ -1003,3 +1003,49 @@ class GetSubnetsAddressScopeTestCase(base.BaseTestCase):
|
|||||||
address4, address6 = utils.get_subnets_address_scopes(
|
address4, address6 = utils.get_subnets_address_scopes(
|
||||||
mock.ANY, subnets, fixed_ips, self.ml2_plugin)
|
mock.ANY, subnets, fixed_ips, self.ml2_plugin)
|
||||||
self.assertEqual(('scope4', 'scope6'), (address4, address6))
|
self.assertEqual(('scope4', 'scope6'), (address4, address6))
|
||||||
|
|
||||||
|
|
||||||
|
class GetPortTypeVirtualAndParentsTestCase(base.BaseTestCase):
|
||||||
|
|
||||||
|
def test_no_subnets(self):
|
||||||
|
subnets = []
|
||||||
|
fixed_ips = []
|
||||||
|
port_type, virtual_ip, virtual_parents = (
|
||||||
|
utils.get_port_type_virtual_and_parents(subnets, fixed_ips, 'net1',
|
||||||
|
'port1', mock.ANY))
|
||||||
|
self.assertEqual(('', None, None),
|
||||||
|
(port_type, virtual_ip, virtual_parents))
|
||||||
|
|
||||||
|
@mock.patch.object(utils, 'get_virtual_port_parents', return_value=[])
|
||||||
|
def test_no_parents(self, *args):
|
||||||
|
subnets = [
|
||||||
|
{'id': 'subnet1'},
|
||||||
|
{'id': 'subnet2'},
|
||||||
|
]
|
||||||
|
fixed_ips = [
|
||||||
|
{'subnet_id': 'subnet1', 'ip_address': '1.2.3.4'},
|
||||||
|
{'subnet_id': 'subnet2', 'ip_address': '1.2.3.5'},
|
||||||
|
]
|
||||||
|
port_type, virtual_ip, virtual_parents = (
|
||||||
|
utils.get_port_type_virtual_and_parents(subnets, fixed_ips, 'net1',
|
||||||
|
'port1', mock.ANY))
|
||||||
|
self.assertEqual(('', None, None),
|
||||||
|
(port_type, virtual_ip, virtual_parents))
|
||||||
|
|
||||||
|
@mock.patch.object(utils, 'get_virtual_port_parents',
|
||||||
|
return_value=['parent1', 'parent2'])
|
||||||
|
def test_with_parents(self, *args):
|
||||||
|
subnets = [
|
||||||
|
{'id': 'subnet1'},
|
||||||
|
{'id': 'subnet2'},
|
||||||
|
]
|
||||||
|
fixed_ips = [
|
||||||
|
{'subnet_id': 'subnet1', 'ip_address': '1.2.3.4'},
|
||||||
|
{'subnet_id': 'subnet2', 'ip_address': '1.2.3.5'},
|
||||||
|
]
|
||||||
|
port_type, virtual_ip, virtual_parents = (
|
||||||
|
utils.get_port_type_virtual_and_parents(subnets, fixed_ips, 'net1',
|
||||||
|
'port1', mock.ANY))
|
||||||
|
self.assertEqual((constants.LSP_TYPE_VIRTUAL, '1.2.3.4',
|
||||||
|
'parent1,parent2'),
|
||||||
|
(port_type, virtual_ip, virtual_parents))
|
||||||
|
Loading…
Reference in New Issue
Block a user