From e73000209d46461b1196f560bf5c36bade020134 Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Tue, 14 Feb 2017 14:37:05 +0100 Subject: Fix flake8 violations in releng Change-Id: I45769ff9c9db2de9fbba69117a92de414dd7f651 Signed-off-by: jose.lausuch --- .../dashboard/dashboard/common/elastic_access.py | 2 +- utils/test/dashboard/dashboard/conf/testcases.py | 2 +- .../dashboard/dashboard/elastic2kibana/utility.py | 3 ++- utils/test/dashboard/dashboard/functest/format.py | 22 ++++++++++++++-------- .../test/dashboard/dashboard/mongo2elastic/main.py | 22 ++++++++++++++-------- utils/test/dashboard/kibana_cleanup.py | 17 +++++++++++------ 6 files changed, 43 insertions(+), 25 deletions(-) (limited to 'utils/test/dashboard') diff --git a/utils/test/dashboard/dashboard/common/elastic_access.py b/utils/test/dashboard/dashboard/common/elastic_access.py index aaf776f7a..eb29ce879 100644 --- a/utils/test/dashboard/dashboard/common/elastic_access.py +++ b/utils/test/dashboard/dashboard/common/elastic_access.py @@ -30,7 +30,7 @@ def publish_docs(url, creds=None, body=None): def _get_docs_nr(url, creds=None, body=None): res_data = _get('{}/_search?size=0'.format(url), creds=creds, body=body) - print type(res_data), res_data + print(type(res_data), res_data) return res_data['hits']['total'] diff --git a/utils/test/dashboard/dashboard/conf/testcases.py b/utils/test/dashboard/dashboard/conf/testcases.py index ff801b4c9..98ce20984 100644 --- a/utils/test/dashboard/dashboard/conf/testcases.py +++ b/utils/test/dashboard/dashboard/conf/testcases.py @@ -21,4 +21,4 @@ def get_format(project, case): if __name__ == '__main__': fmt = get_format('functest', 'vping_ssh') - print fmt + print(fmt) diff --git a/utils/test/dashboard/dashboard/elastic2kibana/utility.py b/utils/test/dashboard/dashboard/elastic2kibana/utility.py index 55578bd8c..40d9202a6 100644 --- a/utils/test/dashboard/dashboard/elastic2kibana/utility.py +++ b/utils/test/dashboard/dashboard/elastic2kibana/utility.py @@ -2,7 +2,8 @@ import json from jinja2 import Environment, PackageLoader -env = Environment(loader=PackageLoader('dashboard', 'elastic2kibana/templates')) +env = Environment(loader=PackageLoader('dashboard', + 'elastic2kibana/templates')) env.filters['jsonify'] = json.dumps diff --git a/utils/test/dashboard/dashboard/functest/format.py b/utils/test/dashboard/dashboard/functest/format.py index ef485bae0..75d361ff8 100644 --- a/utils/test/dashboard/dashboard/functest/format.py +++ b/utils/test/dashboard/dashboard/functest/format.py @@ -6,7 +6,8 @@ def _convert_value(value): def _convert_duration(duration): - if (isinstance(duration, str) or isinstance(duration, unicode)) and ':' in duration: + if ((isinstance(duration, str) or + isinstance(duration, unicode)) and ':' in duration): hours, minutes, seconds = duration.split(":") hours = _convert_value(hours) minutes = _convert_value(minutes) @@ -42,11 +43,11 @@ def format_normal(testcase): testcase_tests = float(testcase_details['tests']) testcase_failures = float(testcase_details['failures']) if testcase_tests != 0: - testcase_details['success_percentage'] = 100 * (testcase_tests - testcase_failures) / testcase_tests + testcase_details['success_percentage'] = 100 * \ + (testcase_tests - testcase_failures) / testcase_tests else: testcase_details['success_percentage'] = 0 - return found @@ -115,28 +116,33 @@ def format_onos(testcase): """ testcase_details = testcase['details'] - if 'FUNCvirNet' not in testcase_details or 'FUNCvirNetL3' not in testcase_details: + if ('FUNCvirNet' not in testcase_details or + 'FUNCvirNetL3' not in testcase_details): return False funcvirnet_details = testcase_details['FUNCvirNet']['status'] - funcvirnet_stats = _get_statistics(funcvirnet_details, ('Case result',), ('PASS', 'FAIL')) + funcvirnet_stats = _get_statistics( + funcvirnet_details, ('Case result',), ('PASS', 'FAIL')) funcvirnet_passed = funcvirnet_stats['PASS'] funcvirnet_failed = funcvirnet_stats['FAIL'] funcvirnet_all = funcvirnet_passed + funcvirnet_failed funcvirnetl3_details = testcase_details['FUNCvirNetL3']['status'] - funcvirnetl3_stats = _get_statistics(funcvirnetl3_details, ('Case result',), ('PASS', 'FAIL')) + funcvirnetl3_stats = _get_statistics( + funcvirnetl3_details, ('Case result',), ('PASS', 'FAIL')) funcvirnetl3_passed = funcvirnetl3_stats['PASS'] funcvirnetl3_failed = funcvirnetl3_stats['FAIL'] funcvirnetl3_all = funcvirnetl3_passed + funcvirnetl3_failed testcase_details['FUNCvirNet'] = { - 'duration': _convert_duration(testcase_details['FUNCvirNet']['duration']), + 'duration': + _convert_duration(testcase_details['FUNCvirNet']['duration']), 'tests': funcvirnet_all, 'failures': funcvirnet_failed } testcase_details['FUNCvirNetL3'] = { - 'duration': _convert_duration(testcase_details['FUNCvirNetL3']['duration']), + 'duration': + _convert_duration(testcase_details['FUNCvirNetL3']['duration']), 'tests': funcvirnetl3_all, 'failures': funcvirnetl3_failed } diff --git a/utils/test/dashboard/dashboard/mongo2elastic/main.py b/utils/test/dashboard/dashboard/mongo2elastic/main.py index 688f55f7d..e33252df2 100644 --- a/utils/test/dashboard/dashboard/mongo2elastic/main.py +++ b/utils/test/dashboard/dashboard/mongo2elastic/main.py @@ -27,7 +27,8 @@ parser.add_argument('-ld', '--latest-days', metavar='N', help='get entries old at most N days from mongodb and' ' parse those that are not already in elasticsearch.' - ' If not present, will get everything from mongodb, which is the default') + ' If not present, will get everything from mongodb,' + ' which is the default') args = parser.parse_args() CONF = APIConfig().parse(args.config_file) @@ -37,6 +38,7 @@ tmp_docs_file = './mongo-{}.json'.format(uuid.uuid4()) class DocumentVerification(object): + def __init__(self, doc): super(DocumentVerification, self).__init__() self.doc = doc @@ -55,8 +57,8 @@ class DocumentVerification(object): for key, value in self.doc.items(): if key in mandatory_fields: if value is None: - logger.info("Skip testcase '%s' because field '%s' missing" % - (self.doc_id, key)) + logger.info("Skip testcase '%s' because field " + "'%s' missing" % (self.doc_id, key)) self.skip = True else: mandatory_fields.remove(key) @@ -131,10 +133,12 @@ class DocumentPublisher(object): self._publish() def _publish(self): - status, data = elastic_access.publish_docs(self.elastic_url, self.creds, self.doc) + status, data = elastic_access.publish_docs( + self.elastic_url, self.creds, self.doc) if status > 300: logger.error('Publish record[{}] failed, due to [{}]' - .format(self.doc, json.loads(data)['error']['reason'])) + .format(self.doc, + json.loads(data)['error']['reason'])) def _fix_date(self, date_string): if isinstance(date_string, dict): @@ -163,7 +167,8 @@ class DocumentsPublisher(object): def export(self): if self.days > 0: - past_time = datetime.datetime.today() - datetime.timedelta(days=self.days) + past_time = datetime.datetime.today( + ) - datetime.timedelta(days=self.days) query = '''{{ "project_name": "{}", "case_name": "{}", @@ -182,7 +187,7 @@ class DocumentsPublisher(object): try: subprocess.check_call(cmd) return self - except Exception, err: + except Exception as err: logger.error("export mongodb failed: %s" % err) self._remove() exit(-1) @@ -217,7 +222,8 @@ class DocumentsPublisher(object): }}'''.format(self.project, self.case, self.days) else: raise Exception('Update days must be non-negative') - self.existed_docs = elastic_access.get_docs(self.elastic_url, self.creds, body) + self.existed_docs = elastic_access.get_docs( + self.elastic_url, self.creds, body) return self def publish(self): diff --git a/utils/test/dashboard/kibana_cleanup.py b/utils/test/dashboard/kibana_cleanup.py index ee0190049..7e3662c29 100644 --- a/utils/test/dashboard/kibana_cleanup.py +++ b/utils/test/dashboard/kibana_cleanup.py @@ -9,7 +9,8 @@ from dashboard.common import elastic_access logger = logging.getLogger('clear_kibana') logger.setLevel(logging.DEBUG) file_handler = logging.FileHandler('/var/log/{}.log'.format('clear_kibana')) -file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s')) +file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: ' + '%(message)s')) logger.addHandler(file_handler) @@ -21,12 +22,17 @@ def delete_all(url, es_creds): if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Delete saved kibana searches, visualizations and dashboards') - parser.add_argument('-e', '--elasticsearch-url', default='http://localhost:9200', - help='the url of elasticsearch, defaults to http://localhost:9200') + parser = argparse.ArgumentParser( + description=('Delete saved kibana searches, ' + 'visualizations and dashboards')) + parser.add_argument('-e', '--elasticsearch-url', + default='http://localhost:9200', + help=('the url of elasticsearch, ' + 'defaults to http://localhost:9200')) parser.add_argument('-u', '--elasticsearch-username', default=None, - help='The username with password for elasticsearch in format username:password') + help=('The username with password for elasticsearch ' + 'in format username:password')) args = parser.parse_args() base_elastic_url = args.elasticsearch_url @@ -38,4 +44,3 @@ if __name__ == '__main__': for url in urls: delete_all(url, es_creds) - -- cgit 1.2.3-korg