From 44afde12259d551b74cd0a5d66637e53443ad045 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 +- dashboard/dashboard/conf/testcases.py | 2 +- dashboard/dashboard/elastic2kibana/utility.py | 3 ++- dashboard/dashboard/functest/format.py | 22 +++++++++++------- dashboard/dashboard/mongo2elastic/main.py | 22 +++++++++++------- dashboard/kibana_cleanup.py | 17 +++++++++----- reporting/functest/reporting-tempest.py | 8 +++---- reporting/functest/reporting-vims.py | 4 ++-- reporting/functest/testCase.py | 33 +++++++++++++-------------- reporting/utils/reporting_utils.py | 28 +++++++++++------------ testapi/htmlize/htmlize.py | 6 +++-- testapi/update/templates/utils.py | 2 +- 12 files changed, 84 insertions(+), 65 deletions(-) diff --git a/dashboard/dashboard/common/elastic_access.py b/dashboard/dashboard/common/elastic_access.py index aaf776f..eb29ce8 100644 --- a/dashboard/dashboard/common/elastic_access.py +++ b/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/dashboard/dashboard/conf/testcases.py b/dashboard/dashboard/conf/testcases.py index ff801b4..98ce209 100644 --- a/dashboard/dashboard/conf/testcases.py +++ b/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/dashboard/dashboard/elastic2kibana/utility.py b/dashboard/dashboard/elastic2kibana/utility.py index 55578bd..40d9202 100644 --- a/dashboard/dashboard/elastic2kibana/utility.py +++ b/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/dashboard/dashboard/functest/format.py b/dashboard/dashboard/functest/format.py index ef485ba..75d361f 100644 --- a/dashboard/dashboard/functest/format.py +++ b/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/dashboard/dashboard/mongo2elastic/main.py b/dashboard/dashboard/mongo2elastic/main.py index 688f55f..e33252d 100644 --- a/dashboard/dashboard/mongo2elastic/main.py +++ b/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/dashboard/kibana_cleanup.py b/dashboard/kibana_cleanup.py index ee01900..7e3662c 100644 --- a/dashboard/kibana_cleanup.py +++ b/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) - diff --git a/reporting/functest/reporting-tempest.py b/reporting/functest/reporting-tempest.py index 5d6bcc0..6e6585a 100755 --- a/reporting/functest/reporting-tempest.py +++ b/reporting/functest/reporting-tempest.py @@ -44,7 +44,7 @@ for version in rp_utils.get_config('general.versions'): response = urlopen(request) k = response.read() results = json.loads(k) - except URLError, e: + except URLError as e: logger.error("Error code: %s" % e) test_results = results['results'] @@ -73,9 +73,9 @@ for version in rp_utils.get_config('general.versions'): nb_tests_run = result['details']['tests'] nb_tests_failed = result['details']['failures'] if nb_tests_run != 0: - success_rate = 100*((int(nb_tests_run) - - int(nb_tests_failed)) / - int(nb_tests_run)) + success_rate = 100 * ((int(nb_tests_run) - + int(nb_tests_failed)) / + int(nb_tests_run)) else: success_rate = 0 diff --git a/reporting/functest/reporting-vims.py b/reporting/functest/reporting-vims.py index 2077d2a..b236b89 100755 --- a/reporting/functest/reporting-vims.py +++ b/reporting/functest/reporting-vims.py @@ -51,7 +51,7 @@ for version in versions: response = urlopen(request) k = response.read() results = json.loads(k) - except URLError, e: + except URLError as e: logger.error("Error code: %s" % e) test_results = results['results'] @@ -91,7 +91,7 @@ for version in versions: result['pr_step_ok'] = 0 if nb_step != 0: - result['pr_step_ok'] = (float(nb_step_ok)/nb_step)*100 + result['pr_step_ok'] = (float(nb_step_ok) / nb_step) * 100 try: logger.debug("Scenario %s, Installer %s" % (s_result[1]['scenario'], installer)) diff --git a/reporting/functest/testCase.py b/reporting/functest/testCase.py index 8d90fc8..df0874e 100644 --- a/reporting/functest/testCase.py +++ b/reporting/functest/testCase.py @@ -36,14 +36,14 @@ class TestCase(object): 'moon': 'Moon', 'copper': 'Copper', 'security_scan': 'Security', - 'multisite':'Multisite', - 'domino':'Domino', - 'odl-sfc':'SFC', - 'onos_sfc':'SFC', - 'parser':'Parser', - 'connection_check':'Health (connection)', - 'api_check':'Health (api)', - 'snaps_smoke':'SNAPS' } + 'multisite': 'Multisite', + 'domino': 'Domino', + 'odl-sfc': 'SFC', + 'onos_sfc': 'SFC', + 'parser': 'Parser', + 'connection_check': 'Health (connection)', + 'api_check': 'Health (api)', + 'snaps_smoke': 'SNAPS'} try: self.displayName = display_name_matrix[self.name] except: @@ -131,14 +131,14 @@ class TestCase(object): 'moon': 'moon_authentication', 'copper': 'copper-notification', 'security_scan': 'security', - 'multisite':'multisite', - 'domino':'domino-multinode', - 'odl-sfc':'functest-odl-sfc', - 'onos_sfc':'onos_sfc', - 'parser':'parser-basics', - 'connection_check':'connection_check', - 'api_check':'api_check', - 'snaps_smoke':'snaps_smoke' + 'multisite': 'multisite', + 'domino': 'domino-multinode', + 'odl-sfc': 'functest-odl-sfc', + 'onos_sfc': 'onos_sfc', + 'parser': 'parser-basics', + 'connection_check': 'connection_check', + 'api_check': 'api_check', + 'snaps_smoke': 'snaps_smoke' } try: return test_match_matrix[self.name] @@ -147,4 +147,3 @@ class TestCase(object): def getDisplayName(self): return self.displayName - diff --git a/reporting/utils/reporting_utils.py b/reporting/utils/reporting_utils.py index da97953..fc5d188 100644 --- a/reporting/utils/reporting_utils.py +++ b/reporting/utils/reporting_utils.py @@ -93,8 +93,8 @@ def getApiResults(case, installer, scenario, version): response = urlopen(request) k = response.read() results = json.loads(k) - except URLError, e: - print 'No kittez. Got an error code:', e + except URLError as e: + print('No kittez. Got an error code:', e) return results @@ -115,8 +115,8 @@ def getScenarios(case, installer, version): k = response.read() results = json.loads(k) test_results = results['results'] - except URLError, e: - print 'Got an error code:', e + except URLError as e: + print('Got an error code:', e) if test_results is not None: test_results.reverse() @@ -132,8 +132,8 @@ def getScenarios(case, installer, version): exclude_virtual_pod = get_config('functest.exclude_virtual') exclude_noha = get_config('functest.exclude_noha') if ((exclude_virtual_pod and "virtual" in r['pod_name']) or - (exclude_noha and "noha" in r['scenario'])): - print "exclude virtual pod results..." + (exclude_noha and "noha" in r['scenario'])): + print("exclude virtual pod results...") else: scenario_results[r['scenario']].append(r) @@ -164,8 +164,8 @@ def getScenarioStatus(installer, version): response.close() results = json.loads(k) test_results = results['results'] - except URLError, e: - print 'Got an error code:', e + except URLError as e: + print('Got an error code:', e) scenario_results = {} result_dict = {} @@ -198,7 +198,7 @@ def getNbtestOk(results): if "PASS" in v: nb_test_ok += 1 except: - print "Cannot retrieve test status" + print("Cannot retrieve test status") return nb_test_ok @@ -269,10 +269,10 @@ def getJenkinsUrl(build_tag): url_base = get_config('functest.jenkins_url') try: build_id = [int(s) for s in build_tag.split("-") if s.isdigit()] - url_id = build_tag[8:-(len(build_id)+3)] + "/" + str(build_id[0]) + url_id = build_tag[8:-(len(build_id) + 3)] + "/" + str(build_id[0]) jenkins_url = url_base + url_id + "/console" except: - print 'Impossible to get jenkins url:' + print('Impossible to get jenkins url:') return jenkins_url @@ -282,7 +282,7 @@ def getScenarioPercent(scenario_score, scenario_criteria): try: score = float(scenario_score) / float(scenario_criteria) * 100 except: - print 'Impossible to calculate the percentage score' + print('Impossible to calculate the percentage score') return score @@ -330,8 +330,8 @@ def get_percent(four_list, ten_list): def _test(): status = getScenarioStatus("compass", "master") - print "status:++++++++++++++++++++++++" - print json.dumps(status, indent=4) + print("status:++++++++++++++++++++++++") + print(json.dumps(status, indent=4)) # ---------------------------------------------------------- diff --git a/testapi/htmlize/htmlize.py b/testapi/htmlize/htmlize.py index 075e31f..b8c4fb4 100644 --- a/testapi/htmlize/htmlize.py +++ b/testapi/htmlize/htmlize.py @@ -39,12 +39,14 @@ if __name__ == '__main__': parser.add_argument('-ru', '--resource-listing-url', type=str, required=False, - default='http://testresults.opnfv.org/test/swagger/spec.json', + default=('http://testresults.opnfv.org' + '/test/swagger/spec.json'), help='Resource Listing Spec File') parser.add_argument('-au', '--api-declaration-url', type=str, required=False, - default='http://testresults.opnfv.org/test/swagger/spec', + default=('http://testresults.opnfv.org' + '/test/swagger/spec'), help='API Declaration Spec File') parser.add_argument('-o', '--output-directory', required=True, diff --git a/testapi/update/templates/utils.py b/testapi/update/templates/utils.py index a18ff03..4254fee 100644 --- a/testapi/update/templates/utils.py +++ b/testapi/update/templates/utils.py @@ -44,5 +44,5 @@ def main(method, parser): args = parser.parse_args() try: method(args) - except AssertionError, msg: + except AssertionError as msg: print(msg) -- cgit 1.2.3-korg