Commit cb40fb36 authored by Jake Yip's avatar Jake Yip Committed by Michal Nasiadka
Browse files

Add back pep8 test

In Change I523a4a85867f82d234ba1f3e6fad8b8cd2291182, the pep8 test was
accidentally dropped.

Fix up code so that pep8 passes.

In addition to that following change has been added here to unbreak CI:

Add WebTest as an indirect test dependency

Pecan has made webtest an optional dependency for testing only [1].
Since it is still used for testing we need to add it to our
test-requirements.txt.

[1]: https://github.com/pecan/pecan/pull/140

Change-Id: I2f85adb4ef29a43389897c201e6152fd4c7be9d6
parent a5797a5e
......@@ -72,7 +72,7 @@ def _delete_loadbalancers(context, lbs, cluster, octavia_client,
return candidates
def delete_loadbalancers(context, cluster):
def delete_loadbalancers(context, cluster): # noqa: C901
"""Delete loadbalancers for the cluster.
The following load balancers are deleted:
......
......@@ -45,7 +45,7 @@ class Handler(object):
LOG.debug("Creating self signed x509 certificate")
try:
ca_cert_type = certificate.ca_cert_type
except Exception as e:
except Exception:
LOG.debug("There is no CA cert type specified for the CSR")
ca_cert_type = "kubernetes"
......
......@@ -18,8 +18,7 @@ from magnum.conductor.handlers.common.cert_manager import create_client_files
class KubernetesAPI:
"""
Simple Kubernetes API client using requests.
"""Simple Kubernetes API client using requests.
This API wrapper allows for a set of very simple operations to be
performed on a Kubernetes cluster using the `requests` library. The
......@@ -55,9 +54,7 @@ class KubernetesAPI:
return response.text
def get_healthz(self):
"""
Get the health of the cluster from API
"""
"""Get the health of the cluster from API"""
return self._request(
'GET',
f"{self.cluster.api_address}/healthz",
......@@ -65,8 +62,7 @@ class KubernetesAPI:
)
def list_node(self):
"""
List all nodes in the cluster.
"""List all nodes in the cluster.
:return: List of nodes.
"""
......@@ -76,8 +72,7 @@ class KubernetesAPI:
)
def list_namespaced_pod(self, namespace):
"""
List all pods in the given namespace.
"""List all pods in the given namespace.
:param namespace: Namespace to list pods from.
:return: List of pods.
......@@ -88,9 +83,9 @@ class KubernetesAPI:
)
def __del__(self):
"""
Close all of the file descriptions for the certificates, since they
are left open by `create_client_files`.
"""Close all of the file descriptions for the certificates
They are left open by `create_client_files`.
TODO(mnaser): Use a context manager and avoid having these here.
"""
......
......@@ -344,7 +344,7 @@ class Connection(api.Connection):
query = self._add_tenant_filters(context, query)
public_q = model_query(models.ClusterTemplate).filter_by(public=True)
query = query.union(public_q)
query = query.filter(models.ClusterTemplate.id==cluster_template_id)
query = query.filter(models.ClusterTemplate.id == cluster_template_id)
try:
return query.one()
except NoResultFound:
......@@ -356,7 +356,8 @@ class Connection(api.Connection):
query = self._add_tenant_filters(context, query)
public_q = model_query(models.ClusterTemplate).filter_by(public=True)
query = query.union(public_q)
query = query.filter(models.ClusterTemplate.uuid==cluster_template_uuid)
query = query.filter(
models.ClusterTemplate.uuid == cluster_template_uuid)
try:
return query.one()
except NoResultFound:
......@@ -368,7 +369,8 @@ class Connection(api.Connection):
query = self._add_tenant_filters(context, query)
public_q = model_query(models.ClusterTemplate).filter_by(public=True)
query = query.union(public_q)
query = query.filter(models.ClusterTemplate.name==cluster_template_name)
query = query.filter(
models.ClusterTemplate.name == cluster_template_name)
try:
return query.one()
except MultipleResultsFound:
......
......@@ -10,8 +10,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import ast
from oslo_utils import strutils
from magnum.common import utils
......
......@@ -44,4 +44,3 @@ class Certificate(base.MagnumPersistentObject, base.MagnumObject):
return cls(project_id=cluster['project_id'],
user_id=cluster['user_id'],
cluster_uuid=cluster['uuid'])
......@@ -189,7 +189,8 @@ class TestListCluster(api_base.FunctionalTest):
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.objects.Cluster.obj_load_attr")
@mock.patch("magnum.objects.Cluster.cluster_template")
def test_get_all_with_all_projects(self, mock_context, mock_policy, mock_load, mock_template):
def test_get_all_with_all_projects(self, mock_context, mock_policy,
mock_load, mock_template):
for id_ in range(4):
temp_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster(self.context, id=id_,
......
......@@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization
from unittest import mock
......
......@@ -247,8 +247,8 @@ class CertManagerTestCase(base.BaseTestCase):
mock_cluster, ca_cert_type="front-proxy")
self.CertManager.get_cert.assert_called_once_with(
mock_cluster.front_proxy_ca_cert_ref, resource_ref=mock_cluster.uuid,
context=None)
mock_cluster.front_proxy_ca_cert_ref,
resource_ref=mock_cluster.uuid, context=None)
self.assertEqual(mock_ca_cert, cluster_ca_cert)
def test_get_cluster_magnum_cert(self):
......
......@@ -610,7 +610,8 @@ class MonitorsTestCase(base.TestCase):
'api': 'ok', 'k8s-cluster-node-1.Ready': True})
@mock.patch('magnum.conductor.k8s_api.create_client_files')
def test_k8s_monitor_health_unreachable_cluster(self, mock_create_client_files):
def test_k8s_monitor_health_unreachable_cluster(
self, mock_create_client_files):
mock_create_client_files.return_value = (
tempfile.NamedTemporaryFile(),
tempfile.NamedTemporaryFile(),
......@@ -634,7 +635,8 @@ class MonitorsTestCase(base.TestCase):
m_fields.ClusterHealthStatus.UNKNOWN)
@mock.patch('magnum.conductor.k8s_api.create_client_files')
def test_k8s_monitor_health_unreachable_with_master_lb(self, mock_create_client_files):
def test_k8s_monitor_health_unreachable_with_master_lb(
self, mock_create_client_files):
mock_create_client_files.return_value = (
tempfile.NamedTemporaryFile(),
tempfile.NamedTemporaryFile(),
......
......@@ -190,7 +190,8 @@ class TestK8sScaleManager(base.TestCase):
@mock.patch('magnum.objects.Cluster.get_by_uuid')
@mock.patch('magnum.conductor.k8s_api.create_client_files')
def test_get_hosts_with_container(self, mock_create_client_files, mock_get):
def test_get_hosts_with_container(
self, mock_create_client_files, mock_get):
mock_cluster = mock.MagicMock()
mock_cluster.api_address = "https://foobar.com:6443"
......
......@@ -624,7 +624,8 @@ class AtomicK8sTemplateDefinitionTestCase(BaseK8sTemplateDefinitionTestCase):
'master_lb_allowed_cidrs')
octavia_provider = mock_cluster.labels.get('octavia_provider')
octavia_lb_algorithm = mock_cluster.labels.get('octavia_lb_algorithm')
octavia_lb_healthcheck = mock_cluster.labels.get('octavia_lb_healthcheck')
octavia_lb_healthcheck = mock_cluster.labels.get(
'octavia_lb_healthcheck')
k8s_def = k8sa_tdef.AtomicK8sTemplateDefinition()
......@@ -1186,7 +1187,8 @@ class AtomicK8sTemplateDefinitionTestCase(BaseK8sTemplateDefinitionTestCase):
octavia_provider = mock_cluster.labels.get('octavia_provider')
octavia_lb_algorithm = mock_cluster.labels.get('octavia_lb_algorithm')
octavia_lb_healthcheck = mock_cluster.labels.get('octavia_lb_healthcheck')
octavia_lb_healthcheck = mock_cluster.labels.get(
'octavia_lb_healthcheck')
k8s_def = k8sa_tdef.AtomicK8sTemplateDefinition()
......
......@@ -21,3 +21,4 @@ testrepository>=0.0.20 # Apache-2.0/BSD
stestr>=3.1.0 # Apache-2.0
testscenarios>=0.4 # Apache-2.0/BSD
testtools>=2.4.0 # MIT
WebTest>=2.0.27 # MIT
......@@ -93,6 +93,19 @@ commands =
find . -type f -name "*.py[c|o]" -delete
stestr run {posargs}
[testenv:pep8]
commands =
doc8 -e .rst specs/ doc/source/ contrib/ CONTRIBUTING.rst HACKING.rst README.rst
bash tools/flake8wrap.sh {posargs}
bandit -r magnum -x tests -n5 -ll
bash -c "find {toxinidir} \
-not \( -type d -name .?\* -prune \) \
-not \( -type d -name doc -prune \) \
-not \( -type d -name contrib -prune \) \
-type f \
-name \*.sh \
-print0 | xargs -0 bashate -v -iE006,E010,E042 -eE005"
[testenv:venv]
commands = {posargs}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment