xref: /openbmc/openbmc-test-automation/lib/bmc_cleanup.robot (revision 20ccfc7186271c9621ce864235e62edb6e6b027c)
122d293b5SSunil M*** Settings ***
222d293b5SSunil MResource                ../lib/utils.robot
322d293b5SSunil MResource                ../lib/connection_client.robot
422d293b5SSunil MResource                ../lib/boot_utils.robot
522d293b5SSunil M
622d293b5SSunil M*** Variables ***
722d293b5SSunil M# User defined path to do the cleanup.
822d293b5SSunil M${CLEANUP_DIR_PATH}  ${EMPTY}
922d293b5SSunil M# List that holds space separated filepaths to skip from cleanup.
1022d293b5SSunil M${SKIP_LIST}  ${EMPTY}
1122d293b5SSunil M
1222d293b5SSunil M*** Keywords ***
1322d293b5SSunil M
1422d293b5SSunil M
1522d293b5SSunil MCleanup Dir
1622d293b5SSunil M    [Documentation]  Remove leftover files in cleanup directory path.
1722d293b5SSunil M    [Arguments]      ${cleanup_dir_path}=${CLEANUP_DIR_PATH}
1822d293b5SSunil M    ...              ${skip_list}=${SKIP_LIST}
1922d293b5SSunil M
2022d293b5SSunil M    # Description of argument(s):
2122d293b5SSunil M    # cleanup_dir_path  Directory path to do the cleanup.
2222d293b5SSunil M    # skip_list  List of files to skip from cleanup.
2322d293b5SSunil M
2422d293b5SSunil M    Should Not Be Empty  ${cleanup_dir_path}
2522d293b5SSunil M    Should Not Be Empty  ${SKIP_LIST}
269b66897bSJoy Onyerikwu
279b66897bSJoy Onyerikwu    ${skip_list_string}=  Set Variable  cd ${cleanup_dir_path}
28*20ccfc71SMarissa Garza    FOR  ${file}  IN  @{skip_list}
29*20ccfc71SMarissa Garza        ${skip_list_string}=   Set Variable  ${skip_list_string} && rm ${file}
30*20ccfc71SMarissa Garza    END
3122d293b5SSunil M
329b66897bSJoy Onyerikwu    ${file_count1}  ${stderr}  ${rc}=  BMC Execute Command
339b66897bSJoy Onyerikwu    ...  find ${cleanup_dir_path} | wc -l
349b66897bSJoy Onyerikwu    BMC Execute Command  ${skip_list_string}
3522d293b5SSunil M
369b66897bSJoy Onyerikwu    ${file_count2}  ${stderrt}  ${rc}=  BMC Execute Command
379b66897bSJoy Onyerikwu    ...  find ${cleanup_dir_path} | wc -l
3822d293b5SSunil M    Should Be True  ${file_count2} < ${file_count1}
399b66897bSJoy Onyerikwu    # Delete the directory if it is empty.
409b66897bSJoy Onyerikwu    Run Keyword If  ${file_count2} <= 1
419b66897bSJoy Onyerikwu    ...  BMC Execute Command  rm -r ${cleanup_dir_path}
42