From e609bd46b04840fd95dc8a23afdcd429c249fb88 Mon Sep 17 00:00:00 2001 From: Amir Mofakhar Date: Wed, 11 Apr 2018 11:41:39 +0200 Subject: [PATCH] Update pep8 checks * set the maximum line length to 100 * cleaned up the codes for pep8 * removed pep8 check ignores Change-Id: I5d3e2f13117638b0a8af051b9faa64ce1a2dd04e Signed-off-by: Amir Mofakhar --- .gitignore | 1 + monitoring/alarmdefs/forms.py | 7 ++++--- monitoring/alarmdefs/tables.py | 2 +- monitoring/alarmdefs/tests.py | 4 ++-- monitoring/alarmdefs/views.py | 8 +++++--- monitoring/alarmdefs/workflows.py | 6 +++--- monitoring/alarms/forms.py | 2 +- monitoring/alarms/tables.py | 6 +++--- monitoring/alarms/tests.py | 8 ++++---- monitoring/alarms/views.py | 15 +++++++-------- monitoring/api/client.py | 6 ++++-- monitoring/api/monitor.py | 14 +++++++------- monitoring/notifications/forms.py | 5 +++-- monitoring/notifications/tables.py | 2 +- monitoring/notifications/tests.py | 4 ++-- monitoring/notifications/views.py | 8 +++++--- monitoring/overview/tests.py | 5 ++--- monitoring/overview/urls.py | 4 ++-- monitoring/overview/views.py | 22 +++++++++++++--------- monitoring/test/client_tests.py | 2 +- tox.ini | 11 +---------- 21 files changed, 72 insertions(+), 70 deletions(-) diff --git a/.gitignore b/.gitignore index d7162a44..6343d1c1 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ AUTHORS ChangeLog tags openstack_dashboard/dummydb.sqlite +.idea diff --git a/monitoring/alarmdefs/forms.py b/monitoring/alarmdefs/forms.py index 9114c8e5..09ec5061 100644 --- a/monitoring/alarmdefs/forms.py +++ b/monitoring/alarmdefs/forms.py @@ -13,8 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import json from itertools import chain +import json from django.template.loader import get_template from django.utils.translation import ugettext as _ # noqa @@ -23,8 +23,8 @@ from horizon import exceptions from horizon import forms from horizon import messages -from monitoring import api from monitoring.alarmdefs import constants +from monitoring import api def _get_metrics(request): @@ -228,7 +228,8 @@ class EditAlarmForm(forms.SelfHandlingForm): notifications = [] exceptions.handle(request, _('Unable to retrieve notifications: %s') % e) - notification_choices = [(notification['id'], notification) for notification in notifications] + notification_choices = [ + (notification['id'], notification) for notification in notifications] self.fields['notifications'].choices = notification_choices diff --git a/monitoring/alarmdefs/tables.py b/monitoring/alarmdefs/tables.py index 6f885e2f..3a76b6f0 100644 --- a/monitoring/alarmdefs/tables.py +++ b/monitoring/alarmdefs/tables.py @@ -100,7 +100,7 @@ class AlarmsTable(tables.DataTable): def get_object_display(self, obj): return obj['name'] - class Meta: + class Meta(object): name = "alarms" verbose_name = _("Alarm Definitions") row_actions = (EditAlarm, diff --git a/monitoring/alarmdefs/tests.py b/monitoring/alarmdefs/tests.py index 9555e93d..0d05277d 100644 --- a/monitoring/alarmdefs/tests.py +++ b/monitoring/alarmdefs/tests.py @@ -14,12 +14,12 @@ # under the License. from django.core import urlresolvers -from mock import patch, call # noqa +from mock import patch -from monitoring.test import helpers from monitoring.alarmdefs import constants from monitoring.alarmdefs import views from monitoring.alarmdefs import workflows +from monitoring.test import helpers INDEX_URL = urlresolvers.reverse( diff --git a/monitoring/alarmdefs/views.py b/monitoring/alarmdefs/views.py index 49d4ebba..b8beaecd 100644 --- a/monitoring/alarmdefs/views.py +++ b/monitoring/alarmdefs/views.py @@ -15,10 +15,12 @@ import logging from django.contrib import messages -from django.core.paginator import Paginator, EmptyPage -from django.core.urlresolvers import reverse_lazy, reverse # noqa +from django.core.paginator import EmptyPage +from django.core.paginator import Paginator +from django.core.urlresolvers import reverse +from django.core.urlresolvers import reverse_lazy from django.utils.translation import ugettext as _ # noqa -from django.views.generic import TemplateView # noqa +from django.views.generic import TemplateView import six from horizon import exceptions diff --git a/monitoring/alarmdefs/workflows.py b/monitoring/alarmdefs/workflows.py index 49c40836..690a2ba0 100644 --- a/monitoring/alarmdefs/workflows.py +++ b/monitoring/alarmdefs/workflows.py @@ -13,16 +13,16 @@ # under the License. from django.utils.translation import ugettext_lazy as _ # noqa -from django.views.decorators.debug import sensitive_variables # noqa +from django.views.decorators.debug import sensitive_variables from horizon import exceptions from horizon import forms -from horizon import workflows from horizon.utils import memoized +from horizon import workflows -from monitoring import api from monitoring.alarmdefs import constants from monitoring.alarmdefs import forms as ad_forms +from monitoring import api class SetAlarmNotificationsAction(workflows.Action): diff --git a/monitoring/alarms/forms.py b/monitoring/alarms/forms.py index 06083f04..98bf4953 100644 --- a/monitoring/alarms/forms.py +++ b/monitoring/alarms/forms.py @@ -25,8 +25,8 @@ from horizon import exceptions from horizon import forms from horizon import messages -from monitoring import api from monitoring.alarms import constants +from monitoring import api class ExpressionWidget(forms.Widget): diff --git a/monitoring/alarms/tables.py b/monitoring/alarms/tables.py index 695123da..aa4a5568 100644 --- a/monitoring/alarms/tables.py +++ b/monitoring/alarms/tables.py @@ -24,9 +24,9 @@ from django.utils.translation import ungettext_lazy from horizon import tables from monitoring.alarms import constants +from monitoring import api from monitoring.config import local_settings from monitoring.overview import constants as ov_constants -from monitoring import api STATUS = ["OK", "WARNING", "CRITICAL", "UNKNOWN"] @@ -254,7 +254,7 @@ class AlarmsTable(tables.DataTable): def get_object_display(self, obj): return obj['id'] - class Meta: + class Meta(object): name = "alarms" verbose_name = _("Alarms") row_actions = (GraphMetric, @@ -285,6 +285,6 @@ class AlarmHistoryTable(tables.DataTable): def get_object_id(self, obj): return obj['alarm_id'] + obj['timestamp'] - class Meta: + class Meta(object): name = "history" verbose_name = _("Alarm History") diff --git a/monitoring/alarms/tests.py b/monitoring/alarms/tests.py index 9eb68d5c..703591e0 100644 --- a/monitoring/alarms/tests.py +++ b/monitoring/alarms/tests.py @@ -11,11 +11,11 @@ # under the License. from django.core import urlresolvers -from mock import patch, call # noqa +from mock import patch -from monitoring.test import helpers from monitoring.alarms import constants from monitoring.alarms import tables +from monitoring.test import helpers INDEX_URL = urlresolvers.reverse( @@ -56,7 +56,7 @@ class AlarmsTest(helpers.TestCase): def test_metric_conversion_multiple(self): res = tables.show_metric_names({"metrics": [{"name": "mem.used_bytes"}, - {"name": "mem.total_bytes"}]}) + {"name": "mem.total_bytes"}]}) table_res = res.split(', ') self.assertEqual(len(table_res), 2) self.assertTrue("mem.used_bytes" in table_res) @@ -64,5 +64,5 @@ class AlarmsTest(helpers.TestCase): def test_metric_conversion_unique(self): res = tables.show_metric_names({"metrics": [{"name": "mem.used_bytes"}, - {"name": "mem.used_bytes"}]}) + {"name": "mem.used_bytes"}]}) self.assertEqual(res, "mem.used_bytes") diff --git a/monitoring/alarms/views.py b/monitoring/alarms/views.py index 2c1fe46e..86024004 100644 --- a/monitoring/alarms/views.py +++ b/monitoring/alarms/views.py @@ -16,15 +16,17 @@ import base64 from datetime import timedelta import logging -from django.conf import settings # noqa +from django.conf import settings from django.contrib import messages -from django.core.paginator import Paginator, EmptyPage -from django.core.urlresolvers import reverse_lazy, reverse # noqa +from django.core.paginator import EmptyPage +from django.core.paginator import Paginator +from django.core.urlresolvers import reverse +from django.core.urlresolvers import reverse_lazy from django.shortcuts import redirect from django.utils.dateparse import parse_datetime from django.utils.translation import ugettext as _ # noqa from django.utils.translation import ugettext_lazy -from django.views.generic import View # noqa +from django.views.generic import View import six from horizon import exceptions @@ -297,10 +299,7 @@ class AlarmHistoryView(tables.DataTableView): page_offset = 0 limit = utils.get_page_size(self.request) try: - results = api.monitor.alarm_history(self.request, - object_id, - page_offset, - limit) + results = api.monitor.alarm_history(self.request, object_id, page_offset, limit) paginator = Paginator(results, limit) contacts = paginator.page(1) except EmptyPage: diff --git a/monitoring/api/client.py b/monitoring/api/client.py index d8c4d20e..79da6021 100644 --- a/monitoring/api/client.py +++ b/monitoring/api/client.py @@ -53,9 +53,11 @@ def _get_endpoint(request): def _get_auth_params_from_request(request): - """Extracts the properties from the request object needed by the monascaclient - call below. These will be used to memoize the calls to monascaclient + """Extracts the properties from the request object needed by the monascaclient call below. + + These will be used to memoize the calls to monascaclient """ + LOG.debug('Extracting intel from request') return ( request.user.user_domain_id, diff --git a/monitoring/api/monitor.py b/monitoring/api/monitor.py index e279f2fc..5f288a9f 100644 --- a/monitoring/api/monitor.py +++ b/monitoring/api/monitor.py @@ -43,13 +43,13 @@ def alarm_list_by_dimension(request, dimensions, offset=0, limit=10000, dim_dict[item] = None if metric: result = client.monascaclient(request).alarms.list(offset=offset, - limit=limit, - metric_dimensions=dim_dict, - metric_name=metric) + limit=limit, + metric_dimensions=dim_dict, + metric_name=metric) else: result = client.monascaclient(request).alarms.list(offset=offset, - limit=limit, - metric_dimensions=dim_dict) + limit=limit, + metric_dimensions=dim_dict) return result['elements'] if type(result) is dict else result @@ -67,8 +67,8 @@ def alarm_delete(request, alarm_id): @profiler.trace def alarm_history(request, alarm_id, offset=0, limit=10000): result = client.monascaclient(request).alarms.history(alarm_id=alarm_id, - offset=offset, - limit=limit) + offset=offset, + limit=limit) return result['elements'] if type(result) is dict else result diff --git a/monitoring/notifications/forms.py b/monitoring/notifications/forms.py index 7cb11c2a..10d87315 100644 --- a/monitoring/notifications/forms.py +++ b/monitoring/notifications/forms.py @@ -72,6 +72,7 @@ class BaseNotificationMethodForm(forms.SelfHandlingForm): def clean_period(self): '''Check to make sure period is zero unless type is WEBHOOK. + For WEBHOOK period must be set to 0 or 60. ''' data = self.cleaned_data @@ -85,8 +86,8 @@ class BaseNotificationMethodForm(forms.SelfHandlingForm): return data['period'] def clean_address(self): - '''Check to make sure address is the correct format depending on the - type of notification. + '''Check to make sure address is the correct format depending on the type of notification. + ''' data = self.cleaned_data if data['type'] == constants.NotificationType.EMAIL: diff --git a/monitoring/notifications/tables.py b/monitoring/notifications/tables.py index 4ccf425a..2ac1fde6 100644 --- a/monitoring/notifications/tables.py +++ b/monitoring/notifications/tables.py @@ -105,7 +105,7 @@ class NotificationsTable(tables.DataTable): def get_object_display(self, obj): return obj['name'] - class Meta: + class Meta(object): name = "notifications" verbose_name = _("Notifications") row_actions = (EditNotification, DeleteNotification, ) diff --git a/monitoring/notifications/tests.py b/monitoring/notifications/tests.py index 7dbb8bc1..fa8d2948 100644 --- a/monitoring/notifications/tests.py +++ b/monitoring/notifications/tests.py @@ -11,10 +11,10 @@ # under the License. from django.core import urlresolvers -from mock import patch, call # noqa +from mock import patch -from monitoring.test import helpers from monitoring.notifications import constants +from monitoring.test import helpers INDEX_URL = urlresolvers.reverse( diff --git a/monitoring/notifications/views.py b/monitoring/notifications/views.py index 9ba71826..75ac936e 100644 --- a/monitoring/notifications/views.py +++ b/monitoring/notifications/views.py @@ -13,8 +13,10 @@ # under the License. from django.contrib import messages -from django.core.paginator import Paginator, EmptyPage -from django.core.urlresolvers import reverse_lazy, reverse # noqa +from django.core.paginator import EmptyPage +from django.core.paginator import Paginator +from django.core.urlresolvers import reverse +from django.core.urlresolvers import reverse_lazy from django.utils.translation import ugettext as _ # noqa from horizon import exceptions @@ -22,10 +24,10 @@ from horizon import forms from horizon import tables from horizon.utils import functions as utils +from monitoring import api from monitoring.notifications import constants from monitoring.notifications import forms as notification_forms from monitoring.notifications import tables as notification_tables -from monitoring import api from openstack_dashboard import policy diff --git a/monitoring/overview/tests.py b/monitoring/overview/tests.py index 33287b54..40c34f35 100644 --- a/monitoring/overview/tests.py +++ b/monitoring/overview/tests.py @@ -14,11 +14,10 @@ from django.core import urlresolvers from django.test import RequestFactory -from mock import patch, call # noqa -from monitoring.test import helpers from monitoring.overview import constants from monitoring.overview import views +from monitoring.test import helpers INDEX_URL = urlresolvers.reverse( @@ -49,7 +48,7 @@ class KibanaProxyViewTest(helpers.TestCase): '/', data={'a': 1, 'b': 2} ) expected_path = ('/elasticsearch/.kibana/search' - '/New-Saved-Search%E3%81%82') + '/New-Saved-Search%E3%81%82') expected_qs = {'a': ['1'], 'b': ['2']} url = self.view.get_relative_url( diff --git a/monitoring/overview/urls.py b/monitoring/overview/urls.py index d22d918a..21d4b78f 100644 --- a/monitoring/overview/urls.py +++ b/monitoring/overview/urls.py @@ -11,10 +11,10 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from django.conf.urls import url # noqa +from django.conf.urls import url -from monitoring.overview import views from monitoring.config import local_settings as settings +from monitoring.overview import views urlpatterns = [ diff --git a/monitoring/overview/views.py b/monitoring/overview/views.py index e1ac80b4..4e72d20f 100644 --- a/monitoring/overview/views.py +++ b/monitoring/overview/views.py @@ -17,14 +17,14 @@ import copy import json import logging -from django import http from django.contrib import messages from django.core.urlresolvers import reverse_lazy -from django.http import HttpResponse # noqa +from django import http +from django.http import HttpResponse from django.utils.translation import ugettext_lazy as _ # noqa -from django.views import generic from django.views.decorators.csrf import csrf_exempt -from django.views.generic import TemplateView # noqa +from django.views import generic +from django.views.generic import TemplateView from openstack_auth import utils as auth_utils from openstack_dashboard import policy import six @@ -32,8 +32,8 @@ from six.moves import urllib from horizon import exceptions -from monitoring import api from monitoring.alarms import tables as alarm_tables +from monitoring import api from monitoring.config import local_settings as settings from monitoring.overview import constants @@ -244,7 +244,8 @@ class IndexView(TemplateView): for link in context["dashboards"]: link['raw'] = link.get('raw', False) context['can_access_logs'] = policy.check( - ((getattr(settings, 'KIBANA_POLICY_SCOPE'), getattr(settings, 'KIBANA_POLICY_RULE')), ), self.request + ((getattr(settings, 'KIBANA_POLICY_SCOPE'), getattr(settings, 'KIBANA_POLICY_RULE')), ), + self.request ) context['enable_kibana_button'] = settings.ENABLE_KIBANA_BUTTON context['show_grafana_home'] = settings.SHOW_GRAFANA_HOME @@ -255,7 +256,9 @@ class MonascaProxyView(TemplateView): template_name = "" def _convert_dimensions(self, req_kwargs): - """this method converts the dimension string + """Converts the dimension string service:monitoring into a dict + + This method converts the dimension string service:monitoring (requested by a query string arg) into a python dict that looks like {"service": "monitoring"} (used by monasca api calls) @@ -310,7 +313,7 @@ class MonascaProxyView(TemplateView): **req_kwargs)} if not results: LOG.warning("There was a request made for the path %s that" - " is not supported." % restpath) + " is not supported." % restpath) results = {} return HttpResponse(json.dumps(results), content_type='application/json') @@ -418,5 +421,6 @@ class KibanaProxyView(generic.View): def _can_access_kibana(self): return policy.check( - ((getattr(settings, 'KIBANA_POLICY_SCOPE'), getattr(settings, 'KIBANA_POLICY_RULE')), ), self.request + ((getattr(settings, 'KIBANA_POLICY_SCOPE'), getattr(settings, 'KIBANA_POLICY_RULE')), ), + self.request ) diff --git a/monitoring/test/client_tests.py b/monitoring/test/client_tests.py index ba62f03d..1ccd24c0 100644 --- a/monitoring/test/client_tests.py +++ b/monitoring/test/client_tests.py @@ -22,10 +22,10 @@ from mock import patch from monascaclient import client as mon_client from monascaclient import v2_0 -from monitoring.test import helpers from monitoring.api.client import _get_auth_params_from_request from monitoring.api.client import _get_to_verify from monitoring.api.client import monascaclient as api_mon_client +from monitoring.test import helpers def _mock_url_for(request, service_name): diff --git a/tox.ini b/tox.ini index e8daa59c..985e557b 100644 --- a/tox.ini +++ b/tox.ini @@ -37,18 +37,9 @@ commands = {posargs} commands = /bin/bash run_tests.sh -N --coverage {posargs} [flake8] +max-line-length = 100 builtins = _ exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,panel_template,dash_template,local_settings.py,*/local/*,*/test/test_plugins/* -# E127 continuation line over-indented for visual indent -# E128 continuation line under-indented for visual indent -# E501 line too long -# H102 Apache 2.0 license header not found -# H238 old style class declaration, use new style -# H301 one import per line -# H306 imports not in alphabetical order -# H405 multi line docstring summary not separated with an empty line -# H904 Wrap long lines in parentheses instead of a backslash -ignore = E127,E128,E501,H102,H238,H301,H306,H405,H904 [testenv:lower-constraints] deps =