xref: /openbmc/openbmc-test-automation/pldm/test_pldm_bios.robot (revision 62b0c90e54c41276e2d41aff217f93c91d9df4a7)
1*** Settings ***
2
3Documentation    Module to test PLDM BIOS commands.
4
5Library          Collections
6Library          String
7Library          ../lib/pldm_utils.py
8Variables        ../data/pldm_variables.py
9Resource         ../lib/openbmc_ffdc.robot
10
11Test Setup       Printn
12Test Teardown    FFDC On Test Case Fail
13Suite Setup      PLDM BIOS Suite Setup
14Suite Teardown   Run Keyword And Ignore Error  PLDM BIOS Suite Cleanup
15
16Test Tags       Pldm_Bios
17
18*** Test Cases ***
19
20Verify GetDateTime
21    [Documentation]  Verify host date & time.
22    [Tags]  Verify_GetDateTime
23
24    # Example output:
25    # {
26    #     "Response": "2020-11-07 07:10:10"
27    # }
28
29    ${pldm_output}=  Pldmtool  bios GetDateTime
30    @{date_time}=  Split String  ${pldm_output['Response']}  ${SPACE}
31    @{time}=  Split String  ${date_time}[1]  :
32
33    ${bmc_date}=  Get Current Date from BMC
34    # Date format example: 2022-10-12 16:31:17
35    Log To Console  BMC Date: ${bmc_date}
36    # Example : ['2022-10-12', '16:31:17']
37    @{current_time}=  Split String  ${bmc_date}  ${EMPTY}
38
39    # verify date matching pldmtool vs BMC current time.
40    Should Contain  ${current_time}  ${date_time[0]}
41
42
43Verify SetDateTime
44    [Documentation]  Verify set date & time for the host.
45    [Tags]  Verify_SetDateTime
46
47    # Example output:
48    # {
49    #     "Response": "SUCCESS"
50    # }
51
52    ${current_date_time}=  Get Current Date  UTC  exclude_millis=True
53    # Example output:
54    # 2020-11-25 07:34:30
55
56    ${date}=  Add Time To Date  ${current_date_time}  400 days  exclude_millis=True
57    ${upgrade_date}=  Evaluate  re.sub(r'-* *:*', "", '${date}')  modules=re
58
59    ${time}=  Add Time To Date  ${current_date_time}  01:01:00  exclude_millis=True
60    ${upgrade_time}=  Evaluate  re.sub(r'-* *:*', "", '${time}')  modules=re
61
62    # Set date.
63    ${cmd_set_date}=  Evaluate  $CMD_SETDATETIME % '${upgrade_date}'
64    ${pldm_output}=  Pldmtool  ${cmd_set_date}
65    Valid Value  pldm_output['Response']  ['SUCCESS']
66
67    # Set time.
68    ${cmd_set_time}=  Evaluate  $CMD_SETDATETIME % '${upgrade_time}'
69    ${pldm_output}=  Pldmtool  ${cmd_set_time}
70
71
72Verify GetBIOSTable For AttributeValueTable
73    [Documentation]  Verify if attribute value table content exist for
74    ...              GetBIOSTable with table type attribute value table.
75    [Tags]  Verify_GetBIOSTable_For_AttributeValueTable
76
77    # Example pldm_output:
78    # [pldm_attributevaluetable]:                     True
79    # [attributehandle]:                              0
80    # [     attributetype]:                           BIOSStringReadOnly
81    # [     currentstringlength]:                     15
82
83    ${count}=  Get Length  ${attr_table_data}
84    ${attr_val_list}=  Create List
85    FOR  ${i}  IN RANGE  ${count}
86        Append To List  ${attr_val_list}  ${attr_table_data}[${i}][AttributeType]
87    END
88    Valid List  attr_val_list  required_values=${RESPONSE_LIST_GETBIOSTABLE_ATTRVALTABLE}
89
90
91Verify GetBIOSAttributeCurrentValueByHandle
92    [Documentation]  Verify GetBIOSAttributeCurrentValueByHandle with the
93    ...              various BIOS attribute handle and its values.
94    [Tags]  Verify_GetBIOSAttributeCurrentValueByHandle
95
96    # Example output:
97    #
98    # pldmtool bios GetBIOSAttributeCurrentValueByHandle -a pvm_fw_boot_side
99    # {
100    #     "CurrentValue": "Temp"
101    # }
102
103    ${attr_val_data}=  GetBIOSEnumAttributeOptionalValues  ${attr_table_data}
104    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
105    FOR  ${i}  IN  @{attr_handles}
106        ${cur_attr}=  Pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${i}
107        @{attr_val_list}=  Set Variable  ${attr_val_data}[${i}]
108        IF  '${cur_attr['CurrentValue']}' not in @{attr_val_list}
109            Fail  Invalid GetBIOSAttributeCurrentValueByHandle value found.
110        END
111    END
112
113
114*** Keywords ***
115
116PLDM BIOS Suite Setup
117    [Documentation]  Perform PLDM BIOS suite setup.
118
119    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
120    Set Global Variable  ${attr_table_data}  ${pldm_output}
121
122    Set Time To Manual Mode
123
124    Sleep  10s
125
126
127PLDM BIOS Suite Cleanup
128    [Documentation]  Perform PLDM BIOS suite cleanup.
129
130    ${result}=  Get Current Date  UTC  exclude_millis=True
131    ${current_date_time}=  Evaluate  re.sub(r'-* *:*', "", '${result}')  modules=re
132    ${cmd_set_date_time}=  Evaluate  $CMD_SETDATETIME % '${current_date_time}'
133    ${pldm_output}=  Pldmtool  ${cmd_set_date_time}
134    Valid Value  pldm_output['Response']  ['SUCCESS']
135
136
137Set Time To Manual Mode
138    [Documentation]  Set date time to manual mode via Redfish.
139
140    Redfish.Login
141    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}  body={'NTP':{'ProtocolEnabled': ${False}}}
142    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
143
144
145Get Current Date from BMC
146    [Documentation]  Runs the date command from BMC and returns current date and time.
147
148    # Get Current Date from BMC.
149    ${date}  ${stderr}  ${rc}=  BMC Execute Command   date
150
151    # Split the string and remove first and 2nd last value from the list and
152    # join to form %d %b %H:%M:%S %Y date format
153    ${date}=  Split String  ${date}
154    Remove From List  ${date}  0
155    Remove From List  ${date}  -2
156    ${date}=  Evaluate  " ".join(${date})
157
158    # Convert the date format to %Y/%m/%d %H:%M:%S
159    ${date}=  Convert Date  ${date}  date_format=%b %d %H:%M:%S %Y
160    ...  result_format=%Y-%m-%d %H:%M:%S  exclude_millis=True
161
162    RETURN   ${date}
163