1*** Settings ***
2Documentation            Redfish test to switch image sides and boot.
3
4Resource                 ../../lib/resource.robot
5Resource                 ../../lib/bmc_redfish_resource.robot
6Resource                 ../../lib/openbmc_ffdc.robot
7Resource                 ../../lib/redfish_code_update_utils.robot
8Library                  ../../lib/tftp_update_utils.py
9
10Suite Setup              Suite Setup Execution
11Suite Teardown           Run Keyword And Ignore Error  Redfish.Logout
12Test Teardown            FFDC On Test Case Fail
13
14Test Tags               Bmc_Image_Switch
15
16*** Variables ***
17
18# Switch iteration count. By default it does only 2 switch.
19# User can input -v LOOP_COUNT:n  to drive the switch back and forth for
20# nth iteration.
21${LOOP_COUNT}    ${2}
22
23*** Test Cases ***
24
25Test Firmware Image Switch Without Powering Host
26    [Documentation]  Switch image at host powered off.
27    [Tags]  Test_Firmware_Image_Switch_Without_Powering_Host
28    [Template]  Firmware Switch Loop
29
30    # iteration          power_on
31    ${LOOP_COUNT}        NO
32
33
34Test Firmware Image Switch And Power On Host
35    [Documentation]  Switch image and power on host and verify that it boots.
36    [Tags]  Test_Firmware_Image_Switch_And_Power_On_Host
37    [Template]  Firmware Switch Loop
38
39    # iteration          power_on
40    ${LOOP_COUNT}        YES
41
42
43*** Keywords ***
44
45Firmware Switch Loop
46    [Documentation]  Wrapper keyword for iteration for firmware side switch.
47    [Arguments]  ${iteration}  ${power_on}
48
49    # Description of argument(s):
50    # iteration      Number of switch it needs to perform.
51    # power_on       If YES, boot the system post firmware image switch,
52    #                if NO, do not perform any poweron operation.
53
54    FOR  ${count}  IN RANGE  0  ${iteration}
55        Log To Console   LOOP_COUNT:${count} execution.
56        Redfish BMC Switch Firmware Side
57
58        Continue For Loop If  '${power_on}' == 'NO'
59
60        Log To Console   Power on requested, issuing power on.
61        Redfish Power On
62
63        # Power Off for next iteration. Firmware image switch ideally needs to be
64        # to be executed when Host is powered off.
65        Log To Console   Power off requested, issuing power off.
66        Redfish Power Off
67    END
68
69
70Suite Setup Execution
71    [Documentation]  Do the suite setup.
72
73    Redfish.Login
74    Run Keyword And Ignore Error  Redfish Purge Event Log
75    Redfish Power Off  stack_mode=skip
76
77
78Redfish BMC Switch Firmware Side
79    [Documentation]  Switch back up image to running and verify.
80    [Tags]  Redfish_BMC_Switch_Firmware_Side
81
82    # fw_inv_dict:
83    #  [19a3ef3e]:
84    #    [image_type]:                                 BMC image
85    #    [image_id]:                                   19a3ef3e
86    #    [functional]:                                 True
87    #    [version]:                                    2.12.0-dev-1440-g8dada0a1a
88    #  [62d16947]:
89    #    [image_type]:                                 BMC image
90    #    [image_id]:                                   62d16947
91    #    [functional]:                                 False
92    #    [version]:                                    2.12.0-dev-1441-g8deadbeef
93    ${fw_inv_dict}=  Get Software Inventory State
94    Rprint Vars  fw_inv_dict
95
96    # Get the backup firmware version for reference.
97    FOR  ${id}  IN  @{fw_inv_dict.keys()}
98        Continue For Loop If  '${fw_inv_dict['${id}']['functional']}' == 'True'
99        # Find the non functional id and fetch the version.
100        ${image_version}=  Set Variable  ${fw_inv_dict['${id}']['version']}
101    END
102
103    Log To Console  Backup firmware version: ${image_version}
104
105    Switch Firmware Side  ${image_version}
106
107    Match BMC Release And Redifsh Firmware Version
108    Log To Console  The backup firmware image ${image_version} is now functional.
109
110
111Match BMC Release And Redifsh Firmware Version
112    [Documentation]  The /etc/os-release vs Redfish FirmwareVersion attribute value from
113    ...             /redfish/v1/Managers/${MANAGER_ID} should match.
114
115    # Python module: get_bmc_release_info()
116    ${bmc_release_info}=  utils.Get BMC Release Info
117    ${bmc_release}=  Set Variable  ${bmc_release_info['version_id']}
118    Rprint Vars  bmc_release
119
120    ${firmware_version}=  Redfish.Get Attribute  /redfish/v1/Managers/${MANAGER_ID}  FirmwareVersion
121    Rprint Vars  firmware_version
122
123    Should Be Equal As Strings   ${bmc_release}   ${firmware_version}
124    ...  msg=${bmc_release} does not match redfish version ${firmware_version}
125
126
127Switch Firmware Side
128    [Documentation]  Set the backup firmware to functional and verify after BMC rebooted.
129    [Arguments]  ${image_version}
130
131    # Description of argument(s):
132    # image_version     Version of image.
133
134    ${state}=  Get Pre Reboot State
135
136    Print Timen  Switch to back up and rebooting.
137    Switch Backup Firmware Image To Functional
138    Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
139    Print Timen  Switch to back up completed.
140
141    # Check if the BMC version after rebooted is the same version asked to switch.
142    ${firmware_version}=  Redfish.Get Attribute  /redfish/v1/Managers/${MANAGER_ID}  FirmwareVersion
143    Should Be Equal As Strings   ${image_version}   ${firmware_version}
144    ...  msg=${image_version} does not match redfish version ${firmware_version}
145