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 <amofakhar@op5.com>
This commit is contained in:
parent
78d764718a
commit
e609bd46b0
1
.gitignore
vendored
1
.gitignore
vendored
@ -28,3 +28,4 @@ AUTHORS
|
||||
ChangeLog
|
||||
tags
|
||||
openstack_dashboard/dummydb.sqlite
|
||||
.idea
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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, )
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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 = [
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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):
|
||||
|
11
tox.ini
11
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 =
|
||||
|
Loading…
Reference in New Issue
Block a user