xref: /openbmc/openbmc-test-automation/lib/common_utils.robot (revision e16f158fb9a0a66dc731acfb9681766f58fbda58)
1f60cbcfbSSteven Sombar*** Settings ***
2f60cbcfbSSteven Sombar
3f60cbcfbSSteven SombarDocumentation  Utilities for Robot keywords that do not use REST.
4f60cbcfbSSteven Sombar
5839a0c27SSandhya SomashekarResource                ../lib/resource.robot
6f60cbcfbSSteven SombarResource                ../lib/connection_client.robot
7f60cbcfbSSteven SombarResource                ../lib/boot_utils.robot
8f60cbcfbSSteven SombarLibrary                 String
9f60cbcfbSSteven SombarLibrary                 DateTime
10f60cbcfbSSteven SombarLibrary                 Process
11f60cbcfbSSteven SombarLibrary                 OperatingSystem
12f60cbcfbSSteven SombarLibrary                 gen_print.py
13f60cbcfbSSteven SombarLibrary                 gen_robot_print.py
14f60cbcfbSSteven SombarLibrary                 gen_cmd.py
1507ed7944SMichael WalshLibrary                 gen_robot_valid.py
16f60cbcfbSSteven SombarLibrary                 gen_robot_keyword.py
17f60cbcfbSSteven SombarLibrary                 bmc_ssh_utils.py
18f60cbcfbSSteven SombarLibrary                 utils.py
19f60cbcfbSSteven SombarLibrary                 var_funcs.py
20f60cbcfbSSteven SombarLibrary                 SCPLibrary  WITH NAME  scp
21f60cbcfbSSteven Sombar
22f60cbcfbSSteven Sombar*** Variables ***
23f60cbcfbSSteven Sombar
24f60cbcfbSSteven Sombar${pflash_cmd}             /usr/sbin/pflash -r /dev/stdout -P VERSION
25f60cbcfbSSteven Sombar
26f60cbcfbSSteven Sombar${dbuscmdBase}
27f60cbcfbSSteven Sombar...  dbus-send --system --print-reply --dest=${OPENBMC_BASE_DBUS}.settings.Host
28f60cbcfbSSteven Sombar${dbuscmdGet}
29f60cbcfbSSteven Sombar...  ${SETTINGS_URI}host0  org.freedesktop.DBus.Properties.Get
30f60cbcfbSSteven Sombar${dbuscmdString}=  string:"xyz.openbmc_project.settings.Host" string:
31f60cbcfbSSteven Sombar
32f60cbcfbSSteven Sombar# Assign default value to QUIET for programs which may not define it.
33f60cbcfbSSteven Sombar${QUIET}  ${0}
34f60cbcfbSSteven Sombar
35f60cbcfbSSteven Sombar${bmc_mem_free_cmd}=   free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f4
36f60cbcfbSSteven Sombar${bmc_mem_total_cmd}=   free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f2
37f60cbcfbSSteven Sombar${bmc_cpu_usage_cmd}=   top -n 1  | grep CPU: | cut -c 7-9
38f60cbcfbSSteven Sombar${HOST_SETTING}    ${SETTINGS_URI}host0
39f60cbcfbSSteven Sombar
40f60cbcfbSSteven Sombar# /run/initramfs/ro associate filesystem  should be 100% full always
41f60cbcfbSSteven Sombar${bmc_file_system_usage_cmd}=  df -h | cut -c 52-54 | grep 100 | wc -l
42f60cbcfbSSteven Sombar${total_pnor_ro_file_system_cmd}=  df -h | grep /media/pnor-ro | wc -l
43f60cbcfbSSteven Sombar${total_bmc_ro_file_system_cmd}=  df -h | grep /media/rofs | wc -l
44f60cbcfbSSteven Sombar
45f60cbcfbSSteven Sombar${BOOT_TIME}     ${0}
46f60cbcfbSSteven Sombar${BOOT_COUNT}    ${0}
47f60cbcfbSSteven Sombar${count}  ${0}
48f60cbcfbSSteven Sombar${devicetree_base}  /sys/firmware/devicetree/base/model
49f60cbcfbSSteven Sombar
50f60cbcfbSSteven Sombar# Initialize default debug value to 0.
51f60cbcfbSSteven Sombar${DEBUG}         ${0}
52f60cbcfbSSteven Sombar
53f60cbcfbSSteven Sombar${probe_cpu_tool_path}     ${EXECDIR}/tools/ras/probe_cpus.sh
54f60cbcfbSSteven Sombar${scom_addrs_tool_path}    ${EXECDIR}/tools/ras/scom_addr_p9.sh
55f60cbcfbSSteven Sombar${target_file_path}        /root/
56f60cbcfbSSteven Sombar
57f60cbcfbSSteven Sombar${default_tarball}  ${EXECDIR}/obmc-phosphor-debug-tarball-witherspoon.tar.xz
58f60cbcfbSSteven Sombar
59f60cbcfbSSteven Sombar# These variables are used to straddle between new and old methods of setting
60f60cbcfbSSteven Sombar# values.
61f60cbcfbSSteven Sombar${bmc_power_policy_method}        ${EMPTY}
62f60cbcfbSSteven Sombar@{valid_power_policy_vars}        RESTORE_LAST_STATE  ALWAYS_POWER_ON
63f60cbcfbSSteven Sombar...                               ALWAYS_POWER_OFF
64f60cbcfbSSteven Sombar
65b9f3f776SGeorge Keishing${check_performance}              ${1}
66b9f3f776SGeorge Keishing
67f60cbcfbSSteven Sombar
68f60cbcfbSSteven Sombar*** Keywords ***
69f60cbcfbSSteven Sombar
70f60cbcfbSSteven SombarCheck BMC Performance
71f60cbcfbSSteven Sombar    [Documentation]  Check BMC basic CPU Mem File system performance.
72f60cbcfbSSteven Sombar
73b9f3f776SGeorge Keishing    Return From Keyword If   not ${check_performance}
74b9f3f776SGeorge Keishing
75f60cbcfbSSteven Sombar    Check BMC CPU Performance
76f60cbcfbSSteven Sombar    Check BMC Mem Performance
77f60cbcfbSSteven Sombar    Check BMC File System Performance
78f60cbcfbSSteven Sombar
79f60cbcfbSSteven Sombar
80f60cbcfbSSteven SombarVerify PNOR Update
81f60cbcfbSSteven Sombar    [Documentation]  Verify that the PNOR is not corrupted.
82f60cbcfbSSteven Sombar    # Example:
83f60cbcfbSSteven Sombar    # FFS: Flash header not found. Code: 100
84f60cbcfbSSteven Sombar    # Error 100 opening ffs !
85f60cbcfbSSteven Sombar
86f60cbcfbSSteven Sombar    ${stdout}  ${stderr}  ${rc}=
87f60cbcfbSSteven Sombar    ...  BMC Execute Command  /usr/sbin/pflash -h | egrep -q skip
88f60cbcfbSSteven Sombar    ...  ignore_err=${1}
89f60cbcfbSSteven Sombar    ${pflash_cmd}=  Set Variable If  ${rc} == ${0}  ${pflash_cmd} --skip=4096
90f60cbcfbSSteven Sombar    ...  ${pflash_cmd}
91f60cbcfbSSteven Sombar    ${pnor_info}=  BMC Execute Command  ${pflash_cmd}
92f60cbcfbSSteven Sombar    Should Not Contain Any  ${pnor_info}  Flash header not found  Error
93f60cbcfbSSteven Sombar
94f60cbcfbSSteven Sombar
95f60cbcfbSSteven SombarGet BMC System Model
96f60cbcfbSSteven Sombar    [Documentation]  Get the BMC model from the device tree and return it.
97f60cbcfbSSteven Sombar
98f60cbcfbSSteven Sombar    ${bmc_model}  ${stderr}  ${rc}=  BMC Execute Command
99f60cbcfbSSteven Sombar    ...  cat ${devicetree_base} | cut -d " " -f 1  return_stderr=True
100f60cbcfbSSteven Sombar    ...  test_mode=0
101f60cbcfbSSteven Sombar    Should Be Empty  ${stderr}
102f60cbcfbSSteven Sombar    Should Not Be Empty  ${bmc_model}  msg=BMC model is empty.
103f60cbcfbSSteven Sombar    [Return]  ${bmc_model}
104f60cbcfbSSteven Sombar
105f60cbcfbSSteven Sombar
106f60cbcfbSSteven SombarVerify BMC System Model
107f60cbcfbSSteven Sombar    [Documentation]  Verify the BMC model with ${OPENBMC_MODEL}.
108f60cbcfbSSteven Sombar    [Arguments]  ${bmc_model}
109f60cbcfbSSteven Sombar
110f60cbcfbSSteven Sombar    # Description of argument(s):
111f60cbcfbSSteven Sombar    # bmc_model System model (e.g. "witherspoon").
112f60cbcfbSSteven Sombar
113f60cbcfbSSteven Sombar    ${tmp_bmc_model}=  Fetch From Right  ${OPENBMC_MODEL}  /
114f60cbcfbSSteven Sombar    ${tmp_bmc_model}=  Fetch From Left  ${tmp_bmc_model}  .
115f60cbcfbSSteven Sombar    ${ret}=  Run Keyword And Return Status  Should Contain  ${bmc_model}
116f60cbcfbSSteven Sombar    ...  ${tmp_bmc_model}  ignore_case=True
117f60cbcfbSSteven Sombar    [Return]  ${ret}
118f60cbcfbSSteven Sombar
119f60cbcfbSSteven Sombar
120f60cbcfbSSteven SombarWait For Host To Ping
121f60cbcfbSSteven Sombar    [Documentation]  Wait for the given host to ping.
122f60cbcfbSSteven Sombar    [Arguments]  ${host}  ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
123f60cbcfbSSteven Sombar    ...          ${interval}=5 sec
124f60cbcfbSSteven Sombar
125f60cbcfbSSteven Sombar    # Description of argument(s):
126f60cbcfbSSteven Sombar    # host      The host name or IP of the host to ping.
127f60cbcfbSSteven Sombar    # timeout   The amount of time after which ping attempts cease.
128f60cbcfbSSteven Sombar    #           This should be expressed in Robot Framework's time format
129f60cbcfbSSteven Sombar    #           (e.g. "10 seconds").
130f60cbcfbSSteven Sombar    # interval  The amount of time in between attempts to ping.
131f60cbcfbSSteven Sombar    #           This should be expressed in Robot Framework's time format
132f60cbcfbSSteven Sombar    #           (e.g. "5 seconds").
133f60cbcfbSSteven Sombar
134f60cbcfbSSteven Sombar    Wait Until Keyword Succeeds  ${timeout}  ${interval}  Ping Host  ${host}
135f60cbcfbSSteven Sombar
136f60cbcfbSSteven Sombar
137f60cbcfbSSteven SombarPing Host
138f60cbcfbSSteven Sombar    [Documentation]  Ping the given host.
139f60cbcfbSSteven Sombar    [Arguments]     ${host}
140f60cbcfbSSteven Sombar
141f60cbcfbSSteven Sombar    # Description of argument(s):
142f60cbcfbSSteven Sombar    # host      The host name or IP of the host to ping.
143f60cbcfbSSteven Sombar
144f60cbcfbSSteven Sombar    Should Not Be Empty    ${host}   msg=No host provided
145f60cbcfbSSteven Sombar    ${RC}   ${output}=     Run and return RC and Output    ping -c 4 ${host}
146f60cbcfbSSteven Sombar    Log     RC: ${RC}\nOutput:\n${output}
147f60cbcfbSSteven Sombar    Should be equal     ${RC}   ${0}
148f60cbcfbSSteven Sombar
149f60cbcfbSSteven Sombar
150f60cbcfbSSteven SombarCheck OS
151f60cbcfbSSteven Sombar    [Documentation]  Attempts to ping the host OS and then checks that the host
152f60cbcfbSSteven Sombar    ...              OS is up by running an SSH command.
153f60cbcfbSSteven Sombar
154f60cbcfbSSteven Sombar    [Arguments]  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
155f60cbcfbSSteven Sombar    ...          ${os_password}=${OS_PASSWORD}  ${quiet}=${QUIET}
156f60cbcfbSSteven Sombar    ...          ${print_string}=${EMPTY}
157f60cbcfbSSteven Sombar    [Teardown]  SSHLibrary.Close Connection
158f60cbcfbSSteven Sombar
159f60cbcfbSSteven Sombar    # Description of argument(s):
160f60cbcfbSSteven Sombar    # os_host           The DNS name/IP of the OS host associated with our BMC.
161f60cbcfbSSteven Sombar    # os_username       The username to be used to sign on to the OS host.
162f60cbcfbSSteven Sombar    # os_password       The password to be used to sign on to the OS host.
163f60cbcfbSSteven Sombar    # quiet             Indicates whether this keyword should write to console.
164f60cbcfbSSteven Sombar    # print_string      A string to be printed before checking the OS.
165f60cbcfbSSteven Sombar
166c108e429SMichael Walsh    Log To Console  ${print_string}  no_newline=True
167f60cbcfbSSteven Sombar
168f60cbcfbSSteven Sombar    # Attempt to ping the OS. Store the return code to check later.
169f60cbcfbSSteven Sombar    ${ping_rc}=  Run Keyword and Return Status  Ping Host  ${os_host}
170f60cbcfbSSteven Sombar
171f60cbcfbSSteven Sombar    SSHLibrary.Open connection  ${os_host}
172f60cbcfbSSteven Sombar
1733075166eSGeorge Keishing    ${status}  ${msg}=  Run Keyword And Ignore Error  SSHLibrary.Login  ${os_username}
174f60cbcfbSSteven Sombar    ...  ${os_password}
175f60cbcfbSSteven Sombar    ${err_msg1}=  Sprint Error  ${msg}
176f60cbcfbSSteven Sombar    ${err_msg}=  Catenate  SEPARATOR=  \n  ${err_msg1}
177f60cbcfbSSteven Sombar    Run Keyword If  '${status}' == 'FAIL'  Fail  msg=${err_msg}
178f60cbcfbSSteven Sombar    ${output}  ${stderr}  ${rc}=  Execute Command  uptime  return_stderr=True
179f60cbcfbSSteven Sombar    ...        return_rc=True
180f60cbcfbSSteven Sombar
181f60cbcfbSSteven Sombar    ${temp_msg}=  Catenate  Could not execute a command on the operating
182f60cbcfbSSteven Sombar    ...  system.\n
183f60cbcfbSSteven Sombar    ${err_msg1}=  Sprint Error  ${temp_msg}
184f60cbcfbSSteven Sombar    ${err_msg}=  Catenate  SEPARATOR=  \n  ${err_msg1}
185f60cbcfbSSteven Sombar
186f60cbcfbSSteven Sombar    # If the return code returned by "Execute Command" is non-zero, this
187f60cbcfbSSteven Sombar    # keyword will fail.
188f60cbcfbSSteven Sombar    Should Be Equal  ${rc}  ${0}  msg=${err_msg}
189f60cbcfbSSteven Sombar    # We will likewise fail if there is any stderr data.
190f60cbcfbSSteven Sombar    Should Be Empty  ${stderr}
191f60cbcfbSSteven Sombar
192f60cbcfbSSteven Sombar    ${temp_msg}=  Set Variable  Could not ping the operating system.\n
193f60cbcfbSSteven Sombar    ${err_msg1}=  Sprint Error  ${temp_msg}
194f60cbcfbSSteven Sombar    ${err_msg}=  Catenate  SEPARATOR=  \n  ${err_msg1}
195f60cbcfbSSteven Sombar    # We will likewise fail if the OS did not ping, as we could SSH but not
196f60cbcfbSSteven Sombar    # ping
197f60cbcfbSSteven Sombar    Should Be Equal As Strings  ${ping_rc}  ${TRUE}  msg=${err_msg}
198f60cbcfbSSteven Sombar
199f60cbcfbSSteven Sombar
200f60cbcfbSSteven SombarWait for OS
201f60cbcfbSSteven Sombar    [Documentation]  Waits for the host OS to come up via calls to "Check OS".
202f60cbcfbSSteven Sombar    [Arguments]  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
203f60cbcfbSSteven Sombar    ...          ${os_password}=${OS_PASSWORD}  ${timeout}=${OS_WAIT_TIMEOUT}
204f60cbcfbSSteven Sombar    ...          ${quiet}=${0}
205c108e429SMichael Walsh    [Teardown]  Printn
206f60cbcfbSSteven Sombar
207f60cbcfbSSteven Sombar    # Description of argument(s):
208f60cbcfbSSteven Sombar    # os_host           The DNS name or IP of the OS host associated with our
209f60cbcfbSSteven Sombar    #                   BMC.
210f60cbcfbSSteven Sombar    # os_username       The username to be used to sign on to the OS host.
211f60cbcfbSSteven Sombar    # os_password       The password to be used to sign on to the OS host.
212f60cbcfbSSteven Sombar    # timeout           The timeout in seconds indicating how long you're
213f60cbcfbSSteven Sombar    #                   willing to wait for the OS to respond.
214f60cbcfbSSteven Sombar    # quiet             Indicates whether this keyword should write to console.
215f60cbcfbSSteven Sombar
216f60cbcfbSSteven Sombar    # The interval to be used between calls to "Check OS".
217f60cbcfbSSteven Sombar    ${interval}=  Set Variable  5
218f60cbcfbSSteven Sombar
219f60cbcfbSSteven Sombar    ${message}=  Catenate  Checking every ${interval} seconds for up to
220f60cbcfbSSteven Sombar    ...  ${timeout} seconds for the operating system to communicate.
221c108e429SMichael Walsh    Qprint Timen  ${message}
222f60cbcfbSSteven Sombar
223f60cbcfbSSteven Sombar    Wait Until Keyword Succeeds  ${timeout} sec  ${interval}  Check OS
224f60cbcfbSSteven Sombar    ...                          ${os_host}  ${os_username}  ${os_password}
225f60cbcfbSSteven Sombar    ...                          print_string=\#
226f60cbcfbSSteven Sombar
227c108e429SMichael Walsh    Qprintn
228f60cbcfbSSteven Sombar
229c108e429SMichael Walsh    Qprint Timen  The operating system is now communicating.
230f60cbcfbSSteven Sombar
231f60cbcfbSSteven Sombar
232f60cbcfbSSteven SombarCopy PNOR to BMC
233f60cbcfbSSteven Sombar    [Documentation]  Copy the PNOR image to the BMC.
234f60cbcfbSSteven Sombar    Import Library      SCPLibrary      WITH NAME       scp
235f60cbcfbSSteven Sombar    Open Connection for SCP
236f60cbcfbSSteven Sombar    Log    Copying ${PNOR_IMAGE_PATH} to /tmp
237f60cbcfbSSteven Sombar    scp.Put File    ${PNOR_IMAGE_PATH}   /tmp
238f60cbcfbSSteven Sombar
239f60cbcfbSSteven Sombar
240f60cbcfbSSteven SombarIs OS Starting
241f60cbcfbSSteven Sombar    [Documentation]  Check if boot progress is OS starting.
242f60cbcfbSSteven Sombar    ${boot_progress}=  Get Boot Progress
243f60cbcfbSSteven Sombar    Should Be Equal  ${boot_progress}  OSStart
244f60cbcfbSSteven Sombar
245f60cbcfbSSteven Sombar
246f60cbcfbSSteven SombarIs OS Off
247f60cbcfbSSteven Sombar    [Documentation]  Check if boot progress is "Off".
248f60cbcfbSSteven Sombar    ${boot_progress}=  Get Boot Progress
249f60cbcfbSSteven Sombar    Should Be Equal  ${boot_progress}  Off
250f60cbcfbSSteven Sombar
251f60cbcfbSSteven Sombar
252f60cbcfbSSteven SombarGet Boot Progress To OS Starting State
253f60cbcfbSSteven Sombar    [Documentation]  Get the system to a boot progress state of 'FW Progress,
254f60cbcfbSSteven Sombar    ...  Starting OS'.
255f60cbcfbSSteven Sombar
256f60cbcfbSSteven Sombar    ${boot_progress}=  Get Boot Progress
257f60cbcfbSSteven Sombar    Run Keyword If  '${boot_progress}' == 'OSStart'
258f60cbcfbSSteven Sombar    ...  Log  Host is already in OS starting state
259f60cbcfbSSteven Sombar    ...  ELSE
260f60cbcfbSSteven Sombar    ...  Run Keywords  Initiate Host PowerOff  AND  Initiate Host Boot
261f60cbcfbSSteven Sombar    ...  AND  Wait Until Keyword Succeeds  10 min  10 sec  Is OS Starting
262f60cbcfbSSteven Sombar
263f60cbcfbSSteven Sombar
264f60cbcfbSSteven SombarCheck If warmReset is Initiated
265f60cbcfbSSteven Sombar    [Documentation]  Ping would be still alive, so try SSH to connect
266f60cbcfbSSteven Sombar    ...              if fails the ports are down indicating reboot
267f60cbcfbSSteven Sombar    ...              is in progress
268f60cbcfbSSteven Sombar
269f60cbcfbSSteven Sombar    # Warm reset adds 3 seconds delay before forcing reboot
270f60cbcfbSSteven Sombar    # To minimize race conditions, we wait for 7 seconds
271f60cbcfbSSteven Sombar    Sleep  7s
272f60cbcfbSSteven Sombar    ${alive}=   Run Keyword and Return Status
273f60cbcfbSSteven Sombar    ...    Open Connection And Log In
274f60cbcfbSSteven Sombar    Return From Keyword If   '${alive}' == '${False}'    ${False}
275f60cbcfbSSteven Sombar    [Return]    ${True}
276f60cbcfbSSteven Sombar
277f60cbcfbSSteven Sombar
278f60cbcfbSSteven SombarInitialize DBUS cmd
279f60cbcfbSSteven Sombar    [Documentation]  Initialize dbus string with property string to extract
280f60cbcfbSSteven Sombar    [Arguments]   ${boot_property}
281f60cbcfbSSteven Sombar
282f60cbcfbSSteven Sombar    # Description of argument(s):
283f60cbcfbSSteven Sombar    # boot_property   Property string.
284f60cbcfbSSteven Sombar
285f60cbcfbSSteven Sombar    ${cmd}=     Catenate  ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
286f60cbcfbSSteven Sombar    ${cmd}=     Catenate  ${cmd}${boot_property}
287f60cbcfbSSteven Sombar    Set Global Variable   ${dbuscmd}     ${cmd}
288f60cbcfbSSteven Sombar
289f60cbcfbSSteven Sombar
290f60cbcfbSSteven SombarCreate OS Console Command String
291f60cbcfbSSteven Sombar    [Documentation]  Return a command string to start OS console logging.
292f60cbcfbSSteven Sombar
293f60cbcfbSSteven Sombar    # First make sure that the ssh_pw program is available.
294f60cbcfbSSteven Sombar    ${cmd}=  Catenate  which ssh_pw 2>/dev/null || find
295f60cbcfbSSteven Sombar    ...  ${EXECDIR} -name 'ssh_pw'
296f60cbcfbSSteven Sombar
297c108e429SMichael Walsh    Dprint Issuing  ${cmd}
298f60cbcfbSSteven Sombar    ${rc}  ${output}=  Run And Return Rc And Output  ${cmd}
299f60cbcfbSSteven Sombar    Rdpvars  rc  output
300f60cbcfbSSteven Sombar
301f60cbcfbSSteven Sombar    Should Be Equal As Integers  0  ${rc}  msg=Could not find ssh_pw.
302f60cbcfbSSteven Sombar
303f60cbcfbSSteven Sombar    ${ssh_pw_file_path}=  Set Variable  ${output}
304f60cbcfbSSteven Sombar
305088166c6SGeorge Keishing    ${cmd}=  Catenate  ${ssh_pw_file_path} ${OPENBMC_PASSWORD} -p ${HOST_SOL_PORT}
306f196b244SJorge Cisneros    ...  -o "StrictHostKeyChecking no" ${OPENBMC_USERNAME}@${OPENBMC_HOST} ${OPENBMC_CONSOLE_CLIENT}
307f60cbcfbSSteven Sombar
308f196b244SJorge Cisneros    [Return]  ${cmd.strip()}
309f60cbcfbSSteven Sombar
310f60cbcfbSSteven Sombar
311f60cbcfbSSteven SombarGet SOL Console Pid
312f60cbcfbSSteven Sombar    [Documentation]  Get the pid of the active SOL console job.
31307ed7944SMichael Walsh    [Arguments]  ${expect_running}=${0}  ${log_file_path}=${EMPTY}
314f60cbcfbSSteven Sombar
315f60cbcfbSSteven Sombar    # Description of argument(s):
31607ed7944SMichael Walsh    # expect_running                If set and if no SOL console job is found, print debug info and fail.
31707ed7944SMichael Walsh    # log_file_path                 Needed to print debug info if expect_running is set and no pid is found.
318f60cbcfbSSteven Sombar
319f60cbcfbSSteven Sombar    # Find the pid of the active system console logging session (if any).
320f60cbcfbSSteven Sombar    ${search_string}=  Create OS Console Command String
321f60cbcfbSSteven Sombar    # At least in some cases, ps output does not show double quotes so we must
322f60cbcfbSSteven Sombar    # replace them in our search string with the regexes to indicate that they
323f60cbcfbSSteven Sombar    # are optional.
324f60cbcfbSSteven Sombar    ${search_string}=  Replace String  ${search_string}  "  ["]?
325f60cbcfbSSteven Sombar    ${ps_cmd}=  Catenate  ps axwwo user,pid,cmd
326f60cbcfbSSteven Sombar    ${cmd_buf}=  Catenate  echo $(${ps_cmd} | egrep '${search_string}' |
327f60cbcfbSSteven Sombar    ...  egrep -v grep | cut -c10-14)
328c108e429SMichael Walsh    Dprint Issuing  ${cmd_buf}
329f60cbcfbSSteven Sombar    ${rc}  ${os_con_pid}=  Run And Return Rc And Output  ${cmd_buf}
330f60cbcfbSSteven Sombar    Rdpvars  os_con_pid
331f60cbcfbSSteven Sombar    # If rc is not zero it just means that there is no OS Console process
332f60cbcfbSSteven Sombar    # running.
333f60cbcfbSSteven Sombar
334f60cbcfbSSteven Sombar    Return From Keyword If  '${os_con_pid}' != '${EMPTY}'  ${os_con_pid}
335f60cbcfbSSteven Sombar    Return From Keyword If  '${expect_running}' == '${0}'  ${os_con_pid}
336f60cbcfbSSteven Sombar
337f60cbcfbSSteven Sombar    Cmd Fnc  cat ${log_file_path} ; echo ; ${ps_cmd}  quiet=${0}
338f60cbcfbSSteven Sombar    ...  print_output=${1}  show_err=${1}
33907ed7944SMichael Walsh    Valid Value  os_con_pid
340f60cbcfbSSteven Sombar
341f60cbcfbSSteven Sombar
342f60cbcfbSSteven SombarStop SOL Console Logging
343f60cbcfbSSteven Sombar    [Documentation]  Stop system console logging and return log output.
344f60cbcfbSSteven Sombar    [Arguments]  ${log_file_path}=${EMPTY}
345f60cbcfbSSteven Sombar    ...          ${targ_file_path}=${EXECDIR}${/}logs${/}
346f60cbcfbSSteven Sombar    ...          ${return_data}=${1}
347f60cbcfbSSteven Sombar
348*e16f158fSGeorge Keishing    # If there are multiple system console processes, they will all be stopped.
349f60cbcfbSSteven Sombar    # If there is no existing log file this keyword will return an error
350f60cbcfbSSteven Sombar    # message to that effect (and write that message to targ_file_path, if
351f60cbcfbSSteven Sombar    # specified).
352f60cbcfbSSteven Sombar    # NOTE: This keyword will not fail if there is no running system console
353f60cbcfbSSteven Sombar    # process.
354f60cbcfbSSteven Sombar
355f60cbcfbSSteven Sombar    # Description of arguments:
356f60cbcfbSSteven Sombar    # log_file_path   The file path that was used to call "Start SOL
357f60cbcfbSSteven Sombar    #                 Console Logging".  See that keyword (above) for details.
358f60cbcfbSSteven Sombar    # targ_file_path  If specified, the file path to which the source
359f60cbcfbSSteven Sombar    #                 file path (i.e. "log_file_path") should be copied.
360f60cbcfbSSteven Sombar    # return_data     If this is set to ${1}, this keyword will return the SOL
361f60cbcfbSSteven Sombar    #                 data to the caller as a unicode string.
362f60cbcfbSSteven Sombar
363f60cbcfbSSteven Sombar    ${log_file_path}=  Create OS Console File Path  ${log_file_path}
364f60cbcfbSSteven Sombar
365f60cbcfbSSteven Sombar    ${os_con_pid}=  Get SOL Console Pid
366f60cbcfbSSteven Sombar
367f60cbcfbSSteven Sombar    ${cmd_buf}=  Catenate  kill -9 ${os_con_pid}
368c108e429SMichael Walsh    Run Keyword If  '${os_con_pid}' != '${EMPTY}'  Dprint Issuing  ${cmd_buf}
369f60cbcfbSSteven Sombar    ${rc}  ${output}=  Run Keyword If  '${os_con_pid}' != '${EMPTY}'
370f60cbcfbSSteven Sombar    ...  Run And Return Rc And Output  ${cmd_buf}
371f60cbcfbSSteven Sombar    Run Keyword If  '${os_con_pid}' != '${EMPTY}'  Rdpvars  rc  output
372f60cbcfbSSteven Sombar
373f60cbcfbSSteven Sombar    Run Keyword If  '${targ_file_path}' != '${EMPTY}'
374f60cbcfbSSteven Sombar    ...  Run Keyword And Ignore Error
375f60cbcfbSSteven Sombar    ...  Copy File  ${log_file_path}  ${targ_file_path}
376f60cbcfbSSteven Sombar
377f60cbcfbSSteven Sombar    ${output}=  Set Variable  ${EMPTY}
378f60cbcfbSSteven Sombar    ${loc_quiet}=  Evaluate  ${debug}^1
379f60cbcfbSSteven Sombar    ${rc}  ${output}=  Run Keyword If  '${return_data}' == '${1}'
380f60cbcfbSSteven Sombar    ...  Cmd Fnc  cat ${log_file_path} 2>/dev/null  quiet=${loc_quiet}
381f60cbcfbSSteven Sombar    ...  print_output=${0}  show_err=${0}
382f60cbcfbSSteven Sombar
383f60cbcfbSSteven Sombar    [Return]  ${output}
384f60cbcfbSSteven Sombar
385f60cbcfbSSteven Sombar
386f60cbcfbSSteven SombarStart SOL Console Logging
387f60cbcfbSSteven Sombar    [Documentation]  Start system console log to file.
388f60cbcfbSSteven Sombar    [Arguments]  ${log_file_path}=${EMPTY}  ${return_data}=${1}
389f60cbcfbSSteven Sombar
390f60cbcfbSSteven Sombar    # This keyword will first call "Stop SOL Console Logging".  Only then will
391f60cbcfbSSteven Sombar    # it start SOL console logging.  The data returned by "Stop SOL Console
392f60cbcfbSSteven Sombar    # Logging" will in turn be returned by this keyword.
393f60cbcfbSSteven Sombar
394f60cbcfbSSteven Sombar    # Description of arguments:
395f60cbcfbSSteven Sombar    # log_file_path   The file path to which system console log data should be
396f60cbcfbSSteven Sombar    #                 written.  Note that this path is taken to be a location
397f60cbcfbSSteven Sombar    #                 on the machine where this program is running rather than
398f60cbcfbSSteven Sombar    #                 on the Open BMC system.
399f60cbcfbSSteven Sombar    # return_data     If this is set to ${1}, this keyword will return any SOL
400f60cbcfbSSteven Sombar    #                 data to the caller as a unicode string.
401f60cbcfbSSteven Sombar
402f60cbcfbSSteven Sombar    ${log_file_path}=  Create OS Console File Path  ${log_file_path}
403f60cbcfbSSteven Sombar
404f60cbcfbSSteven Sombar    ${log_output}=  Stop SOL Console Logging  ${log_file_path}
405f60cbcfbSSteven Sombar    ...  return_data=${return_data}
406f60cbcfbSSteven Sombar
407f60cbcfbSSteven Sombar    # Validate by making sure we can create the file.  Problems creating the
408f60cbcfbSSteven Sombar    # file would not be noticed by the subsequent ssh command because we fork
409f60cbcfbSSteven Sombar    # the command.
410f60cbcfbSSteven Sombar    Create File  ${log_file_path}
411f60cbcfbSSteven Sombar    ${sub_cmd_buf}=  Create OS Console Command String
412f60cbcfbSSteven Sombar    # Routing stderr to stdout so that any startup error text will go to the
413f60cbcfbSSteven Sombar    # output file.
414f60cbcfbSSteven Sombar    ${cmd_buf}=  Catenate  ${sub_cmd_buf} > ${log_file_path} 2>&1 &
415c108e429SMichael Walsh    Dprint Issuing  ${cmd_buf}
416f60cbcfbSSteven Sombar    ${rc}  ${output}=  Run And Return Rc And Output  ${cmd_buf}
417f60cbcfbSSteven Sombar    # Because we are forking this command, we essentially will never get a
418f60cbcfbSSteven Sombar    # non-zero return code or any output.
419f60cbcfbSSteven Sombar    Should Be Equal  ${rc}  ${0}
420f60cbcfbSSteven Sombar
421f60cbcfbSSteven Sombar    Wait Until Keyword Succeeds  10 seconds  0 seconds
42207ed7944SMichael Walsh    ...   Get SOL Console Pid  ${1}  ${log_file_path}
423f60cbcfbSSteven Sombar
424f60cbcfbSSteven Sombar    [Return]  ${log_output}
425f60cbcfbSSteven Sombar
426f60cbcfbSSteven Sombar
427f60cbcfbSSteven SombarGet Time Stamp
428f60cbcfbSSteven Sombar    [Documentation]     Get the current time stamp data
429f60cbcfbSSteven Sombar    ${cur_time}=    Get Current Date   result_format=%Y%m%d%H%M%S%f
430f60cbcfbSSteven Sombar    [Return]   ${cur_time}
431f60cbcfbSSteven Sombar
432f60cbcfbSSteven Sombar
433f60cbcfbSSteven SombarStart Journal Log
434f60cbcfbSSteven Sombar    [Documentation]   Start capturing journal log to a file in /tmp using
435f60cbcfbSSteven Sombar    ...               journalctl command. By default journal log is collected
436f60cbcfbSSteven Sombar    ...               at /tmp/journal_log else user input location.
437f60cbcfbSSteven Sombar    ...               The File is appended with datetime.
438f60cbcfbSSteven Sombar    [Arguments]       ${file_path}=/tmp/journal_log  ${filter}=${EMPTY}
439f60cbcfbSSteven Sombar
440f60cbcfbSSteven Sombar    # Description of arguments:
441f60cbcfbSSteven Sombar    # file_path   The file path of the journal file.
442f60cbcfbSSteven Sombar
443f60cbcfbSSteven Sombar    ${cur_time}=    Get Time Stamp
444f60cbcfbSSteven Sombar    Set Global Variable   ${LOG_TIME}   ${cur_time}
445f60cbcfbSSteven Sombar    Open Connection And Log In
446f60cbcfbSSteven Sombar    Start Command
447f60cbcfbSSteven Sombar    ...  journalctl -f ${filter} > ${file_path}-${LOG_TIME}
448f60cbcfbSSteven Sombar    Log    Journal Log Started: ${file_path}-${LOG_TIME}
449f60cbcfbSSteven Sombar
450f60cbcfbSSteven Sombar
451f60cbcfbSSteven SombarStop Journal Log
452f60cbcfbSSteven Sombar    [Documentation]   Stop journalctl process if its running.
453f60cbcfbSSteven Sombar    ...               By default return log from /tmp/journal_log else
454f60cbcfbSSteven Sombar    ...               user input location.
455f60cbcfbSSteven Sombar    [Arguments]       ${file_path}=/tmp/journal_log
456f60cbcfbSSteven Sombar
457f60cbcfbSSteven Sombar    # Description of arguments:
458f60cbcfbSSteven Sombar    # file_path   The file path of the journal file.
459f60cbcfbSSteven Sombar
460f60cbcfbSSteven Sombar    Open Connection And Log In
461f60cbcfbSSteven Sombar
462f60cbcfbSSteven Sombar    ${rc}=
463f60cbcfbSSteven Sombar    ...  Execute Command
464f60cbcfbSSteven Sombar    ...  ps | grep journalctl | grep -v grep
465f60cbcfbSSteven Sombar    ...  return_stdout=False  return_rc=True
466f60cbcfbSSteven Sombar
467f60cbcfbSSteven Sombar    Return From Keyword If   '${rc}' == '${1}'
468f60cbcfbSSteven Sombar    ...   No journal log process running
469f60cbcfbSSteven Sombar
470f60cbcfbSSteven Sombar    ${output}  ${stderr}=
471f60cbcfbSSteven Sombar    ...  Execute Command   killall journalctl
472f60cbcfbSSteven Sombar    ...  return_stderr=True
473f60cbcfbSSteven Sombar    Should Be Empty     ${stderr}
474f60cbcfbSSteven Sombar
475f60cbcfbSSteven Sombar    ${journal_log}  ${stderr}=
476f60cbcfbSSteven Sombar    ...  Execute Command
477f60cbcfbSSteven Sombar    ...  cat ${file_path}-${LOG_TIME}
478f60cbcfbSSteven Sombar    ...  return_stderr=True
479f60cbcfbSSteven Sombar    Should Be Empty     ${stderr}
480f60cbcfbSSteven Sombar
481f60cbcfbSSteven Sombar    Log    ${journal_log}
482f60cbcfbSSteven Sombar
483f60cbcfbSSteven Sombar    Execute Command    rm ${file_path}-${LOG_TIME}
484f60cbcfbSSteven Sombar
485f60cbcfbSSteven Sombar    [Return]    ${journal_log}
486f60cbcfbSSteven Sombar
487f60cbcfbSSteven Sombar
488f60cbcfbSSteven SombarMac Address To Hex String
489f60cbcfbSSteven Sombar    [Documentation]   Converts MAC address into hex format.
490f60cbcfbSSteven Sombar    ...               Example
491f60cbcfbSSteven Sombar    ...               Given the following MAC: 00:01:6C:80:02:78
492f60cbcfbSSteven Sombar    ...               This keyword will return: 0x00 0x01 0x6C 0x80 0x02 0x78
493f60cbcfbSSteven Sombar    ...               Description of arguments:
494f60cbcfbSSteven Sombar    ...               i_macaddress  MAC address in the following format
495f60cbcfbSSteven Sombar    ...               00:01:6C:80:02:78
496f60cbcfbSSteven Sombar    [Arguments]    ${i_macaddress}
497f60cbcfbSSteven Sombar
498f60cbcfbSSteven Sombar    # Description of arguments:
499f60cbcfbSSteven Sombar    # i_macaddress   The MAC address.
500f60cbcfbSSteven Sombar
501f60cbcfbSSteven Sombar    ${mac_hex}=  Catenate  0x${i_macaddress.replace(':', ' 0x')}
502f60cbcfbSSteven Sombar    [Return]    ${mac_hex}
503f60cbcfbSSteven Sombar
504f60cbcfbSSteven Sombar
505f60cbcfbSSteven SombarIP Address To Hex String
506f60cbcfbSSteven Sombar    [Documentation]   Converts IP address into hex format.
507f60cbcfbSSteven Sombar    ...               Example:
508f60cbcfbSSteven Sombar    ...               Given the following IP: 10.3.164.100
509f60cbcfbSSteven Sombar    ...               This keyword will return: 0xa 0x3 0xa4 0xa0
510f60cbcfbSSteven Sombar    [Arguments]    ${i_ipaddress}
511f60cbcfbSSteven Sombar
512f60cbcfbSSteven Sombar    # Description of arguments:
513f60cbcfbSSteven Sombar    # i_macaddress   The IP address in the format 10.10.10.10.
514f60cbcfbSSteven Sombar
515f60cbcfbSSteven Sombar    @{ip}=  Split String  ${i_ipaddress}    .
516f60cbcfbSSteven Sombar    ${index}=  Set Variable  ${0}
517f60cbcfbSSteven Sombar
51820ccfc71SMarissa Garza    FOR    ${item}     IN      @{ip}
51920ccfc71SMarissa Garza        ${hex}=  Convert To Hex    ${item}    prefix=0x    lowercase=yes
52020ccfc71SMarissa Garza        Set List Value    ${ip}    ${index}    ${hex}
52120ccfc71SMarissa Garza        ${index}=  Set Variable    ${index + 1}
52220ccfc71SMarissa Garza    END
523f60cbcfbSSteven Sombar    ${ip_hex}=  Catenate    @{ip}
524f60cbcfbSSteven Sombar
525f60cbcfbSSteven Sombar    [Return]    ${ip_hex}
526f60cbcfbSSteven Sombar
527f60cbcfbSSteven Sombar
528f60cbcfbSSteven SombarBMC CPU Performance Check
529f60cbcfbSSteven Sombar   [Documentation]   Minimal 10% of proc should be free in this instance
530f60cbcfbSSteven Sombar
531f60cbcfbSSteven Sombar    ${bmc_cpu_usage_output}  ${stderr}  ${rc}=  BMC Execute Command
532f60cbcfbSSteven Sombar    ...  ${bmc_cpu_usage_cmd}
533f60cbcfbSSteven Sombar    ${bmc_cpu_usage_output}  ${stderr}  ${rc}=  BMC Execute Command
534f60cbcfbSSteven Sombar    ...  ${bmc_cpu_usage_cmd}
535f60cbcfbSSteven Sombar    ${bmc_cpu_percentage}=  Fetch From Left  ${bmc_cpu_usage_output}  %
53614426bcbSSivas SRR    Rprint Vars  bmc_cpu_percentage
537f60cbcfbSSteven Sombar    Should be true  ${bmc_cpu_percentage} < 90
538f60cbcfbSSteven Sombar
539f60cbcfbSSteven Sombar
540f60cbcfbSSteven SombarBMC Mem Performance Check
541f60cbcfbSSteven Sombar    [Documentation]   Minimal 10% of memory should be free in this instance
542f60cbcfbSSteven Sombar
543f60cbcfbSSteven Sombar    ${bmc_mem_free_output}  ${stderr}  ${rc}=   BMC Execute Command
544f60cbcfbSSteven Sombar    ...  ${bmc_mem_free_cmd}
545f60cbcfbSSteven Sombar
546f60cbcfbSSteven Sombar    ${bmc_mem_total_output}  ${stderr}  ${rc}=  BMC Execute Command
547f60cbcfbSSteven Sombar    ...  ${bmc_mem_total_cmd}
548f60cbcfbSSteven Sombar    ${bmc_mem_free_output}  ${stderr}  ${rc}=   BMC Execute Command
549f60cbcfbSSteven Sombar    ...  ${bmc_mem_free_cmd}
550f60cbcfbSSteven Sombar
551f60cbcfbSSteven Sombar    ${bmc_mem_total_output}  ${stderr}  ${rc}=  BMC Execute Command
552f60cbcfbSSteven Sombar    ...  ${bmc_mem_total_cmd}
553f60cbcfbSSteven Sombar
554f60cbcfbSSteven Sombar    ${bmc_mem_percentage}=  Evaluate  ${bmc_mem_free_output}*100
555f60cbcfbSSteven Sombar    ${bmc_mem_percentage}=  Evaluate
556f60cbcfbSSteven Sombar    ...   ${bmc_mem_percentage}/${bmc_mem_total_output}
55714426bcbSSivas SRR    Rprint Vars  bmc_mem_percentage
558f60cbcfbSSteven Sombar    Should be true  ${bmc_mem_percentage} > 10
559f60cbcfbSSteven Sombar
560f60cbcfbSSteven Sombar
561f60cbcfbSSteven SombarBMC File System Usage Check
562f60cbcfbSSteven Sombar    [Documentation]   Check the file system space. 4 file system should be
563f60cbcfbSSteven Sombar    ...  100% full which is expected
564f60cbcfbSSteven Sombar    # Filesystem            Size    Used Available Use% Mounted on
565f60cbcfbSSteven Sombar    # /dev/root            14.4M     14.4M       0 100% /
566f60cbcfbSSteven Sombar    # /dev/ubiblock0_0     14.4M     14.4M       0 100% /media/rofs-c9249b0e
567f60cbcfbSSteven Sombar    # /dev/ubiblock8_0     19.6M     19.6M       0 100% /media/pnor-ro-8764baa3
568f60cbcfbSSteven Sombar    # /dev/ubiblock4_0     14.4M     14.4M       0 100% /media/rofs-407816c
569f60cbcfbSSteven Sombar    # /dev/ubiblock8_4     21.1M     21.1M       0 100% /media/pnor-ro-cecc64c4
570f60cbcfbSSteven Sombar    ${bmc_fs_usage_output}  ${stderr}  ${rc}=  BMC Execute Command
571f60cbcfbSSteven Sombar    ...  ${bmc_file_system_usage_cmd}
572f60cbcfbSSteven Sombar    ${bmc_pnor_fs_usage_output}  ${stderr}  ${rc}=  BMC Execute Command
573f60cbcfbSSteven Sombar    ...  ${total_pnor_ro_file_system_cmd}
574f60cbcfbSSteven Sombar    ${bmc_bmc_fs_usage_output}  ${stderr}  ${rc}=  BMC Execute Command
575f60cbcfbSSteven Sombar    ...  ${total_bmc_ro_file_system_cmd}
576f60cbcfbSSteven Sombar    ${total_bmc_pnor_image}=  Evaluate
577f60cbcfbSSteven Sombar    ...  ${bmc_pnor_fs_usage_output}+${bmc_bmc_fs_usage_output}
578f60cbcfbSSteven Sombar    # Considering /dev/root also in total 100% used file system
579f60cbcfbSSteven Sombar    ${total_full_fs}=  Evaluate  ${total_bmc_pnor_image}+1
58014426bcbSSivas SRR    Rprint Vars  bmc_fs_usage_output  bmc_pnor_fs_usage_output  bmc_bmc_fs_usage_output
58114426bcbSSivas SRR    ...  total_full_fs
582f60cbcfbSSteven Sombar    Should Be True  ${bmc_fs_usage_output}==${total_full_fs}
583f60cbcfbSSteven Sombar
584f60cbcfbSSteven Sombar
585f60cbcfbSSteven SombarCheck BMC CPU Performance
586f60cbcfbSSteven Sombar    [Documentation]   Minimal 10% of proc should be free in 3 sample
58720ccfc71SMarissa Garza    FOR  ${var}  IN RANGE  1  4
58820ccfc71SMarissa Garza        BMC CPU Performance Check
58920ccfc71SMarissa Garza    END
590f60cbcfbSSteven Sombar
591f60cbcfbSSteven SombarCheck BMC Mem Performance
592f60cbcfbSSteven Sombar    [Documentation]   Minimal 10% of memory should be free
593f60cbcfbSSteven Sombar
59420ccfc71SMarissa Garza    FOR  ${var}  IN RANGE  1  4
59520ccfc71SMarissa Garza        BMC Mem Performance Check
59620ccfc71SMarissa Garza    END
597f60cbcfbSSteven Sombar
598f60cbcfbSSteven SombarCheck BMC File System Performance
599f60cbcfbSSteven Sombar    [Documentation]  Check for file system usage for 4 times
600f60cbcfbSSteven Sombar
60120ccfc71SMarissa Garza    FOR  ${var}  IN RANGE  1  4
60220ccfc71SMarissa Garza        BMC File System Usage check
60320ccfc71SMarissa Garza    END
604f60cbcfbSSteven Sombar
605f60cbcfbSSteven SombarGet URL List
606f60cbcfbSSteven Sombar    [Documentation]  Return list of URLs under given URL.
607f60cbcfbSSteven Sombar    [Arguments]  ${openbmc_url}
608f60cbcfbSSteven Sombar
609f60cbcfbSSteven Sombar    # Description of argument(s):
610f60cbcfbSSteven Sombar    # openbmc_url  URL for list operation (e.g.
611f60cbcfbSSteven Sombar    #              /xyz/openbmc_project/inventory).
612f60cbcfbSSteven Sombar
613aaaab222SSteven Sombar    ${url_list}=  Read Properties  ${openbmc_url}list  quiet=${1}
614f60cbcfbSSteven Sombar    Sort List  ${url_list}
615f60cbcfbSSteven Sombar
616f60cbcfbSSteven Sombar    [Return]  ${url_list}
617f60cbcfbSSteven Sombar
618f60cbcfbSSteven Sombar
619f60cbcfbSSteven SombarCheck Zombie Process
620f60cbcfbSSteven Sombar    [Documentation]    Check if any defunct process exist or not on BMC
621f60cbcfbSSteven Sombar    ${count}  ${stderr}  ${rc}=  Execute Command  ps -o stat | grep Z | wc -l
622f60cbcfbSSteven Sombar    ...    return_stderr=True  return_rc=True
623f60cbcfbSSteven Sombar    Should Be True    ${count}==0
624f60cbcfbSSteven Sombar    Should Be Empty    ${stderr}
625f60cbcfbSSteven Sombar
626f60cbcfbSSteven Sombar
627f60cbcfbSSteven SombarPrune Journal Log
628f60cbcfbSSteven Sombar    [Documentation]   Prune archived journal logs.
629f60cbcfbSSteven Sombar    [Arguments]   ${vacuum_size}=1M
630f60cbcfbSSteven Sombar
631f60cbcfbSSteven Sombar    # This keyword can be used to prevent the journal
632f60cbcfbSSteven Sombar    # log from filling up the /run filesystem.
633f60cbcfbSSteven Sombar    # This command will retain only the latest logs
634f60cbcfbSSteven Sombar    # of the user specified size.
635f60cbcfbSSteven Sombar
636f60cbcfbSSteven Sombar    # Description of argument(s):
637f60cbcfbSSteven Sombar    # vacuum_size    Size of journal.
638f60cbcfbSSteven Sombar
639f60cbcfbSSteven Sombar    Open Connection And Log In
640f60cbcfbSSteven Sombar    ${output}  ${stderr}  ${rc}=
641f60cbcfbSSteven Sombar    ...  Execute Command
642f60cbcfbSSteven Sombar    ...  journalctl --vacuum-size=${vacuum_size}
643f60cbcfbSSteven Sombar    ...  return_stderr=True  return_rc=True
644f60cbcfbSSteven Sombar
645f60cbcfbSSteven Sombar    Should Be Equal  ${rc}  ${0}  msg=${stderr}
646f60cbcfbSSteven Sombar
647f60cbcfbSSteven Sombar
648f60cbcfbSSteven SombarGet System Power Policy
649f60cbcfbSSteven Sombar    [Documentation]  Returns the BMC power policy.
650f60cbcfbSSteven Sombar
651f60cbcfbSSteven Sombar    # Set the bmc_power_policy_method to either 'Old' or 'New'.
652f60cbcfbSSteven Sombar    Set Power Policy Method
653f60cbcfbSSteven Sombar    ${cmd_buf}=  Create List  ${bmc_power_policy_method} Get Power Policy
654f60cbcfbSSteven Sombar    # Run the appropriate keyword.
655f60cbcfbSSteven Sombar    ${currentPolicy}=  Run Keyword  @{cmd_buf}
656f60cbcfbSSteven Sombar
657f60cbcfbSSteven Sombar    [Return]  ${currentPolicy}
658f60cbcfbSSteven Sombar
659f60cbcfbSSteven Sombar
660f60cbcfbSSteven SombarSet BMC Reset Reference Time
661f60cbcfbSSteven Sombar    [Documentation]  Set current boot time as a reference and increment
662f60cbcfbSSteven Sombar    ...              boot count.
663f60cbcfbSSteven Sombar
664f60cbcfbSSteven Sombar    ${cur_btime}=  Get BMC Boot Time
665f60cbcfbSSteven Sombar    Run Keyword If  ${BOOT_TIME} == ${0} and ${BOOT_COUNT} == ${0}
666f60cbcfbSSteven Sombar    ...  Set Global Variable  ${BOOT_TIME}  ${cur_btime}
667f60cbcfbSSteven Sombar    ...  ELSE IF  ${cur_btime} > ${BOOT_TIME}
668f60cbcfbSSteven Sombar    ...  Run Keywords  Set Global Variable  ${BOOT_TIME}  ${cur_btime}
669f60cbcfbSSteven Sombar    ...  AND
670f60cbcfbSSteven Sombar    ...  Set Global Variable  ${BOOT_COUNT}  ${BOOT_COUNT + 1}
671f60cbcfbSSteven Sombar
672f60cbcfbSSteven Sombar
673f60cbcfbSSteven SombarGet BMC Boot Time
674f60cbcfbSSteven Sombar    [Documentation]  Returns boot time from /proc/stat.
675f60cbcfbSSteven Sombar
676f60cbcfbSSteven Sombar    Open Connection And Log In
677f60cbcfbSSteven Sombar    ${output}  ${stderr}=
678f60cbcfbSSteven Sombar    ...  Execute Command  egrep '^btime ' /proc/stat | cut -f 2 -d ' '
679f60cbcfbSSteven Sombar    ...  return_stderr=True
680f60cbcfbSSteven Sombar    Should Be Empty  ${stderr}
681f60cbcfbSSteven Sombar    ${btime}=  Convert To Integer  ${output}
682f60cbcfbSSteven Sombar    [Return]  ${btime}
683f60cbcfbSSteven Sombar
684f60cbcfbSSteven Sombar
685f60cbcfbSSteven SombarEnable Core Dump On BMC
686f60cbcfbSSteven Sombar    [Documentation]  Enable core dump collection.
687f60cbcfbSSteven Sombar    ${core_pattern}  ${stderr}  ${rc}=  BMC Execute Command
688f60cbcfbSSteven Sombar    ...  echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern
689f60cbcfbSSteven Sombar    Should Be Equal As Strings  ${core_pattern}  /tmp/core_%e.%p
690f60cbcfbSSteven Sombar
691f60cbcfbSSteven Sombar
692f60cbcfbSSteven SombarGet Number Of BMC Core Dump Files
693f60cbcfbSSteven Sombar    [Documentation]  Returns number of core dump files on BMC.
694f60cbcfbSSteven Sombar    Open Connection And Log In
695f60cbcfbSSteven Sombar    ${num_of_core_dump}=  Execute Command
696f60cbcfbSSteven Sombar    ...  ls /tmp/core* 2>/dev/null | wc -l
697f60cbcfbSSteven Sombar    [Return]  ${num_of_core_dump}
698f60cbcfbSSteven Sombar
699f60cbcfbSSteven Sombar
700f60cbcfbSSteven SombarSet Core Dump File Size Unlimited
701f60cbcfbSSteven Sombar    [Documentation]  Set core dump file size to unlimited.
702f60cbcfbSSteven Sombar    BMC Execute Command  ulimit -c unlimited
703f60cbcfbSSteven Sombar
704f60cbcfbSSteven Sombar
705f60cbcfbSSteven SombarCheck For Core Dumps
706f60cbcfbSSteven Sombar    [Documentation]  Check for any core dumps exist.
707f60cbcfbSSteven Sombar    ${output}=  Get Number Of BMC Core Dump Files
708f60cbcfbSSteven Sombar    Run Keyword If  ${output} > 0
709f60cbcfbSSteven Sombar    ...  Log  **Warning** BMC core dump files exist  level=WARN
710f60cbcfbSSteven Sombar
711f60cbcfbSSteven Sombar
712f60cbcfbSSteven SombarConfigure Initial Settings
713f60cbcfbSSteven Sombar    [Documentation]  Restore old IP and route.
714f60cbcfbSSteven Sombar    ...  This keyword requires initial settings viz IP address,
71516b3c7bfSGeorge Keishing    ...  Network Mask, default gateway and serial console IP and port
716f60cbcfbSSteven Sombar    ...  information which should be provided in command line.
717f60cbcfbSSteven Sombar
718f60cbcfbSSteven Sombar    [Arguments]  ${host}=${OPENBMC_HOST}  ${mask}=${NET_MASK}
719f60cbcfbSSteven Sombar    ...          ${gw_ip}=${GW_IP}
720f60cbcfbSSteven Sombar
721f60cbcfbSSteven Sombar    # Description of arguments:
722f60cbcfbSSteven Sombar    # host  IP address of the OS Host.
723f60cbcfbSSteven Sombar    # mask  Network mask.
724f60cbcfbSSteven Sombar    # gu_ip  Gateway IP address or hostname.
725f60cbcfbSSteven Sombar
726f60cbcfbSSteven Sombar    # Open telnet connection and ignore the error, in case telnet session is
727f60cbcfbSSteven Sombar    # already opened by the program calling this keyword.
728f60cbcfbSSteven Sombar    Run Keyword And Ignore Error  Open Telnet Connection to BMC Serial Console
729f60cbcfbSSteven Sombar    Telnet.write  ifconfig eth0 ${host} netmask ${mask}
730f60cbcfbSSteven Sombar    Telnet.write  route add default gw ${gw_ip}
731f60cbcfbSSteven Sombar
732f60cbcfbSSteven Sombar
733f60cbcfbSSteven SombarInstall Debug Tarball On BMC
734f60cbcfbSSteven Sombar    [Documentation]  Copy the debug tar file to BMC and install.
735f60cbcfbSSteven Sombar    [Arguments]  ${tarball_file_path}=${default_tarball}
736f60cbcfbSSteven Sombar    ...  ${targ_tarball_dir_path}=/tmp/tarball/
737f60cbcfbSSteven Sombar
738f60cbcfbSSteven Sombar    # Description of arguments:
739f60cbcfbSSteven Sombar    # tarball_file_path      Path of the debug tarball file.
740f60cbcfbSSteven Sombar    #                        The tar file is downloaded from the build page
741ed61612cSGeorge Keishing    #                        https://jenkins.openbmc.org/job/latest-master/
742f60cbcfbSSteven Sombar    #                        obmc-phosphor-debug-tarball-witherspoon.tar.xz
743f60cbcfbSSteven Sombar    #
744f60cbcfbSSteven Sombar    # targ_tarball_dir_path  The directory path where the tarball is to be
745f60cbcfbSSteven Sombar    #                        installed.
746f60cbcfbSSteven Sombar
747f60cbcfbSSteven Sombar    OperatingSystem.File Should Exist  ${tarball_file_path}
748f60cbcfbSSteven Sombar    ...  msg=${tarball_file_path} doesn't exist.
749f60cbcfbSSteven Sombar
750f60cbcfbSSteven Sombar    # Upload the file to BMC.
751f60cbcfbSSteven Sombar    Import Library  SCPLibrary  WITH NAME  scp
752f60cbcfbSSteven Sombar    Open Connection for SCP
753f60cbcfbSSteven Sombar    scp.Put File  ${tarball_file_path}  /tmp/debug-tarball.tar.xz
754f60cbcfbSSteven Sombar
755f60cbcfbSSteven Sombar    # Create tarball directory and install.
756f60cbcfbSSteven Sombar    BMC Execute Command  mkdir -p ${targ_tarball_dir_path}
757f60cbcfbSSteven Sombar    BMC Execute Command
758f60cbcfbSSteven Sombar    ...  tar -xf /tmp/debug-tarball.tar.xz -C ${targ_tarball_dir_path}
759f60cbcfbSSteven Sombar
760f60cbcfbSSteven Sombar    # Remove the tarball file from BMC.
761f60cbcfbSSteven Sombar    BMC Execute Command  rm -f /tmp/debug-tarball.tar.xz
762f60cbcfbSSteven Sombar
763f60cbcfbSSteven Sombar
764f60cbcfbSSteven SombarGet BMC Boot Count
765f60cbcfbSSteven Sombar    [Documentation]  Returns BMC boot count based on boot time.
766f60cbcfbSSteven Sombar    ${cur_btime}=  Get BMC Boot Time
767f60cbcfbSSteven Sombar
768f60cbcfbSSteven Sombar    # Set global variable BOOT_TIME to current boot time if current boot time
769f60cbcfbSSteven Sombar    # is changed. Also increase value of global variable BOOT_COUNT by 1.
770f60cbcfbSSteven Sombar    Run Keyword If  ${cur_btime} > ${BOOT_TIME}
771f60cbcfbSSteven Sombar    ...  Run Keywords  Set Global Variable  ${BOOT_TIME}  ${cur_btime}
772f60cbcfbSSteven Sombar    ...  AND
773f60cbcfbSSteven Sombar    ...  Set Global Variable  ${BOOT_COUNT}  ${BOOT_COUNT + 1}
774f60cbcfbSSteven Sombar
775f60cbcfbSSteven Sombar    [Return]  ${BOOT_COUNT}
776f60cbcfbSSteven Sombar
777f60cbcfbSSteven Sombar
778f60cbcfbSSteven SombarSet BMC Boot Count
779f60cbcfbSSteven Sombar    [Documentation]  Set BMC boot count to given value.
780f60cbcfbSSteven Sombar    [Arguments]  ${count}
781f60cbcfbSSteven Sombar
782f60cbcfbSSteven Sombar    # Description of arguments:
783f60cbcfbSSteven Sombar    # count  boot count value.
784f60cbcfbSSteven Sombar    ${cur_btime}=  Get BMC Boot Time
785f60cbcfbSSteven Sombar
786f60cbcfbSSteven Sombar    # Set global variable BOOT_COUNT to given value.
787f60cbcfbSSteven Sombar    Set Global Variable  ${BOOT_COUNT}  ${count}
788f60cbcfbSSteven Sombar
789f60cbcfbSSteven Sombar    # Set BOOT_TIME variable to current boot time.
790073fbc0dSTony Lee    Set Global Variable  ${BOOT_TIME}  ${cur_btime}
791f60cbcfbSSteven Sombar
792f60cbcfbSSteven Sombar
793f60cbcfbSSteven SombarDelete Error Log Entry
794f60cbcfbSSteven Sombar    [Documentation]  Delete error log entry.
795cc490b41SMichael Shepos    [Arguments]  ${entry_path}  ${quiet}=${0}
796f60cbcfbSSteven Sombar
797f60cbcfbSSteven Sombar    # Description of argument(s):
798cc490b41SMichael Shepos    # quiet    If enabled, turns off logging to console.
799f60cbcfbSSteven Sombar    # entry_path  Delete an error log entry.
800f60cbcfbSSteven Sombar    #             Ex. /xyz/openbmc_project/logging/entry/1
801f60cbcfbSSteven Sombar
802f60cbcfbSSteven Sombar    # Skip delete if entry URI is a callout.
803f60cbcfbSSteven Sombar    # Examples:
804f60cbcfbSSteven Sombar    # /xyz/openbmc_project/logging/entry/1/callout
805f60cbcfbSSteven Sombar    # /xyz/openbmc_project/logging/entry/1/callouts/0
806f60cbcfbSSteven Sombar    ${callout_entry}=  Run Keyword And Return Status
807f60cbcfbSSteven Sombar    ...  Should Match Regexp  ${entry_path}  /callout[s]?(/|$)
808f60cbcfbSSteven Sombar    Return From Keyword If  ${callout_entry}
809f60cbcfbSSteven Sombar
810f60cbcfbSSteven Sombar    ${data}=  Create Dictionary  data=@{EMPTY}
811cc490b41SMichael Shepos    ${resp}=  Openbmc Delete Request  ${entry_path}  data=${data}  quiet=${quiet}
812f60cbcfbSSteven Sombar    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
813f60cbcfbSSteven Sombar
814f60cbcfbSSteven Sombar
815f60cbcfbSSteven SombarGet BMC Version
816f60cbcfbSSteven Sombar    [Documentation]  Returns BMC version from /etc/os-release.
817f60cbcfbSSteven Sombar    ...              e.g. "v1.99.6-141-ge662190"
818f60cbcfbSSteven Sombar
819f60cbcfbSSteven Sombar    ${cmd}=  Set Variable  grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '='
820f60cbcfbSSteven Sombar    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
821f60cbcfbSSteven Sombar    [Return]  ${output}
822f60cbcfbSSteven Sombar
823f60cbcfbSSteven Sombar
824f60cbcfbSSteven SombarGet PNOR Version
825f60cbcfbSSteven Sombar    [Documentation]  Returns the PNOR version from the BMC.
826f60cbcfbSSteven Sombar
827f60cbcfbSSteven Sombar    ${pnor_attrs}=  Get PNOR Attributes
828f60cbcfbSSteven Sombar    [Return]  ${pnor_attrs['version']}
829f60cbcfbSSteven Sombar
830f60cbcfbSSteven Sombar
831f60cbcfbSSteven SombarGet PNOR Attributes
832f60cbcfbSSteven Sombar    [Documentation]  Return PNOR software attributes as a dictionary.
833f60cbcfbSSteven Sombar
834f60cbcfbSSteven Sombar    # This keyword parses /var/lib/phosphor-software-manager/pnor/ro/pnor.toc
835f60cbcfbSSteven Sombar    # into key/value pairs.
836f60cbcfbSSteven Sombar
837f60cbcfbSSteven Sombar    ${outbuf}  ${stderr}  ${rc}=  BMC Execute Command
838f60cbcfbSSteven Sombar    ...  cat /var/lib/phosphor-software-manager/pnor/ro/pnor.toc
839f60cbcfbSSteven Sombar    ${pnor_attrs}=  Key Value Outbuf To Dict  ${outbuf}  delim==
840f60cbcfbSSteven Sombar
841f60cbcfbSSteven Sombar    [Return]  ${pnor_attrs}
842f60cbcfbSSteven Sombar
843f60cbcfbSSteven Sombar
84417dae1aeSSivas SRRGET BMC PNOR Version
84517dae1aeSSivas SRR    [Documentation]  Return BMC & PNOR version from openbmc shell.
84617dae1aeSSivas SRR
84717dae1aeSSivas SRR    ${bmc_version}=  GET BMC Version
84817dae1aeSSivas SRR    ${pnor_version}=  GET PNOR Version
84917dae1aeSSivas SRR    Log  ${bmc_version}
85017dae1aeSSivas SRR    Rprint Vars  bmc_version
85117dae1aeSSivas SRR    Log  ${pnor_version}
85217dae1aeSSivas SRR    Rprint Vars  pnor_version
85317dae1aeSSivas SRR
85417dae1aeSSivas SRR    [Return]  ${bmc_version}  ${pnor_version}
85517dae1aeSSivas SRR
85617dae1aeSSivas SRR
8575ea86d02SSushil SinghRedfish Get BMC Version
8585ea86d02SSushil Singh    [Documentation]  Get BMC version via Redfish.
8595ea86d02SSushil Singh
8605ea86d02SSushil Singh    ${output}=  Redfish.Get Attribute  ${REDFISH_BASE_URI}Managers/bmc  FirmwareVersion
8615ea86d02SSushil Singh    [Return]  ${output}
8625ea86d02SSushil Singh
8635ea86d02SSushil SinghRedfish Get Host Version
8645ea86d02SSushil Singh    [Documentation]  Get host version via Redfish.
8655ea86d02SSushil Singh
8665ea86d02SSushil Singh    ${output}=  Redfish.Get Attribute  ${REDFISH_BASE_URI}Systems/system  BiosVersion
8675ea86d02SSushil Singh    [Return]  ${output}
8685ea86d02SSushil Singh
8695ea86d02SSushil Singh
870f60cbcfbSSteven SombarCopy Address Translation Utils To HOST OS
871f60cbcfbSSteven Sombar    [Documentation]  Copy address translation utils to host OS.
872f60cbcfbSSteven Sombar
873f60cbcfbSSteven Sombar    OperatingSystem.File Should Exist  ${probe_cpu_tool_path}
874f60cbcfbSSteven Sombar    ...  msg=${probe_cpu_tool_path} doesn't exist.
875f60cbcfbSSteven Sombar    OperatingSystem.File Should Exist  ${probe_cpu_tool_path}
876f60cbcfbSSteven Sombar    ...  msg=${probe_cpu_tool_path} doesn't exist.
877f60cbcfbSSteven Sombar
878f60cbcfbSSteven Sombar    scp.Open connection  ${OS_HOST}  username=${OS_USERNAME}
879f60cbcfbSSteven Sombar    ...  password=${OS_PASSWORD}
880f60cbcfbSSteven Sombar    scp.Put File  ${probe_cpu_tool_path}  ${target_file_path}
881f60cbcfbSSteven Sombar    scp.Put File  ${scom_addrs_tool_path}  ${target_file_path}
882f60cbcfbSSteven Sombar
883f60cbcfbSSteven Sombar
884f60cbcfbSSteven SombarVerify BMC RTC And UTC Time Drift
885f60cbcfbSSteven Sombar    [Documentation]  Verify that the RTC and UTC time difference is less than
886f60cbcfbSSteven Sombar    ...              the given time_drift_max.
887f60cbcfbSSteven Sombar    [Arguments]  ${time_diff_max}=${10}
888f60cbcfbSSteven Sombar
889f60cbcfbSSteven Sombar    # Description of argument(s):
890f60cbcfbSSteven Sombar    # time_diff_max   The max allowable RTC and UTC time difference in seconds.
891f60cbcfbSSteven Sombar
892f60cbcfbSSteven Sombar    # Example:
893f60cbcfbSSteven Sombar    # time_dict:
894f60cbcfbSSteven Sombar    #   [local_time]:               Fri 2017-11-03 152756 UTC
895f60cbcfbSSteven Sombar    #   [local_time_seconds]:       1509740876
896f60cbcfbSSteven Sombar    #   [universal_time]:           Fri 2017-11-03 152756 UTC
897f60cbcfbSSteven Sombar    #   [universal_time_seconds]:   1509740876
898f60cbcfbSSteven Sombar    #   [rtc_time]:                 Fri 2016-05-20 163403
899f60cbcfbSSteven Sombar    #   [rtc_time_seconds]:         1463780043
900f60cbcfbSSteven Sombar    #   [time_zone]:                n/a (UTC, +0000)
901f60cbcfbSSteven Sombar    #   [network_time_on]:          yes
902f60cbcfbSSteven Sombar    #   [ntp_synchronized]:         no
903f60cbcfbSSteven Sombar    #   [rtc_in_local_tz]:          no
904f60cbcfbSSteven Sombar
905f60cbcfbSSteven Sombar    ${time}=  Get BMC Date Time
906f60cbcfbSSteven Sombar    ${time_diff}=  Evaluate
907f60cbcfbSSteven Sombar    ...  ${time['universal_time_seconds']} - ${time['rtc_time_seconds']}
908f60cbcfbSSteven Sombar    Should Be True  ${time_diff} < ${time_diff_max}
909f60cbcfbSSteven Sombar
910f60cbcfbSSteven Sombar
911f60cbcfbSSteven SombarValidate IP On BMC
912f60cbcfbSSteven Sombar    [Documentation]  Validate IP address is present in set of IP addresses.
913f60cbcfbSSteven Sombar    [Arguments]  ${ip_address}  ${ip_data}
914f60cbcfbSSteven Sombar
915f60cbcfbSSteven Sombar    # Description of argument(s):
916f60cbcfbSSteven Sombar    # ip_address  IP address to check (e.g. xx.xx.xx.xx).
917f60cbcfbSSteven Sombar    # ip_data     Set of the IP addresses present.
918f60cbcfbSSteven Sombar
919f60cbcfbSSteven Sombar    Should Contain Match  ${ip_data}  ${ip_address}/*
920f60cbcfbSSteven Sombar    ...  msg=${ip_address} not found in the list provided.
921f60cbcfbSSteven Sombar
922f60cbcfbSSteven Sombar
923f60cbcfbSSteven SombarRemove Journald Logs
924f60cbcfbSSteven Sombar    [Documentation]  Remove all journald logs and restart service.
925f60cbcfbSSteven Sombar
926f60cbcfbSSteven Sombar    ${cmd}=  Catenate  systemctl stop systemd-journald.service &&
927f60cbcfbSSteven Sombar    ...  rm -rf /var/log/journal && systemctl start systemd-journald.service
928f60cbcfbSSteven Sombar
929f60cbcfbSSteven Sombar    BMC Execute Command  ${cmd}
930f60cbcfbSSteven Sombar
931f60cbcfbSSteven Sombar
932f60cbcfbSSteven SombarCheck For Regex In Journald
933f60cbcfbSSteven Sombar    [Documentation]  Parse the journal log and check for regex string.
934f60cbcfbSSteven Sombar    [Arguments]  ${regex}=${ERROR_REGEX}  ${error_check}=${0}  ${boot}=${EMPTY}
935140351fcSGeorge Keishing    ...          ${filter_string}=${EMPTY}
936f60cbcfbSSteven Sombar
937f60cbcfbSSteven Sombar    # Description of argument(s):
938f60cbcfbSSteven Sombar    # regex            Strings to be filter.
939f60cbcfbSSteven Sombar    # error_check      Check for errors.
940f60cbcfbSSteven Sombar    # boot             Argument to check current or persistent full boot log
941f60cbcfbSSteven Sombar    #                  (e.g. "-b").
942140351fcSGeorge Keishing    # filter_string    String to be stripped out.
943f60cbcfbSSteven Sombar
944140351fcSGeorge Keishing
945140351fcSGeorge Keishing    ${cmd} =  Run Keyword If   '${filter_string}' == '${EMPTY}'
946140351fcSGeorge Keishing    ...      Catenate  journalctl --no-pager ${boot} | egrep '${regex}'
947140351fcSGeorge Keishing    ...   ELSE
948140351fcSGeorge Keishing    ...      Catenate  journalctl --no-pager ${boot} | egrep '${regex}' |  sed '/${filter_string}/d'
949140351fcSGeorge Keishing
950140351fcSGeorge Keishing    ${journal_log}  ${stderr}  ${rc}=  BMC Execute Command   ${cmd}  ignore_err=1
951f60cbcfbSSteven Sombar
952f60cbcfbSSteven Sombar    Run Keyword If  ${error_check} == ${0}
953f60cbcfbSSteven Sombar    ...    Should Be Empty  ${journal_log}
954f60cbcfbSSteven Sombar    ...  ELSE
955f60cbcfbSSteven Sombar    ...    Should Not Be Empty  ${journal_log}
956f60cbcfbSSteven Sombar
957f60cbcfbSSteven Sombar
958f60cbcfbSSteven SombarGet Service Attribute
959f60cbcfbSSteven Sombar    [Documentation]  Get service attribute policy output.
960f60cbcfbSSteven Sombar    [Arguments]  ${option}  ${servicename}
961f60cbcfbSSteven Sombar
962f60cbcfbSSteven Sombar    # Description of argument(s):
963f60cbcfbSSteven Sombar    # option       systemctl supported options
964f60cbcfbSSteven Sombar    # servicename  Qualified service name
965f60cbcfbSSteven Sombar    ${cmd}=  Set Variable
966f60cbcfbSSteven Sombar    ...  systemctl -p ${option} show ${servicename} | cut -d = -f2
967f60cbcfbSSteven Sombar    ${attr}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
968f60cbcfbSSteven Sombar    [Return]  ${attr}
969eda09492SAnusha Dathatri
970eda09492SAnusha Dathatri
971eda09492SAnusha DathatriVerify Watchdog Enabled
972eda09492SAnusha Dathatri    [Documentation]  Check that watchdog settings are enabled.
973eda09492SAnusha Dathatri
974eda09492SAnusha Dathatri    ${properties}=  Read Properties  /xyz/openbmc_project/watchdog/host0
975eda09492SAnusha Dathatri    Should Be Equal As Strings  ${properties["Enabled"]}  ${True}
976eda09492SAnusha Dathatri    Should Not Be Equal As Strings  ${properties["TimeRemaining"]}  0
977233d9659SAshwini Chandrappa
978233d9659SAshwini Chandrappa
979233d9659SAshwini ChandrappaIs BMC Unpingable
980233d9659SAshwini Chandrappa    [Documentation]  Check if BMC is unpingable.
981233d9659SAshwini Chandrappa
982233d9659SAshwini Chandrappa    ${RC}  ${output}=  Run and return RC and Output  ping -c 4 ${OPENBMC_HOST}
983233d9659SAshwini Chandrappa    Log  RC: ${RC}\nOutput:\n${output}
984233d9659SAshwini Chandrappa    Should be equal  ${RC}  ${1}
9856d170ad1SSushil Singh
9866d170ad1SSushil SinghKernel Panic BMC Reset Operation
9876d170ad1SSushil Singh    [Documentation]  Create kernel panic to reset BMC.
9886d170ad1SSushil Singh
9896d170ad1SSushil Singh    ${kernel_panic_cmd_file}=  Set Variable  /bin/sh -c "echo c > /proc/sysrq-trigger"
9906d170ad1SSushil Singh    ${status}=  Run Keyword And Return Status  BMC Execute Command  ${kernel_panic_cmd_file}  time_out=120
9916d170ad1SSushil Singh
9926d170ad1SSushil Singh    [Return]  ${status}
9936d170ad1SSushil Singh
994