xref: /openbmc/openbmc-test-automation/redfish/update_service/test_redfish_bmc_code_update.robot (revision d5a41a1ab15032ea8def81cd7bc813246b921257)
1*** Settings ***
2Documentation            Update firmware on a target BMC via Redifsh.
3
4# Test Parameters:
5# IMAGE_FILE_PATH        The path to the BMC image file.
6#
7# Firmware update states:
8#     Enabled            Image is installed and either functional or active.
9#     Disabled           Image installation failed or ready for activation.
10#     Updating           Image installation currently in progress.
11
12Resource                 ../../lib/resource.robot
13Resource                 ../../lib/bmc_redfish_resource.robot
14Resource                 ../../lib/openbmc_ffdc.robot
15Resource                 ../../lib/common_utils.robot
16Resource                 ../../lib/code_update_utils.robot
17Resource                 ../../lib/dump_utils.robot
18Resource                 ../../lib/logging_utils.robot
19Resource                 ../../lib/redfish_code_update_utils.robot
20Resource                 ../../lib/utils.robot
21Resource                 ../../lib/bmc_redfish_utils.robot
22Library                  ../../lib/gen_robot_valid.py
23Library                  ../../lib/tftp_update_utils.py
24Library                  ../../lib/gen_robot_keyword.py
25
26Suite Setup              Suite Setup Execution
27Suite Teardown           Redfish.Logout
28Test Setup               Printn
29Test Teardown            FFDC On Test Case Fail
30
31Force Tags               BMC_Code_Update
32
33*** Variables ***
34
35@{ADMIN}          admin_user  TestPwd123
36&{USERS}          Administrator=${ADMIN}
37${LOOP_COUNT}     ${2}
38
39*** Test Cases ***
40
41Redfish Code Update With ApplyTime OnReset
42    [Documentation]  Update the firmware image with ApplyTime of OnReset.
43    [Tags]  Redfish_Code_Update_With_ApplyTime_OnReset
44    [Template]  Redfish Update Firmware
45
46    # policy
47    OnReset
48
49
50Redfish Code Update With ApplyTime Immediate
51    [Documentation]  Update the firmware image with ApplyTime of Immediate.
52    [Tags]  Redfish_Code_Update_With_ApplyTime_Immediate
53    [Template]  Redfish Update Firmware
54
55    # policy
56    Immediate
57
58
59Redfish Code Update Same Firmware Multiple Times
60    [Documentation]  Multiple times update the firmware image for update service.
61    [Tags]  Redfish_Code_Update_Same_Firmware_Multiple_Times
62
63    ${temp_update_loop_count}=  Evaluate  ${LOOP_COUNT} + 1
64
65    FOR  ${count}  IN RANGE  1  ${temp_update_loop_count}
66       Print Timen  **************************************
67       Print Timen  * The Current Loop Count is ${count} of ${LOOP_COUNT} *
68       Print Timen  **************************************
69
70       Redfish Update Firmware  apply_time=OnReset
71    END
72
73
74
75Redfish Code Update With Multiple Firmware
76    [Documentation]  Update the firmware image with ApplyTime of Immediate.
77    [Tags]  Redfish_Code_Update_With_Multiple_Firmware
78    [Template]  Redfish Multiple Upload Image And Check Progress State
79
80    # policy   image_file_path     alternate_image_file_path
81    Immediate  ${IMAGE_FILE_PATH}  ${ALTERNATE_IMAGE_FILE_PATH}
82
83
84Verify If The Modified Admin Credential Is Valid Post Image Switched To Backup
85    [Documentation]  Verify updated admin credential remain same post switch to back up image.
86    [Tags]  Verify_If_The_Modified_Admin_Credential_Is_Valid_Post_Image_Switched_To_Backup
87    [Setup]  Create Users With Different Roles  users=${USERS}  force=${True}
88    [Teardown]  Run Keywords  Redfish.Login  AND  Delete BMC Users Via Redfish  users=${USERS}
89
90    ${post_code_update_actions}=  Get Post Boot Action
91    ${state}=  Get Pre Reboot State
92    Expire And Update New Password Via Redfish  ${ADMIN[0]}  ${ADMIN[1]}  0penBmc123
93
94    Redfish.Login
95    # change to backup image and reset the BMC.
96    Switch Backup Firmware Image To Functional
97    Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
98
99    # verify modified admin password on backup image.
100    Redfish.Login  admin_user  0penBmc123
101    Redfish.Logout
102
103
104Verify If The Modified Admin Credential Is Valid Post Update
105    [Documentation]  Verify updated admin credential remain same post code update image.
106    [Tags]  Verify_If_The_Modified_Admin_Credential_Is_Valid_Post_Update
107    [Setup]  Create Users With Different Roles  users=${USERS}  force=${True}
108    [Teardown]  Run Keywords  Redfish.Login  AND  Delete BMC Users Via Redfish  users=${USERS}
109
110    Expire And Update New Password Via Redfish  ${ADMIN[0]}  ${ADMIN[1]}  0penBmc123
111
112    Redfish.Login
113    # Flash latest firmware using redfish.
114    Redfish Update Firmware  OnReset
115
116    # verify modified admin credentails on latest image.
117    Redfish.Login  admin_user  0penBmc123
118    Redfish.Logout
119
120*** Keywords ***
121
122Suite Setup Execution
123    [Documentation]  Do the suite setup.
124
125    Valid File Path  IMAGE_FILE_PATH
126    Redfish.Login
127    Redfish Delete All BMC Dumps
128    Redfish Purge Event Log
129
130
131Redfish Update Firmware
132    [Documentation]  Update the BMC firmware via redfish interface.
133    [Arguments]  ${apply_time}
134
135    # Description of argument(s):
136    # policy     ApplyTime allowed values (e.g. "OnReset", "Immediate").
137
138    ${post_code_update_actions}=  Get Post Boot Action
139    ${state}=  Get Pre Reboot State
140    Rprint Vars  state
141    Set ApplyTime  policy=${apply_Time}
142
143    ${task_inv_dict}=  Get Task State from File
144
145    ${file_bin_data}=  OperatingSystem.Get Binary File  ${image_file_path}
146
147    Log To Console   Start uploading image to BMC.
148    Upload Image To BMC  ${REDFISH_BASE_URI}UpdateService  timeout=${600}  data=${file_bin_data}
149    Log To Console   Completed image upload to BMC.
150
151    ${task_inv}=  Check Task With Match TargetUri  /redfish/v1/UpdateService
152
153    Rprint Vars  task_inv
154
155    Wait Until Keyword Succeeds  5 min  10 sec
156    ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskCompleted']}
157
158    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
159    Redfish.Login
160    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
161    Verify Get ApplyTime  ${apply_time}
162
163
164Redfish Multiple Upload Image And Check Progress State
165    [Documentation]  Update multiple BMC firmware via redfish interface and check status.
166    [Arguments]  ${apply_time}  ${IMAGE_FILE_PATH}  ${ALTERNATE_IMAGE_FILE_PATH}
167
168    # Description of argument(s):
169    # apply_time                 ApplyTime allowed values (e.g. "OnReset", "Immediate").
170    # IMAGE_FILE_PATH            The path to BMC image file.
171    # ALTERNATE_IMAGE_FILE_PATH  The path to alternate BMC image file.
172
173    ${post_code_update_actions}=  Get Post Boot Action
174    Valid File Path  ALTERNATE_IMAGE_FILE_PATH
175    ${state}=  Get Pre Reboot State
176    Rprint Vars  state
177
178    Set ApplyTime  policy=${apply_time}
179    Redfish Upload Image  ${REDFISH_BASE_URI}UpdateService  ${IMAGE_FILE_PATH}
180
181    ${first_image_id}=  Get Latest Image ID
182    Rprint Vars  first_image_id
183    Sleep  5s
184    Redfish Upload Image  ${REDFISH_BASE_URI}UpdateService  ${ALTERNATE_IMAGE_FILE_PATH}
185
186    ${second_image_id}=  Get Latest Image ID
187    Rprint Vars  second_image_id
188
189    Check Image Update Progress State
190    ...  match_state='Updating', 'Disabled'  image_id=${second_image_id}
191
192    Check Image Update Progress State
193    ...  match_state='Updating'  image_id=${first_image_id}
194
195    Wait Until Keyword Succeeds  8 min  20 sec
196    ...  Check Image Update Progress State
197    ...    match_state='Enabled'  image_id=${first_image_id}
198    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
199    Redfish.Login
200    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
201