Add network id to pools keys
This is one of the first steps needed to have pools support when
pods can be allocated on different networks. Otherwise, a common
pool could serve pods on different networks if they share
hostIP/hostname, project_id and security groups.
Closes-Bug: 1752600
Change-Id: If9c8e898ec711576afc125f0d3af50d1bd2f3eff
(cherry picked from commit bc7e900082
)
This commit is contained in:
parent
fdeaff69b4
commit
acb62b0205
|
@ -126,13 +126,23 @@ class BaseVIFPool(base.VIFPoolDriver):
|
|||
def _get_host_addr(self, pod):
|
||||
return pod['status']['hostIP']
|
||||
|
||||
def _get_pool_key(self, host, project_id, security_groups, net_id=None,
|
||||
subnets=None):
|
||||
if not net_id and subnets:
|
||||
net_obj = list(subnets.values())[0]
|
||||
net_id = net_obj.id
|
||||
pool_key = (host, project_id, tuple(sorted(security_groups)),
|
||||
net_id)
|
||||
return pool_key
|
||||
|
||||
def request_vif(self, pod, project_id, subnets, security_groups):
|
||||
try:
|
||||
host_addr = self._get_host_addr(pod)
|
||||
except KeyError:
|
||||
LOG.warning("Pod has not been scheduled yet.")
|
||||
raise
|
||||
pool_key = (host_addr, project_id, tuple(sorted(security_groups)))
|
||||
pool_key = self._get_pool_key(host_addr, project_id, security_groups,
|
||||
None, subnets)
|
||||
|
||||
try:
|
||||
return self._get_port_from_pool(pool_key, pod, subnets)
|
||||
|
@ -172,7 +182,9 @@ class BaseVIFPool(base.VIFPoolDriver):
|
|||
|
||||
def release_vif(self, pod, vif, project_id, security_groups):
|
||||
host_addr = self._get_host_addr(pod)
|
||||
pool_key = (host_addr, project_id, tuple(sorted(security_groups)))
|
||||
|
||||
pool_key = self._get_pool_key(host_addr, project_id, security_groups,
|
||||
vif.network.id, None)
|
||||
|
||||
if not self._existing_vifs.get(vif.id):
|
||||
self._existing_vifs[vif.id] = vif
|
||||
|
@ -323,13 +335,16 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
if port['id'] not in in_use_ports]
|
||||
|
||||
for port in available_ports:
|
||||
pool_key = (port['binding:host_id'], port['project_id'],
|
||||
tuple(port['security_groups']))
|
||||
subnet_id = port['fixed_ips'][0]['subnet_id']
|
||||
subnet = {
|
||||
subnet_id: default_subnet._get_subnet(subnet_id)}
|
||||
vif_plugin = self._drv_vif._get_vif_plugin(port)
|
||||
vif = ovu.neutron_to_osvif_vif(vif_plugin, port, subnet)
|
||||
net_obj = subnet[subnet_id]
|
||||
pool_key = self._get_pool_key(port['binding:host_id'],
|
||||
port['project_id'],
|
||||
port['security_groups'],
|
||||
net_obj.id, None)
|
||||
|
||||
self._existing_vifs[port['id']] = vif
|
||||
self._available_ports_pools.setdefault(
|
||||
|
@ -552,13 +567,16 @@ class NestedVIFPool(BaseVIFPool):
|
|||
for subport in parent_port.get('subports'):
|
||||
kuryr_subport = available_subports.get(subport['port_id'])
|
||||
if kuryr_subport:
|
||||
pool_key = (host_addr, kuryr_subport['project_id'],
|
||||
tuple(sorted(kuryr_subport['security_groups']))
|
||||
)
|
||||
subnet_id = kuryr_subport['fixed_ips'][0]['subnet_id']
|
||||
subnet = subnets[subnet_id]
|
||||
net_obj = subnet[subnet_id]
|
||||
pool_key = self._get_pool_key(host_addr,
|
||||
kuryr_subport['project_id'],
|
||||
kuryr_subport[
|
||||
'security_groups'],
|
||||
net_obj.id, None)
|
||||
|
||||
if action == 'recover':
|
||||
subnet_id = kuryr_subport['fixed_ips'][0]['subnet_id']
|
||||
subnet = subnets[subnet_id]
|
||||
vif = ovu.neutron_to_osvif_vif_nested_vlan(
|
||||
kuryr_subport, subnet, subport['segmentation_id'])
|
||||
|
||||
|
@ -605,7 +623,8 @@ class NestedVIFPool(BaseVIFPool):
|
|||
num_ports=num_ports,
|
||||
trunk_ip=trunk_ip)
|
||||
|
||||
pool_key = (trunk_ip, project_id, tuple(sorted(security_groups)))
|
||||
pool_key = self._get_pool_key(trunk_ip, project_id, security_groups,
|
||||
None, subnets)
|
||||
for vif in vifs:
|
||||
self._existing_vifs[vif.id] = vif
|
||||
self._available_ports_pools.setdefault(pool_key,
|
||||
|
|
|
@ -19,6 +19,7 @@ import mock
|
|||
from neutronclient.common import exceptions as n_exc
|
||||
from oslo_config import cfg as oslo_cfg
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from os_vif.objects import vif as osv_vif
|
||||
|
||||
|
@ -27,6 +28,7 @@ from kuryr_kubernetes.controller.drivers import nested_vlan_vif
|
|||
from kuryr_kubernetes.controller.drivers import neutron_vif
|
||||
from kuryr_kubernetes.controller.drivers import vif_pool
|
||||
from kuryr_kubernetes import exceptions
|
||||
from kuryr_kubernetes import os_vif_util as ovu
|
||||
from kuryr_kubernetes.tests import base as test_base
|
||||
from kuryr_kubernetes.tests.unit import kuryr_fixtures as k_fix
|
||||
|
||||
|
@ -112,8 +114,11 @@ class BaseVIFPool(test_base.TestCase):
|
|||
m_driver = mock.MagicMock(spec=cls)
|
||||
|
||||
pod = get_pod_obj()
|
||||
project_id = mock.sentinel.project_id
|
||||
subnets = mock.sentinel.subnets
|
||||
project_id = uuidutils.generate_uuid()
|
||||
subnet_id = uuidutils.generate_uuid()
|
||||
net_id = uuidutils.generate_uuid()
|
||||
network = ovu.neutron_to_osvif_network({'id': net_id})
|
||||
subnets = {subnet_id: network}
|
||||
security_groups = [mock.sentinel.security_groups]
|
||||
vif = mock.sentinel.vif
|
||||
|
||||
|
@ -137,8 +142,11 @@ class BaseVIFPool(test_base.TestCase):
|
|||
pod_status.__getitem__.return_value = host_addr
|
||||
pod = mock.MagicMock()
|
||||
pod.__getitem__.return_value = pod_status
|
||||
project_id = mock.sentinel.project_id
|
||||
subnets = mock.sentinel.subnets
|
||||
project_id = uuidutils.generate_uuid()
|
||||
subnet_id = uuidutils.generate_uuid()
|
||||
net_id = uuidutils.generate_uuid()
|
||||
network = ovu.neutron_to_osvif_network({'id': net_id})
|
||||
subnets = {subnet_id: network}
|
||||
security_groups = [mock.sentinel.security_groups]
|
||||
m_driver._get_port_from_pool.side_effect = (
|
||||
exceptions.ResourceNotReady(pod))
|
||||
|
@ -152,7 +160,7 @@ class BaseVIFPool(test_base.TestCase):
|
|||
m_driver = mock.MagicMock(spec=cls)
|
||||
|
||||
pod = get_pod_obj()
|
||||
project_id = mock.sentinel.project_id
|
||||
project_id = uuidutils.generate_uuid()
|
||||
subnets = mock.sentinel.subnets
|
||||
security_groups = [mock.sentinel.security_groups]
|
||||
m_driver._get_host_addr.side_effect = KeyError
|
||||
|
@ -172,7 +180,7 @@ class BaseVIFPool(test_base.TestCase):
|
|||
m_driver._drv_vif = vif_driver
|
||||
|
||||
pod = mock.sentinel.pod
|
||||
project_id = mock.sentinel.project_id
|
||||
project_id = uuidutils.generate_uuid()
|
||||
subnets = mock.sentinel.subnets
|
||||
security_groups = [mock.sentinel.security_groups]
|
||||
pool_key = (mock.sentinel.host_addr, project_id,
|
||||
|
@ -203,7 +211,7 @@ class BaseVIFPool(test_base.TestCase):
|
|||
m_driver = mock.MagicMock(spec=cls)
|
||||
|
||||
pod = mock.sentinel.pod
|
||||
project_id = mock.sentinel.project_id
|
||||
project_id = uuidutils.generate_uuid()
|
||||
subnets = mock.sentinel.subnets
|
||||
security_groups = [mock.sentinel.security_groups]
|
||||
pool_key = (mock.sentinel.host_addr, project_id,
|
||||
|
@ -229,7 +237,7 @@ class BaseVIFPool(test_base.TestCase):
|
|||
m_driver._drv_vif = vif_driver
|
||||
|
||||
pod = mock.sentinel.pod
|
||||
project_id = mock.sentinel.project_id
|
||||
project_id = uuidutils.generate_uuid()
|
||||
subnets = mock.sentinel.subnets
|
||||
security_groups = [mock.sentinel.security_groups]
|
||||
pool_key = (mock.sentinel.host_addr, project_id,
|
||||
|
@ -256,7 +264,10 @@ class BaseVIFPool(test_base.TestCase):
|
|||
pod = get_pod_obj()
|
||||
project_id = mock.sentinel.project_id
|
||||
security_groups = [mock.sentinel.security_groups]
|
||||
vif = osv_vif.VIFOpenVSwitch(id='0fa0e837-d34e-4580-a6c4-04f5f607d93e')
|
||||
net_id = uuidutils.generate_uuid()
|
||||
network = ovu.neutron_to_osvif_network({'id': net_id})
|
||||
vif = osv_vif.VIFOpenVSwitch(id='0fa0e837-d34e-4580-a6c4-04f5f607d93e',
|
||||
network=network)
|
||||
|
||||
m_driver._return_ports_to_pool.return_value = None
|
||||
|
||||
|
@ -270,7 +281,7 @@ class BaseVIFPool(test_base.TestCase):
|
|||
|
||||
kubernetes = self.useFixture(k_fix.MockK8sClient()).client
|
||||
pod = get_pod_obj()
|
||||
port_id = 'f2c1b73a-6a0c-4dca-b986-0d07d09e0c02'
|
||||
port_id = uuidutils.generate_uuid()
|
||||
versioned_object = jsonutils.dumps({
|
||||
'versioned_object.data': {
|
||||
'active': True,
|
||||
|
@ -324,7 +335,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = mock.sentinel.pool_key
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
port = mock.sentinel.port
|
||||
subnets = mock.sentinel.subnets
|
||||
|
||||
|
@ -366,7 +377,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = mock.sentinel.pool_key
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
port = mock.sentinel.port
|
||||
subnets = mock.sentinel.subnets
|
||||
|
||||
|
@ -422,7 +433,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 5
|
||||
|
||||
m_driver._recyclable_ports = {port_id: pool_key}
|
||||
|
@ -458,7 +469,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 5
|
||||
|
||||
m_driver._recyclable_ports = {port_id: pool_key}
|
||||
|
@ -485,7 +496,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 10
|
||||
vif = mock.sentinel.vif
|
||||
|
||||
|
@ -511,7 +522,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 5
|
||||
|
||||
m_driver._recyclable_ports = {port_id: pool_key}
|
||||
|
@ -550,7 +561,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 10
|
||||
vif = mock.sentinel.vif
|
||||
|
||||
|
@ -577,7 +588,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 10
|
||||
|
||||
m_driver._recyclable_ports = {port_id: pool_key}
|
||||
|
@ -609,7 +620,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
m_driver._existing_vifs = {}
|
||||
m_driver._available_ports_pools = {}
|
||||
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
port = get_port_obj(port_id=port_id)
|
||||
filtered_ports = [port]
|
||||
m_driver._get_ports_by_attrs.return_value = filtered_ports
|
||||
|
@ -619,23 +630,27 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
oslo_cfg.CONF.set_override('port_debug',
|
||||
False,
|
||||
group='kubernetes')
|
||||
subnet = mock.sentinel.subnet
|
||||
|
||||
subnet_id = port['fixed_ips'][0]['subnet_id']
|
||||
m_get_subnet.return_value = subnet
|
||||
net_id = uuidutils.generate_uuid()
|
||||
network = ovu.neutron_to_osvif_network({'id': net_id})
|
||||
subnet = {subnet_id: network}
|
||||
m_get_subnet.return_value = network
|
||||
vif = mock.sentinel.vif
|
||||
m_to_osvif.return_value = vif
|
||||
|
||||
pool_key = (port['binding:host_id'], port['project_id'],
|
||||
tuple(port['security_groups']), net_id)
|
||||
m_driver._get_pool_key.return_value = pool_key
|
||||
|
||||
cls._recover_precreated_ports(m_driver)
|
||||
|
||||
m_driver._get_ports_by_attrs.assert_called_once()
|
||||
m_get_subnet.assert_called_with(subnet_id)
|
||||
m_driver._drv_vif._get_vif_plugin.assert_called_once_with(port)
|
||||
m_to_osvif.assert_called_once_with(vif_plugin, port,
|
||||
{subnet_id: subnet})
|
||||
m_to_osvif.assert_called_once_with(vif_plugin, port, subnet)
|
||||
|
||||
self.assertEqual(m_driver._existing_vifs[port_id], vif)
|
||||
pool_key = (port['binding:host_id'], port['project_id'],
|
||||
tuple(port['security_groups']))
|
||||
self.assertEqual(m_driver._available_ports_pools[pool_key], [port_id])
|
||||
|
||||
@mock.patch('kuryr_kubernetes.os_vif_util.neutron_to_osvif_vif')
|
||||
|
@ -704,7 +719,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = mock.sentinel.pool_key
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
port = mock.sentinel.port
|
||||
subnets = mock.sentinel.subnets
|
||||
|
||||
|
@ -742,7 +757,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = mock.sentinel.pool_key
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
port = mock.sentinel.port
|
||||
subnets = mock.sentinel.subnets
|
||||
|
||||
|
@ -797,7 +812,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 5
|
||||
|
||||
m_driver._recyclable_ports = {port_id: pool_key}
|
||||
|
@ -832,7 +847,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 5
|
||||
|
||||
m_driver._recyclable_ports = {port_id: pool_key}
|
||||
|
@ -862,12 +877,12 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver._drv_vif = vif_driver
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 10
|
||||
vif = mock.MagicMock()
|
||||
vif.vlan_id = mock.sentinel.vlan_id
|
||||
p_port = mock.sentinel.p_port
|
||||
trunk_id = mock.sentinel.trunk_id
|
||||
trunk_id = uuidutils.generate_uuid()
|
||||
|
||||
m_driver._recyclable_ports = {port_id: pool_key}
|
||||
m_driver._available_ports_pools = {}
|
||||
|
@ -899,7 +914,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 5
|
||||
|
||||
m_driver._recyclable_ports = {port_id: pool_key}
|
||||
|
@ -937,12 +952,12 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver._drv_vif = vif_driver
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 10
|
||||
vif = mock.MagicMock()
|
||||
vif.vlan_id = mock.sentinel.vlan_id
|
||||
p_port = mock.sentinel.p_port
|
||||
trunk_id = mock.sentinel.trunk_id
|
||||
trunk_id = uuidutils.generate_uuid()
|
||||
|
||||
m_driver._recyclable_ports = {port_id: pool_key}
|
||||
m_driver._available_ports_pools = {}
|
||||
|
@ -978,10 +993,10 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver._drv_vif = vif_driver
|
||||
|
||||
pool_key = ('node_ip', 'project_id', tuple(['security_group']))
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
pool_length = 10
|
||||
p_port = mock.sentinel.p_port
|
||||
trunk_id = mock.sentinel.trunk_id
|
||||
trunk_id = uuidutils.generate_uuid()
|
||||
|
||||
m_driver._recyclable_ports = {port_id: pool_key}
|
||||
m_driver._available_ports_pools = {}
|
||||
|
@ -1011,7 +1026,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
ip_address = mock.sentinel.ip_address
|
||||
|
||||
port_obj = get_port_obj(ip_address=ip_address)
|
||||
|
@ -1026,9 +1041,9 @@ class NestedVIFPool(test_base.TestCase):
|
|||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
trunk_port = get_port_obj(port_id=port_id)
|
||||
trunk_id = mock.sentinel.id
|
||||
trunk_id = uuidutils.generate_uuid()
|
||||
trunk_details = {
|
||||
'trunk_id': trunk_id,
|
||||
'sub_ports': [{
|
||||
|
@ -1037,7 +1052,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
'segmentation_id': 4056}]}
|
||||
trunk_port['trunk_details'] = trunk_details
|
||||
|
||||
subport_id = mock.sentinel.subport_id
|
||||
subport_id = uuidutils.generate_uuid()
|
||||
subport = get_port_obj(port_id=subport_id,
|
||||
device_owner='trunk:subport')
|
||||
m_driver._get_ports_by_attrs.return_value = [trunk_port, subport]
|
||||
|
@ -1074,7 +1089,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
port = get_port_obj(port_id=port_id)
|
||||
port = get_port_obj(port_id=port_id, device_owner='compute:nova')
|
||||
m_driver._get_ports_by_attrs.return_value = [port]
|
||||
|
@ -1100,28 +1115,31 @@ class NestedVIFPool(test_base.TestCase):
|
|||
True,
|
||||
group='kubernetes')
|
||||
|
||||
port_id = mock.sentinel.port_id
|
||||
trunk_id = mock.sentinel.trunk_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
trunk_id = uuidutils.generate_uuid()
|
||||
trunk_obj = self._get_trunk_obj(port_id=trunk_id, subport_id=port_id)
|
||||
port = get_port_obj(port_id=port_id, device_owner='trunk:subport')
|
||||
|
||||
p_ports = self._get_parent_ports([trunk_obj])
|
||||
a_subports = {port_id: port}
|
||||
subnet_id = port['fixed_ips'][0]['subnet_id']
|
||||
subnet = mock.sentinel.subnet
|
||||
subnets = {subnet_id: {subnet_id: subnet}}
|
||||
net_id = uuidutils.generate_uuid()
|
||||
network = ovu.neutron_to_osvif_network({'id': net_id})
|
||||
subnets = {subnet_id: {subnet_id: network}}
|
||||
m_driver._get_trunks_info.return_value = (p_ports, a_subports,
|
||||
subnets)
|
||||
|
||||
vif = mock.sentinel.vif
|
||||
m_to_osvif.return_value = vif
|
||||
|
||||
pool_key = (port['binding:host_id'], port['project_id'],
|
||||
tuple(port['security_groups']), net_id)
|
||||
m_driver._get_pool_key.return_value = pool_key
|
||||
|
||||
cls._precreated_ports(m_driver, 'recover')
|
||||
|
||||
m_driver._get_trunks_info.assert_called_once()
|
||||
self.assertEqual(m_driver._existing_vifs[port_id], vif)
|
||||
pool_key = (port['binding:host_id'], port['project_id'],
|
||||
tuple(port['security_groups']))
|
||||
self.assertEqual(m_driver._available_ports_pools[pool_key], [port_id])
|
||||
neutron.delete_port.assert_not_called()
|
||||
|
||||
|
@ -1137,21 +1155,23 @@ class NestedVIFPool(test_base.TestCase):
|
|||
True,
|
||||
group='kubernetes')
|
||||
|
||||
port_id = mock.sentinel.port_id
|
||||
trunk_id = mock.sentinel.trunk_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
trunk_id = uuidutils.generate_uuid()
|
||||
trunk_obj = self._get_trunk_obj(port_id=trunk_id, subport_id=port_id)
|
||||
port = get_port_obj(port_id=port_id, device_owner='trunk:subport')
|
||||
|
||||
p_ports = self._get_parent_ports([trunk_obj])
|
||||
a_subports = {port_id: port}
|
||||
subnet_id = port['fixed_ips'][0]['subnet_id']
|
||||
subnet = mock.sentinel.subnet
|
||||
subnets = {subnet_id: {subnet_id: subnet}}
|
||||
net_id = uuidutils.generate_uuid()
|
||||
network = ovu.neutron_to_osvif_network({'id': net_id})
|
||||
subnets = {subnet_id: {subnet_id: network}}
|
||||
m_driver._get_trunks_info.return_value = (p_ports, a_subports,
|
||||
subnets)
|
||||
|
||||
pool_key = (port['binding:host_id'], port['project_id'],
|
||||
tuple(port['security_groups']))
|
||||
tuple(port['security_groups']), net_id)
|
||||
m_driver._get_pool_key.return_value = pool_key
|
||||
m_driver._available_ports_pools = {pool_key: [port_id]}
|
||||
m_driver._existing_vifs = {port_id: mock.sentinel.vif}
|
||||
|
||||
|
@ -1179,17 +1199,17 @@ class NestedVIFPool(test_base.TestCase):
|
|||
True,
|
||||
group='kubernetes')
|
||||
|
||||
port_id1 = mock.sentinel.port_id1
|
||||
trunk_id1 = mock.sentinel.trunk_id1
|
||||
port_id1 = uuidutils.generate_uuid()
|
||||
trunk_id1 = uuidutils.generate_uuid()
|
||||
|
||||
port_id2 = mock.sentinel.port_id2
|
||||
trunk_id2 = mock.sentinel.trunk_id2
|
||||
port_id2 = uuidutils.generate_uuid()
|
||||
trunk_id2 = uuidutils.generate_uuid()
|
||||
|
||||
trunk_obj1 = self._get_trunk_obj(port_id=trunk_id1,
|
||||
subport_id=port_id1)
|
||||
trunk_obj2 = self._get_trunk_obj(port_id=trunk_id2,
|
||||
subport_id=port_id2,
|
||||
trunk_id=mock.sentinel.id)
|
||||
trunk_id=uuidutils.generate_uuid())
|
||||
|
||||
port1 = get_port_obj(port_id=port_id1, device_owner='trunk:subport')
|
||||
port2 = get_port_obj(port_id=port_id2, device_owner='trunk:subport')
|
||||
|
@ -1197,8 +1217,9 @@ class NestedVIFPool(test_base.TestCase):
|
|||
p_ports = self._get_parent_ports([trunk_obj1, trunk_obj2])
|
||||
a_subports = {port_id1: port1, port_id2: port2}
|
||||
subnet_id = port1['fixed_ips'][0]['subnet_id']
|
||||
subnet = mock.sentinel.subnet
|
||||
subnets = {subnet_id: {subnet_id: subnet}}
|
||||
net_id = uuidutils.generate_uuid()
|
||||
network = ovu.neutron_to_osvif_network({'id': net_id})
|
||||
subnets = {subnet_id: {subnet_id: network}}
|
||||
|
||||
m_driver._get_trunks_info.return_value = (p_ports, a_subports,
|
||||
subnets)
|
||||
|
@ -1226,9 +1247,9 @@ class NestedVIFPool(test_base.TestCase):
|
|||
True,
|
||||
group='kubernetes')
|
||||
|
||||
port_id1 = mock.sentinel.port_id1
|
||||
port_id2 = mock.sentinel.port_id2
|
||||
trunk_id = mock.sentinel.trunk_id
|
||||
port_id1 = uuidutils.generate_uuid()
|
||||
port_id2 = uuidutils.generate_uuid()
|
||||
trunk_id = uuidutils.generate_uuid()
|
||||
trunk_obj = self._get_trunk_obj(port_id=trunk_id,
|
||||
subport_id=port_id1)
|
||||
trunk_obj['sub_ports'].append({'port_id': port_id2,
|
||||
|
@ -1240,8 +1261,9 @@ class NestedVIFPool(test_base.TestCase):
|
|||
p_ports = self._get_parent_ports([trunk_obj])
|
||||
a_subports = {port_id1: port1, port_id2: port2}
|
||||
subnet_id = port1['fixed_ips'][0]['subnet_id']
|
||||
subnet = mock.sentinel.subnet
|
||||
subnets = {subnet_id: {subnet_id: subnet}}
|
||||
net_id = uuidutils.generate_uuid()
|
||||
network = ovu.neutron_to_osvif_network({'id': net_id})
|
||||
subnets = {subnet_id: {subnet_id: network}}
|
||||
|
||||
m_driver._get_trunks_info.return_value = (p_ports, a_subports,
|
||||
subnets)
|
||||
|
@ -1249,13 +1271,14 @@ class NestedVIFPool(test_base.TestCase):
|
|||
vif = mock.sentinel.vif
|
||||
m_to_osvif.return_value = vif
|
||||
|
||||
pool_key = (port1['binding:host_id'], port1['project_id'],
|
||||
tuple(port1['security_groups']), net_id)
|
||||
m_driver._get_pool_key.return_value = pool_key
|
||||
cls._precreated_ports(m_driver, 'recover')
|
||||
|
||||
m_driver._get_trunks_info.assert_called_once()
|
||||
self.assertEqual(m_driver._existing_vifs, {port_id1: vif,
|
||||
port_id2: vif})
|
||||
pool_key = (port1['binding:host_id'], port1['project_id'],
|
||||
tuple(port1['security_groups']))
|
||||
self.assertEqual(m_driver._available_ports_pools[pool_key],
|
||||
[port_id1, port_id2])
|
||||
neutron.delete_port.assert_not_called()
|
||||
|
@ -1301,7 +1324,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
True,
|
||||
group='kubernetes')
|
||||
|
||||
port_id = mock.sentinel.port_id
|
||||
port_id = uuidutils.generate_uuid()
|
||||
port = get_port_obj(port_id=port_id, device_owner='trunk:subport')
|
||||
|
||||
p_ports = {}
|
||||
|
|
Loading…
Reference in New Issue