Refactor all python test libraries to conform to python coding guidelines
Refactor robot Test Case Suite to conform to Robot code coding guidelines

Now that I have pycharm installed in a cloned VM that I resized to allow for
development tools, I see coding issues with the original code that I had

This is mostly a cosmetic change as no fundamental changes were made
to the original code

Rebased and fixed conflicts

Change-Id: I5dc0534e92fa708b45399944994101afd7efed63
diff --git a/tests/atests/common/testCaseUtils.py b/tests/atests/common/testCaseUtils.py
index fe76687..e51199d 100755
--- a/tests/atests/common/testCaseUtils.py
+++ b/tests/atests/common/testCaseUtils.py
@@ -18,69 +18,72 @@
 vOLT-HA Test Case Utils module
 """
 import time
-import os
 import commands
 import subprocess
 import pexpect
 import sys
    
-def configDirs(self, logDir, rootDir = None, volthaDir = None):
-    self.dirs ['log'] = logDir
-    self.dirs ['root'] = rootDir
-    self.dirs ['voltha'] = volthaDir
+
+def config_dirs(self, log_dir, root_dir=None, voltha_dir=None):
+    self.dirs['log'] = log_dir
+    self.dirs['root'] = root_dir
+    self.dirs['voltha'] = voltha_dir
     
-def getDir(self, Dir):
-    return self.dirs.get(Dir)
+
+def get_dir(self, directory):
+    return self.dirs.get(directory)
     
-def removeLeadingLine(logDir, logFile):
-    with open(logDir + '/' + logFile, 'r+') as file:
-        lines = file.readlines()
-        file.seek(0)
+
+def remove_leading_line(log_dir, log_file):
+    with open(log_dir + '/' + log_file, 'r+') as FILE:
+        lines = FILE.readlines()
+        FILE.seek(0)
         lines = lines[1:]
         for line in lines:
-            file.write(line)
-        file.truncate()
-        file.close()      
+            FILE.write(line)
+        FILE.truncate()
+        FILE.close()
 
-def send_command_to_voltha_cli(logDir, logFile1, cmd1, logFile2 = None, cmd2 = None, logFile3 = None, cmd3 = None):
-    output = open(logDir + '/' + logFile1, 'w')
+
+def send_command_to_voltha_cli(log_dir, log_file1, cmd1, log_file2=None, cmd2=None, log_file3=None, cmd3=None):
+    output = open(log_dir + '/' + log_file1, 'w')
     child = pexpect.spawn('ssh -p 30110 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no voltha@localhost')
     child.expect('[pP]assword:')
     child.sendline('admin')
     child.expect('\((\\x1b\[\d*;?\d+m){1,2}voltha(\\x1b\[\d*;?\d+m){1,2}\)')
     time.sleep(10)
-    bytes = child.sendline(cmd1)
+    child.sendline(cmd1)
     i = child.expect(['\((\\x1b\[\d*;?\d+m){1,2}voltha(\\x1b\[\d*;?\d+m){1,2}\)',
-    '\((\\x1b\[\d*;?\d+m){1,2}.*device [0-9a-f]{16}(\\x1b\[\d*;?\d+m){1,2}\)'])
+                     '\((\\x1b\[\d*;?\d+m){1,2}.*device [0-9a-f]{16}(\\x1b\[\d*;?\d+m){1,2}\)'])
     if i == 0:
         output.write(child.before)
         output.close()
-        removeLeadingLine(logDir, logFile1)
+        remove_leading_line(log_dir, log_file1)
     elif i == 1:
-        if logFile2 != None and cmd2 != None:
-            output = open(logDir + '/' + logFile2, 'w')
-            bytes = child.sendline(cmd2)
+        if log_file2 is not None and cmd2 is not None:
+            output = open(log_dir + '/' + log_file2, 'w')
+            child.sendline(cmd2)
             child.expect('\((\\x1b\[\d*;?\d+m){1,2}.*device [0-9a-f]{16}(\\x1b\[\d*;?\d+m){1,2}\)')
             output.write(child.before)
             output.close()
-            removeLeadingLine(logDir, logFile2)
-        if logFile3 != None and cmd3 != None:
-            output = open(logDir + '/' + logFile3, 'w')
-            bytes = child.sendline(cmd3)
+            remove_leading_line(log_dir, log_file2)
+        if log_file3 is not None and cmd3 is not None:
+            output = open(log_dir + '/' + log_file3, 'w')
+            child.sendline(cmd3)
             child.expect('\((\\x1b\[\d*;?\d+m){1,2}.*device [0-9a-f]{16}(\\x1b\[\d*;?\d+m){1,2}\)')
             output.write(child.before)
             output.close()
-            removeLeadingLine(logDir, logFile3)
+            remove_leading_line(log_dir, log_file3)
     child.close()
 
-def send_command_to_onos_cli(logDir, cmd, logFile):
-    output = open(logDir + '/' + logFile, 'w')
+
+def send_command_to_onos_cli(log_dir, cmd, log_file):
+    output = open(log_dir + '/' + log_file, 'w')
     child = pexpect.spawn('ssh -p 30115 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no karaf@localhost')
     child.expect('[pP]assword:')
     child.sendline('karaf')
     child.expect('(\\x1b\[\d*;?\d+m){1,2}onos>(\\x1b\[\d*;?\d+m){1,2}')
-    child.sendline('flows')
-    child.expect('flows')
+    child.sendline(cmd)
     child.expect('(\\x1b\[\d*;?\d+m){1,2}onos>(\\x1b\[\d*;?\d+m){1,2}')
 
     output.write(child.before)
@@ -88,41 +91,46 @@
     output.close()
     child.close()
 
-def get_fields_from_grep_command(self, searchWord, logFile):
+
+def get_fields_from_grep_command(self, search_word, log_file):
     grepCommand =\
-        "grep %s %s/%s" % (searchWord, getDir(self, 'log'), logFile)  
+        "grep %s %s/%s" % (search_word, get_dir(self, 'log'), log_file)
     statusLines = commands.getstatusoutput(grepCommand)[1]
     return statusLines
     
-def parseFields(statusLine):
-    statusList = statusLine.split("|")
+
+def parse_fields(status_line):
+    statusList = status_line.split("|")
     return statusList
 
-def printLogFile(self, logFile):
-    with open(getDir(self, 'log') + '/' + logFile, 'r+') as file:
-        lines = file.readlines()
+
+def print_log_file(self, log_file):
+    with open(get_dir(self, 'log') + '/' + log_file, 'r+') as FILE:
+        lines = FILE.readlines()
         print
         for line in lines:
-            sys.stdout.write (line)
+            sys.stdout.write(line)
 
-def extractPodIpAddr(podName):
+
+def extract_pod_ip_addr(pod_name):
     proc1 = subprocess.Popen(['/usr/bin/kubectl', 'get', 'svc', '--all-namespaces'],
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
-    proc2 = subprocess.Popen(['grep', '-e', podName], stdin=proc1.stdout,
+    proc2 = subprocess.Popen(['grep', '-e', pod_name], stdin=proc1.stdout,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
     proc3 = subprocess.Popen(['awk', "{print $4}"], stdin=proc2.stdout,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
                             
-    proc1.stdout.close
-    proc2.stdout.close
+    proc1.stdout.close()
+    proc2.stdout.close()
     out, err = proc3.communicate()
     return out
     
-def extractRadiusIpAddr(podName):
-    proc1 = subprocess.Popen(['/usr/bin/kubectl', 'describe', 'pod', '-n', 'voltha', podName],
+
+def extract_radius_ip_addr(pod_name):
+    proc1 = subprocess.Popen(['/usr/bin/kubectl', 'describe', 'pod', '-n', 'voltha', pod_name],
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
     proc2 = subprocess.Popen(['grep', '^IP:'], stdin=proc1.stdout,
@@ -131,31 +139,32 @@
     proc3 = subprocess.Popen(['awk', "{print $2}"], stdin=proc2.stdout,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
-                            
-    proc1.stdout.close
-    proc2.stdout.close
+
+    proc1.stdout.close()
+    proc2.stdout.close()
     out, err = proc3.communicate()
     return out
     
-def extractPodName(shortPodName):
+
+def extract_pod_name(short_pod_name):
     proc1 = subprocess.Popen(['/usr/bin/kubectl', 'get', 'pods', '--all-namespaces'],
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
-    proc2 = subprocess.Popen(['grep', '-e', shortPodName], stdin=proc1.stdout,
+    proc2 = subprocess.Popen(['grep', '-e', short_pod_name], stdin=proc1.stdout,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
     proc3 = subprocess.Popen(['awk', "{print $2}"], stdin=proc2.stdout,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
-                      
-                      
-    proc1.stdout.close
-    proc2.stdout.close
+
+    proc1.stdout.close()
+    proc2.stdout.close()
     out, err = proc3.communicate()
     return out
     
-def modifyRadiusIpInJsonUsingSed(self, newIpAddr):
-    sedCommand ="sed -i '/radiusIp/c\  \"radiusIp\":\"'%s'\",' %s/tests/atests/build/aaa_json" % (newIpAddr, getDir(self, 'voltha'))
+
+def modify_radius_ip_in_json_using_sed(self, new_ip_addr):
+    sedCommand = "sed -i '/radiusIp/c\      \"radiusIp\":\"'%s'\",' %s/tests/atests/build/aaa_json" \
+                 % (new_ip_addr, get_dir(self, 'voltha'))
     status = commands.getstatusoutput(sedCommand)[0]
     return status
-