xref: /openbmc/openbmc-test-automation/extended/code_update/code_update_utils.robot (revision 6c0f715bc3b324d22f1af93259b63020b9f7fbdd)
1*** Settings ***
2Documentation    Code update utility
3
4Resource         ../../lib/rest_client.robot
5Resource         ../../lib/connection_client.robot
6Resource         ../../lib/utils.robot
7Library          OperatingSystem
8
9*** Variables ***
10
11${BMC_UPD_METHOD}    /org/openbmc/control/flash/bmc/action/update
12${BMC_PREP_METHOD}   /org/openbmc/control/flash/bmc/action/PrepareForUpdate
13${BMC_UPD_ATTR}      /org/openbmc/control/flash/bmc
14
15*** Keywords ***
16
17Preserve BMC Network Setting
18    [Documentation]   Preserve Network setting
19    ${policy} =       Set Variable   ${1}
20    ${value} =    create dictionary   data=${policy}
21    Write Attribute   ${BMC_UPD_ATTR}  preserve_network_settings  data=${value}
22    ${data}=      Read Properties   ${BMC_UPD_ATTR}
23    should be equal as strings    ${data['preserve_network_settings']}   ${1}
24    ...   msg=0 indicates network is not preserved
25
26
27Activate BMC flash image
28    [Documentation]   Activate and verify the update status
29    ...               The status could be either one of these
30    ...               'Deferred for mounted filesystem. reboot BMC to apply.'
31    ...               'Image ready to apply.'
32    @{img_path} =   Create List    /tmp/flashimg
33    ${data} =   create dictionary   data=@{img_path}
34    ${resp}=    openbmc post request    ${BMC_UPD_METHOD}   data=${data}
35    should be equal as strings   ${resp.status_code}   ${HTTP_OK}
36
37    ${data}=      Read Properties     ${BMC_UPD_ATTR}
38    should be equal as strings   ${data["filename"]}   /tmp/flashimg
39    should contain    ${data['status']}   to apply
40
41
42Prepare For Update
43    [Documentation]   Switch to update mode in progress. This method calls
44    ...               the Abort method to remove the pending update if there
45    ...               is any before code activation.
46    ${data} =   create dictionary   data=@{EMPTY}
47    ${resp}=    openbmc post request    ${BMC_PREP_METHOD}   data=${data}
48    should be equal as strings   ${resp.status_code}   ${HTTP_OK}
49
50    ${data}=      Read Properties     ${BMC_UPD_ATTR}
51    should contain    ${data['status']}   Switch to update mode in progress
52
53
54SCP Tar Image File to BMC
55    [arguments]         ${filepath}
56    Open Connection for SCP
57    scp.Put File      ${filepath}   /tmp/flashimg
58
59
60Check If File Exist
61    [Arguments]  ${filepath}
62    Log   \n PATH: ${filepath}
63    OperatingSystem.File Should Exist  ${filepath}
64    ...    msg=${filepath} doesn't exist [ ERROR ]
65
66    Set Global Variable   ${FILE_PATH}  ${filepath}
67
68
69System Readiness Test
70    ${l_status} =   Run Keyword and Return Status
71    ...   Verify Ping and REST Authentication
72    Run Keyword If  '${l_status}' == '${False}'
73    ...   Fail  msg=System not in ideal state to use [ERROR]
74
75
76Validate BMC Version
77    [Arguments]   ${args}=post
78    # Check BMC installed version
79    Open Connection And Log In
80    ${version}   ${stderr}=    Execute Command   cat /etc/version
81    ...    return_stderr=True
82    Should Be Empty     ${stderr}
83    # The File name contains the version installed
84    Run Keyword If   '${args}' == 'before'
85    ...    Should not Contain  ${FILE_PATH}   ${version}
86    ...    msg=Same version already installed
87    ...    ELSE
88    ...    Should Contain      ${FILE_PATH}   ${version}
89    ...    msg=Code update Failed
90
91
92Trigger Warm Reset via Reboot
93    [Documentation]    Execute reboot command on the remote BMC and
94    ...                returns immediately. This keyword "Start Command"
95    ...                returns nothing and does not wait for the command
96    ...                execution to be finished.
97    Open Connection And Log In
98
99    Start Command   /sbin/reboot
100