xref: /openbmc/openbmc-test-automation/lib/common_utils.robot (revision 409df05d4b10b9a8c81e282da8fef0199db5bdea)
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.
103*409df05dSGeorge Keishing    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
117*409df05dSGeorge Keishing    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
1237d5a4300SSushil Singh    ...          ${interval}=5 sec  ${expected_rc}=${0}
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").
1337d5a4300SSushil Singh    # expected_rc    Expected return code of ping command.
134f60cbcfbSSteven Sombar
1357d5a4300SSushil Singh    Wait Until Keyword Succeeds  ${timeout}  ${interval}  Ping Host  ${host}  ${expected_rc}
136f60cbcfbSSteven Sombar
137f60cbcfbSSteven Sombar
138f60cbcfbSSteven SombarPing Host
139f60cbcfbSSteven Sombar    [Documentation]  Ping the given host.
1407d5a4300SSushil Singh    [Arguments]     ${host}  ${expected_rc}=${0}
141f60cbcfbSSteven Sombar
142f60cbcfbSSteven Sombar    # Description of argument(s):
143f60cbcfbSSteven Sombar    # host           The host name or IP of the host to ping.
1447d5a4300SSushil Singh    # expected_rc    Expected return code of ping command.
145f60cbcfbSSteven Sombar
146f60cbcfbSSteven Sombar    Should Not Be Empty    ${host}   msg=No host provided
1477d5a4300SSushil Singh    ${rc}   ${output}=     Run and return RC and Output    ping -c 4 ${host}
1487d5a4300SSushil Singh    Log     RC: ${rc}\nOutput:\n${output}
1497d5a4300SSushil Singh    Should be equal     ${rc}   ${expected_rc}
150f60cbcfbSSteven Sombar
151f60cbcfbSSteven Sombar
152f60cbcfbSSteven SombarCheck OS
153f60cbcfbSSteven Sombar    [Documentation]  Attempts to ping the host OS and then checks that the host
154f60cbcfbSSteven Sombar    ...              OS is up by running an SSH command.
155f60cbcfbSSteven Sombar
156f60cbcfbSSteven Sombar    [Arguments]  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
157f60cbcfbSSteven Sombar    ...          ${os_password}=${OS_PASSWORD}  ${quiet}=${QUIET}
158f60cbcfbSSteven Sombar    ...          ${print_string}=${EMPTY}
159f60cbcfbSSteven Sombar    [Teardown]  SSHLibrary.Close Connection
160f60cbcfbSSteven Sombar
161f60cbcfbSSteven Sombar    # Description of argument(s):
162f60cbcfbSSteven Sombar    # os_host           The DNS name/IP of the OS host associated with our BMC.
163f60cbcfbSSteven Sombar    # os_username       The username to be used to sign on to the OS host.
164f60cbcfbSSteven Sombar    # os_password       The password to be used to sign on to the OS host.
165f60cbcfbSSteven Sombar    # quiet             Indicates whether this keyword should write to console.
166f60cbcfbSSteven Sombar    # print_string      A string to be printed before checking the OS.
167f60cbcfbSSteven Sombar
168c108e429SMichael Walsh    Log To Console  ${print_string}  no_newline=True
169f60cbcfbSSteven Sombar
170f60cbcfbSSteven Sombar    # Attempt to ping the OS. Store the return code to check later.
171f60cbcfbSSteven Sombar    ${ping_rc}=  Run Keyword and Return Status  Ping Host  ${os_host}
172f60cbcfbSSteven Sombar
173f60cbcfbSSteven Sombar    SSHLibrary.Open connection  ${os_host}
174f60cbcfbSSteven Sombar
1753075166eSGeorge Keishing    ${status}  ${msg}=  Run Keyword And Ignore Error  SSHLibrary.Login  ${os_username}
176f60cbcfbSSteven Sombar    ...  ${os_password}
177f60cbcfbSSteven Sombar    ${err_msg1}=  Sprint Error  ${msg}
178f60cbcfbSSteven Sombar    ${err_msg}=  Catenate  SEPARATOR=  \n  ${err_msg1}
179f60cbcfbSSteven Sombar    Run Keyword If  '${status}' == 'FAIL'  Fail  msg=${err_msg}
180f60cbcfbSSteven Sombar    ${output}  ${stderr}  ${rc}=  Execute Command  uptime  return_stderr=True
181f60cbcfbSSteven Sombar    ...        return_rc=True
182f60cbcfbSSteven Sombar
183f60cbcfbSSteven Sombar    ${temp_msg}=  Catenate  Could not execute a command on the operating
184f60cbcfbSSteven Sombar    ...  system.\n
185f60cbcfbSSteven Sombar    ${err_msg1}=  Sprint Error  ${temp_msg}
186f60cbcfbSSteven Sombar    ${err_msg}=  Catenate  SEPARATOR=  \n  ${err_msg1}
187f60cbcfbSSteven Sombar
188f60cbcfbSSteven Sombar    # If the return code returned by "Execute Command" is non-zero, this
189f60cbcfbSSteven Sombar    # keyword will fail.
190f60cbcfbSSteven Sombar    Should Be Equal  ${rc}  ${0}  msg=${err_msg}
191f60cbcfbSSteven Sombar    # We will likewise fail if there is any stderr data.
192f60cbcfbSSteven Sombar    Should Be Empty  ${stderr}
193f60cbcfbSSteven Sombar
194f60cbcfbSSteven Sombar    ${temp_msg}=  Set Variable  Could not ping the operating system.\n
195f60cbcfbSSteven Sombar    ${err_msg1}=  Sprint Error  ${temp_msg}
196f60cbcfbSSteven Sombar    ${err_msg}=  Catenate  SEPARATOR=  \n  ${err_msg1}
197f60cbcfbSSteven Sombar    # We will likewise fail if the OS did not ping, as we could SSH but not
198f60cbcfbSSteven Sombar    # ping
199f60cbcfbSSteven Sombar    Should Be Equal As Strings  ${ping_rc}  ${TRUE}  msg=${err_msg}
200f60cbcfbSSteven Sombar
201f60cbcfbSSteven Sombar
202f60cbcfbSSteven SombarWait for OS
203f60cbcfbSSteven Sombar    [Documentation]  Waits for the host OS to come up via calls to "Check OS".
204f60cbcfbSSteven Sombar    [Arguments]  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
205f60cbcfbSSteven Sombar    ...          ${os_password}=${OS_PASSWORD}  ${timeout}=${OS_WAIT_TIMEOUT}
206f60cbcfbSSteven Sombar    ...          ${quiet}=${0}
207c108e429SMichael Walsh    [Teardown]  Printn
208f60cbcfbSSteven Sombar
209f60cbcfbSSteven Sombar    # Description of argument(s):
210f60cbcfbSSteven Sombar    # os_host           The DNS name or IP of the OS host associated with our
211f60cbcfbSSteven Sombar    #                   BMC.
212f60cbcfbSSteven Sombar    # os_username       The username to be used to sign on to the OS host.
213f60cbcfbSSteven Sombar    # os_password       The password to be used to sign on to the OS host.
214f60cbcfbSSteven Sombar    # timeout           The timeout in seconds indicating how long you're
215f60cbcfbSSteven Sombar    #                   willing to wait for the OS to respond.
216f60cbcfbSSteven Sombar    # quiet             Indicates whether this keyword should write to console.
217f60cbcfbSSteven Sombar
218f60cbcfbSSteven Sombar    # The interval to be used between calls to "Check OS".
219f60cbcfbSSteven Sombar    ${interval}=  Set Variable  5
220f60cbcfbSSteven Sombar
221f60cbcfbSSteven Sombar    ${message}=  Catenate  Checking every ${interval} seconds for up to
222f60cbcfbSSteven Sombar    ...  ${timeout} seconds for the operating system to communicate.
223c108e429SMichael Walsh    Qprint Timen  ${message}
224f60cbcfbSSteven Sombar
225f60cbcfbSSteven Sombar    Wait Until Keyword Succeeds  ${timeout} sec  ${interval}  Check OS
226f60cbcfbSSteven Sombar    ...                          ${os_host}  ${os_username}  ${os_password}
227f60cbcfbSSteven Sombar    ...                          print_string=\#
228f60cbcfbSSteven Sombar
229c108e429SMichael Walsh    Qprintn
230f60cbcfbSSteven Sombar
231c108e429SMichael Walsh    Qprint Timen  The operating system is now communicating.
232f60cbcfbSSteven Sombar
233f60cbcfbSSteven Sombar
234f60cbcfbSSteven SombarCopy PNOR to BMC
235f60cbcfbSSteven Sombar    [Documentation]  Copy the PNOR image to the BMC.
236f60cbcfbSSteven Sombar    Import Library      SCPLibrary      WITH NAME       scp
237f60cbcfbSSteven Sombar    Open Connection for SCP
238f60cbcfbSSteven Sombar    Log    Copying ${PNOR_IMAGE_PATH} to /tmp
239f60cbcfbSSteven Sombar    scp.Put File    ${PNOR_IMAGE_PATH}   /tmp
240f60cbcfbSSteven Sombar
241f60cbcfbSSteven Sombar
242f60cbcfbSSteven SombarIs OS Starting
243f60cbcfbSSteven Sombar    [Documentation]  Check if boot progress is OS starting.
244f60cbcfbSSteven Sombar    ${boot_progress}=  Get Boot Progress
245f60cbcfbSSteven Sombar    Should Be Equal  ${boot_progress}  OSStart
246f60cbcfbSSteven Sombar
247f60cbcfbSSteven Sombar
248f60cbcfbSSteven SombarIs OS Off
249f60cbcfbSSteven Sombar    [Documentation]  Check if boot progress is "Off".
250f60cbcfbSSteven Sombar    ${boot_progress}=  Get Boot Progress
251f60cbcfbSSteven Sombar    Should Be Equal  ${boot_progress}  Off
252f60cbcfbSSteven Sombar
253f60cbcfbSSteven Sombar
254f60cbcfbSSteven SombarGet Boot Progress To OS Starting State
255f60cbcfbSSteven Sombar    [Documentation]  Get the system to a boot progress state of 'FW Progress,
256f60cbcfbSSteven Sombar    ...  Starting OS'.
257f60cbcfbSSteven Sombar
258f60cbcfbSSteven Sombar    ${boot_progress}=  Get Boot Progress
259f60cbcfbSSteven Sombar    Run Keyword If  '${boot_progress}' == 'OSStart'
260f60cbcfbSSteven Sombar    ...  Log  Host is already in OS starting state
261f60cbcfbSSteven Sombar    ...  ELSE
262f60cbcfbSSteven Sombar    ...  Run Keywords  Initiate Host PowerOff  AND  Initiate Host Boot
263f60cbcfbSSteven Sombar    ...  AND  Wait Until Keyword Succeeds  10 min  10 sec  Is OS Starting
264f60cbcfbSSteven Sombar
265f60cbcfbSSteven Sombar
266f60cbcfbSSteven SombarCheck If warmReset is Initiated
267f60cbcfbSSteven Sombar    [Documentation]  Ping would be still alive, so try SSH to connect
268f60cbcfbSSteven Sombar    ...              if fails the ports are down indicating reboot
269f60cbcfbSSteven Sombar    ...              is in progress
270f60cbcfbSSteven Sombar
271f60cbcfbSSteven Sombar    # Warm reset adds 3 seconds delay before forcing reboot
272f60cbcfbSSteven Sombar    # To minimize race conditions, we wait for 7 seconds
273f60cbcfbSSteven Sombar    Sleep  7s
274f60cbcfbSSteven Sombar    ${alive}=   Run Keyword and Return Status
275f60cbcfbSSteven Sombar    ...    Open Connection And Log In
276f60cbcfbSSteven Sombar    Return From Keyword If   '${alive}' == '${False}'    ${False}
277*409df05dSGeorge Keishing    RETURN    ${True}
278f60cbcfbSSteven Sombar
279f60cbcfbSSteven Sombar
280f60cbcfbSSteven SombarInitialize DBUS cmd
281f60cbcfbSSteven Sombar    [Documentation]  Initialize dbus string with property string to extract
282f60cbcfbSSteven Sombar    [Arguments]   ${boot_property}
283f60cbcfbSSteven Sombar
284f60cbcfbSSteven Sombar    # Description of argument(s):
285f60cbcfbSSteven Sombar    # boot_property   Property string.
286f60cbcfbSSteven Sombar
287f60cbcfbSSteven Sombar    ${cmd}=     Catenate  ${dbuscmdBase} ${dbuscmdGet} ${dbuscmdString}
288f60cbcfbSSteven Sombar    ${cmd}=     Catenate  ${cmd}${boot_property}
289f60cbcfbSSteven Sombar    Set Global Variable   ${dbuscmd}     ${cmd}
290f60cbcfbSSteven Sombar
291f60cbcfbSSteven Sombar
292f60cbcfbSSteven SombarCreate OS Console Command String
293f60cbcfbSSteven Sombar    [Documentation]  Return a command string to start OS console logging.
294f60cbcfbSSteven Sombar
295f60cbcfbSSteven Sombar    # First make sure that the ssh_pw program is available.
296f60cbcfbSSteven Sombar    ${cmd}=  Catenate  which ssh_pw 2>/dev/null || find
297f60cbcfbSSteven Sombar    ...  ${EXECDIR} -name 'ssh_pw'
298f60cbcfbSSteven Sombar
299c108e429SMichael Walsh    Dprint Issuing  ${cmd}
300f60cbcfbSSteven Sombar    ${rc}  ${output}=  Run And Return Rc And Output  ${cmd}
301f60cbcfbSSteven Sombar    Rdpvars  rc  output
302f60cbcfbSSteven Sombar
303f60cbcfbSSteven Sombar    Should Be Equal As Integers  0  ${rc}  msg=Could not find ssh_pw.
304f60cbcfbSSteven Sombar
305f60cbcfbSSteven Sombar    ${ssh_pw_file_path}=  Set Variable  ${output}
306f60cbcfbSSteven Sombar
307088166c6SGeorge Keishing    ${cmd}=  Catenate  ${ssh_pw_file_path} ${OPENBMC_PASSWORD} -p ${HOST_SOL_PORT}
308f196b244SJorge Cisneros    ...  -o "StrictHostKeyChecking no" ${OPENBMC_USERNAME}@${OPENBMC_HOST} ${OPENBMC_CONSOLE_CLIENT}
309f60cbcfbSSteven Sombar
310*409df05dSGeorge Keishing    RETURN  ${cmd.strip()}
311f60cbcfbSSteven Sombar
312f60cbcfbSSteven Sombar
313f60cbcfbSSteven SombarGet SOL Console Pid
314f60cbcfbSSteven Sombar    [Documentation]  Get the pid of the active SOL console job.
31507ed7944SMichael Walsh    [Arguments]  ${expect_running}=${0}  ${log_file_path}=${EMPTY}
316f60cbcfbSSteven Sombar
317f60cbcfbSSteven Sombar    # Description of argument(s):
31807ed7944SMichael Walsh    # expect_running                If set and if no SOL console job is found, print debug info and fail.
31907ed7944SMichael Walsh    # log_file_path                 Needed to print debug info if expect_running is set and no pid is found.
320f60cbcfbSSteven Sombar
321f60cbcfbSSteven Sombar    # Find the pid of the active system console logging session (if any).
322f60cbcfbSSteven Sombar    ${search_string}=  Create OS Console Command String
323f60cbcfbSSteven Sombar    # At least in some cases, ps output does not show double quotes so we must
324f60cbcfbSSteven Sombar    # replace them in our search string with the regexes to indicate that they
325f60cbcfbSSteven Sombar    # are optional.
326f60cbcfbSSteven Sombar    ${search_string}=  Replace String  ${search_string}  "  ["]?
327f60cbcfbSSteven Sombar    ${ps_cmd}=  Catenate  ps axwwo user,pid,cmd
328f60cbcfbSSteven Sombar    ${cmd_buf}=  Catenate  echo $(${ps_cmd} | egrep '${search_string}' |
329f60cbcfbSSteven Sombar    ...  egrep -v grep | cut -c10-14)
330c108e429SMichael Walsh    Dprint Issuing  ${cmd_buf}
331f60cbcfbSSteven Sombar    ${rc}  ${os_con_pid}=  Run And Return Rc And Output  ${cmd_buf}
332f60cbcfbSSteven Sombar    Rdpvars  os_con_pid
333f60cbcfbSSteven Sombar    # If rc is not zero it just means that there is no OS Console process
334f60cbcfbSSteven Sombar    # running.
335f60cbcfbSSteven Sombar
336f60cbcfbSSteven Sombar    Return From Keyword If  '${os_con_pid}' != '${EMPTY}'  ${os_con_pid}
337f60cbcfbSSteven Sombar    Return From Keyword If  '${expect_running}' == '${0}'  ${os_con_pid}
338f60cbcfbSSteven Sombar
339f60cbcfbSSteven Sombar    Cmd Fnc  cat ${log_file_path} ; echo ; ${ps_cmd}  quiet=${0}
340f60cbcfbSSteven Sombar    ...  print_output=${1}  show_err=${1}
34107ed7944SMichael Walsh    Valid Value  os_con_pid
342f60cbcfbSSteven Sombar
343f60cbcfbSSteven Sombar
344f60cbcfbSSteven SombarStop SOL Console Logging
345f60cbcfbSSteven Sombar    [Documentation]  Stop system console logging and return log output.
346f60cbcfbSSteven Sombar    [Arguments]  ${log_file_path}=${EMPTY}
347f60cbcfbSSteven Sombar    ...          ${targ_file_path}=${EXECDIR}${/}logs${/}
348f60cbcfbSSteven Sombar    ...          ${return_data}=${1}
349f60cbcfbSSteven Sombar
350e16f158fSGeorge Keishing    # If there are multiple system console processes, they will all be stopped.
351f60cbcfbSSteven Sombar    # If there is no existing log file this keyword will return an error
352f60cbcfbSSteven Sombar    # message to that effect (and write that message to targ_file_path, if
353f60cbcfbSSteven Sombar    # specified).
354f60cbcfbSSteven Sombar    # NOTE: This keyword will not fail if there is no running system console
355f60cbcfbSSteven Sombar    # process.
356f60cbcfbSSteven Sombar
357f60cbcfbSSteven Sombar    # Description of arguments:
358f60cbcfbSSteven Sombar    # log_file_path   The file path that was used to call "Start SOL
359f60cbcfbSSteven Sombar    #                 Console Logging".  See that keyword (above) for details.
360f60cbcfbSSteven Sombar    # targ_file_path  If specified, the file path to which the source
361f60cbcfbSSteven Sombar    #                 file path (i.e. "log_file_path") should be copied.
362f60cbcfbSSteven Sombar    # return_data     If this is set to ${1}, this keyword will return the SOL
363f60cbcfbSSteven Sombar    #                 data to the caller as a unicode string.
364f60cbcfbSSteven Sombar
365f60cbcfbSSteven Sombar    ${log_file_path}=  Create OS Console File Path  ${log_file_path}
366f60cbcfbSSteven Sombar
367f60cbcfbSSteven Sombar    ${os_con_pid}=  Get SOL Console Pid
368f60cbcfbSSteven Sombar
369f60cbcfbSSteven Sombar    ${cmd_buf}=  Catenate  kill -9 ${os_con_pid}
370c108e429SMichael Walsh    Run Keyword If  '${os_con_pid}' != '${EMPTY}'  Dprint Issuing  ${cmd_buf}
371f60cbcfbSSteven Sombar    ${rc}  ${output}=  Run Keyword If  '${os_con_pid}' != '${EMPTY}'
372f60cbcfbSSteven Sombar    ...  Run And Return Rc And Output  ${cmd_buf}
373f60cbcfbSSteven Sombar    Run Keyword If  '${os_con_pid}' != '${EMPTY}'  Rdpvars  rc  output
374f60cbcfbSSteven Sombar
375f60cbcfbSSteven Sombar    Run Keyword If  '${targ_file_path}' != '${EMPTY}'
376f60cbcfbSSteven Sombar    ...  Run Keyword And Ignore Error
377f60cbcfbSSteven Sombar    ...  Copy File  ${log_file_path}  ${targ_file_path}
378f60cbcfbSSteven Sombar
379f60cbcfbSSteven Sombar    ${output}=  Set Variable  ${EMPTY}
380f60cbcfbSSteven Sombar    ${loc_quiet}=  Evaluate  ${debug}^1
381f60cbcfbSSteven Sombar    ${rc}  ${output}=  Run Keyword If  '${return_data}' == '${1}'
382f60cbcfbSSteven Sombar    ...  Cmd Fnc  cat ${log_file_path} 2>/dev/null  quiet=${loc_quiet}
383f60cbcfbSSteven Sombar    ...  print_output=${0}  show_err=${0}
384f60cbcfbSSteven Sombar
385*409df05dSGeorge Keishing    RETURN  ${output}
386f60cbcfbSSteven Sombar
387f60cbcfbSSteven Sombar
388f60cbcfbSSteven SombarStart SOL Console Logging
389f60cbcfbSSteven Sombar    [Documentation]  Start system console log to file.
390f60cbcfbSSteven Sombar    [Arguments]  ${log_file_path}=${EMPTY}  ${return_data}=${1}
391f60cbcfbSSteven Sombar
392f60cbcfbSSteven Sombar    # This keyword will first call "Stop SOL Console Logging".  Only then will
393f60cbcfbSSteven Sombar    # it start SOL console logging.  The data returned by "Stop SOL Console
394f60cbcfbSSteven Sombar    # Logging" will in turn be returned by this keyword.
395f60cbcfbSSteven Sombar
396f60cbcfbSSteven Sombar    # Description of arguments:
397f60cbcfbSSteven Sombar    # log_file_path   The file path to which system console log data should be
398f60cbcfbSSteven Sombar    #                 written.  Note that this path is taken to be a location
399f60cbcfbSSteven Sombar    #                 on the machine where this program is running rather than
400f60cbcfbSSteven Sombar    #                 on the Open BMC system.
401f60cbcfbSSteven Sombar    # return_data     If this is set to ${1}, this keyword will return any SOL
402f60cbcfbSSteven Sombar    #                 data to the caller as a unicode string.
403f60cbcfbSSteven Sombar
404f60cbcfbSSteven Sombar    ${log_file_path}=  Create OS Console File Path  ${log_file_path}
405f60cbcfbSSteven Sombar
406f60cbcfbSSteven Sombar    ${log_output}=  Stop SOL Console Logging  ${log_file_path}
407f60cbcfbSSteven Sombar    ...  return_data=${return_data}
408f60cbcfbSSteven Sombar
409f60cbcfbSSteven Sombar    # Validate by making sure we can create the file.  Problems creating the
410f60cbcfbSSteven Sombar    # file would not be noticed by the subsequent ssh command because we fork
411f60cbcfbSSteven Sombar    # the command.
412f60cbcfbSSteven Sombar    Create File  ${log_file_path}
413f60cbcfbSSteven Sombar    ${sub_cmd_buf}=  Create OS Console Command String
414f60cbcfbSSteven Sombar    # Routing stderr to stdout so that any startup error text will go to the
415f60cbcfbSSteven Sombar    # output file.
416f60cbcfbSSteven Sombar    ${cmd_buf}=  Catenate  ${sub_cmd_buf} > ${log_file_path} 2>&1 &
417c108e429SMichael Walsh    Dprint Issuing  ${cmd_buf}
418f60cbcfbSSteven Sombar    ${rc}  ${output}=  Run And Return Rc And Output  ${cmd_buf}
419f60cbcfbSSteven Sombar    # Because we are forking this command, we essentially will never get a
420f60cbcfbSSteven Sombar    # non-zero return code or any output.
421f60cbcfbSSteven Sombar    Should Be Equal  ${rc}  ${0}
422f60cbcfbSSteven Sombar
423f60cbcfbSSteven Sombar    Wait Until Keyword Succeeds  10 seconds  0 seconds
42407ed7944SMichael Walsh    ...   Get SOL Console Pid  ${1}  ${log_file_path}
425f60cbcfbSSteven Sombar
426*409df05dSGeorge Keishing    RETURN  ${log_output}
427f60cbcfbSSteven Sombar
428f60cbcfbSSteven Sombar
429f60cbcfbSSteven SombarGet Time Stamp
430f60cbcfbSSteven Sombar    [Documentation]     Get the current time stamp data
431f60cbcfbSSteven Sombar    ${cur_time}=    Get Current Date   result_format=%Y%m%d%H%M%S%f
432*409df05dSGeorge Keishing    RETURN   ${cur_time}
433f60cbcfbSSteven Sombar
434f60cbcfbSSteven Sombar
435f60cbcfbSSteven SombarStart Journal Log
436f60cbcfbSSteven Sombar    [Documentation]   Start capturing journal log to a file in /tmp using
437f60cbcfbSSteven Sombar    ...               journalctl command. By default journal log is collected
438f60cbcfbSSteven Sombar    ...               at /tmp/journal_log else user input location.
439f60cbcfbSSteven Sombar    ...               The File is appended with datetime.
440f60cbcfbSSteven Sombar    [Arguments]       ${file_path}=/tmp/journal_log  ${filter}=${EMPTY}
441f60cbcfbSSteven Sombar
442f60cbcfbSSteven Sombar    # Description of arguments:
443f60cbcfbSSteven Sombar    # file_path   The file path of the journal file.
444f60cbcfbSSteven Sombar
445f60cbcfbSSteven Sombar    ${cur_time}=    Get Time Stamp
446f60cbcfbSSteven Sombar    Set Global Variable   ${LOG_TIME}   ${cur_time}
447f60cbcfbSSteven Sombar    Open Connection And Log In
448f60cbcfbSSteven Sombar    Start Command
449f60cbcfbSSteven Sombar    ...  journalctl -f ${filter} > ${file_path}-${LOG_TIME}
450f60cbcfbSSteven Sombar    Log    Journal Log Started: ${file_path}-${LOG_TIME}
451f60cbcfbSSteven Sombar
452f60cbcfbSSteven Sombar
453f60cbcfbSSteven SombarStop Journal Log
454f60cbcfbSSteven Sombar    [Documentation]   Stop journalctl process if its running.
455f60cbcfbSSteven Sombar    ...               By default return log from /tmp/journal_log else
456f60cbcfbSSteven Sombar    ...               user input location.
457f60cbcfbSSteven Sombar    [Arguments]       ${file_path}=/tmp/journal_log
458f60cbcfbSSteven Sombar
459f60cbcfbSSteven Sombar    # Description of arguments:
460f60cbcfbSSteven Sombar    # file_path   The file path of the journal file.
461f60cbcfbSSteven Sombar
462f60cbcfbSSteven Sombar    Open Connection And Log In
463f60cbcfbSSteven Sombar
464f60cbcfbSSteven Sombar    ${rc}=
465f60cbcfbSSteven Sombar    ...  Execute Command
466f60cbcfbSSteven Sombar    ...  ps | grep journalctl | grep -v grep
467f60cbcfbSSteven Sombar    ...  return_stdout=False  return_rc=True
468f60cbcfbSSteven Sombar
469f60cbcfbSSteven Sombar    Return From Keyword If   '${rc}' == '${1}'
470f60cbcfbSSteven Sombar    ...   No journal log process running
471f60cbcfbSSteven Sombar
472f60cbcfbSSteven Sombar    ${output}  ${stderr}=
473f60cbcfbSSteven Sombar    ...  Execute Command   killall journalctl
474f60cbcfbSSteven Sombar    ...  return_stderr=True
475f60cbcfbSSteven Sombar    Should Be Empty     ${stderr}
476f60cbcfbSSteven Sombar
477f60cbcfbSSteven Sombar    ${journal_log}  ${stderr}=
478f60cbcfbSSteven Sombar    ...  Execute Command
479f60cbcfbSSteven Sombar    ...  cat ${file_path}-${LOG_TIME}
480f60cbcfbSSteven Sombar    ...  return_stderr=True
481f60cbcfbSSteven Sombar    Should Be Empty     ${stderr}
482f60cbcfbSSteven Sombar
483f60cbcfbSSteven Sombar    Log    ${journal_log}
484f60cbcfbSSteven Sombar
485f60cbcfbSSteven Sombar    Execute Command    rm ${file_path}-${LOG_TIME}
486f60cbcfbSSteven Sombar
487*409df05dSGeorge Keishing    RETURN    ${journal_log}
488f60cbcfbSSteven Sombar
489f60cbcfbSSteven Sombar
490f60cbcfbSSteven SombarMac Address To Hex String
491f60cbcfbSSteven Sombar    [Documentation]   Converts MAC address into hex format.
492f60cbcfbSSteven Sombar    ...               Example
493f60cbcfbSSteven Sombar    ...               Given the following MAC: 00:01:6C:80:02:78
494f60cbcfbSSteven Sombar    ...               This keyword will return: 0x00 0x01 0x6C 0x80 0x02 0x78
495f60cbcfbSSteven Sombar    ...               Description of arguments:
496f60cbcfbSSteven Sombar    ...               i_macaddress  MAC address in the following format
497f60cbcfbSSteven Sombar    ...               00:01:6C:80:02:78
498f60cbcfbSSteven Sombar    [Arguments]    ${i_macaddress}
499f60cbcfbSSteven Sombar
500f60cbcfbSSteven Sombar    # Description of arguments:
501f60cbcfbSSteven Sombar    # i_macaddress   The MAC address.
502f60cbcfbSSteven Sombar
503f60cbcfbSSteven Sombar    ${mac_hex}=  Catenate  0x${i_macaddress.replace(':', ' 0x')}
504*409df05dSGeorge Keishing    RETURN    ${mac_hex}
505f60cbcfbSSteven Sombar
506f60cbcfbSSteven Sombar
507f60cbcfbSSteven SombarIP Address To Hex String
508f60cbcfbSSteven Sombar    [Documentation]   Converts IP address into hex format.
509f60cbcfbSSteven Sombar    ...               Example:
510f60cbcfbSSteven Sombar    ...               Given the following IP: 10.3.164.100
511f60cbcfbSSteven Sombar    ...               This keyword will return: 0xa 0x3 0xa4 0xa0
512f60cbcfbSSteven Sombar    [Arguments]    ${i_ipaddress}
513f60cbcfbSSteven Sombar
514f60cbcfbSSteven Sombar    # Description of arguments:
515f60cbcfbSSteven Sombar    # i_macaddress   The IP address in the format 10.10.10.10.
516f60cbcfbSSteven Sombar
517f60cbcfbSSteven Sombar    @{ip}=  Split String  ${i_ipaddress}    .
518f60cbcfbSSteven Sombar    ${index}=  Set Variable  ${0}
519f60cbcfbSSteven Sombar
52020ccfc71SMarissa Garza    FOR    ${item}     IN      @{ip}
52120ccfc71SMarissa Garza        ${hex}=  Convert To Hex    ${item}    prefix=0x    lowercase=yes
52220ccfc71SMarissa Garza        Set List Value    ${ip}    ${index}    ${hex}
52320ccfc71SMarissa Garza        ${index}=  Set Variable    ${index + 1}
52420ccfc71SMarissa Garza    END
525f60cbcfbSSteven Sombar    ${ip_hex}=  Catenate    @{ip}
526f60cbcfbSSteven Sombar
527*409df05dSGeorge Keishing    RETURN    ${ip_hex}
528f60cbcfbSSteven Sombar
529f60cbcfbSSteven Sombar
530f60cbcfbSSteven SombarBMC CPU Performance Check
531f60cbcfbSSteven Sombar   [Documentation]   Minimal 10% of proc should be free in this instance
532f60cbcfbSSteven Sombar
533f60cbcfbSSteven Sombar    ${bmc_cpu_usage_output}  ${stderr}  ${rc}=  BMC Execute Command
534f60cbcfbSSteven Sombar    ...  ${bmc_cpu_usage_cmd}
535f60cbcfbSSteven Sombar    ${bmc_cpu_usage_output}  ${stderr}  ${rc}=  BMC Execute Command
536f60cbcfbSSteven Sombar    ...  ${bmc_cpu_usage_cmd}
537f60cbcfbSSteven Sombar    ${bmc_cpu_percentage}=  Fetch From Left  ${bmc_cpu_usage_output}  %
53814426bcbSSivas SRR    Rprint Vars  bmc_cpu_percentage
539f60cbcfbSSteven Sombar    Should be true  ${bmc_cpu_percentage} < 90
540f60cbcfbSSteven Sombar
541f60cbcfbSSteven Sombar
542f60cbcfbSSteven SombarBMC Mem Performance Check
543f60cbcfbSSteven Sombar    [Documentation]   Minimal 10% of memory should be free in this instance
544f60cbcfbSSteven Sombar
545f60cbcfbSSteven Sombar    ${bmc_mem_free_output}  ${stderr}  ${rc}=   BMC Execute Command
546f60cbcfbSSteven Sombar    ...  ${bmc_mem_free_cmd}
547f60cbcfbSSteven Sombar
548f60cbcfbSSteven Sombar    ${bmc_mem_total_output}  ${stderr}  ${rc}=  BMC Execute Command
549f60cbcfbSSteven Sombar    ...  ${bmc_mem_total_cmd}
550f60cbcfbSSteven Sombar    ${bmc_mem_free_output}  ${stderr}  ${rc}=   BMC Execute Command
551f60cbcfbSSteven Sombar    ...  ${bmc_mem_free_cmd}
552f60cbcfbSSteven Sombar
553f60cbcfbSSteven Sombar    ${bmc_mem_total_output}  ${stderr}  ${rc}=  BMC Execute Command
554f60cbcfbSSteven Sombar    ...  ${bmc_mem_total_cmd}
555f60cbcfbSSteven Sombar
556f60cbcfbSSteven Sombar    ${bmc_mem_percentage}=  Evaluate  ${bmc_mem_free_output}*100
557f60cbcfbSSteven Sombar    ${bmc_mem_percentage}=  Evaluate
558f60cbcfbSSteven Sombar    ...   ${bmc_mem_percentage}/${bmc_mem_total_output}
55914426bcbSSivas SRR    Rprint Vars  bmc_mem_percentage
560f60cbcfbSSteven Sombar    Should be true  ${bmc_mem_percentage} > 10
561f60cbcfbSSteven Sombar
562f60cbcfbSSteven Sombar
563f60cbcfbSSteven SombarBMC File System Usage Check
564f60cbcfbSSteven Sombar    [Documentation]   Check the file system space. 4 file system should be
565f60cbcfbSSteven Sombar    ...  100% full which is expected
566f60cbcfbSSteven Sombar    # Filesystem            Size    Used Available Use% Mounted on
567f60cbcfbSSteven Sombar    # /dev/root            14.4M     14.4M       0 100% /
568f60cbcfbSSteven Sombar    # /dev/ubiblock0_0     14.4M     14.4M       0 100% /media/rofs-c9249b0e
569f60cbcfbSSteven Sombar    # /dev/ubiblock8_0     19.6M     19.6M       0 100% /media/pnor-ro-8764baa3
570f60cbcfbSSteven Sombar    # /dev/ubiblock4_0     14.4M     14.4M       0 100% /media/rofs-407816c
571f60cbcfbSSteven Sombar    # /dev/ubiblock8_4     21.1M     21.1M       0 100% /media/pnor-ro-cecc64c4
572f60cbcfbSSteven Sombar    ${bmc_fs_usage_output}  ${stderr}  ${rc}=  BMC Execute Command
573f60cbcfbSSteven Sombar    ...  ${bmc_file_system_usage_cmd}
574f60cbcfbSSteven Sombar    ${bmc_pnor_fs_usage_output}  ${stderr}  ${rc}=  BMC Execute Command
575f60cbcfbSSteven Sombar    ...  ${total_pnor_ro_file_system_cmd}
576f60cbcfbSSteven Sombar    ${bmc_bmc_fs_usage_output}  ${stderr}  ${rc}=  BMC Execute Command
577f60cbcfbSSteven Sombar    ...  ${total_bmc_ro_file_system_cmd}
578f60cbcfbSSteven Sombar    ${total_bmc_pnor_image}=  Evaluate
579f60cbcfbSSteven Sombar    ...  ${bmc_pnor_fs_usage_output}+${bmc_bmc_fs_usage_output}
580f60cbcfbSSteven Sombar    # Considering /dev/root also in total 100% used file system
581f60cbcfbSSteven Sombar    ${total_full_fs}=  Evaluate  ${total_bmc_pnor_image}+1
58214426bcbSSivas SRR    Rprint Vars  bmc_fs_usage_output  bmc_pnor_fs_usage_output  bmc_bmc_fs_usage_output
58314426bcbSSivas SRR    ...  total_full_fs
584f60cbcfbSSteven Sombar    Should Be True  ${bmc_fs_usage_output}==${total_full_fs}
585f60cbcfbSSteven Sombar
586f60cbcfbSSteven Sombar
587f60cbcfbSSteven SombarCheck BMC CPU Performance
588f60cbcfbSSteven Sombar    [Documentation]   Minimal 10% of proc should be free in 3 sample
58920ccfc71SMarissa Garza    FOR  ${var}  IN RANGE  1  4
59020ccfc71SMarissa Garza        BMC CPU Performance Check
59120ccfc71SMarissa Garza    END
592f60cbcfbSSteven Sombar
593f60cbcfbSSteven SombarCheck BMC Mem Performance
594f60cbcfbSSteven Sombar    [Documentation]   Minimal 10% of memory should be free
595f60cbcfbSSteven Sombar
59620ccfc71SMarissa Garza    FOR  ${var}  IN RANGE  1  4
59720ccfc71SMarissa Garza        BMC Mem Performance Check
59820ccfc71SMarissa Garza    END
599f60cbcfbSSteven Sombar
600f60cbcfbSSteven SombarCheck BMC File System Performance
601f60cbcfbSSteven Sombar    [Documentation]  Check for file system usage for 4 times
602f60cbcfbSSteven Sombar
60320ccfc71SMarissa Garza    FOR  ${var}  IN RANGE  1  4
60420ccfc71SMarissa Garza        BMC File System Usage check
60520ccfc71SMarissa Garza    END
606f60cbcfbSSteven Sombar
607f60cbcfbSSteven SombarGet URL List
608f60cbcfbSSteven Sombar    [Documentation]  Return list of URLs under given URL.
609f60cbcfbSSteven Sombar    [Arguments]  ${openbmc_url}
610f60cbcfbSSteven Sombar
611f60cbcfbSSteven Sombar    # Description of argument(s):
612f60cbcfbSSteven Sombar    # openbmc_url  URL for list operation (e.g.
613f60cbcfbSSteven Sombar    #              /xyz/openbmc_project/inventory).
614f60cbcfbSSteven Sombar
615aaaab222SSteven Sombar    ${url_list}=  Read Properties  ${openbmc_url}list  quiet=${1}
616f60cbcfbSSteven Sombar    Sort List  ${url_list}
617f60cbcfbSSteven Sombar
618*409df05dSGeorge Keishing    RETURN  ${url_list}
619f60cbcfbSSteven Sombar
620f60cbcfbSSteven Sombar
621f60cbcfbSSteven SombarCheck Zombie Process
622f60cbcfbSSteven Sombar    [Documentation]    Check if any defunct process exist or not on BMC
623f60cbcfbSSteven Sombar    ${count}  ${stderr}  ${rc}=  Execute Command  ps -o stat | grep Z | wc -l
624f60cbcfbSSteven Sombar    ...    return_stderr=True  return_rc=True
625f60cbcfbSSteven Sombar    Should Be True    ${count}==0
626f60cbcfbSSteven Sombar    Should Be Empty    ${stderr}
627f60cbcfbSSteven Sombar
628f60cbcfbSSteven Sombar
629f60cbcfbSSteven SombarPrune Journal Log
630f60cbcfbSSteven Sombar    [Documentation]   Prune archived journal logs.
631f60cbcfbSSteven Sombar    [Arguments]   ${vacuum_size}=1M
632f60cbcfbSSteven Sombar
633f60cbcfbSSteven Sombar    # This keyword can be used to prevent the journal
634f60cbcfbSSteven Sombar    # log from filling up the /run filesystem.
635f60cbcfbSSteven Sombar    # This command will retain only the latest logs
636f60cbcfbSSteven Sombar    # of the user specified size.
637f60cbcfbSSteven Sombar
638f60cbcfbSSteven Sombar    # Description of argument(s):
639f60cbcfbSSteven Sombar    # vacuum_size    Size of journal.
640f60cbcfbSSteven Sombar
641f60cbcfbSSteven Sombar    Open Connection And Log In
642f60cbcfbSSteven Sombar    ${output}  ${stderr}  ${rc}=
643f60cbcfbSSteven Sombar    ...  Execute Command
644f60cbcfbSSteven Sombar    ...  journalctl --vacuum-size=${vacuum_size}
645f60cbcfbSSteven Sombar    ...  return_stderr=True  return_rc=True
646f60cbcfbSSteven Sombar
647f60cbcfbSSteven Sombar    Should Be Equal  ${rc}  ${0}  msg=${stderr}
648f60cbcfbSSteven Sombar
649f60cbcfbSSteven Sombar
650f60cbcfbSSteven SombarGet System Power Policy
651f60cbcfbSSteven Sombar    [Documentation]  Returns the BMC power policy.
652f60cbcfbSSteven Sombar
653f60cbcfbSSteven Sombar    # Set the bmc_power_policy_method to either 'Old' or 'New'.
654f60cbcfbSSteven Sombar    Set Power Policy Method
655f60cbcfbSSteven Sombar    ${cmd_buf}=  Create List  ${bmc_power_policy_method} Get Power Policy
656f60cbcfbSSteven Sombar    # Run the appropriate keyword.
657f60cbcfbSSteven Sombar    ${currentPolicy}=  Run Keyword  @{cmd_buf}
658f60cbcfbSSteven Sombar
659*409df05dSGeorge Keishing    RETURN  ${currentPolicy}
660f60cbcfbSSteven Sombar
661f60cbcfbSSteven Sombar
662f60cbcfbSSteven SombarSet BMC Reset Reference Time
663f60cbcfbSSteven Sombar    [Documentation]  Set current boot time as a reference and increment
664f60cbcfbSSteven Sombar    ...              boot count.
665f60cbcfbSSteven Sombar
666f60cbcfbSSteven Sombar    ${cur_btime}=  Get BMC Boot Time
667f60cbcfbSSteven Sombar    Run Keyword If  ${BOOT_TIME} == ${0} and ${BOOT_COUNT} == ${0}
668f60cbcfbSSteven Sombar    ...  Set Global Variable  ${BOOT_TIME}  ${cur_btime}
669f60cbcfbSSteven Sombar    ...  ELSE IF  ${cur_btime} > ${BOOT_TIME}
670f60cbcfbSSteven Sombar    ...  Run Keywords  Set Global Variable  ${BOOT_TIME}  ${cur_btime}
671f60cbcfbSSteven Sombar    ...  AND
672f60cbcfbSSteven Sombar    ...  Set Global Variable  ${BOOT_COUNT}  ${BOOT_COUNT + 1}
673f60cbcfbSSteven Sombar
674f60cbcfbSSteven Sombar
675f60cbcfbSSteven SombarGet BMC Boot Time
676f60cbcfbSSteven Sombar    [Documentation]  Returns boot time from /proc/stat.
677f60cbcfbSSteven Sombar
678f60cbcfbSSteven Sombar    Open Connection And Log In
679f60cbcfbSSteven Sombar    ${output}  ${stderr}=
680f60cbcfbSSteven Sombar    ...  Execute Command  egrep '^btime ' /proc/stat | cut -f 2 -d ' '
681f60cbcfbSSteven Sombar    ...  return_stderr=True
682f60cbcfbSSteven Sombar    Should Be Empty  ${stderr}
683f60cbcfbSSteven Sombar    ${btime}=  Convert To Integer  ${output}
684*409df05dSGeorge Keishing    RETURN  ${btime}
685f60cbcfbSSteven Sombar
686f60cbcfbSSteven Sombar
687f60cbcfbSSteven SombarEnable Core Dump On BMC
688f60cbcfbSSteven Sombar    [Documentation]  Enable core dump collection.
689f60cbcfbSSteven Sombar    ${core_pattern}  ${stderr}  ${rc}=  BMC Execute Command
690f60cbcfbSSteven Sombar    ...  echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern
691f60cbcfbSSteven Sombar    Should Be Equal As Strings  ${core_pattern}  /tmp/core_%e.%p
692f60cbcfbSSteven Sombar
693f60cbcfbSSteven Sombar
694f60cbcfbSSteven SombarGet Number Of BMC Core Dump Files
695f60cbcfbSSteven Sombar    [Documentation]  Returns number of core dump files on BMC.
696f60cbcfbSSteven Sombar    Open Connection And Log In
697f60cbcfbSSteven Sombar    ${num_of_core_dump}=  Execute Command
698f60cbcfbSSteven Sombar    ...  ls /tmp/core* 2>/dev/null | wc -l
699*409df05dSGeorge Keishing    RETURN  ${num_of_core_dump}
700f60cbcfbSSteven Sombar
701f60cbcfbSSteven Sombar
702f60cbcfbSSteven SombarSet Core Dump File Size Unlimited
703f60cbcfbSSteven Sombar    [Documentation]  Set core dump file size to unlimited.
704f60cbcfbSSteven Sombar    BMC Execute Command  ulimit -c unlimited
705f60cbcfbSSteven Sombar
706f60cbcfbSSteven Sombar
707f60cbcfbSSteven SombarCheck For Core Dumps
708f60cbcfbSSteven Sombar    [Documentation]  Check for any core dumps exist.
709f60cbcfbSSteven Sombar    ${output}=  Get Number Of BMC Core Dump Files
710f60cbcfbSSteven Sombar    Run Keyword If  ${output} > 0
711f60cbcfbSSteven Sombar    ...  Log  **Warning** BMC core dump files exist  level=WARN
712f60cbcfbSSteven Sombar
713f60cbcfbSSteven Sombar
714f60cbcfbSSteven SombarConfigure Initial Settings
715f60cbcfbSSteven Sombar    [Documentation]  Restore old IP and route.
716f60cbcfbSSteven Sombar    ...  This keyword requires initial settings viz IP address,
71716b3c7bfSGeorge Keishing    ...  Network Mask, default gateway and serial console IP and port
718f60cbcfbSSteven Sombar    ...  information which should be provided in command line.
719f60cbcfbSSteven Sombar
720f60cbcfbSSteven Sombar    [Arguments]  ${host}=${OPENBMC_HOST}  ${mask}=${NET_MASK}
721f60cbcfbSSteven Sombar    ...          ${gw_ip}=${GW_IP}
722f60cbcfbSSteven Sombar
723f60cbcfbSSteven Sombar    # Description of arguments:
724f60cbcfbSSteven Sombar    # host  IP address of the OS Host.
725f60cbcfbSSteven Sombar    # mask  Network mask.
726f60cbcfbSSteven Sombar    # gu_ip  Gateway IP address or hostname.
727f60cbcfbSSteven Sombar
728f60cbcfbSSteven Sombar    # Open telnet connection and ignore the error, in case telnet session is
729f60cbcfbSSteven Sombar    # already opened by the program calling this keyword.
730f60cbcfbSSteven Sombar    Run Keyword And Ignore Error  Open Telnet Connection to BMC Serial Console
731f60cbcfbSSteven Sombar    Telnet.write  ifconfig eth0 ${host} netmask ${mask}
732f60cbcfbSSteven Sombar    Telnet.write  route add default gw ${gw_ip}
733f60cbcfbSSteven Sombar
734f60cbcfbSSteven Sombar
735f60cbcfbSSteven SombarInstall Debug Tarball On BMC
736f60cbcfbSSteven Sombar    [Documentation]  Copy the debug tar file to BMC and install.
737f60cbcfbSSteven Sombar    [Arguments]  ${tarball_file_path}=${default_tarball}
738f60cbcfbSSteven Sombar    ...  ${targ_tarball_dir_path}=/tmp/tarball/
739f60cbcfbSSteven Sombar
740f60cbcfbSSteven Sombar    # Description of arguments:
741f60cbcfbSSteven Sombar    # tarball_file_path      Path of the debug tarball file.
742f60cbcfbSSteven Sombar    #                        The tar file is downloaded from the build page
743ed61612cSGeorge Keishing    #                        https://jenkins.openbmc.org/job/latest-master/
744f60cbcfbSSteven Sombar    #                        obmc-phosphor-debug-tarball-witherspoon.tar.xz
745f60cbcfbSSteven Sombar    #
746f60cbcfbSSteven Sombar    # targ_tarball_dir_path  The directory path where the tarball is to be
747f60cbcfbSSteven Sombar    #                        installed.
748f60cbcfbSSteven Sombar
749f60cbcfbSSteven Sombar    OperatingSystem.File Should Exist  ${tarball_file_path}
750f60cbcfbSSteven Sombar    ...  msg=${tarball_file_path} doesn't exist.
751f60cbcfbSSteven Sombar
752f60cbcfbSSteven Sombar    # Upload the file to BMC.
753f60cbcfbSSteven Sombar    Import Library  SCPLibrary  WITH NAME  scp
754f60cbcfbSSteven Sombar    Open Connection for SCP
755f60cbcfbSSteven Sombar    scp.Put File  ${tarball_file_path}  /tmp/debug-tarball.tar.xz
756f60cbcfbSSteven Sombar
757f60cbcfbSSteven Sombar    # Create tarball directory and install.
758f60cbcfbSSteven Sombar    BMC Execute Command  mkdir -p ${targ_tarball_dir_path}
759f60cbcfbSSteven Sombar    BMC Execute Command
760f60cbcfbSSteven Sombar    ...  tar -xf /tmp/debug-tarball.tar.xz -C ${targ_tarball_dir_path}
761f60cbcfbSSteven Sombar
762f60cbcfbSSteven Sombar    # Remove the tarball file from BMC.
763f60cbcfbSSteven Sombar    BMC Execute Command  rm -f /tmp/debug-tarball.tar.xz
764f60cbcfbSSteven Sombar
765f60cbcfbSSteven Sombar
766f60cbcfbSSteven SombarGet BMC Boot Count
767f60cbcfbSSteven Sombar    [Documentation]  Returns BMC boot count based on boot time.
768f60cbcfbSSteven Sombar    ${cur_btime}=  Get BMC Boot Time
769f60cbcfbSSteven Sombar
770f60cbcfbSSteven Sombar    # Set global variable BOOT_TIME to current boot time if current boot time
771f60cbcfbSSteven Sombar    # is changed. Also increase value of global variable BOOT_COUNT by 1.
772f60cbcfbSSteven Sombar    Run Keyword If  ${cur_btime} > ${BOOT_TIME}
773f60cbcfbSSteven Sombar    ...  Run Keywords  Set Global Variable  ${BOOT_TIME}  ${cur_btime}
774f60cbcfbSSteven Sombar    ...  AND
775f60cbcfbSSteven Sombar    ...  Set Global Variable  ${BOOT_COUNT}  ${BOOT_COUNT + 1}
776f60cbcfbSSteven Sombar
777*409df05dSGeorge Keishing    RETURN  ${BOOT_COUNT}
778f60cbcfbSSteven Sombar
779f60cbcfbSSteven Sombar
780f60cbcfbSSteven SombarSet BMC Boot Count
781f60cbcfbSSteven Sombar    [Documentation]  Set BMC boot count to given value.
782f60cbcfbSSteven Sombar    [Arguments]  ${count}
783f60cbcfbSSteven Sombar
784f60cbcfbSSteven Sombar    # Description of arguments:
785f60cbcfbSSteven Sombar    # count  boot count value.
786f60cbcfbSSteven Sombar    ${cur_btime}=  Get BMC Boot Time
787f60cbcfbSSteven Sombar
788f60cbcfbSSteven Sombar    # Set global variable BOOT_COUNT to given value.
789f60cbcfbSSteven Sombar    Set Global Variable  ${BOOT_COUNT}  ${count}
790f60cbcfbSSteven Sombar
791f60cbcfbSSteven Sombar    # Set BOOT_TIME variable to current boot time.
792073fbc0dSTony Lee    Set Global Variable  ${BOOT_TIME}  ${cur_btime}
793f60cbcfbSSteven Sombar
794f60cbcfbSSteven Sombar
795f60cbcfbSSteven SombarDelete Error Log Entry
796f60cbcfbSSteven Sombar    [Documentation]  Delete error log entry.
797cc490b41SMichael Shepos    [Arguments]  ${entry_path}  ${quiet}=${0}
798f60cbcfbSSteven Sombar
799f60cbcfbSSteven Sombar    # Description of argument(s):
800cc490b41SMichael Shepos    # quiet    If enabled, turns off logging to console.
801f60cbcfbSSteven Sombar    # entry_path  Delete an error log entry.
802f60cbcfbSSteven Sombar    #             Ex. /xyz/openbmc_project/logging/entry/1
803f60cbcfbSSteven Sombar
804f60cbcfbSSteven Sombar    # Skip delete if entry URI is a callout.
805f60cbcfbSSteven Sombar    # Examples:
806f60cbcfbSSteven Sombar    # /xyz/openbmc_project/logging/entry/1/callout
807f60cbcfbSSteven Sombar    # /xyz/openbmc_project/logging/entry/1/callouts/0
808f60cbcfbSSteven Sombar    ${callout_entry}=  Run Keyword And Return Status
809f60cbcfbSSteven Sombar    ...  Should Match Regexp  ${entry_path}  /callout[s]?(/|$)
810f60cbcfbSSteven Sombar    Return From Keyword If  ${callout_entry}
811f60cbcfbSSteven Sombar
812f60cbcfbSSteven Sombar    ${data}=  Create Dictionary  data=@{EMPTY}
813cc490b41SMichael Shepos    ${resp}=  Openbmc Delete Request  ${entry_path}  data=${data}  quiet=${quiet}
814f60cbcfbSSteven Sombar    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
815f60cbcfbSSteven Sombar
816f60cbcfbSSteven Sombar
817f60cbcfbSSteven SombarGet BMC Version
818f60cbcfbSSteven Sombar    [Documentation]  Returns BMC version from /etc/os-release.
819f60cbcfbSSteven Sombar    ...              e.g. "v1.99.6-141-ge662190"
820f60cbcfbSSteven Sombar
821f60cbcfbSSteven Sombar    ${cmd}=  Set Variable  grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '='
822f60cbcfbSSteven Sombar    ${output}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
823*409df05dSGeorge Keishing    RETURN  ${output}
824f60cbcfbSSteven Sombar
825f60cbcfbSSteven Sombar
826f60cbcfbSSteven SombarGet PNOR Version
827f60cbcfbSSteven Sombar    [Documentation]  Returns the PNOR version from the BMC.
828f60cbcfbSSteven Sombar
829f60cbcfbSSteven Sombar    ${pnor_attrs}=  Get PNOR Attributes
830*409df05dSGeorge Keishing    RETURN  ${pnor_attrs['version']}
831f60cbcfbSSteven Sombar
832f60cbcfbSSteven Sombar
833f60cbcfbSSteven SombarGet PNOR Attributes
834f60cbcfbSSteven Sombar    [Documentation]  Return PNOR software attributes as a dictionary.
835f60cbcfbSSteven Sombar
836f60cbcfbSSteven Sombar    # This keyword parses /var/lib/phosphor-software-manager/pnor/ro/pnor.toc
837f60cbcfbSSteven Sombar    # into key/value pairs.
838f60cbcfbSSteven Sombar
839f60cbcfbSSteven Sombar    ${outbuf}  ${stderr}  ${rc}=  BMC Execute Command
840f60cbcfbSSteven Sombar    ...  cat /var/lib/phosphor-software-manager/pnor/ro/pnor.toc
841f60cbcfbSSteven Sombar    ${pnor_attrs}=  Key Value Outbuf To Dict  ${outbuf}  delim==
842f60cbcfbSSteven Sombar
843*409df05dSGeorge Keishing    RETURN  ${pnor_attrs}
844f60cbcfbSSteven Sombar
845f60cbcfbSSteven Sombar
84617dae1aeSSivas SRRGET BMC PNOR Version
84717dae1aeSSivas SRR    [Documentation]  Return BMC & PNOR version from openbmc shell.
84817dae1aeSSivas SRR
84917dae1aeSSivas SRR    ${bmc_version}=  GET BMC Version
85017dae1aeSSivas SRR    ${pnor_version}=  GET PNOR Version
85117dae1aeSSivas SRR    Log  ${bmc_version}
85217dae1aeSSivas SRR    Rprint Vars  bmc_version
85317dae1aeSSivas SRR    Log  ${pnor_version}
85417dae1aeSSivas SRR    Rprint Vars  pnor_version
85517dae1aeSSivas SRR
856*409df05dSGeorge Keishing    RETURN  ${bmc_version}  ${pnor_version}
85717dae1aeSSivas SRR
85817dae1aeSSivas SRR
8595ea86d02SSushil SinghRedfish Get BMC Version
8605ea86d02SSushil Singh    [Documentation]  Get BMC version via Redfish.
8615ea86d02SSushil Singh
8624d430283Sganesanb    ${output}=  Redfish.Get Attribute  ${REDFISH_BASE_URI}Managers/${MANAGER_ID}  FirmwareVersion
863*409df05dSGeorge Keishing    RETURN  ${output}
8645ea86d02SSushil Singh
8655ea86d02SSushil SinghRedfish Get Host Version
8665ea86d02SSushil Singh    [Documentation]  Get host version via Redfish.
8675ea86d02SSushil Singh
868c32434a3SYi Hu    ${output}=  Redfish.Get Attribute  ${REDFISH_BASE_URI}Systems/${SYSTEM_ID}  BiosVersion
869*409df05dSGeorge Keishing    RETURN  ${output}
8705ea86d02SSushil Singh
8715ea86d02SSushil Singh
872f60cbcfbSSteven SombarCopy Address Translation Utils To HOST OS
873f60cbcfbSSteven Sombar    [Documentation]  Copy address translation utils to host OS.
874f60cbcfbSSteven Sombar
875f60cbcfbSSteven Sombar    OperatingSystem.File Should Exist  ${probe_cpu_tool_path}
876f60cbcfbSSteven Sombar    ...  msg=${probe_cpu_tool_path} doesn't exist.
877f60cbcfbSSteven Sombar    OperatingSystem.File Should Exist  ${probe_cpu_tool_path}
878f60cbcfbSSteven Sombar    ...  msg=${probe_cpu_tool_path} doesn't exist.
879f60cbcfbSSteven Sombar
880f60cbcfbSSteven Sombar    scp.Open connection  ${OS_HOST}  username=${OS_USERNAME}
881f60cbcfbSSteven Sombar    ...  password=${OS_PASSWORD}
882f60cbcfbSSteven Sombar    scp.Put File  ${probe_cpu_tool_path}  ${target_file_path}
883f60cbcfbSSteven Sombar    scp.Put File  ${scom_addrs_tool_path}  ${target_file_path}
884f60cbcfbSSteven Sombar
885f60cbcfbSSteven Sombar
886f60cbcfbSSteven SombarVerify BMC RTC And UTC Time Drift
887f60cbcfbSSteven Sombar    [Documentation]  Verify that the RTC and UTC time difference is less than
888f60cbcfbSSteven Sombar    ...              the given time_drift_max.
889f60cbcfbSSteven Sombar    [Arguments]  ${time_diff_max}=${10}
890f60cbcfbSSteven Sombar
891f60cbcfbSSteven Sombar    # Description of argument(s):
892f60cbcfbSSteven Sombar    # time_diff_max   The max allowable RTC and UTC time difference in seconds.
893f60cbcfbSSteven Sombar
894f60cbcfbSSteven Sombar    # Example:
895f60cbcfbSSteven Sombar    # time_dict:
896f60cbcfbSSteven Sombar    #   [local_time]:               Fri 2017-11-03 152756 UTC
897f60cbcfbSSteven Sombar    #   [local_time_seconds]:       1509740876
898f60cbcfbSSteven Sombar    #   [universal_time]:           Fri 2017-11-03 152756 UTC
899f60cbcfbSSteven Sombar    #   [universal_time_seconds]:   1509740876
900f60cbcfbSSteven Sombar    #   [rtc_time]:                 Fri 2016-05-20 163403
901f60cbcfbSSteven Sombar    #   [rtc_time_seconds]:         1463780043
902f60cbcfbSSteven Sombar    #   [time_zone]:                n/a (UTC, +0000)
903f60cbcfbSSteven Sombar    #   [network_time_on]:          yes
904f60cbcfbSSteven Sombar    #   [ntp_synchronized]:         no
905f60cbcfbSSteven Sombar    #   [rtc_in_local_tz]:          no
906f60cbcfbSSteven Sombar
907f60cbcfbSSteven Sombar    ${time}=  Get BMC Date Time
908f60cbcfbSSteven Sombar    ${time_diff}=  Evaluate
909f60cbcfbSSteven Sombar    ...  ${time['universal_time_seconds']} - ${time['rtc_time_seconds']}
910f60cbcfbSSteven Sombar    Should Be True  ${time_diff} < ${time_diff_max}
911f60cbcfbSSteven Sombar
912f60cbcfbSSteven Sombar
913f60cbcfbSSteven SombarValidate IP On BMC
914f60cbcfbSSteven Sombar    [Documentation]  Validate IP address is present in set of IP addresses.
915f60cbcfbSSteven Sombar    [Arguments]  ${ip_address}  ${ip_data}
916f60cbcfbSSteven Sombar
917f60cbcfbSSteven Sombar    # Description of argument(s):
918f60cbcfbSSteven Sombar    # ip_address  IP address to check (e.g. xx.xx.xx.xx).
919f60cbcfbSSteven Sombar    # ip_data     Set of the IP addresses present.
920f60cbcfbSSteven Sombar
921f60cbcfbSSteven Sombar    Should Contain Match  ${ip_data}  ${ip_address}/*
922f60cbcfbSSteven Sombar    ...  msg=${ip_address} not found in the list provided.
923f60cbcfbSSteven Sombar
924f60cbcfbSSteven Sombar
925f60cbcfbSSteven SombarRemove Journald Logs
926f60cbcfbSSteven Sombar    [Documentation]  Remove all journald logs and restart service.
927f60cbcfbSSteven Sombar
928f60cbcfbSSteven Sombar    ${cmd}=  Catenate  systemctl stop systemd-journald.service &&
929f60cbcfbSSteven Sombar    ...  rm -rf /var/log/journal && systemctl start systemd-journald.service
930f60cbcfbSSteven Sombar
931f60cbcfbSSteven Sombar    BMC Execute Command  ${cmd}
932f60cbcfbSSteven Sombar
933f60cbcfbSSteven Sombar
934f60cbcfbSSteven SombarCheck For Regex In Journald
935f60cbcfbSSteven Sombar    [Documentation]  Parse the journal log and check for regex string.
936f60cbcfbSSteven Sombar    [Arguments]  ${regex}=${ERROR_REGEX}  ${error_check}=${0}  ${boot}=${EMPTY}
937140351fcSGeorge Keishing    ...          ${filter_string}=${EMPTY}
938f60cbcfbSSteven Sombar
939f60cbcfbSSteven Sombar    # Description of argument(s):
940f60cbcfbSSteven Sombar    # regex            Strings to be filter.
941f60cbcfbSSteven Sombar    # error_check      Check for errors.
942f60cbcfbSSteven Sombar    # boot             Argument to check current or persistent full boot log
943f60cbcfbSSteven Sombar    #                  (e.g. "-b").
944140351fcSGeorge Keishing    # filter_string    String to be stripped out.
945f60cbcfbSSteven Sombar
946140351fcSGeorge Keishing
947140351fcSGeorge Keishing    ${cmd} =  Run Keyword If   '${filter_string}' == '${EMPTY}'
948140351fcSGeorge Keishing    ...      Catenate  journalctl --no-pager ${boot} | egrep '${regex}'
949140351fcSGeorge Keishing    ...   ELSE
950140351fcSGeorge Keishing    ...      Catenate  journalctl --no-pager ${boot} | egrep '${regex}' |  sed '/${filter_string}/d'
951140351fcSGeorge Keishing
952140351fcSGeorge Keishing    ${journal_log}  ${stderr}  ${rc}=  BMC Execute Command   ${cmd}  ignore_err=1
953f60cbcfbSSteven Sombar
954f60cbcfbSSteven Sombar    Run Keyword If  ${error_check} == ${0}
955f60cbcfbSSteven Sombar    ...    Should Be Empty  ${journal_log}
956f60cbcfbSSteven Sombar    ...  ELSE
957f60cbcfbSSteven Sombar    ...    Should Not Be Empty  ${journal_log}
958f60cbcfbSSteven Sombar
959f60cbcfbSSteven Sombar
960f60cbcfbSSteven SombarGet Service Attribute
961f60cbcfbSSteven Sombar    [Documentation]  Get service attribute policy output.
962f60cbcfbSSteven Sombar    [Arguments]  ${option}  ${servicename}
963f60cbcfbSSteven Sombar
964f60cbcfbSSteven Sombar    # Description of argument(s):
965f60cbcfbSSteven Sombar    # option       systemctl supported options
966f60cbcfbSSteven Sombar    # servicename  Qualified service name
967f60cbcfbSSteven Sombar    ${cmd}=  Set Variable
968f60cbcfbSSteven Sombar    ...  systemctl -p ${option} show ${servicename} | cut -d = -f2
969f60cbcfbSSteven Sombar    ${attr}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
970*409df05dSGeorge Keishing    RETURN  ${attr}
971eda09492SAnusha Dathatri
972eda09492SAnusha Dathatri
973eda09492SAnusha DathatriVerify Watchdog Enabled
974eda09492SAnusha Dathatri    [Documentation]  Check that watchdog settings are enabled.
975eda09492SAnusha Dathatri
976eda09492SAnusha Dathatri    ${properties}=  Read Properties  /xyz/openbmc_project/watchdog/host0
977eda09492SAnusha Dathatri    Should Be Equal As Strings  ${properties["Enabled"]}  ${True}
978eda09492SAnusha Dathatri    Should Not Be Equal As Strings  ${properties["TimeRemaining"]}  0
979233d9659SAshwini Chandrappa
980233d9659SAshwini Chandrappa
981233d9659SAshwini ChandrappaIs BMC Unpingable
982233d9659SAshwini Chandrappa    [Documentation]  Check if BMC is unpingable.
983233d9659SAshwini Chandrappa
984233d9659SAshwini Chandrappa    ${RC}  ${output}=  Run and return RC and Output  ping -c 4 ${OPENBMC_HOST}
985233d9659SAshwini Chandrappa    Log  RC: ${RC}\nOutput:\n${output}
986233d9659SAshwini Chandrappa    Should be equal  ${RC}  ${1}
9876d170ad1SSushil Singh
98884c8015bSSushil Singh
989011c5f3bSNagarjun BIs Host Unpingable
990011c5f3bSNagarjun B    [Documentation]  Check if Given IP is unpingable.
991011c5f3bSNagarjun B    [Arguments]  ${ip}
992011c5f3bSNagarjun B
993011c5f3bSNagarjun B    # Description of argument(s):
994011c5f3bSNagarjun B    # ip           HostOS IP address (e.g. "10.7.7.7").
995011c5f3bSNagarjun B
996011c5f3bSNagarjun B    ${RC}  ${output}=  Run and return RC and Output  ping -c 4 ${ip}
997011c5f3bSNagarjun B    Log  RC: ${RC}\nOutput:\n${output}
998011c5f3bSNagarjun B    Should be equal  ${RC}  ${1}
999011c5f3bSNagarjun B
1000011c5f3bSNagarjun B
100184c8015bSSushil SinghRedfish BMC Match States
100284c8015bSSushil Singh    [Documentation]  Verify the BMC match state.
100384c8015bSSushil Singh    [Arguments]  ${match_state}
100484c8015bSSushil Singh
100584c8015bSSushil Singh    # Description of argument(s):
100684c8015bSSushil Singh    # match_state    Match the state of BMC.
100784c8015bSSushil Singh
100884c8015bSSushil Singh    ${bmc_state}=  Redfish Get BMC State
100984c8015bSSushil Singh    Should Be Equal As Strings  ${match_state}  ${bmc_state}
101084c8015bSSushil Singh
101184c8015bSSushil Singh
10126d170ad1SSushil SinghKernel Panic BMC Reset Operation
10136d170ad1SSushil Singh    [Documentation]  Create kernel panic to reset BMC.
10146d170ad1SSushil Singh
10156d170ad1SSushil Singh    ${kernel_panic_cmd_file}=  Set Variable  /bin/sh -c "echo c > /proc/sysrq-trigger"
1016a83bba0aSSushil Singh    ${status}=  Run Keyword And Return Status  BMC Execute Command  ${kernel_panic_cmd_file}  time_out=20
10176d170ad1SSushil Singh
1018*409df05dSGeorge Keishing    RETURN  ${status}
10196d170ad1SSushil Singh
1020e444dcd3SAnusha Dathatri
1021e444dcd3SAnusha DathatriGet Property Value Of Systemd Service In BMC
1022e444dcd3SAnusha Dathatri    [Documentation]  Get property of systemd service in BMC.
1023e444dcd3SAnusha Dathatri    [Arguments]  ${service_name}  ${property_name}
1024e444dcd3SAnusha Dathatri
1025e444dcd3SAnusha Dathatri    # Description of argument(s):
1026e444dcd3SAnusha Dathatri    # service_name   Systemd service name. E.g. bmcweb etc.
1027e444dcd3SAnusha Dathatri    # property_name  Property name. E.g. MainPID etc.
1028e444dcd3SAnusha Dathatri
1029e444dcd3SAnusha Dathatri    # ~# systemctl show --property MainPID --value bmcweb
1030e444dcd3SAnusha Dathatri    # 1273
1031e444dcd3SAnusha Dathatri
1032e444dcd3SAnusha Dathatri    ${stdout}  ${stderr}  ${rc}=  BMC Execute Command
1033e444dcd3SAnusha Dathatri    ...  systemctl show --property ${property_name} --value ${service_name}
1034e444dcd3SAnusha Dathatri
1035*409df05dSGeorge Keishing    RETURN  ${stdout}
1036