1*** Settings ***
2Resource                ../lib/utils.robot
3Resource                ../lib/connection_client.robot
4Resource                ../lib/boot_utils.robot
5
6*** Variables ***
7# User defined path to do the cleanup.
8${CLEANUP_DIR_PATH}  ${EMPTY}
9# List that holds space separated filepaths to skip from cleanup.
10${SKIP_LIST}  ${EMPTY}
11
12*** Keywords ***
13
14
15Cleanup Dir
16    [Documentation]  Remove leftover files in cleanup directory path.
17    [Arguments]      ${cleanup_dir_path}=${CLEANUP_DIR_PATH}
18    ...              ${skip_list}=${SKIP_LIST}
19
20    # Description of argument(s):
21    # cleanup_dir_path  Directory path to do the cleanup.
22    # skip_list  List of files to skip from cleanup.
23
24    Should Not Be Empty  ${cleanup_dir_path}
25    Should Not Be Empty  ${SKIP_LIST}
26    Open Connection And Log In
27    @{skip_list}=  Set Variable  ${skip_list.split()}
28    ${skip_list_string}=  Set Variable  ${EMPTY}
29    :FOR  ${file}  IN  @{skip_list}
30    \  ${skip_list_string}=   Set Variable  ${skip_list_string} ! -path "${file}"
31
32    ${file_count1}=  Execute Command On BMC  find ${cleanup_dir_path} | wc -l
33    Set Global Variable  ${file_count1}
34    Write  find ${cleanup_dir_path} \\( ${skip_list_string} \\) | xargs rm
35    Write  find ${cleanup_dir_path} \\( ${skip_list_string} \\) | xargs rmdir
36    ${file_count2}=  Execute Command On BMC  find ${cleanup_dir_path} | wc -l
37
38    Run Keyword If  ${file_count2} < ${file_count1}
39    ...  Reboot And Verify
40
41Reboot And Verify
42    [Documentation]  Reboot BMC and verify cleanup.
43    [Arguments]      ${cleanup_dir_path}=${CLEANUP_DIR_PATH}
44
45    # Description of argument(s):
46    # cleanup_dir_path  Directory path to do the cleanup.
47
48    OBMC Reboot (off)
49    # Take SSH session post BMC reboot before executing command.
50    Open Connection And Log In
51    ${file_count2}=  Execute Command On BMC  find ${cleanup_dir_path} | wc -l
52    Should Be True  ${file_count2} < ${file_count1}
53