Updated uses of "Execute Command On BMC" in lib folder.

Change-Id: I5358f01e93deb4f3df7c147fb8fe50924c4cd774
Signed-off-by: Joy Onyerikwu <onyekachukwu.joy.onyerikwu@ibm.com>
diff --git a/lib/bmc_cleanup.robot b/lib/bmc_cleanup.robot
index b54aa82..2058cd1 100644
--- a/lib/bmc_cleanup.robot
+++ b/lib/bmc_cleanup.robot
@@ -23,30 +23,18 @@
 
     Should Not Be Empty  ${cleanup_dir_path}
     Should Not Be Empty  ${SKIP_LIST}
-    Open Connection And Log In
-    @{skip_list}=  Set Variable  ${skip_list.split()}
-    ${skip_list_string}=  Set Variable  ${EMPTY}
+
+    ${skip_list_string}=  Set Variable  cd ${cleanup_dir_path}
     :FOR  ${file}  IN  @{skip_list}
-    \  ${skip_list_string}=   Set Variable  ${skip_list_string} ! -path "${file}"
+    \  ${skip_list_string}=   Set Variable  ${skip_list_string} && rm ${file}
 
-    ${file_count1}=  Execute Command On BMC  find ${cleanup_dir_path} | wc -l
-    Set Global Variable  ${file_count1}
-    Write  find ${cleanup_dir_path} \\( ${skip_list_string} \\) | xargs rm
-    Write  find ${cleanup_dir_path} \\( ${skip_list_string} \\) | xargs rmdir
-    ${file_count2}=  Execute Command On BMC  find ${cleanup_dir_path} | wc -l
+    ${file_count1}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  find ${cleanup_dir_path} | wc -l
+    BMC Execute Command  ${skip_list_string}
 
-    Run Keyword If  ${file_count2} < ${file_count1}
-    ...  Reboot And Verify
-
-Reboot And Verify
-    [Documentation]  Reboot BMC and verify cleanup.
-    [Arguments]      ${cleanup_dir_path}=${CLEANUP_DIR_PATH}
-
-    # Description of argument(s):
-    # cleanup_dir_path  Directory path to do the cleanup.
-
-    OBMC Reboot (off)
-    # Take SSH session post BMC reboot before executing command.
-    Open Connection And Log In
-    ${file_count2}=  Execute Command On BMC  find ${cleanup_dir_path} | wc -l
+    ${file_count2}  ${stderrt}  ${rc}=  BMC Execute Command
+    ...  find ${cleanup_dir_path} | wc -l
     Should Be True  ${file_count2} < ${file_count1}
+    # Delete the directory if it is empty.
+    Run Keyword If  ${file_count2} <= 1
+    ...  BMC Execute Command  rm -r ${cleanup_dir_path}
diff --git a/lib/bmc_network_utils.robot b/lib/bmc_network_utils.robot
index 07521dd..231eb0e 100644
--- a/lib/bmc_network_utils.robot
+++ b/lib/bmc_network_utils.robot
@@ -21,7 +21,8 @@
 
     Should Not Be Empty  ${mac_address}
     Open Connection And Log In
-    ${bmc_mac_addr}=  Execute Command On BMC  cat /sys/class/net/eth0/address
+    ${bmc_mac_addr}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  cat /sys/class/net/eth0/address
     Run Keyword If  '${mac_address.lower()}' != '${bmc_mac_addr.lower()}'
     ...  Set MAC Address
 
@@ -38,14 +39,14 @@
 
     # Take SSH session post BMC reboot.
     Open Connection And Log In
-    ${bmc_mac_addr}=  Execute Command On BMC  cat /sys/class/net/eth0/address
+    ${bmc_mac_addr}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  cat /sys/class/net/eth0/address
     Should Be Equal  ${bmc_mac_addr}  ${mac_address}  ignore_case=True
 
 
 Get BMC IP Info
     [Documentation]  Get system IP address and prefix length.
 
-    Open Connection And Login
 
     # Get system IP address and prefix length details using "ip addr"
     # Sample Output of "ip addr":
@@ -53,7 +54,8 @@
     #     link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
     #     inet xx.xx.xx.xx/24 brd xx.xx.xx.xx scope global eth0
 
-    ${cmd_output}=  Execute Command On BMC  /sbin/ip addr | grep eth0
+    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  /sbin/ip addr | grep eth0
 
     # Get line having IP address details.
     ${lines}=  Get Lines Containing String  ${cmd_output}  inet
@@ -74,14 +76,14 @@
 Get BMC Route Info
     [Documentation]  Get system route info.
 
-    Open Connection And Login
 
     # Sample output of "ip route":
     # default via xx.xx.xx.x dev eth0
     # xx.xx.xx.0/23 dev eth0  src xx.xx.xx.xx
     # xx.xx.xx.0/24 dev eth0  src xx.xx.xx.xx
 
-    ${cmd_output}=  Execute Command On BMC  /sbin/ip route
+    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  /sbin/ip route
 
     [Return]  ${cmd_output}
 
@@ -89,12 +91,12 @@
 Get BMC MAC Address
     [Documentation]  Get system MAC address.
 
-    Open Connection And Login
 
     # Sample output of "ip addr | grep ether":
     # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff
 
-    ${cmd_output}=  Execute Command On BMC  /sbin/ip addr | grep ether
+    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  /sbin/ip addr | grep ether
 
     # Split the line and return MAC address.
     # Split list data:
@@ -111,7 +113,8 @@
     # Sample output of "ip addr | grep ether":
     # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff
 
-    ${cmd_output}=  BMC Execute Command  /sbin/ip addr | grep ether
+    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  /sbin/ip addr | grep ether
 
     # Split the line and return MAC address.
     # Split list data:
@@ -119,7 +122,7 @@
     # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
 
     ${mac_list}=  Create List
-    @{lines}=  Split To Lines  ${cmd_output[0]}
+    @{lines}=  Split To Lines  ${cmd_output}
     :FOR  ${line}  IN  @{lines}
     \  @{words}=  Split String  ${line}
     \   Append To List  ${mac_list}  ${words[1]}
@@ -138,7 +141,8 @@
     #            Kernel: Linux 4.10.17-d6ae40dc4c4dff3265cc254d404ed6b03fcc2206
     #      Architecture: arm
 
-    ${output}=  Execute Command on BMC  hostnamectl | grep hostname
+    ${output}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  hostnamectl | grep hostname
 
     [Return]  ${output}
 
diff --git a/lib/code_update_utils.py b/lib/code_update_utils.py
index 9b9fbf7..948cedb 100644
--- a/lib/code_update_utils.py
+++ b/lib/code_update_utils.py
@@ -14,6 +14,7 @@
 repo_data_path = re.sub('/lib', '/data', robot_pgm_dir_path)
 sys.path.append(repo_data_path)
 
+import bmc_ssh_utils as bsu
 import gen_robot_keyword as keyword
 import gen_print as gp
 import variables as var
@@ -132,11 +133,11 @@
                 calling function.
     """
 
-    keyword.run_key_u("Open Connection And Log In")
-    status, ret_values =\
-        keyword.run_key("Execute Command On BMC  cd " + dir_path
-                        + "; stat -c '%Y %n' * | sort -k1,1nr | head -n 1", ignore=1)
-    return ret_values.split(" ")[-1]
+    stdout, stderr, rc = \
+        bsu.bmc_execute_command("cd " + dir_path +
+                                "; stat -c '%Y %n' * |" +
+                                " sort -k1,1nr | head -n 1")
+    return stdout.split(" ")[-1]
 
 
 def get_version_tar(tar_file_path):
@@ -169,11 +170,10 @@
     file_path    The path to a file that holds the image version.
     """
 
-    keyword.run_key_u("Open Connection And Log In")
-    status, ret_values =\
-        keyword.run_key("Execute Command On BMC  cat "
-                        + file_path + " | grep \"version=\"", ignore=1)
-    return (ret_values.split("\n")[0]).split("=")[-1]
+    stdout, stderr, rc = \
+        bsu.bmc_execute_command("cat "  + file_path +
+                                " | grep \"version=\"", ignore_err=1)
+    return (stdout.split("\n")[0]).split("=")[-1]
 
 
 def get_image_purpose(file_path):
@@ -184,11 +184,10 @@
     file_path    The path to a file that holds the image purpose.
     """
 
-    keyword.run_key_u("Open Connection And Log In")
-    status, ret_values =\
-        keyword.run_key("Execute Command On BMC  cat "
-                        + file_path + " | grep \"purpose=\"", ignore=1)
-    return ret_values.split("=")[-1]
+    stdout, stderr, rc = \
+        bsu.bmc_execute_command("cat " + file_path +
+                                " | grep \"purpose=\"", ignore_err=1)
+    return stdout.split("=")[-1]
 
 
 def get_image_path(image_version):
@@ -203,12 +202,11 @@
                      of the images in the upload dir.
     """
 
-    keyword.run_key_u("Open Connection And Log In")
-    status, image_list =\
-        keyword.run_key("Execute Command On BMC  ls -d "
-                        + var.IMAGE_UPLOAD_DIR_PATH + "*/")
+    stdout, stderr, rc = \
+        bsu.bmc_execute_command("ls -d " + var.IMAGE_UPLOAD_DIR_PATH +
+                                "*/")
 
-    image_list = image_list.split("\n")
+    image_list = stdout.split("\n")
     retry = 0
     while (retry < 10):
         for i in range(0, len(image_list)):
@@ -273,13 +271,14 @@
                    Default is 3 minutes.
     """
 
-    keyword.run_key('Open Connection And Log In')
     for i in range(timeout * 2):
-        stat, grep_res = keyword.run_key('Execute Command On BMC  '
-                                         + 'ls ' + var.IMAGE_UPLOAD_DIR_PATH + '*/MANIFEST 2>/dev/null '
-                                         + '| xargs grep -rl "version=' + image_version + '"')
-        image_dir = os.path.dirname(grep_res.split('\n')[0])
+        stdout, stderr, rc = \
+        bsu.bmc_execute_command('ls ' + var.IMAGE_UPLOAD_DIR_PATH +
+                                '*/MANIFEST 2>/dev/null ' +
+                                '| xargs grep -rl "version=' +
+                                image_version + '"')
+        image_dir = os.path.dirname(stdout.split('\n')[0])
         if '' != image_dir:
-            keyword.run_key('Execute Command On BMC  rm -rf ' + image_dir)
+            bsu.bmc_execute_command('rm -rf ' + image_dir)
             BuiltIn().fail('Found invalid BMC Image: ' + image_dir)
         time.sleep(30)
diff --git a/lib/logging_utils.robot b/lib/logging_utils.robot
index 65ab76b..6d4f724 100644
--- a/lib/logging_utils.robot
+++ b/lib/logging_utils.robot
@@ -136,8 +136,7 @@
     #     "Timestamp": 1487743963328,
     #     "associations": []
     # }
-
-    Execute Command On BMC  /tmp/tarball/bin/logging-test -c AutoTestSimple
+    BMC Execute Command  /tmp/tarball/bin/logging-test -c AutoTestSimple
 
 Count Error Entries
     [Documentation]  Count Error entries.
diff --git a/lib/utils.robot b/lib/utils.robot
index 0b7e60d..54bfc89 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -81,8 +81,7 @@
     # FFS: Flash header not found. Code: 100
     # Error 100 opening ffs !
 
-    Open Connection And Log In
-    ${pnor_info}=  Execute Command On BMC  ${pflash_cmd}
+    ${pnor_info}=  OS Execute Command  ${pflash_cmd}
     Should Not Contain Any  ${pnor_info}  Flash header not found  Error
 
 
@@ -1105,8 +1104,7 @@
 
 Enable Core Dump On BMC
     [Documentation]  Enable core dump collection.
-    Open Connection And Log In
-    ${core_pattern}=  Execute Command On BMC
+    ${core_pattern}  ${stderr}  ${rc}=  BMC Execute Command
     ...  echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern
     Should Be Equal As Strings  ${core_pattern}  /tmp/core_%e.%p
 
@@ -1121,9 +1119,7 @@
 
 Set Core Dump File Size Unlimited
     [Documentation]  Set core dump file size to unlimited.
-    Open Connection And Log In
-    Execute Command On BMC
-    ...  ulimit -c unlimited
+    BMC Execute Command  ulimit -c unlimited
 
 
 Check For Core Dumps
@@ -1352,9 +1348,8 @@
     [Documentation]  Returns BMC version from /etc/os-release.
     ...              e.g. "v1.99.6-141-ge662190"
 
-    Open Connection And Log In
     ${cmd}=  Set Variable  grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '='
-    ${output}=  Execute Command On BMC  ${cmd}
+    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
     [Return]  ${output}