Expand PEP8 tests on nsxlib

There were some directories excluded from the pep8 run, and many checks
were ignored.
This cleans the exclude list, and fixes the PEP8 issues.

Change-Id: Ib56d45443009349a42fecfc14a792fdaa6d88d67
This commit is contained in:
Adit Sarfaty 2016-12-19 14:27:46 +02:00
parent b77a3ec496
commit d7473ecf2f
11 changed files with 75 additions and 93 deletions

View File

@ -22,7 +22,7 @@ sys.path.insert(0, os.path.abspath('../..'))
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autodoc',
#'sphinx.ext.intersphinx',
# 'sphinx.ext.intersphinx',
'oslosphinx'
]
@ -72,4 +72,4 @@ latex_documents = [
]
# Example configuration for intersphinx: refer to the Python standard library.
#intersphinx_mapping = {'http://docs.python.org/': None}
# intersphinx_mapping = {'http://docs.python.org/': None}

14
tox.ini
View File

@ -82,22 +82,12 @@ commands = sphinx-build -W -b html doc/source doc/build/html
[flake8]
# E125 continuation line does not distinguish itself from next logical line
# E126 continuation line over-indented for hanging indent
# E128 continuation line under-indented for visual indent
# E129 visually indented line with same indent as next logical line
# E265 block comment should start with #
# H305 imports not grouped correctly
# H307 like imports should be grouped together
# H402 one line docstring needs punctuation
# H404 multi line docstring should start with a summary
# H405 multi line docstring summary not separated with an empty line
# H904 Wrap long lines in parentheses instead of a backslash
# TODO(dougwig) -- uncomment this to test for remaining linkages
# N530 direct neutron imports not allowed
ignore = E125,E126,E128,E129,E265,H305,H307,H402,H404,H405,H904,N530
ignore = N530,E125,E129
show-source = true
builtins = _
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,.ropeproject
exclude = build,dist
[hacking]
import_exceptions = vmware_nsxlib._i18n,

View File

@ -53,10 +53,7 @@ def _mock_create_and_list_nsgroups(test_method):
class TestNSGroupManager(nsxlib_testcase.NsxLibTestCase):
"""
This test suite is responsible for unittesting of class
vmware_nsxlib.v3.ns_group_manager.NSGroupManager.
"""
"""Tests for vmware_nsxlib.v3.ns_group_manager.NSGroupManager."""
@_mock_create_and_list_nsgroups
def test_first_initialization(self):

View File

@ -139,12 +139,12 @@ class NsxLibQosTestCase(nsxlib_testcase.NsxClientTestCase):
expected_path = ('switching-profiles/%s' %
test_constants.FAKE_QOS_PROFILE['id'])
expected_body = self._body_with_shaping(
shaping_enabled=True,
burst_size=burst_size,
peak_bandwidth=peak_bandwidth,
average_bandwidth=average_bandwidth,
qos_marking="untrusted", dscp=10,
direction=direction)
shaping_enabled=True,
burst_size=burst_size,
peak_bandwidth=peak_bandwidth,
average_bandwidth=average_bandwidth,
qos_marking="untrusted", dscp=10,
direction=direction)
self.assertEqual(expected_path, actual_path)
self.assertEqual(expected_body, actual_body)
@ -158,9 +158,9 @@ class NsxLibQosTestCase(nsxlib_testcase.NsxClientTestCase):
def _disable_qos_switching_profile_shaping(
self, direction=nsx_constants.EGRESS):
"""Test updating a qos-switching profile
"""Test updating a qos-switching profile.
returns the correct response
Returns the correct response
"""
burst_size = 100
peak_bandwidth = 200
@ -187,7 +187,7 @@ class NsxLibQosTestCase(nsxlib_testcase.NsxClientTestCase):
expected_path = ('switching-profiles/%s' %
test_constants.FAKE_QOS_PROFILE['id'])
expected_body = self._body_with_shaping(qos_marking="trusted",
direction=direction)
direction=direction)
self.assertEqual(expected_path, actual_path)
self.assertEqual(expected_body, actual_body)

View File

@ -259,7 +259,7 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase):
return fake_pkt_classifiers, fake_binding_repr
def test_create_logical_port(self):
"""Test creating a port
"""Test creating a port.
returns the correct response and 200 status
"""
@ -346,7 +346,7 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase):
data=jsonutils.dumps(resp_body, sort_keys=True))
def test_create_logical_port_admin_down(self):
"""Test creating port with admin_state down"""
"""Test creating port with admin_state down."""
fake_port = test_constants.FAKE_PORT
fake_port['admin_state'] = "DOWN"
@ -362,7 +362,7 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase):
self.assertEqual(fake_port, result)
def test_delete_logical_port(self):
"""Test deleting port"""
"""Test deleting port."""
mocked_resource = self._mocked_lport()
uuid = test_constants.FAKE_PORT['id']
@ -390,9 +390,7 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase):
data=jsonutils.dumps(fake_port, sort_keys=True))
def test_create_logical_port_fail(self):
"""
Test the failure of port creation
"""
"""Test the failure of port creation."""
fake_port = test_constants.FAKE_PORT.copy()
profile_dicts = self._get_profile_dicts(fake_port)
@ -422,7 +420,7 @@ class LogicalRouterTestCase(nsxlib_testcase.NsxClientTestCase):
resources.LogicalRouter, session_response=session_response)
def test_create_logical_router(self):
"""Test creating a router returns the correct response and 201 status
"""Test creating a router returns the correct response and 201 status.
"""
fake_router = test_constants.FAKE_ROUTER.copy()
@ -460,7 +458,7 @@ class LogicalRouterPortTestCase(nsxlib_testcase.NsxClientTestCase):
resources.LogicalRouterPort, session_response=session_response)
def test_create_logical_router_port(self):
"""Test creating a router port
"""Test creating a router port.
returns the correct response and 201 status
"""
@ -487,16 +485,14 @@ class LogicalRouterPortTestCase(nsxlib_testcase.NsxClientTestCase):
data=jsonutils.dumps(data, sort_keys=True))
def test_logical_router_port_max_attempts(self):
"""
Test a router port api has the configured retries
"""
"""Test a router port api has the configured retries."""
lrport = self._mocked_lrport()
self.assertEqual(nsxlib_testcase.NSX_MAX_ATTEMPTS,
lrport._client.max_attempts)
def test_delete_logical_router_port(self):
"""Test deleting router port"""
"""Test deleting router port."""
lrport = self._mocked_lrport()
uuid = test_constants.FAKE_ROUTER_PORT['id']
@ -506,7 +502,7 @@ class LogicalRouterPortTestCase(nsxlib_testcase.NsxClientTestCase):
'https://1.2.3.4/api/v1/logical-router-ports/%s' % uuid)
def test_get_logical_router_port_by_router_id(self):
"""Test getting a router port by router id"""
"""Test getting a router port by router id."""
fake_router_port = test_constants.FAKE_ROUTER_PORT.copy()
resp_resources = {'results': [fake_router_port]}
@ -523,7 +519,7 @@ class LogicalRouterPortTestCase(nsxlib_testcase.NsxClientTestCase):
'logical_router_id=%s' % router_id)
def test_get_logical_router_port_by_switch_id(self):
"""Test getting a router port by switch id"""
"""Test getting a router port by switch id."""
fake_router_port = test_constants.FAKE_ROUTER_PORT.copy()
resp_resources = {
'result_count': 1,

View File

@ -62,9 +62,9 @@ class NsxLib(object):
self.transport_zone = NsxLibTransportZone(
self.client, nsxlib_config)
self.native_dhcp_profile = NsxLibDhcpProfile(
self.client, nsxlib_config)
self.client, nsxlib_config)
self.native_md_proxy = NsxLibMetadataProxy(
self.client, nsxlib_config)
self.client, nsxlib_config)
self.firewall_section = security.NsxLibFirewallSection(
self.client, nsxlib_config)
self.ns_group = security.NsxLibNsGroup(
@ -183,7 +183,7 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase):
return self.client.create(resource, body)
def delete(self, lswitch_id):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self.nsxlib_config.max_attempts)
@ -199,7 +199,7 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase):
return self.client.get(resource)
def update(self, lswitch_id, name=None, admin_state=None, tags=None):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self.nsxlib_config.max_attempts)

View File

@ -44,11 +44,11 @@ logging.getLogger(
@six.add_metaclass(abc.ABCMeta)
class AbstractHTTPProvider(object):
"""Interface for providers of HTTP connections which
are responsible for creating and validating connections
"""Interface for providers of HTTP connections.
which are responsible for creating and validating connections
for their underlying HTTP support.
"""
@property
def default_scheme(self):
return 'https'
@ -60,13 +60,14 @@ class AbstractHTTPProvider(object):
@abc.abstractmethod
def validate_connection(self, cluster_api, endpoint, conn):
"""Validate the said connection for the given endpoint and cluster.
"""
"""Validate the said connection for the given endpoint and cluster."""
pass
@abc.abstractmethod
def new_connection(self, cluster_api, provider):
"""Create a new http connection for the said cluster and
"""Create a new http connection.
Create a new http connection for the said cluster and
cluster provider. The actual connection should duck type
requests.Session http methods (get(), put(), etc.).
"""
@ -74,16 +75,14 @@ class AbstractHTTPProvider(object):
@abc.abstractmethod
def is_connection_exception(self, exception):
"""Determine if the given exception is related to connection
failure. Return True if it's a connection exception and
False otherwise.
"""Determine if the given exception is related to connection failure.
Return True if it's a connection exception and False otherwise.
"""
class TimeoutSession(requests.Session):
"""Extends requests.Session to support timeout
at the session level.
"""
"""Extends requests.Session to support timeout at the session level."""
def __init__(self, timeout, read_timeout):
self.timeout = timeout
@ -99,7 +98,8 @@ class TimeoutSession(requests.Session):
class NSXRequestsHTTPProvider(AbstractHTTPProvider):
"""Concrete implementation of AbstractHTTPProvider
"""Concrete implementation of AbstractHTTPProvider.
using requests.Session() as the underlying connection.
"""
@ -145,8 +145,9 @@ class NSXRequestsHTTPProvider(AbstractHTTPProvider):
class ClusterHealth(object):
"""Indicator of overall cluster health with respect
to the connectivity of the clusters managed endpoints.
"""Indicator of overall cluster health.
with respect to the connectivity of the clusters managed endpoints.
"""
# all endpoints are UP
GREEN = 'GREEN'
@ -157,8 +158,7 @@ class ClusterHealth(object):
class EndpointState(object):
"""Tracks the connectivity state for a said endpoint.
"""
"""Tracks the connectivity state for a said endpoint."""
# no UP or DOWN state recorded yet
INITIALIZED = 'INITIALIZED'
# endpoint has been validate and is good
@ -168,8 +168,9 @@ class EndpointState(object):
class Provider(object):
"""Data holder for a provider which has a unique id
a connection URL, and the credential details.
"""Data holder for a provider
Which has a unique id a connection URL, and the credential details.
"""
def __init__(self, provider_id, provider_url, username, password, ca_file):
@ -184,7 +185,9 @@ class Provider(object):
class Endpoint(object):
"""A single NSX manager endpoint (host) which includes
"""A single NSX manager endpoint (host).
A single NSX manager endpoint (host) which includes
related information such as the endpoint's provider,
state, etc.. A pool is used to hold connections to the
endpoint which are doled out when proxying HTTP methods
@ -224,8 +227,9 @@ class Endpoint(object):
class EndpointConnection(object):
"""Simple data holder which contains an endpoint and
a connection for that endpoint.
"""Simple data holder
Which contains an endpoint and a connection for that endpoint.
"""
def __init__(self, endpoint, connection):
@ -234,8 +238,9 @@ class EndpointConnection(object):
class ClusteredAPI(object):
"""Duck types the major HTTP based methods of a
requests.Session such as get(), put(), post(), etc.
"""Duck types the major HTTP based methods of a requests.Session
Such as get(), put(), post(), etc.
and transparently proxies those calls to one of
its managed NSX manager endpoints.
"""
@ -444,9 +449,7 @@ class ClusteredAPI(object):
class NSXClusteredAPI(ClusteredAPI):
"""Extends ClusteredAPI to get conf values and setup the
NSX v3 cluster.
"""
"""Extends ClusteredAPI to get conf values and setup the NSXv3 cluster."""
def __init__(self, nsxlib_config):
self.nsxlib_config = nsxlib_config

View File

@ -28,8 +28,8 @@ LOG = log.getLogger(__name__)
class NSGroupManager(object):
"""
This class assists with NSX integration for Neutron security-groups,
"""This class assists with NSX integration for Neutron security-groups
Each Neutron security-group is associated with NSX NSGroup object.
Some specific security policies are the same across all security-groups,
i.e - Default drop rule, DHCP. In order to bind these rules to all
@ -44,7 +44,6 @@ class NSGroupManager(object):
group it should be added, and when deleting an NSGroup (security-group) we
use the same procedure to find which nested group it was added.
"""
NESTED_GROUP_NAME = 'OS Nested Group'
NESTED_GROUP_DESCRIPTION = ('OpenStack NSGroup. Do not delete.')

View File

@ -284,7 +284,7 @@ class LogicalPort(AbstractRESTResource):
return self._client.create(body=body)
def delete(self, lport_id):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self._client.max_attempts)
@ -299,7 +299,7 @@ class LogicalPort(AbstractRESTResource):
tags_update=None,
attachment_type=nsx_constants.ATTACHMENT_VIF,
parent_vif_id=None, parent_tag=None):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self._client.max_attempts)
@ -348,7 +348,7 @@ class LogicalRouter(AbstractRESTResource):
return self._client.url_delete(lrouter_id)
def update(self, lrouter_id, *args, **kwargs):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self._client.max_attempts)
@ -399,7 +399,7 @@ class LogicalRouterPort(AbstractRESTResource):
return self._client.create(body=body)
def update(self, logical_port_id, **kwargs):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self._client.max_attempts)
@ -416,7 +416,7 @@ class LogicalRouterPort(AbstractRESTResource):
return _do_update()
def delete(self, logical_port_id):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self._client.max_attempts)
@ -531,7 +531,7 @@ class LogicalDhcpServer(AbstractRESTResource):
def update(self, uuid, dhcp_profile_id=None, server_ip=None, name=None,
dns_nameservers=None, domain_name=None, gateway_ip=False,
options=None, tags=None):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self._client.max_attempts)
@ -564,7 +564,7 @@ class LogicalDhcpServer(AbstractRESTResource):
return self._client.url_get(url)
def update_binding(self, server_uuid, binding_uuid, **kwargs):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self._client.max_attempts)
@ -582,7 +582,7 @@ class LogicalDhcpServer(AbstractRESTResource):
class IpPool(AbstractRESTResource):
#TODO(asarfaty): Check the DK api - could be different
# TODO(asarfaty): Check the DK api - could be different
@property
def uri_segment(self):
return 'pools/ip-pools'

View File

@ -121,7 +121,7 @@ class NsxLibNsGroup(utils.NsxLibApiBase):
def update(self, nsgroup_id, display_name=None, description=None,
membership_criteria=None, members=None):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self.nsxlib_config.max_attempts)
@ -306,7 +306,7 @@ class NsxLibFirewallSection(utils.NsxLibApiBase):
def update(self, section_id, display_name=None, description=None,
applied_tos=None, rules=None):
#Using internal method so we can access max_attempts in the decorator
# Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception(
exceptions.StaleRevision,
max_attempts=self.nsxlib_config.max_attempts)
@ -355,13 +355,10 @@ class NsxLibFirewallSection(utils.NsxLibApiBase):
return {'target_id': ip_cidr_block,
'target_type': target_type}
def get_rule_dict(
self, display_name, source=None,
destination=None,
direction=consts.IN_OUT,
ip_protocol=consts.IPV4_IPV6,
service=None, action=consts.FW_ACTION_ALLOW,
logged=False):
def get_rule_dict(self, display_name, source=None, destination=None,
direction=consts.IN_OUT, ip_protocol=consts.IPV4_IPV6,
service=None, action=consts.FW_ACTION_ALLOW,
logged=False):
return {'display_name': display_name,
'sources': [source] if source else [],
'destinations': [destination] if destination else [],

View File

@ -72,7 +72,7 @@ def retry_upon_exception(exc, delay=0.5, max_delay=2,
return tenacity.retry(reraise=True,
retry=tenacity.retry_if_exception_type(exc),
wait=tenacity.wait_exponential(
multiplier=delay, max=max_delay),
multiplier=delay, max=max_delay),
stop=tenacity.stop_after_attempt(max_attempts))