Change to use new 'BMC Execute Command'.

Changes to use new 'BMC Execute Command' and to stop using
'Open Connection and Log In'.

Change-Id: Iab86623f8835845913233cfe2cb858c93b5e39b6
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/data/boot_table.json b/data/boot_table.json
index 445dd1c..6b3fd9b 100644
--- a/data/boot_table.json
+++ b/data/boot_table.json
@@ -184,7 +184,7 @@
         },
         "bmc_reboot": 1,
         "method_type": "keyword",
-        "method": "Open Connection And Log In ; Start Command  /sbin/reboot"
+        "method": "BMC Execute Command  /sbin/reboot  fork=${1}"
     },
     # Run a "reboot" on the OBMC while host is off.
     "OBMC Reboot (off)": {
@@ -200,7 +200,7 @@
         },
         "bmc_reboot": 1,
         "method_type": "keyword",
-        "method": "Open Connection And Log In ; Start Command  /sbin/reboot"
+        "method": "BMC Execute Command  /sbin/reboot  fork=${1}"
     },
     # Cycle AC via the PDU while host is off.
     "PDU AC Cycle (run)": {
diff --git a/lib/openbmc_ffdc_list.py b/lib/openbmc_ffdc_list.py
index 915fd4a..1ec9ee6 100755
--- a/lib/openbmc_ffdc_list.py
+++ b/lib/openbmc_ffdc_list.py
@@ -31,7 +31,7 @@
     },
     'APPLICATION DATA':
     {
-        'BMC state': '/usr/sbin/obmcutil  state',
+        'BMC state': '/usr/sbin/obmcutil state',
     },
 }
 
diff --git a/lib/openbmc_ffdc_methods.robot b/lib/openbmc_ffdc_methods.robot
index a6173a3..df959af 100755
--- a/lib/openbmc_ffdc_methods.robot
+++ b/lib/openbmc_ffdc_methods.robot
@@ -9,6 +9,7 @@
 Library            OperatingSystem
 Library            Collections
 Library            String
+Library            gen_print.py
 Library            gen_robot_keyword.py
 
 *** Keywords ***
@@ -34,7 +35,6 @@
     #                     obtained via a call to 'Get FFDC Method Desc' (also
     #                     from lib/openbmc_ffdc_list.py).
 
-    Run Key U  Open Connection And Log In
     @{entries}=  Get FFDC Method Index
     :FOR  ${index}  IN  @{entries}
     \    Method Call Keyword List  ${index}  ${ffdc_function_list}
@@ -119,12 +119,16 @@
     [Arguments]        ${key_index}
     ...                ${cmd}
     ...                ${logpath}=${FFDC_FILE_PATH}
+    ...                ${target}=BMC
 
     Run Keyword If   '${logpath}' == '${FFDC_FILE_PATH}'
     ...    Write Cmd Output to FFDC File   ${key_index}  ${cmd}
 
-    ${stdout}  ${stderr}=
-    ...   Execute Command    ${cmd}   return_stderr=True
+    ${cmd_buf}=  Catenate  ${target} Execute Command \ ${cmd} \ ignore_err=${1}
+    ${status}  ${ret_values}=  Run Key  ${cmd_buf}  ignore=${1}
+
+    ${stdout}=  Set Variable  @{ret_values}[0]
+    ${stderr}=  Set Variable  @{ret_values}[1]
 
     # Write stdout on success and stderr/stdout to the file on failure.
     Run Keyword If  $stderr == '${EMPTY}'
@@ -232,7 +236,8 @@
     @{cmd_list}=  get ffdc os all distros call  ${key_index}
     :FOR  ${cmd}  IN  @{cmd_list}
     \   ${logpath}=  Catenate  SEPARATOR=  ${LOG_PREFIX}  ${cmd[0]}.txt
-    \   Execute Command and Write FFDC  ${cmd[0]}  ${cmd[1]}   ${logpath}
+    \   Execute Command and Write FFDC  ${cmd[0]}  ${cmd[1]}  ${logpath}
+    \   ...  target=OS
 
 
 Log OS SPECIFIC DISTRO FFDC
@@ -244,7 +249,8 @@
     @{cmd_list}=  get ffdc os distro call  ${key_index}  ${linux_distro}
     :FOR  ${cmd}  IN  @{cmd_list}
     \   ${logpath}=  Catenate  SEPARATOR=  ${LOG_PREFIX}  ${cmd[0]}.txt
-    \   Execute Command and Write FFDC  ${cmd[0]}  ${cmd[1]}   ${logpath}
+    \   Execute Command and Write FFDC  ${cmd[0]}  ${cmd[1]}  ${logpath}
+    \   ...  target=OS
 
 
 
@@ -259,29 +265,24 @@
     # If can't ping, return
     ${rc}=  Run Keyword and Return Status  Ping Host  ${OS_HOST}
     Return From Keyword If  '${rc}' == '${False}'
-    ...   Could not ping OS
+    ...   Could not ping OS.
 
-    Open Connection And Log In  host=${OS_HOST}  username=${OS_USERNAME}
-    ...   password=${OS_PASSWORD}
+    ${stdout}  ${stderr}  ${rc}=  OS Execute Command  uptime  ignore_err=${1}
+    Return From Keyword If  '${rc}' != '${0}'  Could not connect to OS.
 
-    ${output}  ${stderr}  ${rc}=  Execute Command  uptime  return_stderr=True
-    ...   return_rc=True
+    ${stdout}  ${stderr}  ${rc}=  OS Execute Command
+    ...  . /etc/os-release; echo $ID  ignore_err=${0}
+    Set Global Variable  ${linux_distro}  ${stdout}
 
-    # If the return code returned by "Execute Command" is non-zero, return
-    Return From Keyword If  '${rc}' != '${0}'
-    ...   Could not connect to OS
+    Rpvars  linux_distro
 
     @{entries}=  Get ffdc os all distros index
     :FOR  ${index}  IN  @{entries}
     \   Log OS ALL DISTROS FFDC  ${index}
 
-    ${linux_distro}=  Execute Command
-    ...   . /etc/os-release; echo $ID
-    ...   return_stdout=True  return_stderr=False  return_rc=False
-
     Return From Keyword If
     ...  '${linux_distro}' == '${EMPTY}' or '${linux_distro}' == 'None'
-    ...  Could not determine Linux Distribution
+    ...  Could not determine Linux Distribution.
 
     @{entries}=  Get ffdc os distro index  ${linux_distro}
     :FOR  ${index}  IN  @{entries}
@@ -291,16 +292,17 @@
 ##############################################################################
 SCP Coredump Files
     [Documentation]  Copy core dump file from BMC to local system.
+
     # Check if core dump exist in the /tmp
-    ${core_files}=  Execute Command  ls /tmp/core_*
+    ${core_files}  ${stderr}  ${rc}=  BMC Execute Command  ls /tmp/core_*
     @{core_list} =  Split String    ${core_files}
     # Copy the core files
     Run Key U  Open Connection for SCP
     :FOR  ${index}  IN  @{core_list}
     \  scp.Get File  ${index}  ${LOG_PREFIX}${index.lstrip("/tmp/")}
     # Remove the file from remote to avoid re-copying on next FFDC call
-    \  Execute Command On BMC  rm ${index}
-    Run Key U  scp.Close Connection
+    \  BMC Execute Command  rm ${index}
+    # I can't find a way to do this: scp.Close Connection
 
 
 ##############################################################################
diff --git a/lib/state.py b/lib/state.py
index 6ac103c..a26d140 100755
--- a/lib/state.py
+++ b/lib/state.py
@@ -507,28 +507,9 @@
         if rc == 0:
             packet_loss = out_buf.rstrip("\n")
 
-    master_req_login = ['uptime', 'epoch_seconds']
-    req_login = [sub_state for sub_state in req_states if sub_state in
-                 master_req_login]
-    must_login = (len(req_login) > 0)
-
-    bmc_login = 0
-    if must_login:
-        cmd_buf = ["Open Connection And Log In"]
-        if not quiet:
-            grp.rpissuing_keyword(cmd_buf)
-        status, ret_values = \
-            BuiltIn().run_keyword_and_ignore_error(*cmd_buf)
-        if status == "PASS":
-            bmc_login = 1
-        else:
-            if re.match('^Authentication failed for user', ret_values):
-                # An authentication failure is worth failing on.
-                BuiltIn().fail(gp.sprint_error(ret_values))
-
-    if 'uptime' in req_states and bmc_login:
-        cmd_buf = ["Execute Command", "cat /proc/uptime | cut -f 1 -d ' '",
-                   "return_stderr=True", "return_rc=True"]
+    if 'uptime' in req_states:
+        cmd_buf = ["BMC Execute Command", "cat /proc/uptime | cut -f 1 -d ' '",
+                   'quiet=${1}']
         if not quiet:
             grp.rpissuing_keyword(cmd_buf)
         status, ret_values = \
@@ -538,11 +519,10 @@
             if rc == 0 and stderr == "":
                 uptime = stdout
 
-    if 'epoch_seconds' in req_states and bmc_login:
+    if 'epoch_seconds' in req_states:
         date_cmd_buf = "date -u +%s"
         if USE_BMC_EPOCH_TIME:
-            cmd_buf = ["Execute Command", date_cmd_buf, "return_stderr=True",
-                       "return_rc=True"]
+            cmd_buf = ["BMC Execute Command", date_cmd_buf, 'quiet=${1}']
             if not quiet:
                 grp.rpissuing_keyword(cmd_buf)
             status, ret_values = \
diff --git a/lib/utils.robot b/lib/utils.robot
index d53aac1..2453e1a 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -9,6 +9,7 @@
 Library                 gen_robot_print.py
 Library                 gen_cmd.py
 Library                 gen_robot_keyword.py
+Library                 bmc_ssh_utils.py
 
 *** Variables ***
 ${pflash_cmd}           /usr/sbin/pflash -r /dev/stdout -P VERSION
@@ -54,8 +55,7 @@
 Get BMC System Model
     [Documentation]  Get the BMC model from the device tree.
 
-    Open Connection And Log In
-    ${bmc_model}  ${stderr}=  Execute Command
+    ${bmc_model}  ${stderr}  ${rc}=  BMC Execute Command
     ...  cat ${devicetree_base} | cut -d " " -f 1  return_stderr=True
     Should Be Empty  ${stderr}
     Should Not Be Empty  ${bmc_model}