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:
Kirill Zaitsev 2017-06-08 15:53:52 +03:00
parent dc37f0f006
commit fcb5cf9840
16 changed files with 208 additions and 162 deletions

View File

@ -35,11 +35,14 @@ k8s_opts = [
help=_("The root URL of the Kubernetes API"), help=_("The root URL of the Kubernetes API"),
default=os.environ.get('K8S_API', 'http://localhost:8080')), default=os.environ.get('K8S_API', 'http://localhost:8080')),
cfg.StrOpt('ssl_client_crt_file', 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', 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', 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', cfg.BoolOpt('ssl_verify_server_crt',
help=_("HTTPS K8S_API server identity verification"), help=_("HTTPS K8S_API server identity verification"),
default=False), default=False),
@ -47,42 +50,51 @@ k8s_opts = [
help=_("The token to talk to the k8s API"), help=_("The token to talk to the k8s API"),
default=''), default=''),
cfg.StrOpt('pod_project_driver', cfg.StrOpt('pod_project_driver',
help=_("The driver to determine OpenStack project for pod ports"), help=_("The driver to determine OpenStack "
"project for pod ports"),
default='default'), default='default'),
cfg.StrOpt('service_project_driver', cfg.StrOpt('service_project_driver',
help=_("The driver to determine OpenStack project for services"), help=_("The driver to determine OpenStack "
"project for services"),
default='default'), default='default'),
cfg.StrOpt('pod_subnets_driver', cfg.StrOpt('pod_subnets_driver',
help=_("The driver to determine Neutron subnets for pod ports"), help=_("The driver to determine Neutron "
"subnets for pod ports"),
default='default'), default='default'),
cfg.StrOpt('service_subnets_driver', cfg.StrOpt('service_subnets_driver',
help=_("The driver to determine Neutron subnets for services"), help=_("The driver to determine Neutron "
"subnets for services"),
default='default'), default='default'),
cfg.StrOpt('pod_security_groups_driver', cfg.StrOpt('pod_security_groups_driver',
help=_("The driver to determine Neutron security groups for pods"), help=_("The driver to determine Neutron "
"security groups for pods"),
default='default'), default='default'),
cfg.StrOpt('service_security_groups_driver', cfg.StrOpt('service_security_groups_driver',
help=_("The driver to determine Neutron security groups for services"), help=_("The driver to determine Neutron "
"security groups for services"),
default='default'), default='default'),
cfg.StrOpt('pod_vif_driver', cfg.StrOpt('pod_vif_driver',
help=_("The driver that provides VIFs for Kubernetes Pods."), help=_("The driver that provides VIFs for Kubernetes Pods."),
default='neutron-vif'), default='neutron-vif'),
cfg.StrOpt('endpoints_lbaas_driver', cfg.StrOpt('endpoints_lbaas_driver',
help=_("The driver that provides LoadBalancers for Kubernetes " help=_("The driver that provides LoadBalancers for "
"Endpoints"), "Kubernetes Endpoints"),
default='lbaasv2'), default='lbaasv2'),
cfg.StrOpt('vif_pool_driver', cfg.StrOpt('vif_pool_driver',
help=_("The driver that manages VIFs pools for Kubernetes Pods."), help=_("The driver that manages VIFs pools for "
"Kubernetes Pods."),
default='noop'), default='noop'),
] ]
neutron_defaults = [ neutron_defaults = [
cfg.StrOpt('project', cfg.StrOpt('project',
help=_("Default OpenStack project ID for Kubernetes resources")), help=_("Default OpenStack project ID for "
"Kubernetes resources")),
cfg.StrOpt('pod_subnet', 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', 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', cfg.StrOpt('ovs_bridge',
help=_("Default OpenVSwitch integration bridge"), help=_("Default OpenVSwitch integration bridge"),
sample_default="br-int"), sample_default="br-int"),

View File

@ -64,7 +64,8 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
with self.lock: with self.lock:
vm_port = self._get_parent_port(neutron, pod) vm_port = self._get_parent_port(neutron, pod)
self._remove_from_allowed_address_pairs(neutron, vm_port, self._remove_from_allowed_address_pairs(neutron, vm_port,
container_ips, container_mac) container_ips,
container_mac)
try: try:
neutron.delete_port(vif.id) 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, def _add_to_allowed_address_pairs(self, neutron, port, ip_addresses,
mac_address=None): mac_address=None):
if not ip_addresses: 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", "allowed_address_pairs of port %s: missing IP address",
port['id']) port['id'])
@ -94,11 +96,13 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
for pair in address_pairs: for pair in address_pairs:
if pair['ip_address'] in ip_addresses: if pair['ip_address'] in ip_addresses:
if pair['mac_address'] is mac: 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 " "present in the 'allowed_address_pair' list. This is "
"due to a misconfiguration or a bug", pair) "due to a misconfiguration or a bug", pair)
else: 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'. " "is already present in the 'allowed_address_pair'. "
"This could indicate a misconfiguration or a " "This could indicate a misconfiguration or a "
"bug", pair['ip_address']) "bug", pair['ip_address'])
@ -111,7 +115,8 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
def _remove_from_allowed_address_pairs(self, neutron, port, ip_addresses, def _remove_from_allowed_address_pairs(self, neutron, port, ip_addresses,
mac_address=None): mac_address=None):
if not ip_addresses: 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", "allowed_address_pairs of port %s: missing IP address",
port['id']) port['id'])

View File

@ -43,8 +43,8 @@ class NestedPodVIFDriver(neutron_vif.NeutronPodVIFDriver):
def _get_parent_port_by_host_ip(self, neutron, node_fixed_ip): def _get_parent_port_by_host_ip(self, neutron, node_fixed_ip):
node_subnet_id = oslo_cfg.CONF.pod_vif_nested.worker_nodes_subnet node_subnet_id = oslo_cfg.CONF.pod_vif_nested.worker_nodes_subnet
if not node_subnet_id: if not node_subnet_id:
raise oslo_cfg.RequiredOptError('worker_nodes_subnet', raise oslo_cfg.RequiredOptError(
oslo_cfg.OptGroup('pod_vif_nested')) 'worker_nodes_subnet', oslo_cfg.OptGroup('pod_vif_nested'))
try: try:
fixed_ips = ['subnet_id=%s' % str(node_subnet_id), fixed_ips = ['subnet_id=%s' % str(node_subnet_id),

View File

@ -64,8 +64,9 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
parent_port = self._get_parent_port(neutron, pod) parent_port = self._get_parent_port(neutron, pod)
trunk_id = self._get_trunk_id(parent_port) trunk_id = self._get_trunk_id(parent_port)
port_rq, subports_info = self._create_subports_info(pod, project_id, port_rq, subports_info = self._create_subports_info(
subnets, security_groups, trunk_id, num_ports, unbound=True) pod, project_id, subnets, security_groups,
trunk_id, num_ports, unbound=True)
if not subports_info: if not subports_info:
LOG.error("There are no vlan ids available to create subports") LOG.error("There are no vlan ids available to create subports")

View File

@ -120,8 +120,9 @@ class NeutronPodVIFDriver(base.PodVIFDriver):
ids = ovu.osvif_to_neutron_network_ids(subnets) ids = ovu.osvif_to_neutron_network_ids(subnets)
if len(ids) != 1: if len(ids) != 1:
raise k_exc.IntegrityError("Subnet mapping %(subnets)s is not " raise k_exc.IntegrityError(
"valid: %(num_networks)s unique networks found" % "Subnet mapping %(subnets)s is not valid: "
"%(num_networks)s unique networks found" %
{'subnets': subnets, 'num_networks': len(ids)}) {'subnets': subnets, 'num_networks': len(ids)})
return ids[0] return ids[0]

View File

@ -33,7 +33,8 @@ LOG = logging.getLogger(__name__)
# Moved out from neutron_default group # Moved out from neutron_default group
vif_pool_driver_opts = [ vif_pool_driver_opts = [
oslo_cfg.IntOpt('ports_pool_max', oslo_cfg.IntOpt('ports_pool_max',
help=_("Set a maximun amount of ports per pool. 0 to disable"), help=_("Set a maximun amount of ports per pool. "
"0 to disable"),
default=0), default=0),
oslo_cfg.IntOpt('ports_pool_min', oslo_cfg.IntOpt('ports_pool_min',
help=_("Set a target minimum size of the pool of ports"), help=_("Set a target minimum size of the pool of ports"),
@ -42,7 +43,8 @@ vif_pool_driver_opts = [
help=_("Number of ports to be created in a bulk request"), help=_("Number of ports to be created in a bulk request"),
default=10), default=10),
oslo_cfg.IntOpt('ports_pool_update_frequency', oslo_cfg.IntOpt('ports_pool_update_frequency',
help=_("Minimun interval (in seconds) between pool updates"), help=_("Minimun interval (in seconds) "
"between pool updates"),
default=20), default=20),
] ]
@ -142,7 +144,8 @@ class BaseVIFPool(base.VIFPoolDriver):
if pool_size < oslo_cfg.CONF.vif_pool.ports_pool_min: if pool_size < oslo_cfg.CONF.vif_pool.ports_pool_min:
num_ports = max(oslo_cfg.CONF.vif_pool.ports_pool_batch, num_ports = max(oslo_cfg.CONF.vif_pool.ports_pool_batch,
oslo_cfg.CONF.vif_pool.ports_pool_min - pool_size) oslo_cfg.CONF.vif_pool.ports_pool_min - pool_size)
vifs = self._drv_vif.request_vifs(pod=pod, vifs = self._drv_vif.request_vifs(
pod=pod,
project_id=pool_key[1], project_id=pool_key[1],
subnets=subnets, subnets=subnets,
security_groups=list(pool_key[2]), security_groups=list(pool_key[2]),
@ -170,7 +173,8 @@ class NeutronVIFPool(BaseVIFPool):
except IndexError: except IndexError:
raise exceptions.ResourceNotReady(pod) raise exceptions.ResourceNotReady(pod)
neutron = clients.get_neutron_client() neutron = clients.get_neutron_client()
neutron.update_port(port_id, neutron.update_port(
port_id,
{ {
"port": { "port": {
'name': pod['metadata']['name'], 'name': pod['metadata']['name'],
@ -201,7 +205,8 @@ class NeutronVIFPool(BaseVIFPool):
self._get_pool_size(pool_key) < self._get_pool_size(pool_key) <
oslo_cfg.CONF.vif_pool.ports_pool_max): oslo_cfg.CONF.vif_pool.ports_pool_max):
try: try:
neutron.update_port(port_id, neutron.update_port(
port_id,
{ {
"port": { "port": {
'name': 'available-port', 'name': 'available-port',
@ -244,7 +249,8 @@ class NestedVIFPool(BaseVIFPool):
except IndexError: except IndexError:
raise exceptions.ResourceNotReady(pod) raise exceptions.ResourceNotReady(pod)
neutron = clients.get_neutron_client() neutron = clients.get_neutron_client()
neutron.update_port(port_id, neutron.update_port(
port_id,
{ {
"port": { "port": {
'name': pod['metadata']['name'], 'name': pod['metadata']['name'],
@ -274,7 +280,8 @@ class NestedVIFPool(BaseVIFPool):
self._get_pool_size(pool_key) < self._get_pool_size(pool_key) <
oslo_cfg.CONF.vif_pool.ports_pool_max): oslo_cfg.CONF.vif_pool.ports_pool_max):
try: try:
neutron.update_port(port_id, neutron.update_port(
port_id,
{ {
"port": { "port": {
'name': 'available-port', 'name': 'available-port',

View File

@ -100,8 +100,9 @@ class K8sClient(object):
"resourceVersion": resource_version, "resourceVersion": resource_version,
} }
}, sort_keys=True) }, sort_keys=True)
response = requests.patch(url, data=data, headers=header, response = requests.patch(url, data=data,
cert=self.cert, verify=self.verify_server) headers=header, cert=self.cert,
verify=self.verify_server)
if response.ok: if response.ok:
return response.json()['metadata']['annotations'] return response.json()['metadata']['annotations']
if response.status_code == requests.codes.conflict: if response.status_code == requests.codes.conflict:

View File

@ -309,7 +309,8 @@ def neutron_to_osvif_vif(vif_translator, neutron_port, subnets):
try: try:
mgr = _VIF_MANAGERS[vif_translator] mgr = _VIF_MANAGERS[vif_translator]
except KeyError: except KeyError:
mgr = stv_driver.DriverManager(namespace=_VIF_TRANSLATOR_NAMESPACE, mgr = stv_driver.DriverManager(
namespace=_VIF_TRANSLATOR_NAMESPACE,
name=vif_translator, invoke_on_load=False) name=vif_translator, invoke_on_load=False)
_VIF_MANAGERS[vif_translator] = mgr _VIF_MANAGERS[vif_translator] = mgr

View File

@ -55,8 +55,8 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
self.assertEqual(vif, cls.request_vif(m_driver, pod, project_id, self.assertEqual(vif, cls.request_vif(m_driver, pod, project_id,
subnets, security_groups)) subnets, security_groups))
m_driver._get_port_request.assert_called_once_with(pod, project_id, m_driver._get_port_request.assert_called_once_with(
subnets, security_groups) pod, project_id, subnets, security_groups)
neutron.create_port.assert_called_once_with(port_request) neutron.create_port.assert_called_once_with(port_request)
m_driver._get_parent_port.assert_called_once_with(neutron, pod) m_driver._get_parent_port.assert_called_once_with(neutron, pod)
m_driver._add_to_allowed_address_pairs.assert_called_once_with( 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, self.assertRaises(n_exc.NeutronClientException, cls.request_vif,
m_driver, pod, project_id, subnets, security_groups) m_driver, pod, project_id, subnets, security_groups)
m_driver._get_port_request.assert_called_once_with(pod, project_id, m_driver._get_port_request.assert_called_once_with(
subnets, security_groups) pod, project_id, subnets, security_groups)
neutron.create_port.assert_called_once_with(port_request) neutron.create_port.assert_called_once_with(port_request)
m_driver._add_to_allowed_address_pairs.assert_not_called() m_driver._add_to_allowed_address_pairs.assert_not_called()
m_to_vif.assert_not_called() m_to_vif.assert_not_called()
@ -111,8 +111,8 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
self.assertRaises(n_exc.NeutronClientException, cls.request_vif, self.assertRaises(n_exc.NeutronClientException, cls.request_vif,
m_driver, pod, project_id, subnets, security_groups) m_driver, pod, project_id, subnets, security_groups)
m_driver._get_port_request.assert_called_once_with(pod, project_id, m_driver._get_port_request.assert_called_once_with(
subnets, security_groups) pod, project_id, subnets, security_groups)
neutron.create_port.assert_called_once_with(port_request) neutron.create_port.assert_called_once_with(port_request)
m_driver._get_parent_port.assert_called_once_with(neutron, pod) m_driver._get_parent_port.assert_called_once_with(neutron, pod)
m_driver._add_to_allowed_address_pairs.assert_not_called() 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, cls._add_to_allowed_address_pairs(m_driver, neutron, vm_port,
frozenset([ip_addr]), m_mac) frozenset([ip_addr]), m_mac)
m_driver._update_port_address_pairs.assert_called_once_with(neutron, m_driver._update_port_address_pairs.assert_called_once_with(
port_id, address_pairs) neutron, port_id, address_pairs)
def test_add_to_allowed_address_pairs_no_ip_addresses(self): def test_add_to_allowed_address_pairs_no_ip_addresses(self):
cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver 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, cls._add_to_allowed_address_pairs(m_driver, neutron, vm_port,
frozenset([ip_addr]), mac_addr) frozenset([ip_addr]), mac_addr)
m_driver._update_port_address_pairs.assert_called_once_with(neutron, m_driver._update_port_address_pairs.assert_called_once_with(
port_id, address_pairs) neutron, port_id, address_pairs)
def test_add_to_allowed_address_pairs_already_present(self): def test_add_to_allowed_address_pairs_already_present(self):
cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver 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']} 'mac_address': m_mac if m_mac else vm_port['mac_address']}
) )
cls._remove_from_allowed_address_pairs(m_driver, neutron, cls._remove_from_allowed_address_pairs(
vm_port, frozenset([ip_addr]), m_mac) m_driver, neutron, vm_port, frozenset([ip_addr]), m_mac)
m_driver._update_port_address_pairs.assert_called_once_with(neutron, m_driver._update_port_address_pairs.assert_called_once_with(
port_id, address_pairs) neutron, port_id, address_pairs)
def test_remove_from_allowed_address_pairs_no_ip_addresses(self): def test_remove_from_allowed_address_pairs_no_ip_addresses(self):
cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
@ -382,11 +382,11 @@ class TestNestedMacvlanPodVIFDriver(test_base.TestCase):
'mac_address': mac_addr}) 'mac_address': mac_addr})
ip_addr = ['10.0.0.29', '10.0.0.28'] ip_addr = ['10.0.0.29', '10.0.0.28']
cls._remove_from_allowed_address_pairs(m_driver, neutron, cls._remove_from_allowed_address_pairs(
vm_port, frozenset(ip_addr), m_mac) m_driver, neutron, vm_port, frozenset(ip_addr), m_mac)
m_driver._update_port_address_pairs.assert_called_once_with(neutron, m_driver._update_port_address_pairs.assert_called_once_with(
port_id, address_pairs) neutron, port_id, address_pairs)
@ddt.data((None), ('fa:16:3e:71:cb:80')) @ddt.data((None), ('fa:16:3e:71:cb:80'))
def test_remove_from_allowed_address_pairs_no_update(self, m_mac): 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'] ip_addr = ['10.0.0.29']
cls._remove_from_allowed_address_pairs(m_driver, neutron, cls._remove_from_allowed_address_pairs(
vm_port, frozenset(ip_addr), m_mac) m_driver, neutron, vm_port, frozenset(ip_addr), m_mac)
m_driver._update_port_address_pairs.assert_not_called() 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) 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}}) {'port': {'allowed_address_pairs': pairs}})
def test_update_port_address_pairs_failure(self): 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, cls._update_port_address_pairs, m_driver, neutron,
port_id, pairs) port_id, pairs)
neutron.update_port.assert_called_with(port_id, neutron.update_port.assert_called_with(
port_id,
{'port': {'allowed_address_pairs': pairs}}) {'port': {'allowed_address_pairs': pairs}})
# TODO(garyloug) consider exending and moving to a parent class # TODO(garyloug) consider exending and moving to a parent class

View File

@ -71,7 +71,8 @@ class TestNestedPodVIFDriver(test_base.TestCase):
group='pod_vif_nested') group='pod_vif_nested')
node_fixed_ip = mock.sentinel.node_fixed_ip node_fixed_ip = mock.sentinel.node_fixed_ip
self.assertRaises(oslo_cfg.RequiredOptError, 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): def test_get_parent_port_by_host_ip_trunk_not_found(self):
cls = nested_vif.NestedPodVIFDriver cls = nested_vif.NestedPodVIFDriver

View File

@ -106,12 +106,12 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
m_driver._get_parent_port.assert_called_once_with(neutron, pod) m_driver._get_parent_port.assert_called_once_with(neutron, pod)
m_driver._get_trunk_id.assert_called_once_with(parent_port) m_driver._get_trunk_id.assert_called_once_with(parent_port)
m_driver._create_subports_info.assert_called_once_with(pod, m_driver._create_subports_info.assert_called_once_with(
project_id, subnets, security_groups, trunk_id, num_ports, pod, project_id, subnets, security_groups, trunk_id, num_ports,
unbound=True) unbound=True)
neutron.create_port.assert_called_once_with(bulk_rq) neutron.create_port.assert_called_once_with(bulk_rq)
neutron.trunk_add_subports.assert_called_once_with(trunk_id, neutron.trunk_add_subports.assert_called_once_with(
{'sub_ports': subports_info}) trunk_id, {'sub_ports': subports_info})
neutron.delete_port.assert_not_called() neutron.delete_port.assert_not_called()
calls = [mock.call(port, subnets, info['segmentation_id']) 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_parent_port.assert_called_once_with(neutron, pod)
m_driver._get_trunk_id.assert_called_once_with(parent_port) m_driver._get_trunk_id.assert_called_once_with(parent_port)
m_driver._create_subports_info.assert_called_once_with(pod, project_id, m_driver._create_subports_info.assert_called_once_with(
subnets, security_groups, trunk_id, num_ports, unbound=True) pod, project_id, subnets, security_groups,
trunk_id, num_ports, unbound=True)
def test_request_vifs_bulk_creation_exception(self): def test_request_vifs_bulk_creation_exception(self):
cls = nested_vlan_vif.NestedVlanPodVIFDriver cls = nested_vlan_vif.NestedVlanPodVIFDriver
@ -177,14 +178,15 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
subports_info) subports_info)
neutron.create_port.side_effect = n_exc.NeutronClientException 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, pod, project_id, subnets, security_groups, num_ports)
m_driver._get_parent_port.assert_called_once_with(neutron, pod) m_driver._get_parent_port.assert_called_once_with(neutron, pod)
m_driver._get_trunk_id.assert_called_once_with(parent_port) m_driver._get_trunk_id.assert_called_once_with(parent_port)
m_driver._create_subports_info.assert_called_once_with(pod, m_driver._create_subports_info.assert_called_once_with(
project_id, subnets, security_groups, trunk_id, num_ports, pod, project_id, subnets, security_groups,
unbound=True) trunk_id, num_ports, unbound=True)
neutron.create_port.assert_called_once_with(bulk_rq) neutron.create_port.assert_called_once_with(bulk_rq)
def test_request_vifs_trunk_subports_conflict(self): 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 neutron.trunk_add_subports.side_effect = n_exc.Conflict
self.assertRaises(n_exc.Conflict, cls.request_vifs, 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_parent_port.assert_called_once_with(neutron, pod)
m_driver._get_trunk_id.assert_called_once_with(parent_port) m_driver._get_trunk_id.assert_called_once_with(parent_port)
m_driver._create_subports_info.assert_called_once_with(pod, m_driver._create_subports_info.assert_called_once_with(
project_id, subnets, security_groups, trunk_id, num_ports, pod, project_id, subnets, security_groups,
unbound=True) trunk_id, num_ports, unbound=True)
neutron.create_port.assert_called_once_with(bulk_rq) neutron.create_port.assert_called_once_with(bulk_rq)
neutron.trunk_add_subports.assert_called_once_with(trunk_id, neutron.trunk_add_subports.assert_called_once_with(
{'sub_ports': subports_info}) trunk_id, {'sub_ports': subports_info})
neutron.delete_port.assert_called_with(port['id']) neutron.delete_port.assert_called_with(port['id'])
def test_request_vifs_trunk_subports_exception(self): 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 neutron.trunk_add_subports.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, pod, project_id, subnets,
security_groups, num_ports)
m_driver._get_parent_port.assert_called_once_with(neutron, pod) m_driver._get_parent_port.assert_called_once_with(neutron, pod)
m_driver._get_trunk_id.assert_called_once_with(parent_port) m_driver._get_trunk_id.assert_called_once_with(parent_port)
m_driver._create_subports_info.assert_called_once_with(pod, m_driver._create_subports_info.assert_called_once_with(
project_id, subnets, security_groups, trunk_id, num_ports, pod, project_id, subnets, security_groups,
unbound=True) trunk_id, num_ports, unbound=True)
neutron.create_port.assert_called_once_with(bulk_rq) neutron.create_port.assert_called_once_with(bulk_rq)
neutron.trunk_add_subports.assert_called_once_with(trunk_id, neutron.trunk_add_subports.assert_called_once_with(
{'sub_ports': subports_info}) trunk_id, {'sub_ports': subports_info})
neutron.delete_port.assert_not_called() neutron.delete_port.assert_not_called()
def test_release_vif(self): def test_release_vif(self):
@ -401,8 +405,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
self.assertEqual(subports_res, subports_info) self.assertEqual(subports_res, subports_info)
m_driver._get_in_use_vlan_ids_set.assert_called_once_with(trunk_id) 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, m_driver._get_port_request.assert_called_once_with(
subnets, security_groups, False) pod, project_id, subnets, security_groups, False)
self.assertEqual(m_allocate_seg_id.call_count, 2) self.assertEqual(m_allocate_seg_id.call_count, 2)
@mock.patch('kuryr.lib.segmentation_type_drivers.allocate_segmentation_id') @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_in_use_vlan_ids_set.return_value = in_use_vlan
m_driver._get_port_request.return_value = {'port': port} m_driver._get_port_request.return_value = {'port': port}
m_allocate_seg_id.side_effect = [2, m_allocate_seg_id.side_effect = [
kl_exc.SegmentationIdAllocationFailure] 2, kl_exc.SegmentationIdAllocationFailure
]
port_res, subports_res = cls._create_subports_info( port_res, subports_res = cls._create_subports_info(
m_driver, pod, project_id, subnets, security_groups, trunk_id, 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) self.assertEqual(subports_res, subports_info)
m_driver._get_in_use_vlan_ids_set.assert_called_once_with(trunk_id) 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, m_driver._get_port_request.assert_called_once_with(
subnets, security_groups, False) pod, project_id, subnets, security_groups, False)
self.assertEqual(m_allocate_seg_id.call_count, 2) self.assertEqual(m_allocate_seg_id.call_count, 2)
@mock.patch('kuryr.lib.segmentation_type_drivers.allocate_segmentation_id') @mock.patch('kuryr.lib.segmentation_type_drivers.allocate_segmentation_id')
@ -465,8 +470,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
self.assertEqual(subports_res, []) self.assertEqual(subports_res, [])
m_driver._get_in_use_vlan_ids_set.assert_called_once_with(trunk_id) 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, m_driver._get_port_request.assert_called_once_with(
subnets, security_groups, False) pod, project_id, subnets, security_groups, False)
self.assertEqual(m_allocate_seg_id.call_count, 1) self.assertEqual(m_allocate_seg_id.call_count, 1)
def test_get_trunk_id(self): def test_get_trunk_id(self):
@ -500,8 +505,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
self.assertEqual(vlan_id, cls._add_subport(m_driver, 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) m_driver._get_vlan_id.assert_called_once_with(trunk_id)
neutron.trunk_add_subports.assert_called_once_with(trunk_id, neutron.trunk_add_subports.assert_called_once_with(
{'sub_ports': subport_dict}) trunk_id, {'sub_ports': subport_dict})
def test_add_subport_get_vlanid_failure(self): def test_add_subport_get_vlanid_failure(self):
cls = nested_vlan_vif.NestedVlanPodVIFDriver cls = nested_vlan_vif.NestedVlanPodVIFDriver
@ -511,8 +516,9 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
subport = mock.sentinel.subport subport = mock.sentinel.subport
m_driver._get_vlan_id.side_effect = n_exc.NeutronClientException m_driver._get_vlan_id.side_effect = n_exc.NeutronClientException
nested_vlan_vif.DEFAULT_MAX_RETRY_COUNT = 1 nested_vlan_vif.DEFAULT_MAX_RETRY_COUNT = 1
self.assertRaises(n_exc.NeutronClientException, self.assertRaises(
cls._add_subport, m_driver, neutron, trunk_id, subport) n_exc.NeutronClientException, cls._add_subport,
m_driver, neutron, trunk_id, subport)
m_driver._get_vlan_id.assert_called_once_with(trunk_id) m_driver._get_vlan_id.assert_called_once_with(trunk_id)
@ -532,8 +538,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
self.assertRaises(n_exc.Conflict, cls._add_subport, m_driver, self.assertRaises(n_exc.Conflict, cls._add_subport, m_driver,
neutron, trunk_id, subport) neutron, trunk_id, subport)
neutron.trunk_add_subports.assert_called_once_with(trunk_id, neutron.trunk_add_subports.assert_called_once_with(
{'sub_ports': subport_dict}) trunk_id, {'sub_ports': subport_dict})
def test_remove_subport(self): def test_remove_subport(self):
cls = nested_vlan_vif.NestedVlanPodVIFDriver cls = nested_vlan_vif.NestedVlanPodVIFDriver
@ -544,8 +550,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
subportid_dict = [{'port_id': subport_id}] subportid_dict = [{'port_id': subport_id}]
cls._remove_subport(m_driver, neutron, trunk_id, subport_id) cls._remove_subport(m_driver, neutron, trunk_id, subport_id)
neutron.trunk_remove_subports.assert_called_once_with(trunk_id, neutron.trunk_remove_subports.assert_called_once_with(
{'sub_ports': subportid_dict}) trunk_id, {'sub_ports': subportid_dict})
@mock.patch('kuryr.lib.segmentation_type_drivers.allocate_segmentation_id') @mock.patch('kuryr.lib.segmentation_type_drivers.allocate_segmentation_id')
def test_get_vlan_id(self, mock_alloc_seg_id): def test_get_vlan_id(self, mock_alloc_seg_id):

View File

@ -108,7 +108,8 @@ class NeutronPodVIFDriver(test_base.TestCase):
neutron.create_port.side_effect = n_exc.NeutronClientException 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, pod, project_id, subnets,
security_groups, num_ports)
m_driver._get_port_request.assert_called_once_with( m_driver._get_port_request.assert_called_once_with(
pod, project_id, subnets, security_groups, unbound=True) pod, project_id, subnets, security_groups, unbound=True)

View File

@ -220,7 +220,8 @@ class NeutronVIFPool(test_base.TestCase):
self.assertEqual(port, cls._get_port_from_pool( self.assertEqual(port, cls._get_port_from_pool(
m_driver, pool_key, pod, subnets)) 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": { "port": {
'name': pod['metadata']['name'], 'name': pod['metadata']['name'],
@ -255,7 +256,8 @@ class NeutronVIFPool(test_base.TestCase):
self.assertEqual(port, cls._get_port_from_pool( self.assertEqual(port, cls._get_port_from_pool(
m_driver, pool_key, pod, subnets)) 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": { "port": {
'name': pod['metadata']['name'], 'name': pod['metadata']['name'],
@ -316,7 +318,8 @@ class NeutronVIFPool(test_base.TestCase):
self.assertRaises(SystemExit, cls._return_ports_to_pool, m_driver) 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": { "port": {
'name': 'available-port', 'name': 'available-port',
@ -370,7 +373,8 @@ class NeutronVIFPool(test_base.TestCase):
self.assertRaises(SystemExit, cls._return_ports_to_pool, m_driver) 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": { "port": {
'name': 'available-port', 'name': 'available-port',
@ -592,7 +596,8 @@ class NestedVIFPool(test_base.TestCase):
self.assertEqual(port, cls._get_port_from_pool( self.assertEqual(port, cls._get_port_from_pool(
m_driver, pool_key, pod, subnets)) 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": { "port": {
'name': pod['metadata']['name'], 'name': pod['metadata']['name'],
@ -626,7 +631,8 @@ class NestedVIFPool(test_base.TestCase):
self.assertEqual(port, cls._get_port_from_pool( self.assertEqual(port, cls._get_port_from_pool(
m_driver, pool_key, pod, subnets)) 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": { "port": {
'name': pod['metadata']['name'], 'name': pod['metadata']['name'],
@ -686,7 +692,8 @@ class NestedVIFPool(test_base.TestCase):
self.assertRaises(SystemExit, cls._return_ports_to_pool, m_driver) 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": { "port": {
'name': 'available-port', 'name': 'available-port',
@ -753,7 +760,8 @@ class NestedVIFPool(test_base.TestCase):
self.assertRaises(SystemExit, cls._return_ports_to_pool, m_driver) 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": { "port": {
'name': 'available-port', 'name': 'available-port',

View File

@ -115,7 +115,8 @@ class TestK8sClient(test_base.TestCase):
m_get.return_value = m_resp m_get.return_value = m_resp
self.assertEqual(ret, self.client.get(path)) 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) cert=(None, None), headers={}, verify=False)
@mock.patch('requests.get') @mock.patch('requests.get')

View File

@ -309,7 +309,8 @@ class TestOSVIFUtils(test_base.TestCase):
@mock.patch('kuryr_kubernetes.os_vif_util._make_vif_network') @mock.patch('kuryr_kubernetes.os_vif_util._make_vif_network')
@mock.patch('kuryr_kubernetes.objects.vif.VIFMacvlanNested') @mock.patch('kuryr_kubernetes.objects.vif.VIFMacvlanNested')
def test_neutron_to_osvif_nested_macvlan(self, m_mk_vif, 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 vif_plugin = const.K8S_OS_VIF_NOOP_PLUGIN
port_id = mock.sentinel.port_id port_id = mock.sentinel.port_id
mac_address = mock.sentinel.mac_address mac_address = mock.sentinel.mac_address

View File

@ -49,8 +49,6 @@ commands =
commands = python setup.py build_sphinx commands = python setup.py build_sphinx
[flake8] [flake8]
# E128 continuation line under-indented for visual indent
ignore = E128
show-source = true show-source = true
# TODO(dougw) neutron/tests/unit/vmware exclusion is a temporary services split hack # TODO(dougw) neutron/tests/unit/vmware exclusion is a temporary services split hack