1c08932eeSSushil Singh*** Settings ***
2c08932eeSSushil SinghDocumentation            Redfish BMC/Host signed and unsigned code update
3c08932eeSSushil Singh...  over BMC functional signed image.
4c08932eeSSushil Singh
5c08932eeSSushil Singh# Test Parameters:
6c08932eeSSushil Singh# IMAGE_FILE_PATH        The path to the BMC/Host image file.
7c08932eeSSushil Singh#
8c08932eeSSushil Singh# Firmware update states:
9c08932eeSSushil Singh#     Enabled            Image is installed and either functional or active.
10c08932eeSSushil Singh#     Disabled           Image installation failed or ready for activation.
11c08932eeSSushil Singh#     Updating           Image installation currently in progress.
12c08932eeSSushil Singh
13c08932eeSSushil SinghResource                 ../../lib/resource.robot
14c08932eeSSushil SinghResource                 ../../lib/bmc_redfish_resource.robot
15c08932eeSSushil SinghResource                 ../../lib/openbmc_ffdc.robot
16c08932eeSSushil SinghResource                 ../../lib/common_utils.robot
17c08932eeSSushil SinghResource                 ../../lib/code_update_utils.robot
18c08932eeSSushil SinghResource                 ../../lib/redfish_code_update_utils.robot
19c08932eeSSushil SinghLibrary                  ../../lib/gen_robot_valid.py
20c08932eeSSushil SinghLibrary                  ../../lib/var_funcs.py
21d7fb62faSSushil SinghLibrary                  ../../lib/gen_robot_keyword.py
22c08932eeSSushil Singh
23c08932eeSSushil SinghSuite Setup              Suite Setup Execution
24c08932eeSSushil SinghSuite Teardown           Redfish.Logout
25c08932eeSSushil SinghTest Setup               Printn
26c08932eeSSushil SinghTest Teardown            FFDC On Test Case Fail
27c08932eeSSushil Singh
28*6fb70d98SMatt FischerTest Tags               Redfish_Signed_Image_Update
29d7fb62faSSushil Singh
30d7fb62faSSushil Singh*** Variables ***
31d7fb62faSSushil Singh
32d7fb62faSSushil Singh${ACTIVATION_WAIT_TIMEOUT}     8 min
33d7fb62faSSushil Singh
34c08932eeSSushil Singh*** Test Cases ***
35c08932eeSSushil Singh
36c08932eeSSushil SinghRedfish Signed Code Update
37c08932eeSSushil Singh    [Documentation]  BMC/Host signed code update over functional signed
38c08932eeSSushil Singh    ...  image, when FieldMode is set to true value.
39c08932eeSSushil Singh    [Tags]  Redfish_Signed_Code_Update
40c08932eeSSushil Singh    [Template]  Redfish Signed Firmware Update
41c08932eeSSushil Singh
42c08932eeSSushil Singh    # image_file_path
43c08932eeSSushil Singh    ${IMAGE_FILE_PATH}
44c08932eeSSushil Singh
45c08932eeSSushil Singh
46c08932eeSSushil SinghRedfish Fail Unsigned Code Update
47c08932eeSSushil Singh    [Documentation]  BMC/Host unsigned code update over functional signed
48c08932eeSSushil Singh    ...  image, when Field Mode is set to true to value.
49c08932eeSSushil Singh    [Tags]  Redfish_Fail_Unsigned_Code_Update
50c08932eeSSushil Singh    [Template]  Redfish Unsigned Firmware Update
51c08932eeSSushil Singh
52c08932eeSSushil Singh    # image_file_path
53c08932eeSSushil Singh    ${IMAGE_FILE_PATH}
54c08932eeSSushil Singh
55c08932eeSSushil Singh
562a520ee3SSushil SinghREST Failure When Field Mode Set To Disable
572a520ee3SSushil Singh    [Documentation]  Verify error while disabling field mode from enabled mode.
582a520ee3SSushil Singh    [Tags]  REST_Failure_When_Field_Mode_Set_To_Disable
592a520ee3SSushil Singh
602a520ee3SSushil Singh    ${args}=  Create Dictionary  data=${0}
612a520ee3SSushil Singh    ${resp}=  OpenBMC Post Request  ${SOFTWARE_VERSION_URI}attr/FieldModeEnabled  data=${args}
622a520ee3SSushil Singh    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_METHOD_NOT_ALLOWED}
632a520ee3SSushil Singh
642a520ee3SSushil Singh
65c08932eeSSushil Singh*** Keywords ***
66c08932eeSSushil Singh
67c08932eeSSushil SinghSuite Setup Execution
68c08932eeSSushil Singh    [Documentation]  Do the suite setup.
69c08932eeSSushil Singh
70c08932eeSSushil Singh    Valid File Path  IMAGE_FILE_PATH
712334948aSSushil Singh    Enable Field Mode And Verify Unmount
72c08932eeSSushil Singh    Redfish.Login
734aff2d02STim Lee    Redfish Delete All BMC Dumps
74c08932eeSSushil Singh    Redfish Purge Event Log
75c08932eeSSushil Singh
76c08932eeSSushil Singh
77c08932eeSSushil SinghRedfish Signed Firmware Update
78c08932eeSSushil Singh    [Documentation]  Update the BMC/Host firmware via redfish interface.
79c08932eeSSushil Singh    [Arguments]  ${image_file_path}
80c08932eeSSushil Singh
81c08932eeSSushil Singh    # Description of argument(s):
82c08932eeSSushil Singh    # IMAGE_FILE_PATH  The path to the image file.
83c08932eeSSushil Singh
84c08932eeSSushil Singh    Field Mode Should Be Enabled
85c08932eeSSushil Singh    ${image_version}=  Get Version Tar  ${image_file_path}
86d7fb62faSSushil Singh
87d7fb62faSSushil Singh    ${post_code_update_actions}=  Get Post Boot Action
88c08932eeSSushil Singh    ${state}=  Get Pre Reboot State
89c08932eeSSushil Singh    Rprint Vars  state
90d7fb62faSSushil Singh
91d7fb62faSSushil Singh    Run Keyword And Ignore Error  Set ApplyTime  policy=OnReset
92d7fb62faSSushil Singh
93d7fb62faSSushil Singh    # Python module:  get_member_list(resource_path)
94d7fb62faSSushil Singh    ${before_inv_list}=  redfish_utils.Get Member List  /redfish/v1/UpdateService/FirmwareInventory
95d7fb62faSSushil Singh    Log To Console   Current images on the BMC before upload: ${before_inv_list}
96d7fb62faSSushil Singh
975eb37da8SSushil Singh    # URI : /redfish/v1/UpdateService
985eb37da8SSushil Singh    # "HttpPushUri": "/redfish/v1/UpdateService/update",
995eb37da8SSushil Singh
1005eb37da8SSushil Singh    ${redfish_update_uri}=  Get Redfish Update Service URI
1015eb37da8SSushil Singh    Redfish Upload Image  ${redfish_update_uri}  ${IMAGE_FILE_PATH}
102d7fb62faSSushil Singh
103d7fb62faSSushil Singh    # Python module:  get_member_list(resource_path)
104d7fb62faSSushil Singh    ${after_inv_list}=  redfish_utils.Get Member List  /redfish/v1/UpdateService/FirmwareInventory
105d7fb62faSSushil Singh    Log To Console  Current images on the BMC after upload: ${after_inv_list}
106d7fb62faSSushil Singh
107d7fb62faSSushil Singh    ${image_id}=  Evaluate  set(${after_inv_list}) - set(${before_inv_list})
108d7fb62faSSushil Singh    Should Not Be Empty    ${image_id}
109d7fb62faSSushil Singh    ${image_id}=  Evaluate  list(${image_id})[0].split('/')[-1]
110d7fb62faSSushil Singh    Log To Console  Firmware installation in progress with image id:: ${image_id}
111d7fb62faSSushil Singh
112d7fb62faSSushil Singh    Wait Until Keyword Succeeds  ${ACTIVATION_WAIT_TIMEOUT}  10 sec
113d7fb62faSSushil Singh    ...  Check Image Update Progress State  match_state='Enabled'  image_id=${image_id}
114d7fb62faSSushil Singh
115d7fb62faSSushil Singh    # Python module:  get_version_tar(tar_file_path)
116d7fb62faSSushil Singh    ${tar_version}=  code_update_utils.Get Version Tar  ${IMAGE_FILE_PATH}
117d7fb62faSSushil Singh    ${image_info}=  Get Software Inventory State By Version  ${tar_version}
118d7fb62faSSushil Singh
119d7fb62faSSushil Singh    Run Key  ${post_code_update_actions['${image_info["image_type"]}']['OnReset']}
120d7fb62faSSushil Singh    Redfish.Login
121d7fb62faSSushil Singh    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
122c08932eeSSushil Singh
123c08932eeSSushil Singh
124c08932eeSSushil SinghRedfish Unsigned Firmware Update
125c08932eeSSushil Singh    [Documentation]  Update the BMC/Host firmware via redfish interface.
126c08932eeSSushil Singh    [Arguments]  ${image_file_path}
127c08932eeSSushil Singh
128c08932eeSSushil Singh    # Description of argument(s):
129c08932eeSSushil Singh    # IMAGE_FILE_PATH  The path to the image file.
130c08932eeSSushil Singh
131c08932eeSSushil Singh    Field Mode Should Be Enabled
132c08932eeSSushil Singh    Set ApplyTime  policy=Immediate
1335eb37da8SSushil Singh
1345eb37da8SSushil Singh    # URI : /redfish/v1/UpdateService
1355eb37da8SSushil Singh    # "HttpPushUri": "/redfish/v1/UpdateService/update",
1365eb37da8SSushil Singh
1375eb37da8SSushil Singh    ${redfish_update_uri}=  Get Redfish Update Service URI
1385eb37da8SSushil Singh    Redfish Upload Image  ${redfish_update_uri}  ${image_file_path}
139c08932eeSSushil Singh    ${image_id}=  Get Latest Image ID
140c08932eeSSushil Singh    Rprint Vars  image_id
141c08932eeSSushil Singh    Sleep  5s
142c08932eeSSushil Singh    Wait Until Keyword Succeeds  8 min  20 sec
143c08932eeSSushil Singh    ...  Check Image Update Progress State
144c08932eeSSushil Singh    ...    match_state='Disabled', 'Updating', 'Disabled'  image_id=${image_id}
145c08932eeSSushil Singh    Delete Software Object
146c08932eeSSushil Singh    ...  /xyz/openbmc_project/software/${image_id}
147c08932eeSSushil Singh
148