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
16*** Test Cases ***
17
18Verify GetDateTime
19    [Documentation]  Verify host date & time.
20    [Tags]  Verify_GetDateTime
21
22    # Example output:
23    # {
24    #     "Response": "2020-11-07 07:10:10"
25    # }
26
27    ${pldm_output}=  Pldmtool  bios GetDateTime
28    @{date_time}=  Split String  ${pldm_output['Response']}  ${SPACE}
29    @{time}=  Split String  ${date_time}[1]  :
30
31    # verify date & time.
32    ${utc}=  Get Current Date  UTC  exclude_millis=True
33    @{current_dmy}=  Split String  ${utc}  ${SPACE}
34    @{current_time}=  Split String  ${current_dmy[1]}  :
35
36    # Example output:
37    # 2020-11-25 07:34:30
38
39    Should Contain  ${current_dmy[0]}  ${date_time[0]}
40
41
42Verify SetDateTime
43    [Documentation]  Verify set date & time for the host.
44    [Tags]  Verify_SetDateTime
45
46    # Example output:
47    # {
48    #     "Response": "SUCCESS"
49    # }
50
51    ${current_date_time}=  Get Current Date  UTC  exclude_millis=True
52    # Example output:
53    # 2020-11-25 07:34:30
54
55    ${date}=  Add Time To Date  ${current_date_time}  400 days  exclude_millis=True
56    ${upgrade_date}=  Evaluate  re.sub(r'-* *:*', "", '${date}')  modules=re
57
58    ${time}=  Add Time To Date  ${current_date_time}  01:01:00  exclude_millis=True
59    ${upgrade_time}=  Evaluate  re.sub(r'-* *:*', "", '${time}')  modules=re
60
61    # Set date.
62    ${cmd_set_date}=  Evaluate  $CMD_SETDATETIME % '${upgrade_date}'
63    ${pldm_output}=  Pldmtool  ${cmd_set_date}
64    Valid Value  pldm_output['Response']  ['SUCCESS']
65
66    # Set time.
67    ${cmd_set_time}=  Evaluate  $CMD_SETDATETIME % '${upgrade_time}'
68    ${pldm_output}=  Pldmtool  ${cmd_set_time}
69
70
71Verify GetBIOSTable For AttributeValueTable
72    [Documentation]  Verify if attribute value table content exist for
73    ...              GetBIOSTable with table type attribute value table.
74    [Tags]  Verify_GetBIOSTable_For_AttributeValueTable
75
76    # Example pldm_output:
77    # [pldm_attributevaluetable]:                     True
78    # [attributehandle]:                              0
79    # [     attributetype]:                           BIOSStringReadOnly
80    # [     currentstringlength]:                     15
81
82    ${count}=  Get Length  ${attr_table_data}
83    ${attr_val_list}=  Create List
84    FOR  ${i}  IN RANGE  ${count}
85        Append To List  ${attr_val_list}  ${attr_table_data}[${i}][AttributeType]
86    END
87    Valid List  attr_val_list  required_values=${RESPONSE_LIST_GETBIOSTABLE_ATTRVALTABLE}
88
89
90Verify GetBIOSAttributeCurrentValueByHandle
91    [Documentation]  Verify GetBIOSAttributeCurrentValueByHandle with the
92    ...              various BIOS attribute handle and its values.
93    [Tags]  Verify_GetBIOSAttributeCurrentValueByHandle
94
95    # Example output:
96    #
97    # pldmtool bios GetBIOSAttributeCurrentValueByHandle -a pvm_fw_boot_side
98    # {
99    #     "CurrentValue": "Temp"
100    # }
101
102    ${attr_val_data}=  GetBIOSEnumAttributeOptionalValues  ${attr_table_data}
103    @{attr_handles}=  Get Dictionary Keys  ${attr_val_data}
104    FOR  ${i}  IN  @{attr_handles}
105        ${cur_attr}=  Pldmtool  bios GetBIOSAttributeCurrentValueByHandle -a ${i}
106        @{attr_val_list}=  Set Variable  ${attr_val_data}[${i}]
107        Run Keyword If  '${cur_attr['CurrentValue']}' not in @{attr_val_list}
108        ...  Fail  Invalid GetBIOSAttributeCurrentValueByHandle value found.
109    END
110
111
112*** Keywords ***
113
114PLDM BIOS Suite Setup
115    [Documentation]  Perform PLDM BIOS suite setup.
116
117    ${pldm_output}=  Pldmtool  bios GetBIOSTable --type AttributeTable
118    Set Global Variable  ${attr_table_data}  ${pldm_output}
119
120    Set Time To Manual Mode
121
122    Sleep  10s
123
124
125PLDM BIOS Suite Cleanup
126    [Documentation]  Perform PLDM BIOS suite cleanup.
127
128    ${result}=  Get Current Date  UTC  exclude_millis=True
129    ${current_date_time}=  Evaluate  re.sub(r'-* *:*', "", '${result}')  modules=re
130    ${cmd_set_date_time}=  Evaluate  $CMD_SETDATETIME % '${current_date_time}'
131    ${pldm_output}=  Pldmtool  ${cmd_set_date_time}
132    Valid Value  pldm_output['Response']  ['SUCCESS']
133
134
135Set Time To Manual Mode
136    [Documentation]  Set date time to manual mode via Redfish.
137
138    Redfish.Login
139    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}  body={'NTP':{'ProtocolEnabled': ${False}}}
140    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
141