Fix flake8 violations in releng 17/28617/5
authorjose.lausuch <jose.lausuch@ericsson.com>
Tue, 14 Feb 2017 13:37:05 +0000 (14:37 +0100)
committerjose.lausuch <jose.lausuch@ericsson.com>
Tue, 14 Feb 2017 15:58:05 +0000 (16:58 +0100)
Change-Id: I45769ff9c9db2de9fbba69117a92de414dd7f651
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
20 files changed:
modules/opnfv/deployment/example.py
modules/opnfv/deployment/manager.py
modules/opnfv/utils/Credentials.py
modules/opnfv/utils/constants.py
modules/opnfv/utils/ovs_logger.py
modules/opnfv/utils/ssh_utils.py
utils/lab-reconfiguration/reconfigUcsNet.py
utils/opnfv-artifacts.py
utils/test/dashboard/dashboard/common/elastic_access.py
utils/test/dashboard/dashboard/conf/testcases.py
utils/test/dashboard/dashboard/elastic2kibana/utility.py
utils/test/dashboard/dashboard/functest/format.py
utils/test/dashboard/dashboard/mongo2elastic/main.py
utils/test/dashboard/kibana_cleanup.py
utils/test/reporting/functest/reporting-tempest.py
utils/test/reporting/functest/reporting-vims.py
utils/test/reporting/functest/testCase.py
utils/test/reporting/utils/reporting_utils.py
utils/test/testapi/htmlize/htmlize.py
utils/test/testapi/update/templates/utils.py

index 6a76eb9..f456832 100644 (file)
@@ -18,4 +18,4 @@ for node in nodes:
     print("Hello, I am node '%s' and my ip is %s." %
           (node.run_cmd('hostname'), node.ip))
 
-print handler.get_deployment_info()
+print(handler.get_deployment_info())
index f0e4429..9f77ff0 100644 (file)
@@ -56,7 +56,7 @@ class Deployment(object):
             version = self.deployment_info['openstack_version'].split('.')[0]
             name = os_versions[version]
             return name
-        except Exception as e:
+        except Exception:
             return 'Unknown release'
 
     def get_dict(self):
index 6441b84..141ecbd 100644 (file)
@@ -77,7 +77,7 @@ class Credentials(object):
         creds_file = '/root/openrc'
         try:
             self.handler.get_file_from_controller(creds_file, target_path)
-        except Exception, e:
+        except Exception as e:
             self.logger.error(
                 "Cannot get %s from controller. %e" % (creds_file, e))
         pass
index ed83488..56008c3 100644 (file)
@@ -14,6 +14,7 @@ EXIT_OK = 0
 EXIT_RUN_ERROR = -1
 EXIT_PUSH_TO_TEST_DB_ERROR = -2
 
+
 class Constants(object):
     INSTALLERS = ['apex', 'fuel', 'compass', 'joid', "daisy"]
     VERSIONS = ['arno', 'brahmaputra', 'colorado', 'danube']
index 3159609..75b4cec 100644 (file)
@@ -16,6 +16,7 @@ logger = OPNFVLogger.Logger('ovs_logger').getLogger()
 
 
 class OVSLogger(object):
+
     def __init__(self, basedir, ft_resdir):
         self.ovs_dir = basedir
         self.ft_resdir = ft_resdir
@@ -32,7 +33,7 @@ class OVSLogger(object):
             hosts = stdout.readline().strip().split(' ')
             found_host = [h for h in hosts if h.startswith(host_prefix)][0]
             return found_host
-        except Exception, e:
+        except Exception as e:
             logger.error(e)
 
     def __dump_to_file(self, operation, host, text, timestamp=None):
@@ -55,7 +56,7 @@ class OVSLogger(object):
                                 .format(cmd, host))
             output = ''.join(stdout.readlines())
             return output
-        except Exception, e:
+        except Exception as e:
             logger.error('[__remote_command(ssh_client, {0})]: {1}'
                          .format(cmd, e))
             return None
@@ -78,7 +79,7 @@ class OVSLogger(object):
             host = self.__ssh_host(ssh_conn)
             self.__dump_to_file(operation, host, output, timestamp=timestamp)
             return output
-        except Exception, e:
+        except Exception as e:
             logger.error('[ofctl_dump_flows(ssh_client, {0}, {1})]: {2}'
                          .format(br, choose_table, e))
             return None
@@ -91,7 +92,7 @@ class OVSLogger(object):
             host = self.__ssh_host(ssh_conn)
             self.__dump_to_file(operation, host, output, timestamp=timestamp)
             return output
-        except Exception, e:
+        except Exception as e:
             logger.error('[vsctl_show(ssh_client)]: {0}'.format(e))
             return None
 
index f900455..d17f5ae 100644 (file)
@@ -47,7 +47,7 @@ def get_ssh_client(hostname,
                            password=password)
 
         return client
-    except Exception, e:
+    except Exception as e:
         logger.error(e)
         return None
 
@@ -57,7 +57,7 @@ def get_file(ssh_conn, src, dest):
         sftp = ssh_conn.open_sftp()
         sftp.get(src, dest)
         return True
-    except Exception, e:
+    except Exception as e:
         logger.error("Error [get_file(ssh_conn, '%s', '%s']: %s" %
                      (src, dest, e))
         return None
@@ -68,7 +68,7 @@ def put_file(ssh_conn, src, dest):
         sftp = ssh_conn.open_sftp()
         sftp.put(src, dest)
         return True
-    except Exception, e:
+    except Exception as e:
         logger.error("Error [put_file(ssh_conn, '%s', '%s']: %s" %
                      (src, dest, e))
         return None
@@ -128,5 +128,5 @@ class ProxyHopClient(paramiko.SSHClient):
                                                 pkey=proxy_key,
                                                 sock=self.proxy_channel)
             os.remove(self.local_ssh_key)
-        except Exception, e:
+        except Exception as e:
             logger.error(e)
index 4c08f3d..0dd902f 100755 (executable)
 # -p PASSWORD, --password=PASSWORD
 #                       [Mandatory] Account Password for UCSM Login
 # -f FILE, --file=FILE
-#                       [Optional] Yaml file with network config you want to set for POD
-#                       If not present only current network config will be printed
+#                       [Optional] Yaml file with network config you
+#                       want to set for POD
+#                       If not present only current network config
+#                       will be printed
 #
 
 import getpass
@@ -32,12 +34,14 @@ import platform
 import yaml
 import time
 import sys
-from UcsSdk import *
-from collections import defaultdict
+from UcsSdk import LsmaintAck, LsPower, LsServer, OrgOrg
+from UcsSdk import UcsHandle, VnicEther, VnicEtherIf, YesOrNo
+
 
 POD_PREFIX = "POD-2"
 INSTALLER = "POD-21"
 
+
 def getpassword(prompt):
     if platform.system() == "Linux":
         return getpass.unix_getpass(prompt=prompt)
@@ -51,7 +55,8 @@ def get_servers(handle=None):
     """
     Return list of servers
     """
-    orgObj = handle.GetManagedObject(None, OrgOrg.ClassId(), {OrgOrg.DN : "org-root"})[0]
+    orgObj = handle.GetManagedObject(
+        None, OrgOrg.ClassId(), {OrgOrg.DN: "org-root"})[0]
     servers = handle.GetManagedObject(orgObj, LsServer.ClassId())
     for server in servers:
         if server.Type == 'instance' and POD_PREFIX in server.Dn:
@@ -63,10 +68,10 @@ def set_boot_policy(handle=None, server=None, policy=None):
     Modify Boot policy of server
     """
     obj = handle.GetManagedObject(None, LsServer.ClassId(), {
-            LsServer.DN: server.Dn})
+        LsServer.DN: server.Dn})
     handle.SetManagedObject(obj, LsServer.ClassId(), {
-            LsServer.BOOT_POLICY_NAME: policy} )
-    print " Configured boot policy: {}".format(policy)
+        LsServer.BOOT_POLICY_NAME: policy})
+    print(" Configured boot policy: {}".format(policy))
 
 
 def ack_pending(handle=None, server=None):
@@ -74,30 +79,32 @@ def ack_pending(handle=None, server=None):
     Acknowledge pending state of server
     """
     handle.AddManagedObject(server, LsmaintAck.ClassId(), {
-            LsmaintAck.DN: server.Dn + "/ack",
-            LsmaintAck.DESCR:"",
-            LsmaintAck.ADMIN_STATE:"trigger-immediate",
-            LsmaintAck.SCHEDULER:"",
-            LsmaintAck.POLICY_OWNER:"local"}, True)
-    print " Pending-reboot -> Acknowledged."
+        LsmaintAck.DN: server.Dn + "/ack",
+        LsmaintAck.DESCR: "",
+        LsmaintAck.ADMIN_STATE: "trigger-immediate",
+        LsmaintAck.SCHEDULER: "",
+        LsmaintAck.POLICY_OWNER: "local"}, True)
+    print(" Pending-reboot -> Acknowledged.")
 
 
 def boot_server(handle=None, server=None):
     """
     Boot server (when is in power-off state)
     """
-    obj = handle.GetManagedObject(None, LsServer.ClassId(), {LsServer.DN: server.Dn})
+    obj = handle.GetManagedObject(
+        None, LsServer.ClassId(), {LsServer.DN: server.Dn})
     handle.AddManagedObject(obj, LsPower.ClassId(), {
-            LsPower.DN: server.Dn + "/power",
-            LsPower.STATE:"admin-up"}, True)
-    print " Booting."
+        LsPower.DN: server.Dn + "/power",
+        LsPower.STATE: "admin-up"}, True)
+    print(" Booting.")
 
 
 def get_vnics(handle=None, server=None):
     """
     Return list of vnics for given server
     """
-    vnics = handle.ConfigResolveChildren(VnicEther.ClassId(), server.Dn, None, YesOrNo.TRUE)
+    vnics = handle.ConfigResolveChildren(
+        VnicEther.ClassId(), server.Dn, None, YesOrNo.TRUE)
     return vnics.OutConfigs.GetChild()
 
 
@@ -105,28 +112,36 @@ def get_network_config(handle=None):
     """
     Print current network config
     """
-    print "\nCURRENT NETWORK CONFIG:"
-    print " d - default, t - tagged"
+    print("\nCURRENT NETWORK CONFIG:")
+    print(" d - default, t - tagged")
     for server in get_servers(handle):
-        print ' {}'.format(server.Name)
-        print '  Boot policy: {}'.format(server.OperBootPolicyName)
+        print(' {}'.format(server.Name))
+        print('  Boot policy: {}'.format(server.OperBootPolicyName))
         for vnic in get_vnics(handle, server):
-            print '  {}'.format(vnic.Name)
-            print '   {}'.format(vnic.Addr)
-            vnicIfs = handle.ConfigResolveChildren(VnicEtherIf.ClassId(), vnic.Dn, None, YesOrNo.TRUE)
+            print('  {}'.format(vnic.Name))
+            print('   {}'.format(vnic.Addr))
+            vnicIfs = handle.ConfigResolveChildren(
+                VnicEtherIf.ClassId(), vnic.Dn, None, YesOrNo.TRUE)
             for vnicIf in vnicIfs.OutConfigs.GetChild():
                 if vnicIf.DefaultNet == 'yes':
-                    print '    Vlan: {}d'.format(vnicIf.Vnet)
+                    print('    Vlan: {}d'.format(vnicIf.Vnet))
                 else:
-                    print '    Vlan: {}t'.format(vnicIf.Vnet)
+                    print('    Vlan: {}t'.format(vnicIf.Vnet))
 
 
-def add_interface(handle=None, lsServerDn=None, vnicEther=None, templName=None, order=None, macAddr=None):
+def add_interface(handle=None,
+                  lsServerDn=None,
+                  vnicEther=None,
+                  templName=None,
+                  order=None,
+                  macAddr=None):
     """
     Add interface to server specified by server.DN name
     """
-    print " Adding interface: {}, template: {}, server.Dn: {}".format(vnicEther, templName, lsServerDn)
-    obj = handle.GetManagedObject(None, LsServer.ClassId(), {LsServer.DN:lsServerDn})
+    print(" Adding interface: {}, template: {}, server.Dn: {}".format(
+        vnicEther, templName, lsServerDn))
+    obj = handle.GetManagedObject(
+        None, LsServer.ClassId(), {LsServer.DN: lsServerDn})
     vnicEtherDn = lsServerDn + "/ether-" + vnicEther
     params = {
         VnicEther.STATS_POLICY_NAME: "default",
@@ -146,8 +161,9 @@ def remove_interface(handle=None, vnicEtherDn=None):
     """
     Remove interface specified by Distinguished Name (vnicEtherDn)
     """
-    print " Removing interface: {}".format(vnicEtherDn)
-    obj = handle.GetManagedObject(None, VnicEther.ClassId(), {VnicEther.DN:vnicEtherDn})
+    print(" Removing interface: {}".format(vnicEtherDn))
+    obj = handle.GetManagedObject(
+        None, VnicEther.ClassId(), {VnicEther.DN: vnicEtherDn})
     handle.RemoveManagedObject(obj)
 
 
@@ -165,32 +181,37 @@ def set_network(handle=None, yamlFile=None):
     Configure VLANs on POD according specified network
     """
     # add interfaces and bind them with vNIC templates
-    print "\nRECONFIGURING VNICs..."
+    print("\nRECONFIGURING VNICs...")
     pod_data = read_yaml_file(yamlFile)
     network = pod_data['network']
 
     for index, server in enumerate(get_servers(handle)):
         # Assign template to interface
         for iface, data in network.iteritems():
-            add_interface(handle, server.Dn, iface, data['template'], data['order'], data['mac-list'][index])
+            add_interface(handle, server.Dn, iface, data['template'], data[
+                          'order'], data['mac-list'][index])
 
-        # Remove other interfaces which have not assigned required vnic template
+        # Remove other interfaces which have not assigned required vnic
+        # template
         vnics = get_vnics(handle, server)
         for vnic in vnics:
-            if not any(data['template'] in vnic.OperNwTemplName for iface, data in network.iteritems()):
+            if not any(data['template'] in vnic.OperNwTemplName for
+                       iface, data in network.iteritems()):
                 remove_interface(handle, vnic.Dn)
-                print "  {} removed, template: {}".format(vnic.Name, vnic.OperNwTemplName)
+                print("  {} removed, template: {}".format(
+                    vnic.Name, vnic.OperNwTemplName))
 
         # Set boot policy template
-        if not INSTALLER in server.Dn:
+        if INSTALLER not in server.Dn:
             set_boot_policy(handle, server, pod_data['boot-policy'])
 
 
 if __name__ == "__main__":
-    print "\n*** SKIPING RECONFIGURATION.***\n"
+    print("\n*** SKIPING RECONFIGURATION.***\n")
     sys.exit(0)
     # Latest urllib2 validate certs by default
-    # The process wide "revert to the old behaviour" hook is to monkeypatch the ssl module
+    # The process wide "revert to the old behaviour" hook is to monkeypatch
+    # the ssl module
     # https://bugs.python.org/issue22417
     import ssl
     if hasattr(ssl, '_create_unverified_context'):
@@ -198,14 +219,15 @@ if __name__ == "__main__":
     try:
         handle = UcsHandle()
         parser = optparse.OptionParser()
-        parser.add_option('-i', '--ip',dest="ip",
-                        help="[Mandatory] UCSM IP Address")
-        parser.add_option('-u', '--username',dest="userName",
-                        help="[Mandatory] Account Username for UCSM Login")
-        parser.add_option('-p', '--password',dest="password",
-                        help="[Mandatory] Account Password for UCSM Login")
-        parser.add_option('-f', '--file',dest="yamlFile",
-                        help="[Optional] Yaml file contains network config you want to set on UCS POD1")
+        parser.add_option('-i', '--ip', dest="ip",
+                          help="[Mandatory] UCSM IP Address")
+        parser.add_option('-u', '--username', dest="userName",
+                          help="[Mandatory] Account Username for UCSM Login")
+        parser.add_option('-p', '--password', dest="password",
+                          help="[Mandatory] Account Password for UCSM Login")
+        parser.add_option('-f', '--file', dest="yamlFile",
+                          help=("[Optional] Yaml file contains network "
+                                "config you want to set on UCS POD1"))
         (options, args) = parser.parse_args()
 
         if not options.ip:
@@ -215,26 +237,27 @@ if __name__ == "__main__":
             parser.print_help()
             parser.error("Provide UCSM UserName")
         if not options.password:
-            options.password=getpassword("UCSM Password:")
+            options.password = getpassword("UCSM Password:")
 
         handle.Login(options.ip, options.userName, options.password)
 
         # Change vnic template if specified in cli option
-        if (options.yamlFile != None):
+        if (options.yamlFile is not None):
             set_network(handle, options.yamlFile)
             time.sleep(5)
 
-        print "\nWait until Overall Status of all nodes is OK..."
-        timeout = time.time() + 60*10   #10 minutes timeout
+        print("\nWait until Overall Status of all nodes is OK...")
+        timeout = time.time() + 60 * 10  # 10 minutes timeout
         while True:
             list_of_states = []
             for server in get_servers(handle):
                 if server.OperState == "power-off":
-                    boot_server(handle,server)
+                    boot_server(handle, server)
                 if server.OperState == "pending-reboot":
-                    ack_pending(handle,server)
+                    ack_pending(handle, server)
                 list_of_states.append(server.OperState)
-            print " {}, {} seconds remains.".format(list_of_states, round(timeout-time.time()))
+            print(" {}, {} seconds remains.".format(
+                list_of_states, round(timeout - time.time())))
             if all(state == "ok" for state in list_of_states):
                 break
             if time.time() > timeout:
@@ -246,11 +269,12 @@ if __name__ == "__main__":
 
         handle.Logout()
 
-    except Exception, err:
+    except Exception as err:
         handle.Logout()
-        print "Exception:", str(err)
-        import traceback, sys
-        print '-'*60
+        print("Exception:", str(err))
+        import traceback
+        import sys
+        print('-' * 60)
         traceback.print_exc(file=sys.stdout)
-        print '-'*60
+        print('-' * 60)
         sys.exit(1)
index 876efed..2f2cc41 100644 (file)
@@ -28,56 +28,55 @@ from apiclient.errors import HttpError
 
 import argparse
 import json
-import os
 import sys
 
 api = {
-  'projects': {},
-  'docs': {},
-  'releases': {},
+    'projects': {},
+    'docs': {},
+    'releases': {},
 }
 
 releases = [
-  'arno.2015.1.0',
-  'arno.2015.2.0',
-  'brahmaputra.1.0',
+    'arno.2015.1.0',
+    'arno.2015.2.0',
+    'brahmaputra.1.0',
 ]
 
 # List of file extensions to filter out
 ignore_extensions = [
-  '.buildinfo',
-  '.woff',
-  '.ttf',
-  '.svg',
-  '.eot',
-  '.pickle',
-  '.doctree',
-  '.js',
-  '.png',
-  '.css',
-  '.gif',
-  '.jpeg',
-  '.jpg',
-  '.bmp',
+    '.buildinfo',
+    '.woff',
+    '.ttf',
+    '.svg',
+    '.eot',
+    '.pickle',
+    '.doctree',
+    '.js',
+    '.png',
+    '.css',
+    '.gif',
+    '.jpeg',
+    '.jpg',
+    '.bmp',
 ]
 
 
 parser = argparse.ArgumentParser(
-             description='OPNFV Artifacts JSON Generator')
+    description='OPNFV Artifacts JSON Generator')
 
 parser.add_argument(
-        '-k',
-        dest='key',
-        default='',
-        help='API Key for Google Cloud Storage')
+    '-k',
+    dest='key',
+    default='',
+    help='API Key for Google Cloud Storage')
 
 parser.add_argument(
-        '-p',
-        default=None,
-        dest='pretty',
-        action='store_const',
-        const=2,
-        help='pretty print the output')
+    '-p',
+    default=None,
+    dest='pretty',
+    action='store_const',
+    const=2,
+    help='pretty print the output')
 
 # Parse and assign arguments
 args = parser.parse_args()
@@ -130,7 +129,6 @@ def has_logs(gerrit_review):
     return False
 
 
-
 def has_ignorable_extension(filename):
     for extension in ignore_extensions:
         if filename.lower().endswith(extension):
@@ -148,11 +146,11 @@ def get_results(key):
     files = storage.objects().list(bucket='artifacts.opnfv.org',
                                    fields='nextPageToken,'
                                           'items('
-                                              'name,'
-                                              'mediaLink,'
-                                              'updated,'
-                                              'contentType,'
-                                              'size'
+                                   'name,'
+                                   'mediaLink,'
+                                   'updated,'
+                                   'contentType,'
+                                   'size'
                                           ')')
     while (files is not None):
         sites = files.execute()
@@ -173,7 +171,8 @@ def get_results(key):
 
             project = site_split[0]
             name = '/'.join(site_split[1:])
-            proxy = "http://build.opnfv.org/artifacts.opnfv.org/%s" % site['name']
+            proxy = "http://build.opnfv.org/artifacts.opnfv.org/%s" % site[
+                'name']
             if name.endswith('.html'):
                 href = "http://artifacts.opnfv.org/%s" % site['name']
                 href_type = 'view'
@@ -183,7 +182,7 @@ def get_results(key):
 
             gerrit = has_gerrit_review(site_split)
             logs = False  # has_logs(gerrit)
-            documentation = has_documentation(site_split)
+            documentation = has_documentation(site_split)
             release = has_release(site_split)
 
             category = 'project'
index aaf776f..eb29ce8 100644 (file)
@@ -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']
 
 
index ff801b4..98ce209 100644 (file)
@@ -21,4 +21,4 @@ def get_format(project, case):
 
 if __name__ == '__main__':
     fmt = get_format('functest', 'vping_ssh')
-    print fmt
+    print(fmt)
index 55578bd..40d9202 100644 (file)
@@ -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
 
 
index ef485ba..75d361f 100644 (file)
@@ -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
     }
index 688f55f..e33252d 100644 (file)
@@ -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):
index ee01900..7e3662c 100644 (file)
@@ -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)
-
index 5d6bcc0..6e6585a 100755 (executable)
@@ -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
 
index 2077d2a..b236b89 100755 (executable)
@@ -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))
index 8d90fc8..df0874e 100644 (file)
@@ -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
-
index da97953..fc5d188 100644 (file)
@@ -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))
 
 
 # ----------------------------------------------------------
index 075e31f..b8c4fb4 100644 (file)
@@ -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,
index a18ff03..4254fee 100644 (file)
@@ -44,5 +44,5 @@ def main(method, parser):
     args = parser.parse_args()
     try:
         method(args)
-    except AssertionError, msg:
+    except AssertionError as msg:
         print(msg)