Enforce E128 pep8 check
This commit removes the last pep8 check that was excluded (E128 continuation line under-indented for visual indent), and cleans up code to match pep8. Change-Id: Ia1a6d672df521c35bbd1579971d27d546f4f5481
This commit is contained in:
parent
dc37f0f006
commit
fcb5cf9840
|
@ -23,71 +23,83 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
kuryr_k8s_opts = [
|
||||
cfg.StrOpt('pybasedir',
|
||||
help=_('Directory where Kuryr-kubernetes python module is '
|
||||
'installed.'),
|
||||
default=os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__),
|
||||
'../../'))),
|
||||
help=_('Directory where Kuryr-kubernetes python module is '
|
||||
'installed.'),
|
||||
default=os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__),
|
||||
'../../'))),
|
||||
]
|
||||
|
||||
k8s_opts = [
|
||||
cfg.StrOpt('api_root',
|
||||
help=_("The root URL of the Kubernetes API"),
|
||||
default=os.environ.get('K8S_API', 'http://localhost:8080')),
|
||||
help=_("The root URL of the Kubernetes API"),
|
||||
default=os.environ.get('K8S_API', 'http://localhost:8080')),
|
||||
cfg.StrOpt('ssl_client_crt_file',
|
||||
help=_("Absolute path to client cert to connect to HTTPS K8S_API")),
|
||||
help=_("Absolute path to client cert to "
|
||||
"connect to HTTPS K8S_API")),
|
||||
cfg.StrOpt('ssl_client_key_file',
|
||||
help=_("Absolute path client key file to connect to HTTPS K8S_API")),
|
||||
help=_("Absolute path client key file to "
|
||||
"connect to HTTPS K8S_API")),
|
||||
cfg.StrOpt('ssl_ca_crt_file',
|
||||
help=_("Absolute path to ca cert file to connect to HTTPS K8S_API")),
|
||||
help=_("Absolute path to ca cert file to "
|
||||
"connect to HTTPS K8S_API")),
|
||||
cfg.BoolOpt('ssl_verify_server_crt',
|
||||
help=_("HTTPS K8S_API server identity verification"),
|
||||
default=False),
|
||||
help=_("HTTPS K8S_API server identity verification"),
|
||||
default=False),
|
||||
cfg.StrOpt('token_file',
|
||||
help=_("The token to talk to the k8s API"),
|
||||
default=''),
|
||||
help=_("The token to talk to the k8s API"),
|
||||
default=''),
|
||||
cfg.StrOpt('pod_project_driver',
|
||||
help=_("The driver to determine OpenStack project for pod ports"),
|
||||
default='default'),
|
||||
help=_("The driver to determine OpenStack "
|
||||
"project for pod ports"),
|
||||
default='default'),
|
||||
cfg.StrOpt('service_project_driver',
|
||||
help=_("The driver to determine OpenStack project for services"),
|
||||
default='default'),
|
||||
help=_("The driver to determine OpenStack "
|
||||
"project for services"),
|
||||
default='default'),
|
||||
cfg.StrOpt('pod_subnets_driver',
|
||||
help=_("The driver to determine Neutron subnets for pod ports"),
|
||||
default='default'),
|
||||
help=_("The driver to determine Neutron "
|
||||
"subnets for pod ports"),
|
||||
default='default'),
|
||||
cfg.StrOpt('service_subnets_driver',
|
||||
help=_("The driver to determine Neutron subnets for services"),
|
||||
default='default'),
|
||||
help=_("The driver to determine Neutron "
|
||||
"subnets for services"),
|
||||
default='default'),
|
||||
cfg.StrOpt('pod_security_groups_driver',
|
||||
help=_("The driver to determine Neutron security groups for pods"),
|
||||
default='default'),
|
||||
help=_("The driver to determine Neutron "
|
||||
"security groups for pods"),
|
||||
default='default'),
|
||||
cfg.StrOpt('service_security_groups_driver',
|
||||
help=_("The driver to determine Neutron security groups for services"),
|
||||
default='default'),
|
||||
help=_("The driver to determine Neutron "
|
||||
"security groups for services"),
|
||||
default='default'),
|
||||
cfg.StrOpt('pod_vif_driver',
|
||||
help=_("The driver that provides VIFs for Kubernetes Pods."),
|
||||
default='neutron-vif'),
|
||||
help=_("The driver that provides VIFs for Kubernetes Pods."),
|
||||
default='neutron-vif'),
|
||||
cfg.StrOpt('endpoints_lbaas_driver',
|
||||
help=_("The driver that provides LoadBalancers for Kubernetes "
|
||||
"Endpoints"),
|
||||
default='lbaasv2'),
|
||||
help=_("The driver that provides LoadBalancers for "
|
||||
"Kubernetes Endpoints"),
|
||||
default='lbaasv2'),
|
||||
cfg.StrOpt('vif_pool_driver',
|
||||
help=_("The driver that manages VIFs pools for Kubernetes Pods."),
|
||||
default='noop'),
|
||||
help=_("The driver that manages VIFs pools for "
|
||||
"Kubernetes Pods."),
|
||||
default='noop'),
|
||||
]
|
||||
|
||||
neutron_defaults = [
|
||||
cfg.StrOpt('project',
|
||||
help=_("Default OpenStack project ID for Kubernetes resources")),
|
||||
help=_("Default OpenStack project ID for "
|
||||
"Kubernetes resources")),
|
||||
cfg.StrOpt('pod_subnet',
|
||||
help=_("Default Neutron subnet ID for Kubernetes pods")),
|
||||
help=_("Default Neutron subnet ID for Kubernetes pods")),
|
||||
cfg.ListOpt('pod_security_groups',
|
||||
help=_("Default Neutron security groups' IDs for Kubernetes pods")),
|
||||
help=_("Default Neutron security groups' IDs "
|
||||
"for Kubernetes pods")),
|
||||
cfg.StrOpt('ovs_bridge',
|
||||
help=_("Default OpenVSwitch integration bridge"),
|
||||
sample_default="br-int"),
|
||||
help=_("Default OpenVSwitch integration bridge"),
|
||||
sample_default="br-int"),
|
||||
cfg.StrOpt('service_subnet',
|
||||
help=_("Default Neutron subnet ID for Kubernetes services")),
|
||||
help=_("Default Neutron subnet ID for Kubernetes services")),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
|
|||
with self.lock:
|
||||
vm_port = self._get_parent_port(neutron, pod)
|
||||
self._add_to_allowed_address_pairs(neutron, vm_port,
|
||||
container_ips, container_mac)
|
||||
container_ips, container_mac)
|
||||
|
||||
return ovu.neutron_to_osvif_vif_nested_macvlan(container_port, subnets)
|
||||
|
||||
|
@ -64,7 +64,8 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
|
|||
with self.lock:
|
||||
vm_port = self._get_parent_port(neutron, pod)
|
||||
self._remove_from_allowed_address_pairs(neutron, vm_port,
|
||||
container_ips, container_mac)
|
||||
container_ips,
|
||||
container_mac)
|
||||
|
||||
try:
|
||||
neutron.delete_port(vif.id)
|
||||
|
@ -83,7 +84,8 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
|
|||
def _add_to_allowed_address_pairs(self, neutron, port, ip_addresses,
|
||||
mac_address=None):
|
||||
if not ip_addresses:
|
||||
raise k_exc.IntegrityError("Cannot add pair from the "
|
||||
raise k_exc.IntegrityError(
|
||||
"Cannot add pair from the "
|
||||
"allowed_address_pairs of port %s: missing IP address",
|
||||
port['id'])
|
||||
|
||||
|
@ -94,11 +96,13 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
|
|||
for pair in address_pairs:
|
||||
if pair['ip_address'] in ip_addresses:
|
||||
if pair['mac_address'] is mac:
|
||||
raise k_exc.AllowedAddressAlreadyPresent("Pair %s already "
|
||||
raise k_exc.AllowedAddressAlreadyPresent(
|
||||
"Pair %s already "
|
||||
"present in the 'allowed_address_pair' list. This is "
|
||||
"due to a misconfiguration or a bug", pair)
|
||||
else:
|
||||
LOG.warning("A pair with IP %s but different MAC address "
|
||||
LOG.warning(
|
||||
"A pair with IP %s but different MAC address "
|
||||
"is already present in the 'allowed_address_pair'. "
|
||||
"This could indicate a misconfiguration or a "
|
||||
"bug", pair['ip_address'])
|
||||
|
@ -111,7 +115,8 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
|
|||
def _remove_from_allowed_address_pairs(self, neutron, port, ip_addresses,
|
||||
mac_address=None):
|
||||
if not ip_addresses:
|
||||
raise k_exc.IntegrityError("Cannot remove pair from the "
|
||||
raise k_exc.IntegrityError(
|
||||
"Cannot remove pair from the "
|
||||
"allowed_address_pairs of port %s: missing IP address",
|
||||
port['id'])
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ LOG = logging.getLogger(__name__)
|
|||
# Moved out from neutron_defaults group
|
||||
nested_vif_driver_opts = [
|
||||
oslo_cfg.StrOpt('worker_nodes_subnet',
|
||||
help=_("Neutron subnet ID for k8s worker node vms.")),
|
||||
help=_("Neutron subnet ID for k8s worker node vms.")),
|
||||
]
|
||||
|
||||
oslo_cfg.CONF.register_opts(nested_vif_driver_opts, "pod_vif_nested")
|
||||
|
@ -43,8 +43,8 @@ class NestedPodVIFDriver(neutron_vif.NeutronPodVIFDriver):
|
|||
def _get_parent_port_by_host_ip(self, neutron, node_fixed_ip):
|
||||
node_subnet_id = oslo_cfg.CONF.pod_vif_nested.worker_nodes_subnet
|
||||
if not node_subnet_id:
|
||||
raise oslo_cfg.RequiredOptError('worker_nodes_subnet',
|
||||
oslo_cfg.OptGroup('pod_vif_nested'))
|
||||
raise oslo_cfg.RequiredOptError(
|
||||
'worker_nodes_subnet', oslo_cfg.OptGroup('pod_vif_nested'))
|
||||
|
||||
try:
|
||||
fixed_ips = ['subnet_id=%s' % str(node_subnet_id),
|
||||
|
|
|
@ -64,8 +64,9 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
|
|||
parent_port = self._get_parent_port(neutron, pod)
|
||||
trunk_id = self._get_trunk_id(parent_port)
|
||||
|
||||
port_rq, subports_info = self._create_subports_info(pod, project_id,
|
||||
subnets, security_groups, trunk_id, num_ports, unbound=True)
|
||||
port_rq, subports_info = self._create_subports_info(
|
||||
pod, project_id, subnets, security_groups,
|
||||
trunk_id, num_ports, unbound=True)
|
||||
|
||||
if not subports_info:
|
||||
LOG.error("There are no vlan ids available to create subports")
|
||||
|
@ -136,7 +137,7 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
|
|||
|
||||
in_use_vlan_ids = self._get_in_use_vlan_ids_set(trunk_id)
|
||||
port_rq = self._get_port_request(pod, project_id, subnets,
|
||||
security_groups, unbound)['port']
|
||||
security_groups, unbound)['port']
|
||||
for i in range(num_ports):
|
||||
try:
|
||||
vlan_id = seg_driver.allocate_segmentation_id(in_use_vlan_ids)
|
||||
|
@ -207,7 +208,7 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
|
|||
subport_id = [{'port_id': subport_id}]
|
||||
try:
|
||||
neutron.trunk_remove_subports(trunk_id,
|
||||
{'sub_ports': subport_id})
|
||||
{'sub_ports': subport_id})
|
||||
except n_exc.NeutronClientException as ex:
|
||||
LOG.error(
|
||||
"Error happened during subport removal from "
|
||||
|
|
|
@ -120,8 +120,9 @@ class NeutronPodVIFDriver(base.PodVIFDriver):
|
|||
ids = ovu.osvif_to_neutron_network_ids(subnets)
|
||||
|
||||
if len(ids) != 1:
|
||||
raise k_exc.IntegrityError("Subnet mapping %(subnets)s is not "
|
||||
"valid: %(num_networks)s unique networks found" %
|
||||
raise k_exc.IntegrityError(
|
||||
"Subnet mapping %(subnets)s is not valid: "
|
||||
"%(num_networks)s unique networks found" %
|
||||
{'subnets': subnets, 'num_networks': len(ids)})
|
||||
|
||||
return ids[0]
|
||||
|
|
|
@ -33,17 +33,19 @@ LOG = logging.getLogger(__name__)
|
|||
# Moved out from neutron_default group
|
||||
vif_pool_driver_opts = [
|
||||
oslo_cfg.IntOpt('ports_pool_max',
|
||||
help=_("Set a maximun amount of ports per pool. 0 to disable"),
|
||||
default=0),
|
||||
help=_("Set a maximun amount of ports per pool. "
|
||||
"0 to disable"),
|
||||
default=0),
|
||||
oslo_cfg.IntOpt('ports_pool_min',
|
||||
help=_("Set a target minimum size of the pool of ports"),
|
||||
default=5),
|
||||
help=_("Set a target minimum size of the pool of ports"),
|
||||
default=5),
|
||||
oslo_cfg.IntOpt('ports_pool_batch',
|
||||
help=_("Number of ports to be created in a bulk request"),
|
||||
default=10),
|
||||
help=_("Number of ports to be created in a bulk request"),
|
||||
default=10),
|
||||
oslo_cfg.IntOpt('ports_pool_update_frequency',
|
||||
help=_("Minimun interval (in seconds) between pool updates"),
|
||||
default=20),
|
||||
help=_("Minimun interval (in seconds) "
|
||||
"between pool updates"),
|
||||
default=20),
|
||||
]
|
||||
|
||||
oslo_cfg.CONF.register_opts(vif_pool_driver_opts, "vif_pool")
|
||||
|
@ -141,8 +143,9 @@ class BaseVIFPool(base.VIFPoolDriver):
|
|||
pool_size = self._get_pool_size(pool_key)
|
||||
if pool_size < oslo_cfg.CONF.vif_pool.ports_pool_min:
|
||||
num_ports = max(oslo_cfg.CONF.vif_pool.ports_pool_batch,
|
||||
oslo_cfg.CONF.vif_pool.ports_pool_min - pool_size)
|
||||
vifs = self._drv_vif.request_vifs(pod=pod,
|
||||
oslo_cfg.CONF.vif_pool.ports_pool_min - pool_size)
|
||||
vifs = self._drv_vif.request_vifs(
|
||||
pod=pod,
|
||||
project_id=pool_key[1],
|
||||
subnets=subnets,
|
||||
security_groups=list(pool_key[2]),
|
||||
|
@ -170,7 +173,8 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
except IndexError:
|
||||
raise exceptions.ResourceNotReady(pod)
|
||||
neutron = clients.get_neutron_client()
|
||||
neutron.update_port(port_id,
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': pod['metadata']['name'],
|
||||
|
@ -201,7 +205,8 @@ class NeutronVIFPool(BaseVIFPool):
|
|||
self._get_pool_size(pool_key) <
|
||||
oslo_cfg.CONF.vif_pool.ports_pool_max):
|
||||
try:
|
||||
neutron.update_port(port_id,
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': 'available-port',
|
||||
|
@ -244,7 +249,8 @@ class NestedVIFPool(BaseVIFPool):
|
|||
except IndexError:
|
||||
raise exceptions.ResourceNotReady(pod)
|
||||
neutron = clients.get_neutron_client()
|
||||
neutron.update_port(port_id,
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': pod['metadata']['name'],
|
||||
|
@ -274,7 +280,8 @@ class NestedVIFPool(BaseVIFPool):
|
|||
self._get_pool_size(pool_key) <
|
||||
oslo_cfg.CONF.vif_pool.ports_pool_max):
|
||||
try:
|
||||
neutron.update_port(port_id,
|
||||
neutron.update_port(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': 'available-port',
|
||||
|
|
|
@ -72,8 +72,8 @@ class K8sClient(object):
|
|||
if self.token:
|
||||
header.update({'Authorization': 'Bearer %s' % self.token})
|
||||
response = requests.get(url, cert=self.cert,
|
||||
verify=self.verify_server,
|
||||
headers=header)
|
||||
verify=self.verify_server,
|
||||
headers=header)
|
||||
if not response.ok:
|
||||
raise exc.K8sClientException(response.text)
|
||||
return response.json()
|
||||
|
@ -100,8 +100,9 @@ class K8sClient(object):
|
|||
"resourceVersion": resource_version,
|
||||
}
|
||||
}, sort_keys=True)
|
||||
response = requests.patch(url, data=data, headers=header,
|
||||
cert=self.cert, verify=self.verify_server)
|
||||
response = requests.patch(url, data=data,
|
||||
headers=header, cert=self.cert,
|
||||
verify=self.verify_server)
|
||||
if response.ok:
|
||||
return response.json()['metadata']['annotations']
|
||||
if response.status_code == requests.codes.conflict:
|
||||
|
@ -133,8 +134,8 @@ class K8sClient(object):
|
|||
while True:
|
||||
with contextlib.closing(
|
||||
requests.get(url, params=params, stream=True,
|
||||
cert=self.cert, verify=self.verify_server,
|
||||
headers=header)) as response:
|
||||
cert=self.cert, verify=self.verify_server,
|
||||
headers=header)) as response:
|
||||
if not response.ok:
|
||||
raise exc.K8sClientException(response.text)
|
||||
for line in response.iter_lines(delimiter='\n'):
|
||||
|
|
|
@ -309,8 +309,9 @@ def neutron_to_osvif_vif(vif_translator, neutron_port, subnets):
|
|||
try:
|
||||
mgr = _VIF_MANAGERS[vif_translator]
|
||||
except KeyError:
|
||||
mgr = stv_driver.DriverManager(namespace=_VIF_TRANSLATOR_NAMESPACE,
|
||||
name=vif_translator, invoke_on_load=False)
|
||||
mgr = stv_driver.DriverManager(
|
||||
namespace=_VIF_TRANSLATOR_NAMESPACE,
|
||||
name=vif_translator, invoke_on_load=False)
|
||||
_VIF_MANAGERS[vif_translator] = mgr
|
||||
|
||||
return mgr.driver(vif_translator, neutron_port, subnets)
|
||||
|
|
|
@ -40,7 +40,7 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
container_mac = mock.sentinel.mac_address
|
||||
container_ip = mock.sentinel.ip_address
|
||||
container_port = self._get_fake_port(mac_address=container_mac,
|
||||
ip_address=container_ip)
|
||||
ip_address=container_ip)
|
||||
|
||||
vif = mock.Mock()
|
||||
port_request = mock.sentinel.port_request
|
||||
|
@ -55,8 +55,8 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
self.assertEqual(vif, cls.request_vif(m_driver, pod, project_id,
|
||||
subnets, security_groups))
|
||||
|
||||
m_driver._get_port_request.assert_called_once_with(pod, project_id,
|
||||
subnets, security_groups)
|
||||
m_driver._get_port_request.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups)
|
||||
neutron.create_port.assert_called_once_with(port_request)
|
||||
m_driver._get_parent_port.assert_called_once_with(neutron, pod)
|
||||
m_driver._add_to_allowed_address_pairs.assert_called_once_with(
|
||||
|
@ -81,8 +81,8 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
|
||||
self.assertRaises(n_exc.NeutronClientException, cls.request_vif,
|
||||
m_driver, pod, project_id, subnets, security_groups)
|
||||
m_driver._get_port_request.assert_called_once_with(pod, project_id,
|
||||
subnets, security_groups)
|
||||
m_driver._get_port_request.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups)
|
||||
neutron.create_port.assert_called_once_with(port_request)
|
||||
m_driver._add_to_allowed_address_pairs.assert_not_called()
|
||||
m_to_vif.assert_not_called()
|
||||
|
@ -101,7 +101,7 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
container_mac = mock.sentinel.mac_address
|
||||
container_ip = mock.sentinel.ip_address
|
||||
container_port = self._get_fake_port(mac_address=container_mac,
|
||||
ip_address=container_ip)
|
||||
ip_address=container_ip)
|
||||
|
||||
port_request = mock.sentinel.port_request
|
||||
m_driver._get_port_request.return_value = port_request
|
||||
|
@ -111,8 +111,8 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
|
||||
self.assertRaises(n_exc.NeutronClientException, cls.request_vif,
|
||||
m_driver, pod, project_id, subnets, security_groups)
|
||||
m_driver._get_port_request.assert_called_once_with(pod, project_id,
|
||||
subnets, security_groups)
|
||||
m_driver._get_port_request.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups)
|
||||
neutron.create_port.assert_called_once_with(port_request)
|
||||
m_driver._get_parent_port.assert_called_once_with(neutron, pod)
|
||||
m_driver._add_to_allowed_address_pairs.assert_not_called()
|
||||
|
@ -256,8 +256,8 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
cls._add_to_allowed_address_pairs(m_driver, neutron, vm_port,
|
||||
frozenset([ip_addr]), m_mac)
|
||||
|
||||
m_driver._update_port_address_pairs.assert_called_once_with(neutron,
|
||||
port_id, address_pairs)
|
||||
m_driver._update_port_address_pairs.assert_called_once_with(
|
||||
neutron, port_id, address_pairs)
|
||||
|
||||
def test_add_to_allowed_address_pairs_no_ip_addresses(self):
|
||||
cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
|
||||
|
@ -293,8 +293,8 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
cls._add_to_allowed_address_pairs(m_driver, neutron, vm_port,
|
||||
frozenset([ip_addr]), mac_addr)
|
||||
|
||||
m_driver._update_port_address_pairs.assert_called_once_with(neutron,
|
||||
port_id, address_pairs)
|
||||
m_driver._update_port_address_pairs.assert_called_once_with(
|
||||
neutron, port_id, address_pairs)
|
||||
|
||||
def test_add_to_allowed_address_pairs_already_present(self):
|
||||
cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
|
||||
|
@ -342,11 +342,11 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
'mac_address': m_mac if m_mac else vm_port['mac_address']}
|
||||
)
|
||||
|
||||
cls._remove_from_allowed_address_pairs(m_driver, neutron,
|
||||
vm_port, frozenset([ip_addr]), m_mac)
|
||||
cls._remove_from_allowed_address_pairs(
|
||||
m_driver, neutron, vm_port, frozenset([ip_addr]), m_mac)
|
||||
|
||||
m_driver._update_port_address_pairs.assert_called_once_with(neutron,
|
||||
port_id, address_pairs)
|
||||
m_driver._update_port_address_pairs.assert_called_once_with(
|
||||
neutron, port_id, address_pairs)
|
||||
|
||||
def test_remove_from_allowed_address_pairs_no_ip_addresses(self):
|
||||
cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
|
||||
|
@ -382,11 +382,11 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
'mac_address': mac_addr})
|
||||
ip_addr = ['10.0.0.29', '10.0.0.28']
|
||||
|
||||
cls._remove_from_allowed_address_pairs(m_driver, neutron,
|
||||
vm_port, frozenset(ip_addr), m_mac)
|
||||
cls._remove_from_allowed_address_pairs(
|
||||
m_driver, neutron, vm_port, frozenset(ip_addr), m_mac)
|
||||
|
||||
m_driver._update_port_address_pairs.assert_called_once_with(neutron,
|
||||
port_id, address_pairs)
|
||||
m_driver._update_port_address_pairs.assert_called_once_with(
|
||||
neutron, port_id, address_pairs)
|
||||
|
||||
@ddt.data((None), ('fa:16:3e:71:cb:80'))
|
||||
def test_remove_from_allowed_address_pairs_no_update(self, m_mac):
|
||||
|
@ -408,8 +408,8 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
|
||||
ip_addr = ['10.0.0.29']
|
||||
|
||||
cls._remove_from_allowed_address_pairs(m_driver, neutron,
|
||||
vm_port, frozenset(ip_addr), m_mac)
|
||||
cls._remove_from_allowed_address_pairs(
|
||||
m_driver, neutron, vm_port, frozenset(ip_addr), m_mac)
|
||||
|
||||
m_driver._update_port_address_pairs.assert_not_called()
|
||||
|
||||
|
@ -423,7 +423,8 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
|
||||
cls._update_port_address_pairs(m_driver, neutron, port_id, pairs)
|
||||
|
||||
neutron.update_port.assert_called_with(port_id,
|
||||
neutron.update_port.assert_called_with(
|
||||
port_id,
|
||||
{'port': {'allowed_address_pairs': pairs}})
|
||||
|
||||
def test_update_port_address_pairs_failure(self):
|
||||
|
@ -439,7 +440,8 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
|
|||
cls._update_port_address_pairs, m_driver, neutron,
|
||||
port_id, pairs)
|
||||
|
||||
neutron.update_port.assert_called_with(port_id,
|
||||
neutron.update_port.assert_called_with(
|
||||
port_id,
|
||||
{'port': {'allowed_address_pairs': pairs}})
|
||||
|
||||
# TODO(garyloug) consider exending and moving to a parent class
|
||||
|
|
|
@ -71,7 +71,8 @@ class TestNestedPodVIFDriver(test_base.TestCase):
|
|||
group='pod_vif_nested')
|
||||
node_fixed_ip = mock.sentinel.node_fixed_ip
|
||||
self.assertRaises(oslo_cfg.RequiredOptError,
|
||||
cls._get_parent_port_by_host_ip, m_driver, neutron, node_fixed_ip)
|
||||
cls._get_parent_port_by_host_ip,
|
||||
m_driver, neutron, node_fixed_ip)
|
||||
|
||||
def test_get_parent_port_by_host_ip_trunk_not_found(self):
|
||||
cls = nested_vif.NestedPodVIFDriver
|
||||
|
@ -90,8 +91,8 @@ class TestNestedPodVIFDriver(test_base.TestCase):
|
|||
neutron.list_ports.return_value = ports
|
||||
|
||||
self.assertRaises(kl_exc.NoResourceException,
|
||||
cls._get_parent_port_by_host_ip, m_driver, neutron,
|
||||
node_fixed_ip)
|
||||
cls._get_parent_port_by_host_ip, m_driver, neutron,
|
||||
node_fixed_ip)
|
||||
fixed_ips = ['subnet_id=%s' % str(node_subnet_id),
|
||||
'ip_address=%s' % str(node_fixed_ip)]
|
||||
neutron.list_ports.assert_called_once_with(fixed_ips=fixed_ips)
|
||||
|
|
|
@ -106,12 +106,12 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
|
||||
m_driver._get_parent_port.assert_called_once_with(neutron, pod)
|
||||
m_driver._get_trunk_id.assert_called_once_with(parent_port)
|
||||
m_driver._create_subports_info.assert_called_once_with(pod,
|
||||
project_id, subnets, security_groups, trunk_id, num_ports,
|
||||
m_driver._create_subports_info.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups, trunk_id, num_ports,
|
||||
unbound=True)
|
||||
neutron.create_port.assert_called_once_with(bulk_rq)
|
||||
neutron.trunk_add_subports.assert_called_once_with(trunk_id,
|
||||
{'sub_ports': subports_info})
|
||||
neutron.trunk_add_subports.assert_called_once_with(
|
||||
trunk_id, {'sub_ports': subports_info})
|
||||
neutron.delete_port.assert_not_called()
|
||||
|
||||
calls = [mock.call(port, subnets, info['segmentation_id'])
|
||||
|
@ -145,8 +145,9 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
|
||||
m_driver._get_parent_port.assert_called_once_with(neutron, pod)
|
||||
m_driver._get_trunk_id.assert_called_once_with(parent_port)
|
||||
m_driver._create_subports_info.assert_called_once_with(pod, project_id,
|
||||
subnets, security_groups, trunk_id, num_ports, unbound=True)
|
||||
m_driver._create_subports_info.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups,
|
||||
trunk_id, num_ports, unbound=True)
|
||||
|
||||
def test_request_vifs_bulk_creation_exception(self):
|
||||
cls = nested_vlan_vif.NestedVlanPodVIFDriver
|
||||
|
@ -177,14 +178,15 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
subports_info)
|
||||
neutron.create_port.side_effect = n_exc.NeutronClientException
|
||||
|
||||
self.assertRaises(n_exc.NeutronClientException, cls.request_vifs,
|
||||
self.assertRaises(
|
||||
n_exc.NeutronClientException, cls.request_vifs,
|
||||
m_driver, pod, project_id, subnets, security_groups, num_ports)
|
||||
|
||||
m_driver._get_parent_port.assert_called_once_with(neutron, pod)
|
||||
m_driver._get_trunk_id.assert_called_once_with(parent_port)
|
||||
m_driver._create_subports_info.assert_called_once_with(pod,
|
||||
project_id, subnets, security_groups, trunk_id, num_ports,
|
||||
unbound=True)
|
||||
m_driver._create_subports_info.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups,
|
||||
trunk_id, num_ports, unbound=True)
|
||||
neutron.create_port.assert_called_once_with(bulk_rq)
|
||||
|
||||
def test_request_vifs_trunk_subports_conflict(self):
|
||||
|
@ -219,16 +221,17 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
neutron.trunk_add_subports.side_effect = n_exc.Conflict
|
||||
|
||||
self.assertRaises(n_exc.Conflict, cls.request_vifs,
|
||||
m_driver, pod, project_id, subnets, security_groups, num_ports)
|
||||
m_driver, pod, project_id, subnets,
|
||||
security_groups, num_ports)
|
||||
|
||||
m_driver._get_parent_port.assert_called_once_with(neutron, pod)
|
||||
m_driver._get_trunk_id.assert_called_once_with(parent_port)
|
||||
m_driver._create_subports_info.assert_called_once_with(pod,
|
||||
project_id, subnets, security_groups, trunk_id, num_ports,
|
||||
unbound=True)
|
||||
m_driver._create_subports_info.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups,
|
||||
trunk_id, num_ports, unbound=True)
|
||||
neutron.create_port.assert_called_once_with(bulk_rq)
|
||||
neutron.trunk_add_subports.assert_called_once_with(trunk_id,
|
||||
{'sub_ports': subports_info})
|
||||
neutron.trunk_add_subports.assert_called_once_with(
|
||||
trunk_id, {'sub_ports': subports_info})
|
||||
neutron.delete_port.assert_called_with(port['id'])
|
||||
|
||||
def test_request_vifs_trunk_subports_exception(self):
|
||||
|
@ -263,16 +266,17 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
neutron.trunk_add_subports.side_effect = n_exc.NeutronClientException
|
||||
|
||||
self.assertRaises(n_exc.NeutronClientException, cls.request_vifs,
|
||||
m_driver, pod, project_id, subnets, security_groups, num_ports)
|
||||
m_driver, pod, project_id, subnets,
|
||||
security_groups, num_ports)
|
||||
|
||||
m_driver._get_parent_port.assert_called_once_with(neutron, pod)
|
||||
m_driver._get_trunk_id.assert_called_once_with(parent_port)
|
||||
m_driver._create_subports_info.assert_called_once_with(pod,
|
||||
project_id, subnets, security_groups, trunk_id, num_ports,
|
||||
unbound=True)
|
||||
m_driver._create_subports_info.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups,
|
||||
trunk_id, num_ports, unbound=True)
|
||||
neutron.create_port.assert_called_once_with(bulk_rq)
|
||||
neutron.trunk_add_subports.assert_called_once_with(trunk_id,
|
||||
{'sub_ports': subports_info})
|
||||
neutron.trunk_add_subports.assert_called_once_with(
|
||||
trunk_id, {'sub_ports': subports_info})
|
||||
neutron.delete_port.assert_not_called()
|
||||
|
||||
def test_release_vif(self):
|
||||
|
@ -401,8 +405,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
self.assertEqual(subports_res, subports_info)
|
||||
|
||||
m_driver._get_in_use_vlan_ids_set.assert_called_once_with(trunk_id)
|
||||
m_driver._get_port_request.assert_called_once_with(pod, project_id,
|
||||
subnets, security_groups, False)
|
||||
m_driver._get_port_request.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups, False)
|
||||
self.assertEqual(m_allocate_seg_id.call_count, 2)
|
||||
|
||||
@mock.patch('kuryr.lib.segmentation_type_drivers.allocate_segmentation_id')
|
||||
|
@ -424,8 +428,9 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
|
||||
m_driver._get_in_use_vlan_ids_set.return_value = in_use_vlan
|
||||
m_driver._get_port_request.return_value = {'port': port}
|
||||
m_allocate_seg_id.side_effect = [2,
|
||||
kl_exc.SegmentationIdAllocationFailure]
|
||||
m_allocate_seg_id.side_effect = [
|
||||
2, kl_exc.SegmentationIdAllocationFailure
|
||||
]
|
||||
|
||||
port_res, subports_res = cls._create_subports_info(
|
||||
m_driver, pod, project_id, subnets, security_groups, trunk_id,
|
||||
|
@ -435,8 +440,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
self.assertEqual(subports_res, subports_info)
|
||||
|
||||
m_driver._get_in_use_vlan_ids_set.assert_called_once_with(trunk_id)
|
||||
m_driver._get_port_request.assert_called_once_with(pod, project_id,
|
||||
subnets, security_groups, False)
|
||||
m_driver._get_port_request.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups, False)
|
||||
self.assertEqual(m_allocate_seg_id.call_count, 2)
|
||||
|
||||
@mock.patch('kuryr.lib.segmentation_type_drivers.allocate_segmentation_id')
|
||||
|
@ -465,8 +470,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
self.assertEqual(subports_res, [])
|
||||
|
||||
m_driver._get_in_use_vlan_ids_set.assert_called_once_with(trunk_id)
|
||||
m_driver._get_port_request.assert_called_once_with(pod, project_id,
|
||||
subnets, security_groups, False)
|
||||
m_driver._get_port_request.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups, False)
|
||||
self.assertEqual(m_allocate_seg_id.call_count, 1)
|
||||
|
||||
def test_get_trunk_id(self):
|
||||
|
@ -483,7 +488,7 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
trunk_id = mock.sentinel.trunk_id
|
||||
port = {'trunk_details_missing': {'trunk_id_missing': trunk_id}}
|
||||
self.assertRaises(k_exc.K8sNodeTrunkPortFailure,
|
||||
cls._get_trunk_id, m_driver, port)
|
||||
cls._get_trunk_id, m_driver, port)
|
||||
|
||||
def test_add_subport(self):
|
||||
cls = nested_vlan_vif.NestedVlanPodVIFDriver
|
||||
|
@ -494,14 +499,14 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
vlan_id = mock.sentinel.vlan_id
|
||||
m_driver._get_vlan_id.return_value = vlan_id
|
||||
subport_dict = [{'segmentation_id': vlan_id,
|
||||
'port_id': subport,
|
||||
'segmentation_type': 'vlan'}]
|
||||
'port_id': subport,
|
||||
'segmentation_type': 'vlan'}]
|
||||
nested_vlan_vif.DEFAULT_MAX_RETRY_COUNT = 1
|
||||
self.assertEqual(vlan_id, cls._add_subport(m_driver,
|
||||
neutron, trunk_id, subport))
|
||||
neutron, trunk_id, subport))
|
||||
m_driver._get_vlan_id.assert_called_once_with(trunk_id)
|
||||
neutron.trunk_add_subports.assert_called_once_with(trunk_id,
|
||||
{'sub_ports': subport_dict})
|
||||
neutron.trunk_add_subports.assert_called_once_with(
|
||||
trunk_id, {'sub_ports': subport_dict})
|
||||
|
||||
def test_add_subport_get_vlanid_failure(self):
|
||||
cls = nested_vlan_vif.NestedVlanPodVIFDriver
|
||||
|
@ -511,8 +516,9 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
subport = mock.sentinel.subport
|
||||
m_driver._get_vlan_id.side_effect = n_exc.NeutronClientException
|
||||
nested_vlan_vif.DEFAULT_MAX_RETRY_COUNT = 1
|
||||
self.assertRaises(n_exc.NeutronClientException,
|
||||
cls._add_subport, m_driver, neutron, trunk_id, subport)
|
||||
self.assertRaises(
|
||||
n_exc.NeutronClientException, cls._add_subport,
|
||||
m_driver, neutron, trunk_id, subport)
|
||||
|
||||
m_driver._get_vlan_id.assert_called_once_with(trunk_id)
|
||||
|
||||
|
@ -525,15 +531,15 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
vlan_id = mock.sentinel.vlan_id
|
||||
m_driver._get_vlan_id.return_value = vlan_id
|
||||
subport_dict = [{'segmentation_id': vlan_id,
|
||||
'port_id': subport,
|
||||
'segmentation_type': 'vlan'}]
|
||||
'port_id': subport,
|
||||
'segmentation_type': 'vlan'}]
|
||||
neutron.trunk_add_subports.side_effect = n_exc.Conflict
|
||||
nested_vlan_vif.DEFAULT_MAX_RETRY_COUNT = 1
|
||||
self.assertRaises(n_exc.Conflict, cls._add_subport, m_driver,
|
||||
neutron, trunk_id, subport)
|
||||
|
||||
neutron.trunk_add_subports.assert_called_once_with(trunk_id,
|
||||
{'sub_ports': subport_dict})
|
||||
neutron.trunk_add_subports.assert_called_once_with(
|
||||
trunk_id, {'sub_ports': subport_dict})
|
||||
|
||||
def test_remove_subport(self):
|
||||
cls = nested_vlan_vif.NestedVlanPodVIFDriver
|
||||
|
@ -544,8 +550,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
subportid_dict = [{'port_id': subport_id}]
|
||||
cls._remove_subport(m_driver, neutron, trunk_id, subport_id)
|
||||
|
||||
neutron.trunk_remove_subports.assert_called_once_with(trunk_id,
|
||||
{'sub_ports': subportid_dict})
|
||||
neutron.trunk_remove_subports.assert_called_once_with(
|
||||
trunk_id, {'sub_ports': subportid_dict})
|
||||
|
||||
@mock.patch('kuryr.lib.segmentation_type_drivers.allocate_segmentation_id')
|
||||
def test_get_vlan_id(self, mock_alloc_seg_id):
|
||||
|
@ -597,4 +603,4 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
trunk.__getitem__.return_value = trunk_obj
|
||||
neutron.show_trunk.return_value = trunk
|
||||
self.assertEqual(vlan_ids,
|
||||
cls._get_in_use_vlan_ids_set(m_driver, trunk_id))
|
||||
cls._get_in_use_vlan_ids_set(m_driver, trunk_id))
|
||||
|
|
|
@ -108,7 +108,8 @@ class NeutronPodVIFDriver(test_base.TestCase):
|
|||
neutron.create_port.side_effect = n_exc.NeutronClientException
|
||||
|
||||
self.assertRaises(n_exc.NeutronClientException, cls.request_vifs,
|
||||
m_driver, pod, project_id, subnets, security_groups, num_ports)
|
||||
m_driver, pod, project_id, subnets,
|
||||
security_groups, num_ports)
|
||||
|
||||
m_driver._get_port_request.assert_called_once_with(
|
||||
pod, project_id, subnets, security_groups, unbound=True)
|
||||
|
|
|
@ -220,7 +220,8 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets))
|
||||
|
||||
neutron.update_port.assert_called_once_with(port_id,
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': pod['metadata']['name'],
|
||||
|
@ -255,7 +256,8 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets))
|
||||
|
||||
neutron.update_port.assert_called_once_with(port_id,
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': pod['metadata']['name'],
|
||||
|
@ -316,7 +318,8 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
|
||||
self.assertRaises(SystemExit, cls._return_ports_to_pool, m_driver)
|
||||
|
||||
neutron.update_port.assert_called_once_with(port_id,
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': 'available-port',
|
||||
|
@ -370,7 +373,8 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
|
||||
self.assertRaises(SystemExit, cls._return_ports_to_pool, m_driver)
|
||||
|
||||
neutron.update_port.assert_called_once_with(port_id,
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': 'available-port',
|
||||
|
@ -592,7 +596,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets))
|
||||
|
||||
neutron.update_port.assert_called_once_with(port_id,
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': pod['metadata']['name'],
|
||||
|
@ -626,7 +631,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
self.assertEqual(port, cls._get_port_from_pool(
|
||||
m_driver, pool_key, pod, subnets))
|
||||
|
||||
neutron.update_port.assert_called_once_with(port_id,
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': pod['metadata']['name'],
|
||||
|
@ -686,7 +692,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
|
||||
self.assertRaises(SystemExit, cls._return_ports_to_pool, m_driver)
|
||||
|
||||
neutron.update_port.assert_called_once_with(port_id,
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': 'available-port',
|
||||
|
@ -753,7 +760,8 @@ class NestedVIFPool(test_base.TestCase):
|
|||
|
||||
self.assertRaises(SystemExit, cls._return_ports_to_pool, m_driver)
|
||||
|
||||
neutron.update_port.assert_called_once_with(port_id,
|
||||
neutron.update_port.assert_called_once_with(
|
||||
port_id,
|
||||
{
|
||||
"port": {
|
||||
'name': 'available-port',
|
||||
|
|
|
@ -115,7 +115,8 @@ class TestK8sClient(test_base.TestCase):
|
|||
m_get.return_value = m_resp
|
||||
|
||||
self.assertEqual(ret, self.client.get(path))
|
||||
m_get.assert_called_once_with(self.base_url + path,
|
||||
m_get.assert_called_once_with(
|
||||
self.base_url + path,
|
||||
cert=(None, None), headers={}, verify=False)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
|
|
|
@ -264,7 +264,7 @@ class TestOSVIFUtils(test_base.TestCase):
|
|||
@mock.patch('kuryr_kubernetes.os_vif_util._make_vif_network')
|
||||
@mock.patch('kuryr_kubernetes.objects.vif.VIFVlanNested')
|
||||
def test_neutron_to_osvif_nested_vlan(self, m_mk_vif, m_make_vif_network,
|
||||
m_is_port_active, m_get_vif_name):
|
||||
m_is_port_active, m_get_vif_name):
|
||||
vif_plugin = const.K8S_OS_VIF_NOOP_PLUGIN
|
||||
port_id = mock.sentinel.port_id
|
||||
mac_address = mock.sentinel.mac_address
|
||||
|
@ -309,7 +309,8 @@ class TestOSVIFUtils(test_base.TestCase):
|
|||
@mock.patch('kuryr_kubernetes.os_vif_util._make_vif_network')
|
||||
@mock.patch('kuryr_kubernetes.objects.vif.VIFMacvlanNested')
|
||||
def test_neutron_to_osvif_nested_macvlan(self, m_mk_vif,
|
||||
m_make_vif_network, m_is_port_active, m_get_vif_name):
|
||||
m_make_vif_network,
|
||||
m_is_port_active, m_get_vif_name):
|
||||
vif_plugin = const.K8S_OS_VIF_NOOP_PLUGIN
|
||||
port_id = mock.sentinel.port_id
|
||||
mac_address = mock.sentinel.mac_address
|
||||
|
|
Loading…
Reference in New Issue