Update vif_pool driver to use OpenStackSDK.
Implements: blueprint switch-to-openstacksdk Change-Id: Ibfc4fb97d898e815a8af18faec5886deca6f73ce
This commit is contained in:
parent
7a51dd90cd
commit
88e5775bec
|
@ -22,7 +22,7 @@ import time
|
|||
|
||||
from kuryr.lib._i18n import _
|
||||
from kuryr.lib import constants as kl_const
|
||||
from neutronclient.common import exceptions as n_exc
|
||||
from openstack import exceptions as os_exc
|
||||
from oslo_cache import core as cache
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_config import cfg as oslo_cfg
|
||||
|
@ -302,7 +302,7 @@ class BaseVIFPool(base.VIFPoolDriver):
|
|||
raise NotImplementedError()
|
||||
|
||||
def remove_sg_from_pools(self, sg_id, net_id):
|
||||
neutron = clients.get_neutron_client()
|
||||
os_net = clients.get_network_client()
|
||||
for pool_key, pool_ports in list(self._available_ports_pools.items()):
|
||||
if self._get_pool_key_net(pool_key) != net_id:
|
||||
continue
|
||||
|
@ -313,13 +313,7 @@ class BaseVIFPool(base.VIFPoolDriver):
|
|||
del self._available_ports_pools[pool_key][sg_key]
|
||||
for port_id in ports:
|
||||
# remove all SGs from the port to be reused
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'security_groups': []
|
||||
}
|
||||
})
|
||||
os_net.update_port(port_id, security_groups=None)
|
||||
# add the port to the default pool
|
||||
self._available_ports_pools[pool_key].setdefault(
|
||||
tuple([]), []).append(port_id)
|
||||
|
@ -392,6 +386,8 @@ class BaseVIFPool(base.VIFPoolDriver):
|
|||
tags = config.CONF.neutron_defaults.resource_tags
|
||||
if tags:
|
||||
attrs['tags'] = tags
|
||||
# TODO(gryf): look out for the object type in list when c_utils will
|
||||
# be migrated to OpenstackSDK
|
||||
all_active_ports = c_utils.get_ports_by_attrs(**attrs)
|
||||
in_use_ports = self._get_in_use_ports()
|
||||
|
||||
|
@ -420,43 +416,40 @@ class BaseVIFPool(base.VIFPoolDriver):
|
|||
return parent_ports, subports, subnets
|
||||
|
||||
def _cleanup_leftover_ports(self):
|
||||
neutron = clients.get_neutron_client()
|
||||
os_net = clients.get_network_client()
|
||||
attrs = {'device_owner': kl_const.DEVICE_OWNER, 'status': 'DOWN'}
|
||||
existing_ports = c_utils.get_ports_by_attrs(**attrs)
|
||||
|
||||
tags = config.CONF.neutron_defaults.resource_tags
|
||||
if tags:
|
||||
nets = neutron.list_networks(tags=tags)['networks']
|
||||
nets_ids = [n['id'] for n in nets]
|
||||
nets = os_net.networks(tags=tags)
|
||||
nets_ids = [n.id for n in nets]
|
||||
for port in existing_ports:
|
||||
net_id = port['network_id']
|
||||
if net_id in nets_ids:
|
||||
if port.get('binding:host_id'):
|
||||
for tag in tags:
|
||||
if tag not in port.get('tags', []):
|
||||
# delete the port if it has binding details, it
|
||||
# belongs to the deployment subnet and it does
|
||||
# not have the right tags
|
||||
try:
|
||||
neutron.delete_port(port['id'])
|
||||
break
|
||||
except n_exc.NeutronClientException:
|
||||
LOG.debug("Problem deleting leftover port "
|
||||
"%s. Skipping.", port['id'])
|
||||
continue
|
||||
if set(tags).difference(set(port.get('tags', []))):
|
||||
# delete the port if it has binding details, it
|
||||
# belongs to the deployment subnet and it does not
|
||||
# have the right tags
|
||||
try:
|
||||
os_net.delete_port(port['id'])
|
||||
except os_exc.SDKException:
|
||||
LOG.debug("Problem deleting leftover port %s. "
|
||||
"Skipping.", port['id'])
|
||||
else:
|
||||
# delete port if they have no binding but belong to the
|
||||
# deployment networks, regardless of their tagging
|
||||
try:
|
||||
neutron.delete_port(port['id'])
|
||||
except n_exc.NeutronClientException:
|
||||
os_net.delete_port(port['id'])
|
||||
except os_exc.SDKException:
|
||||
LOG.debug("Problem deleting leftover port %s. "
|
||||
"Skipping.", port['id'])
|
||||
continue
|
||||
else:
|
||||
for port in existing_ports:
|
||||
if not port.get('binding:host_id'):
|
||||
neutron.delete_port(port['id'])
|
||||
os_net.delete_port(port['id'])
|
||||
|
||||
|
||||
class NeutronVIFPool(BaseVIFPool):
|
||||
|
@ -496,24 +489,12 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
# pool is empty, no port to reuse
|
||||
raise exceptions.ResourceNotReady(pod)
|
||||
port_id = pool_ports[min_sg_group].pop()
|
||||
neutron = clients.get_neutron_client()
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'security_groups': list(security_groups)
|
||||
}
|
||||
})
|
||||
os_net = clients.get_network_client()
|
||||
os_net.update_port(port_id, security_groups=list(security_groups))
|
||||
if config.CONF.kubernetes.port_debug:
|
||||
neutron = clients.get_neutron_client()
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': c_utils.get_port_name(pod),
|
||||
'device_id': pod['metadata']['uid']
|
||||
}
|
||||
})
|
||||
os_net = clients.get_network_client()
|
||||
os_net.update_port(port_id, name=c_utils.get_port_name(pod),
|
||||
device_id=pod['metadata']['uid'])
|
||||
# check if the pool needs to be populated
|
||||
if (self._get_pool_size(pool_key) <
|
||||
oslo_cfg.CONF.vif_pool.ports_pool_min):
|
||||
|
@ -524,7 +505,7 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
def _return_ports_to_pool(self):
|
||||
"""Recycle ports to be reused by future pods.
|
||||
|
||||
For each port in the recyclable_ports dict it reaplies
|
||||
For each port in the recyclable_ports dict it reapplies
|
||||
security group if they have been changed and it changes the port
|
||||
name to available_port if the port_debug option is enabled.
|
||||
Then the port_id is included in the dict with the available_ports.
|
||||
|
@ -542,7 +523,7 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
LOG.info("Kuryr-controller not yet ready to return ports to "
|
||||
"pools.")
|
||||
return
|
||||
neutron = clients.get_neutron_client()
|
||||
os_net = clients.get_network_client()
|
||||
sg_current = {}
|
||||
if not config.CONF.kubernetes.port_debug:
|
||||
attrs = {'device_owner': kl_const.DEVICE_OWNER}
|
||||
|
@ -564,15 +545,9 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
else '')
|
||||
if config.CONF.kubernetes.port_debug:
|
||||
try:
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': port_name,
|
||||
'device_id': ''
|
||||
}
|
||||
})
|
||||
except n_exc.NeutronClientException:
|
||||
os_net.update_port(port_id, name=port_name,
|
||||
device_id='')
|
||||
except os_exc.SDKException:
|
||||
LOG.warning("Error changing name for port %s to be "
|
||||
"reused, put back on the cleanable "
|
||||
"pool.", port_id)
|
||||
|
@ -583,10 +558,7 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
else:
|
||||
try:
|
||||
del self._existing_vifs[port_id]
|
||||
neutron.delete_port(port_id)
|
||||
except n_exc.PortNotFoundClient:
|
||||
LOG.debug('Unable to release port %s as it no longer '
|
||||
'exists.', port_id)
|
||||
os_net.delete_port(port_id)
|
||||
except KeyError:
|
||||
LOG.debug('Port %s is not in the ports list.', port_id)
|
||||
try:
|
||||
|
@ -629,8 +601,8 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
# NOTE(ltomasbo): kuryr-controller is running without the
|
||||
# rights to get the needed information to recover the ports.
|
||||
# Thus, removing the port instead
|
||||
neutron = clients.get_neutron_client()
|
||||
neutron.delete_port(port['id'])
|
||||
os_net = clients.get_network_client()
|
||||
os_net.delete_port(port['id'])
|
||||
continue
|
||||
subnet_id = port['fixed_ips'][0]['subnet_id']
|
||||
subnet = {
|
||||
|
@ -655,7 +627,7 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
LOG.info("Kuryr-controller not yet ready to delete network "
|
||||
"pools.")
|
||||
raise exceptions.ResourceNotReady(net_id)
|
||||
neutron = clients.get_neutron_client()
|
||||
os_net = clients.get_network_client()
|
||||
|
||||
# NOTE(ltomasbo): Note the pods should already be deleted, but their
|
||||
# associated ports may not have been recycled yet, therefore not being
|
||||
|
@ -673,11 +645,10 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
del self._existing_vifs[port_id]
|
||||
except KeyError:
|
||||
LOG.debug('Port %s is not in the ports list.', port_id)
|
||||
try:
|
||||
neutron.delete_port(port_id)
|
||||
except n_exc.PortNotFoundClient:
|
||||
LOG.debug('Unable to release port %s as it no longer '
|
||||
'exists.', port_id)
|
||||
# NOTE(gryf): openstack client doesn't return information, if
|
||||
# the port deos not exists
|
||||
os_net.delete_port(port_id)
|
||||
|
||||
self._available_ports_pools[pool_key] = {}
|
||||
|
||||
|
||||
|
@ -702,15 +673,18 @@ class NestedVIFPool(BaseVIFPool):
|
|||
self._drv_vif = driver
|
||||
|
||||
def _get_parent_port_id(self, vif):
|
||||
neutron = clients.get_neutron_client()
|
||||
os_net = clients.get_network_client()
|
||||
args = {}
|
||||
|
||||
if config.CONF.neutron_defaults.resource_tags:
|
||||
args['tags'] = config.CONF.neutron_defaults.resource_tags
|
||||
trunks = neutron.list_trunks(**args)
|
||||
for trunk in trunks['trunks']:
|
||||
for sp in trunk['sub_ports']:
|
||||
|
||||
trunks = os_net.get_trunks(args)
|
||||
|
||||
for trunk in trunks:
|
||||
for sp in trunk.sub_ports:
|
||||
if sp['port_id'] == vif.id:
|
||||
return trunk['port_id']
|
||||
return trunk.port_id
|
||||
|
||||
return None
|
||||
|
||||
|
@ -741,6 +715,9 @@ class NestedVIFPool(BaseVIFPool):
|
|||
pool_ports = self._available_ports_pools[pool_key]
|
||||
except (KeyError, AttributeError):
|
||||
raise exceptions.ResourceNotReady(pod)
|
||||
|
||||
os_net = clients.get_network_client()
|
||||
|
||||
try:
|
||||
port_id = pool_ports[security_groups].pop()
|
||||
except (KeyError, IndexError):
|
||||
|
@ -767,23 +744,9 @@ class NestedVIFPool(BaseVIFPool):
|
|||
# pool is empty, no port to reuse
|
||||
raise exceptions.ResourceNotReady(pod)
|
||||
port_id = pool_ports[min_sg_group].pop()
|
||||
neutron = clients.get_neutron_client()
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'security_groups': list(security_groups)
|
||||
}
|
||||
})
|
||||
os_net.update_port(port_id, security_groups=list(security_groups))
|
||||
if config.CONF.kubernetes.port_debug:
|
||||
neutron = clients.get_neutron_client()
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': c_utils.get_port_name(pod),
|
||||
}
|
||||
})
|
||||
os_net.update_port(port_id, name=c_utils.get_port_name(pod))
|
||||
# check if the pool needs to be populated
|
||||
if (self._get_pool_size(pool_key) <
|
||||
oslo_cfg.CONF.vif_pool.ports_pool_min):
|
||||
|
@ -794,7 +757,7 @@ class NestedVIFPool(BaseVIFPool):
|
|||
def _return_ports_to_pool(self):
|
||||
"""Recycle ports to be reused by future pods.
|
||||
|
||||
For each port in the recyclable_ports dict it reaplies
|
||||
For each port in the recyclable_ports dict it reapplies
|
||||
security group if they have been changed and it changes the port
|
||||
name to available_port if the port_debug option is enabled.
|
||||
Then the port_id is included in the dict with the available_ports.
|
||||
|
@ -812,7 +775,7 @@ class NestedVIFPool(BaseVIFPool):
|
|||
LOG.info("Kuryr-controller not yet ready to return ports to "
|
||||
"pools.")
|
||||
return
|
||||
neutron = clients.get_neutron_client()
|
||||
os_net = clients.get_network_client()
|
||||
sg_current = {}
|
||||
if not config.CONF.kubernetes.port_debug:
|
||||
attrs = {'device_owner': ['trunk:subport', kl_const.DEVICE_OWNER]}
|
||||
|
@ -834,14 +797,8 @@ class NestedVIFPool(BaseVIFPool):
|
|||
else '')
|
||||
if config.CONF.kubernetes.port_debug:
|
||||
try:
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': port_name,
|
||||
}
|
||||
})
|
||||
except n_exc.NeutronClientException:
|
||||
os_net.update_port(port_id, name=port_name)
|
||||
except os_exc.SDKException:
|
||||
LOG.warning("Error changing name for port %s to be "
|
||||
"reused, put back on the cleanable "
|
||||
"pool.", port_id)
|
||||
|
@ -856,13 +813,10 @@ class NestedVIFPool(BaseVIFPool):
|
|||
self._drv_vif._release_vlan_id(
|
||||
self._existing_vifs[port_id].vlan_id)
|
||||
del self._existing_vifs[port_id]
|
||||
neutron.delete_port(port_id)
|
||||
except n_exc.PortNotFoundClient:
|
||||
LOG.debug('Unable to release port %s as it no longer '
|
||||
'exists.', port_id)
|
||||
os_net.delete_port(port_id)
|
||||
except KeyError:
|
||||
LOG.debug('Port %s is not in the ports list.', port_id)
|
||||
except n_exc.NeutronClientException:
|
||||
except (os_exc.SDKException, os_exc.HttpException):
|
||||
LOG.warning('Error removing the subport %s', port_id)
|
||||
continue
|
||||
try:
|
||||
|
@ -879,9 +833,9 @@ class NestedVIFPool(BaseVIFPool):
|
|||
return trunk_id
|
||||
|
||||
def _get_parent_port_ip(self, port_id):
|
||||
neutron = clients.get_neutron_client()
|
||||
parent_port = neutron.show_port(port_id).get('port')
|
||||
return parent_port['fixed_ips'][0]['ip_address']
|
||||
os_net = clients.get_network_client()
|
||||
parent_port = os_net.get_port(port_id)
|
||||
return parent_port.fixed_ips[0]['ip_address']
|
||||
|
||||
def sync_pools(self):
|
||||
super(NestedVIFPool, self).sync_pools()
|
||||
|
@ -909,7 +863,7 @@ class NestedVIFPool(BaseVIFPool):
|
|||
given trunk ports (or in all of them if none are passed) and will add
|
||||
them (and the needed information) to the respective pools.
|
||||
"""
|
||||
neutron = clients.get_neutron_client()
|
||||
os_net = clients.get_network_client()
|
||||
# Note(ltomasbo): ML2/OVS changes the device_owner to trunk:subport
|
||||
# when a port is attached to a trunk. However, that is not the case
|
||||
# for other ML2 drivers, such as ODL. So we also need to look for
|
||||
|
@ -930,10 +884,8 @@ class NestedVIFPool(BaseVIFPool):
|
|||
for port_id in port_ids_to_delete:
|
||||
LOG.debug("Deleting port with wrong status: %s", port_id)
|
||||
try:
|
||||
neutron.delete_port(port_id)
|
||||
except n_exc.PortNotFoundClient:
|
||||
LOG.debug('Port already deleted: %s', port_id)
|
||||
except n_exc.NeutronClientException:
|
||||
os_net.delete_port(port_id)
|
||||
except os_exc.SDKException:
|
||||
LOG.exception('Error removing the port %s', port_id)
|
||||
|
||||
for trunk_id, parent_port in parent_ports.items():
|
||||
|
@ -965,20 +917,17 @@ class NestedVIFPool(BaseVIFPool):
|
|||
try:
|
||||
self._drv_vif._remove_subport(trunk_id,
|
||||
kuryr_subport['id'])
|
||||
neutron.delete_port(kuryr_subport['id'])
|
||||
os_net.delete_port(kuryr_subport['id'])
|
||||
self._drv_vif._release_vlan_id(
|
||||
subport['segmentation_id'])
|
||||
del self._existing_vifs[kuryr_subport['id']]
|
||||
self._available_ports_pools[pool_key][
|
||||
tuple(sorted(kuryr_subport['security_groups']
|
||||
))].remove(kuryr_subport['id'])
|
||||
except n_exc.PortNotFoundClient:
|
||||
LOG.debug('Unable to release port %s as it no '
|
||||
'longer exists.', kuryr_subport['id'])
|
||||
except KeyError:
|
||||
LOG.debug('Port %s is not in the ports list.',
|
||||
kuryr_subport['id'])
|
||||
except n_exc.NeutronClientException:
|
||||
except (os_exc.SDKException, os_exc.HttpException):
|
||||
LOG.warning('Error removing the subport %s',
|
||||
kuryr_subport['id'])
|
||||
except ValueError:
|
||||
|
@ -1039,7 +988,7 @@ class NestedVIFPool(BaseVIFPool):
|
|||
LOG.info("Kuryr-controller not yet ready to delete network "
|
||||
"pools.")
|
||||
raise exceptions.ResourceNotReady(net_id)
|
||||
neutron = clients.get_neutron_client()
|
||||
os_net = clients.get_network_client()
|
||||
# NOTE(ltomasbo): Note the pods should already be deleted, but their
|
||||
# associated ports may not have been recycled yet, therefore not being
|
||||
# on the available_ports_pools dict. The next call forces it to be on
|
||||
|
@ -1053,7 +1002,7 @@ class NestedVIFPool(BaseVIFPool):
|
|||
for p_id in sg_ports]
|
||||
try:
|
||||
self._drv_vif._remove_subports(trunk_id, ports_id)
|
||||
except n_exc.NeutronClientException:
|
||||
except (os_exc.SDKException, os_exc.HttpException):
|
||||
LOG.exception('Error removing subports from trunk: %s',
|
||||
trunk_id)
|
||||
continue
|
||||
|
@ -1065,11 +1014,8 @@ class NestedVIFPool(BaseVIFPool):
|
|||
del self._existing_vifs[port_id]
|
||||
except KeyError:
|
||||
LOG.debug('Port %s is not in the ports list.', port_id)
|
||||
try:
|
||||
neutron.delete_port(port_id)
|
||||
except n_exc.PortNotFoundClient:
|
||||
LOG.debug('Unable to delete subport %s as it no longer '
|
||||
'exists.', port_id)
|
||||
os_net.delete_port(port_id)
|
||||
|
||||
self._available_ports_pools[pool_key] = {}
|
||||
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
# limitations under the License.
|
||||
|
||||
import collections
|
||||
import ddt
|
||||
import mock
|
||||
import uuid
|
||||
|
||||
import ddt
|
||||
import munch
|
||||
from neutronclient.common import exceptions as n_exc
|
||||
from openstack import exceptions as os_exc
|
||||
from oslo_config import cfg as oslo_cfg
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
|
@ -68,7 +68,7 @@ def get_pod_name(pod):
|
|||
|
||||
|
||||
def get_port_obj(port_id=None, device_owner=None, ip_address=None):
|
||||
port_obj = {
|
||||
port_obj = munch.Munch({
|
||||
'allowed_address_pairs': [],
|
||||
'extra_dhcp_opts': [],
|
||||
'device_owner': 'compute:kuryr',
|
||||
|
@ -76,17 +76,17 @@ def get_port_obj(port_id=None, device_owner=None, ip_address=None):
|
|||
'port_security_enabled': True,
|
||||
'binding:profile': {},
|
||||
'fixed_ips': [
|
||||
{
|
||||
munch.Munch({
|
||||
'subnet_id': 'e1942bb1-5f51-4646-9885-365b66215592',
|
||||
'ip_address': '10.10.0.5'},
|
||||
{
|
||||
'ip_address': '10.10.0.5'}),
|
||||
munch.Munch({
|
||||
'subnet_id': '4894baaf-df06-4a54-9885-9cd99d1cc245',
|
||||
'ip_address': 'fd35:7db5:e3fc:0:f816:3eff:fe80:d421'}],
|
||||
'ip_address': 'fd35:7db5:e3fc:0:f816:3eff:fe80:d421'})],
|
||||
'id': '07cfe856-11cc-43d9-9200-ff4dc02d3620',
|
||||
'security_groups': ['cfb3dfc4-7a43-4ba1-b92d-b8b2650d7f88'],
|
||||
'binding:vif_details': {
|
||||
'binding:vif_details': munch.Munch({
|
||||
'port_filter': True,
|
||||
'ovs_hybrid_plug': False},
|
||||
'ovs_hybrid_plug': False}),
|
||||
'binding:vif_type': 'ovs',
|
||||
'mac_address': 'fa:16:3e:80:d4:21',
|
||||
'project_id': 'b6e8fb2bde594673923afc19cf168f3a',
|
||||
|
@ -100,14 +100,14 @@ def get_port_obj(port_id=None, device_owner=None, ip_address=None):
|
|||
'network_id': 'ba44f957-c467-412b-b985-ae720514bc46',
|
||||
'tenant_id': 'b6e8fb2bde594673923afc19cf168f3a',
|
||||
'created_at': '2017-06-09T13:23:24Z',
|
||||
'binding:vnic_type': 'normal'}
|
||||
'binding:vnic_type': 'normal'})
|
||||
|
||||
if ip_address:
|
||||
port_obj['fixed_ips'][0]['ip_address'] = ip_address
|
||||
port_obj.fixed_ips[0].ip_address = ip_address
|
||||
if port_id:
|
||||
port_obj['id'] = port_id
|
||||
port_obj.id = port_id
|
||||
if device_owner:
|
||||
port_obj['device_owner'] = device_owner
|
||||
port_obj.device_owner = device_owner
|
||||
|
||||
return port_obj
|
||||
|
||||
|
@ -369,7 +369,8 @@ class BaseVIFPool(test_base.TestCase):
|
|||
def test_cleanup_leftover_ports(self, m_get_ports):
|
||||
cls = vif_pool.BaseVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
port_id = str(uuid.uuid4())
|
||||
port = get_port_obj(port_id=port_id)
|
||||
|
@ -383,17 +384,18 @@ class BaseVIFPool(test_base.TestCase):
|
|||
self.addCleanup(oslo_cfg.CONF.clear_override, 'resource_tags',
|
||||
group='neutron_defaults')
|
||||
|
||||
neutron.list_networks.return_value = {'networks': [{'id': net_id}]}
|
||||
os_net.networks.return_value = [munch.Munch({'id': net_id})]
|
||||
|
||||
cls._cleanup_leftover_ports(m_driver)
|
||||
neutron.list_networks.assert_called()
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.networks.assert_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test_cleanup_leftover_ports_different_network(self, m_get_ports):
|
||||
cls = vif_pool.BaseVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
port_id = str(uuid.uuid4())
|
||||
port = get_port_obj(port_id=port_id)
|
||||
|
@ -405,17 +407,18 @@ class BaseVIFPool(test_base.TestCase):
|
|||
group='neutron_defaults')
|
||||
self.addCleanup(oslo_cfg.CONF.clear_override, 'resource_tags',
|
||||
group='neutron_defaults')
|
||||
neutron.list_networks.return_value = {'networks': []}
|
||||
os_net.networks.return_value = []
|
||||
|
||||
cls._cleanup_leftover_ports(m_driver)
|
||||
neutron.list_networks.assert_called()
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.networks.assert_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test_cleanup_leftover_ports_no_binding(self, m_get_ports):
|
||||
cls = vif_pool.BaseVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
port_id = str(uuid.uuid4())
|
||||
port = get_port_obj(port_id=port_id)
|
||||
|
@ -430,17 +433,18 @@ class BaseVIFPool(test_base.TestCase):
|
|||
self.addCleanup(oslo_cfg.CONF.clear_override, 'resource_tags',
|
||||
group='neutron_defaults')
|
||||
|
||||
neutron.list_networks.return_value = {'networks': [{'id': net_id}]}
|
||||
os_net.networks.return_value = [munch.Munch({'id': net_id})]
|
||||
|
||||
cls._cleanup_leftover_ports(m_driver)
|
||||
neutron.list_networks.assert_called()
|
||||
neutron.delete_port.assert_called_once_with(port['id'])
|
||||
os_net.networks.assert_called()
|
||||
os_net.delete_port.assert_called_once_with(port['id'])
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test_cleanup_leftover_ports_no_tags(self, m_get_ports):
|
||||
cls = vif_pool.BaseVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
port_id = str(uuid.uuid4())
|
||||
port = get_port_obj(port_id=port_id)
|
||||
|
@ -453,31 +457,33 @@ class BaseVIFPool(test_base.TestCase):
|
|||
self.addCleanup(oslo_cfg.CONF.clear_override, 'resource_tags',
|
||||
group='neutron_defaults')
|
||||
|
||||
neutron.list_networks.return_value = {'networks': [{'id': net_id}]}
|
||||
os_net.networks.return_value = [munch.Munch({'id': net_id})]
|
||||
|
||||
cls._cleanup_leftover_ports(m_driver)
|
||||
neutron.list_networks.assert_called()
|
||||
neutron.delete_port.assert_called_once_with(port['id'])
|
||||
os_net.networks.assert_called()
|
||||
os_net.delete_port.assert_called_once_with(port['id'])
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test_cleanup_leftover_ports_no_tagging(self, m_get_ports):
|
||||
cls = vif_pool.BaseVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
port_id = str(uuid.uuid4())
|
||||
port = get_port_obj(port_id=port_id)
|
||||
m_get_ports.return_value = [port]
|
||||
|
||||
cls._cleanup_leftover_ports(m_driver)
|
||||
neutron.list_networks.assert_not_called()
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.networks.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test_cleanup_leftover_ports_no_tagging_no_binding(self, m_get_ports):
|
||||
cls = vif_pool.BaseVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
port_id = str(uuid.uuid4())
|
||||
port = get_port_obj(port_id=port_id)
|
||||
|
@ -485,8 +491,8 @@ class BaseVIFPool(test_base.TestCase):
|
|||
m_get_ports.return_value = [port]
|
||||
|
||||
cls._cleanup_leftover_ports(m_driver)
|
||||
neutron.list_networks.assert_not_called()
|
||||
neutron.delete_port.assert_called_once_with(port['id'])
|
||||
os_net.networks.assert_not_called()
|
||||
os_net.delete_port.assert_called_once_with(port.id)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
|
@ -497,7 +503,8 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
def test__get_port_from_pool(self, m_eventlet, m_get_port_name):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = mock.sentinel.pool_key
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -527,14 +534,8 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets, tuple(security_groups)))
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': get_pod_name(pod),
|
||||
'device_id': pod['metadata']['uid']
|
||||
}
|
||||
})
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, name=get_pod_name(pod), device_id=pod['metadata']['uid'])
|
||||
m_eventlet.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_port_name')
|
||||
|
@ -543,7 +544,8 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
m_get_port_name):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = mock.sentinel.pool_key
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -570,20 +572,15 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets, tuple(security_groups)))
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': get_pod_name(pod),
|
||||
'device_id': pod['metadata']['uid']
|
||||
}
|
||||
})
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, name=get_pod_name(pod), device_id=pod['metadata']['uid'])
|
||||
m_eventlet.assert_called_once()
|
||||
|
||||
def test__get_port_from_pool_empty_pool(self):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pod = get_pod_obj()
|
||||
pool_key = mock.sentinel.pool_key
|
||||
|
@ -598,13 +595,14 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
m_driver, pool_key, pod, subnets,
|
||||
tuple(security_groups))
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
os_net.update_port.assert_not_called()
|
||||
|
||||
@mock.patch('eventlet.spawn')
|
||||
def test__get_port_from_pool_empty_pool_reuse(self, m_eventlet):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pod = get_pod_obj()
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -630,13 +628,8 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets, tuple(security_groups)))
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'security_groups': list(security_groups),
|
||||
}
|
||||
})
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, security_groups=list(security_groups))
|
||||
m_eventlet.assert_not_called()
|
||||
|
||||
@mock.patch('eventlet.spawn')
|
||||
|
@ -644,7 +637,8 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
m_eventlet):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pod = get_pod_obj()
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -669,19 +663,15 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets, tuple(security_groups)))
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'security_groups': list(security_groups),
|
||||
}
|
||||
})
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, security_groups=list(security_groups))
|
||||
m_eventlet.assert_not_called()
|
||||
|
||||
def test__get_port_from_pool_empty_pool_reuse_no_ports(self):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pod = get_pod_obj()
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -707,14 +697,15 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
m_driver, pool_key, pod, subnets, tuple(
|
||||
security_groups))
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
os_net.update_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
@ddt.data((0), (10))
|
||||
def test__trigger_return_to_pool(self, max_pool, m_get_ports):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -734,22 +725,17 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': constants.KURYR_PORT_NAME,
|
||||
'device_id': '',
|
||||
}
|
||||
})
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, name=constants.KURYR_PORT_NAME, device_id='')
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
@ddt.data((0), (10))
|
||||
def test__trigger_return_to_pool_no_update(self, max_pool, m_get_ports):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -769,14 +755,15 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.update_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test__trigger_return_to_pool_delete_port(self, m_get_ports):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -795,14 +782,15 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
neutron.delete_port.assert_called_once_with(port_id)
|
||||
os_net.update_port.assert_not_called()
|
||||
os_net.delete_port.assert_called_once_with(port_id)
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test__trigger_return_to_pool_update_exception(self, m_get_ports):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -822,25 +810,20 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
m_get_ports.return_value = [
|
||||
{'id': port_id, 'security_groups': ['security_group_modified']}]
|
||||
m_driver._get_pool_size.return_value = pool_length
|
||||
neutron.update_port.side_effect = n_exc.NeutronClientException
|
||||
os_net.update_port.side_effect = os_exc.SDKException
|
||||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': constants.KURYR_PORT_NAME,
|
||||
'device_id': '',
|
||||
}
|
||||
})
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, name=constants.KURYR_PORT_NAME, device_id='')
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test__trigger_return_to_pool_delete_exception(self, m_get_ports):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -856,18 +839,18 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
m_get_ports.return_value = [
|
||||
{'id': port_id, 'security_groups': ['security_group_modified']}]
|
||||
m_driver._get_pool_size.return_value = pool_length
|
||||
neutron.delete_port.side_effect = n_exc.PortNotFoundClient
|
||||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
neutron.delete_port.assert_called_once_with(port_id)
|
||||
os_net.update_port.assert_not_called()
|
||||
os_net.delete_port.assert_called_once_with(port_id)
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test__trigger_return_to_pool_delete_key_error(self, m_get_ports):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -885,8 +868,8 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.update_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
@mock.patch('kuryr_kubernetes.os_vif_util.neutron_to_osvif_vif')
|
||||
|
@ -967,7 +950,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
net_id = mock.sentinel.net_id
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
|
@ -983,12 +966,12 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
|
||||
m_driver._trigger_return_to_pool.assert_called_once()
|
||||
m_driver._get_pool_key_net.assert_called_once()
|
||||
neutron.delete_port.assert_called_once_with(port_id)
|
||||
os_net.delete_port.assert_called_once_with(port_id)
|
||||
|
||||
def test_delete_network_pools_not_ready(self):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
net_id = mock.sentinel.net_id
|
||||
m_driver._recovered_pools = False
|
||||
|
@ -998,13 +981,13 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
|
||||
m_driver._trigger_return_to_pool.assert_not_called()
|
||||
m_driver._get_pool_key_net.assert_not_called()
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
def test_delete_network_pools_missing_port_id(self):
|
||||
cls = vif_pool.NeutronVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
net_id = mock.sentinel.net_id
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
|
@ -1013,7 +996,6 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
tuple(['security_group']): [port_id]}}
|
||||
m_driver._existing_vifs = {}
|
||||
m_driver._recovered_pools = True
|
||||
neutron.delete_port.side_effect = n_exc.PortNotFoundClient
|
||||
|
||||
m_driver._get_pool_key_net.return_value = net_id
|
||||
|
||||
|
@ -1021,7 +1003,7 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
|
||||
m_driver._trigger_return_to_pool.assert_called_once()
|
||||
m_driver._get_pool_key_net.assert_called_once()
|
||||
neutron.delete_port.assert_called_once_with(port_id)
|
||||
os_net.delete_port.assert_called_once_with(port_id)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
|
@ -1067,7 +1049,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
def test__get_port_from_pool(self, m_eventlet, m_get_port_name):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = mock.sentinel.pool_key
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -1094,13 +1077,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets, tuple(security_groups)))
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': get_pod_name(pod),
|
||||
}
|
||||
})
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, name=get_pod_name(pod))
|
||||
m_eventlet.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_port_name')
|
||||
|
@ -1109,7 +1087,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_get_port_name):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = mock.sentinel.pool_key
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -1136,19 +1115,15 @@ class NestedVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets, tuple(security_groups)))
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': get_pod_name(pod),
|
||||
}
|
||||
})
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, name=get_pod_name(pod))
|
||||
m_eventlet.assert_called_once()
|
||||
|
||||
def test__get_port_from_pool_empty_pool(self):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pod = mock.sentinel.pod
|
||||
pool_key = mock.sentinel.pool_key
|
||||
|
@ -1163,13 +1138,14 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver, pool_key, pod, subnets, tuple(
|
||||
security_groups))
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
os_net.update_port.assert_not_called()
|
||||
|
||||
@mock.patch('eventlet.spawn')
|
||||
def test__get_port_from_pool_empty_pool_reuse(self, m_eventlet):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pod = mock.sentinel.pod
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -1195,13 +1171,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets, tuple(security_groups)))
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'security_groups': list(security_groups),
|
||||
}
|
||||
})
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, security_groups=list(security_groups))
|
||||
m_eventlet.assert_not_called()
|
||||
|
||||
@mock.patch('eventlet.spawn')
|
||||
|
@ -1209,7 +1180,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_eventlet):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pod = mock.sentinel.pod
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -1234,19 +1206,15 @@ class NestedVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets, tuple(security_groups)))
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'security_groups': list(security_groups),
|
||||
}
|
||||
})
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, security_groups=list(security_groups))
|
||||
m_eventlet.assert_not_called()
|
||||
|
||||
def test__get_port_from_pool_empty_pool_reuse_no_ports(self):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pod = mock.sentinel.pod
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -1272,14 +1240,15 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver, pool_key, pod, subnets, tuple(
|
||||
security_groups))
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
os_net.update_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
@ddt.data((0), (10))
|
||||
def test__trigger_return_to_pool(self, max_pool, m_get_ports):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -1299,21 +1268,18 @@ class NestedVIFPool(test_base.TestCase):
|
|||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': constants.KURYR_PORT_NAME,
|
||||
}
|
||||
})
|
||||
neutron.delete_port.assert_not_called()
|
||||
(os_net.update_port
|
||||
.assert_called_once_with(port_id,
|
||||
name=constants.KURYR_PORT_NAME))
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
@ddt.data((0), (10))
|
||||
def test__trigger_return_to_pool_no_update(self, max_pool, m_get_ports):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -1333,14 +1299,16 @@ class NestedVIFPool(test_base.TestCase):
|
|||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.update_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test__trigger_return_to_pool_delete_port(self, m_get_ports):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
cls_vif_driver = nested_vlan_vif.NestedVlanPodVIFDriver
|
||||
vif_driver = mock.MagicMock(spec=cls_vif_driver)
|
||||
m_driver._drv_vif = vif_driver
|
||||
|
@ -1366,8 +1334,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
neutron.delete_port.assert_called_once_with(port_id)
|
||||
os_net.update_port.assert_not_called()
|
||||
os_net.delete_port.assert_called_once_with(port_id)
|
||||
m_driver._get_trunk_id.assert_called_once()
|
||||
m_driver._drv_vif._remove_subport.assert_called_once_with(trunk_id,
|
||||
port_id)
|
||||
|
@ -1376,7 +1344,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
def test__trigger_return_to_pool_update_exception(self, m_get_ports):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
port_id = str(uuid.uuid4())
|
||||
|
@ -1393,24 +1362,19 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_get_ports.return_value = [
|
||||
{'id': port_id, 'security_groups': ['security_group_modified']}]
|
||||
m_driver._get_pool_size.return_value = pool_length
|
||||
neutron.update_port.side_effect = n_exc.NeutronClientException
|
||||
os_net.update_port.side_effect = os_exc.SDKException
|
||||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': constants.KURYR_PORT_NAME,
|
||||
}
|
||||
})
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.update_port.assert_called_once_with(
|
||||
port_id, name=constants.KURYR_PORT_NAME)
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test__trigger_return_to_pool_delete_exception(self, m_get_ports):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
cls_vif_driver = nested_vlan_vif.NestedVlanPodVIFDriver
|
||||
vif_driver = mock.MagicMock(spec=cls_vif_driver)
|
||||
m_driver._drv_vif = vif_driver
|
||||
|
@ -1432,22 +1396,21 @@ class NestedVIFPool(test_base.TestCase):
|
|||
{'id': port_id, 'security_groups': ['security_group_modified']}]
|
||||
m_driver._get_pool_size.return_value = pool_length
|
||||
m_driver._get_trunk_id.return_value = trunk_id
|
||||
neutron.delete_port.side_effect = n_exc.PortNotFoundClient
|
||||
m_driver._known_trunk_ids = {}
|
||||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
os_net.update_port.assert_not_called()
|
||||
m_driver._get_trunk_id.assert_called_once()
|
||||
m_driver._drv_vif._remove_subport.assert_called_once_with(trunk_id,
|
||||
port_id)
|
||||
neutron.delete_port.assert_called_once_with(port_id)
|
||||
os_net.delete_port.assert_called_once_with(port_id)
|
||||
|
||||
@mock.patch('kuryr_kubernetes.controller.drivers.utils.get_ports_by_attrs')
|
||||
def test__trigger_return_to_pool_delete_key_error(self, m_get_ports):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
cls_vif_driver = nested_vlan_vif.NestedVlanPodVIFDriver
|
||||
vif_driver = mock.MagicMock(spec=cls_vif_driver)
|
||||
m_driver._drv_vif = vif_driver
|
||||
|
@ -1471,22 +1434,23 @@ class NestedVIFPool(test_base.TestCase):
|
|||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
||||
neutron.update_port.assert_not_called()
|
||||
os_net.update_port.assert_not_called()
|
||||
m_driver._get_trunk_id.assert_called_once()
|
||||
m_driver._drv_vif._remove_subport.assert_called_once_with(trunk_id,
|
||||
port_id)
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
def test__get_parent_port_ip(self):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
port_id = str(uuid.uuid4())
|
||||
ip_address = mock.sentinel.ip_address
|
||||
|
||||
port_obj = get_port_obj(ip_address=ip_address)
|
||||
neutron.show_port.return_value = {'port': port_obj}
|
||||
os_net.get_port.return_value = port_obj
|
||||
|
||||
self.assertEqual(ip_address, cls._get_parent_port_ip(m_driver,
|
||||
port_id))
|
||||
|
@ -1564,7 +1528,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
def test__precreated_ports_recover(self, m_to_osvif):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
m_driver._available_ports_pools = {}
|
||||
m_driver._existing_vifs = {}
|
||||
|
@ -1572,7 +1537,6 @@ class NestedVIFPool(test_base.TestCase):
|
|||
oslo_cfg.CONF.set_override('port_debug',
|
||||
True,
|
||||
group='kubernetes')
|
||||
|
||||
port_id = str(uuid.uuid4())
|
||||
trunk_id = str(uuid.uuid4())
|
||||
trunk_obj = self._get_trunk_obj(port_id=trunk_id, subport_id=port_id)
|
||||
|
@ -1603,14 +1567,14 @@ class NestedVIFPool(test_base.TestCase):
|
|||
self.assertEqual(m_driver._existing_vifs[port_id], vif)
|
||||
self.assertEqual(m_driver._available_ports_pools[pool_key],
|
||||
{tuple(port['security_groups']): [port_id]})
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.os_vif_util.'
|
||||
'neutron_to_osvif_vif_nested_vlan')
|
||||
def test__precreated_ports_recover_plus_port_cleanup(self, m_to_osvif):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
m_driver._available_ports_pools = {}
|
||||
m_driver._existing_vifs = {}
|
||||
|
@ -1652,12 +1616,12 @@ class NestedVIFPool(test_base.TestCase):
|
|||
self.assertEqual(m_driver._existing_vifs[port_id], vif)
|
||||
self.assertEqual(m_driver._available_ports_pools[pool_key],
|
||||
{tuple(port['security_groups']): [port_id]})
|
||||
neutron.delete_port.assert_called_with(port_to_delete_id)
|
||||
os_net.delete_port.assert_called_with(port_to_delete_id)
|
||||
|
||||
def test__precreated_ports_free(self):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
cls_vif_driver = nested_vlan_vif.NestedVlanPodVIFDriver
|
||||
vif_driver = mock.MagicMock(spec=cls_vif_driver)
|
||||
m_driver._drv_vif = vif_driver
|
||||
|
@ -1694,7 +1658,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
|
||||
m_driver._get_trunks_info.assert_called_once()
|
||||
m_driver._drv_vif._remove_subport.assert_called_once()
|
||||
neutron.delete_port.assert_called_once()
|
||||
os_net.delete_port.assert_called_once()
|
||||
m_driver._drv_vif._release_vlan_id.assert_called_once()
|
||||
|
||||
self.assertEqual(m_driver._existing_vifs, {})
|
||||
|
@ -1706,7 +1670,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
def test__precreated_ports_recover_several_trunks(self, m_to_osvif):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
m_driver._available_ports_pools = {}
|
||||
m_driver._existing_vifs = {}
|
||||
|
@ -1751,14 +1716,15 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver._get_trunks_info.assert_called_once()
|
||||
self.assertEqual(m_driver._existing_vifs, {port_id1: vif,
|
||||
port_id2: vif})
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@mock.patch('kuryr_kubernetes.os_vif_util.'
|
||||
'neutron_to_osvif_vif_nested_vlan')
|
||||
def test__precreated_ports_recover_several_subports(self, m_to_osvif):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
m_driver._available_ports_pools = {}
|
||||
m_driver._existing_vifs = {}
|
||||
|
@ -1805,13 +1771,14 @@ class NestedVIFPool(test_base.TestCase):
|
|||
self.assertEqual(m_driver._available_ports_pools[pool_key],
|
||||
{tuple(port1['security_groups']): [port_id1,
|
||||
port_id2]})
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@ddt.data(('recover'), ('free'))
|
||||
def test__precreated_ports_no_ports(self, m_action):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
oslo_cfg.CONF.set_override('port_debug',
|
||||
True,
|
||||
|
@ -1834,13 +1801,14 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver._get_trunks_info.assert_called_once()
|
||||
self.assertEqual(m_driver._existing_vifs, {})
|
||||
self.assertEqual(m_driver._available_ports_pools, {})
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
@ddt.data(('recover'), ('free'))
|
||||
def test__precreated_ports_no_trunks(self, m_action):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
m_driver = mock.MagicMock(spec=cls)
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
m_driver._available_ports_pools = {}
|
||||
m_driver._existing_vifs = {}
|
||||
|
@ -1862,7 +1830,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver._get_trunks_info.assert_called_once()
|
||||
self.assertEqual(m_driver._existing_vifs, {})
|
||||
self.assertEqual(m_driver._available_ports_pools, {})
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
def test_delete_network_pools(self):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
|
@ -1871,7 +1839,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
vif_driver = mock.MagicMock(spec=cls_vif_driver)
|
||||
m_driver._drv_vif = vif_driver
|
||||
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
net_id = mock.sentinel.net_id
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
|
@ -1896,7 +1864,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver._drv_vif._remove_subports.assert_called_once_with(trunk_id,
|
||||
[port_id])
|
||||
m_driver._drv_vif._release_vlan_id.assert_called_once_with(vlan_id)
|
||||
neutron.delete_port.assert_called_once_with(port_id)
|
||||
os_net.delete_port.assert_called_once_with(port_id)
|
||||
|
||||
def test_delete_network_pools_not_ready(self):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
|
@ -1904,7 +1872,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
cls_vif_driver = nested_vlan_vif.NestedVlanPodVIFDriver
|
||||
vif_driver = mock.MagicMock(spec=cls_vif_driver)
|
||||
m_driver._drv_vif = vif_driver
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
net_id = mock.sentinel.net_id
|
||||
m_driver._recovered_pools = False
|
||||
|
@ -1916,7 +1884,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver._get_pool_key_net.assert_not_called()
|
||||
m_driver._get_trunk_id.assert_not_called()
|
||||
m_driver._drv_vif._remove_subports.assert_not_called()
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
def test_delete_network_pools_exception(self):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
|
@ -1925,7 +1893,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
vif_driver = mock.MagicMock(spec=cls_vif_driver)
|
||||
m_driver._drv_vif = vif_driver
|
||||
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
net_id = mock.sentinel.net_id
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
|
@ -1941,8 +1909,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
|
||||
m_driver._get_trunk_id.return_value = trunk_id
|
||||
m_driver._get_pool_key_net.return_value = net_id
|
||||
m_driver._drv_vif._remove_subports.side_effect = (
|
||||
n_exc.NeutronClientException)
|
||||
m_driver._drv_vif._remove_subports.side_effect = os_exc.SDKException
|
||||
|
||||
cls.delete_network_pools(m_driver, net_id)
|
||||
|
||||
|
@ -1952,7 +1919,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver._drv_vif._remove_subports.assert_called_once_with(trunk_id,
|
||||
[port_id])
|
||||
m_driver._drv_vif._release_vlan_id.assert_not_called()
|
||||
neutron.delete_port.assert_not_called()
|
||||
os_net.delete_port.assert_not_called()
|
||||
|
||||
def test_delete_network_pools_missing_port(self):
|
||||
cls = vif_pool.NestedVIFPool
|
||||
|
@ -1961,7 +1928,7 @@ class NestedVIFPool(test_base.TestCase):
|
|||
vif_driver = mock.MagicMock(spec=cls_vif_driver)
|
||||
m_driver._drv_vif = vif_driver
|
||||
|
||||
neutron = self.useFixture(k_fix.MockNeutronClient()).client
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
net_id = mock.sentinel.net_id
|
||||
pool_key = ('node_ip', 'project_id')
|
||||
|
@ -1977,7 +1944,6 @@ class NestedVIFPool(test_base.TestCase):
|
|||
|
||||
m_driver._get_trunk_id.return_value = trunk_id
|
||||
m_driver._get_pool_key_net.return_value = net_id
|
||||
neutron.delete_port.side_effect = n_exc.PortNotFoundClient
|
||||
|
||||
cls.delete_network_pools(m_driver, net_id)
|
||||
|
||||
|
@ -1987,4 +1953,4 @@ class NestedVIFPool(test_base.TestCase):
|
|||
m_driver._drv_vif._remove_subports.assert_called_once_with(trunk_id,
|
||||
[port_id])
|
||||
m_driver._drv_vif._release_vlan_id.assert_not_called()
|
||||
neutron.delete_port.assert_called_once_with(port_id)
|
||||
os_net.delete_port.assert_called_once_with(port_id)
|
||||
|
|
Loading…
Reference in New Issue