1*** Settings ***
2Documentation    Test Redfish to verify responses for SessionService and Hypermedia.
3
4Resource         ../../lib/bmc_redfish_resource.robot
5Resource         ../../lib/openbmc_ffdc.robot
6
7
8Test Teardown    FFDC On Test Case Fail
9Test Setup       Printn
10
11*** Test Cases ***
12
13Redfish Login And Logout
14    [Documentation]  Login to BMCweb and then logout.
15    [Tags]  Redfish_Login_And_Logout
16
17    Redfish.Login
18    Redfish.Logout
19
20
21GET Redfish Hypermedia Without Login
22    [Documentation]  GET hypermedia URL without login.
23    [Tags]  GET_Redfish_Hypermedia_Without_Login
24    [Setup]  Redfish.Logout
25    [Template]  GET And Verify Redfish Response
26
27    # Expect status      Resource URL Path
28    ${HTTP_OK}           /redfish
29    ${HTTP_OK}           /redfish/v1
30
31
32GET Redfish SessionService Without Login
33    [Documentation]  Get /redfish/v1/SessionService without login
34    [Tags]  GET_Redfish_SessionService_Without_Login
35    [Setup]  Redfish.Logout
36
37    ${resp}=  Redfish.Get  /redfish/v1/SessionService
38    ...  valid_status_codes=[${HTTP_UNAUTHORIZED}]
39
40
41GET Redfish Resources With Login
42    [Documentation]  Login to BMCweb and GET valid resource.
43    [Tags]  GET_Redfish_Resources_With_Login
44    [Setup]  Redfish.Login
45    [Template]  GET And Verify Redfish Response
46
47    # Expect status      Resource URL Path
48    ${HTTP_OK}           /redfish/v1/SessionService
49    ${HTTP_OK}           /redfish/v1/AccountService
50    ${HTTP_OK}           /redfish/v1/Systems/system
51    ${HTTP_OK}           /redfish/v1/Chassis/${CHASSIS_ID}
52    ${HTTP_OK}           /redfish/v1/Managers/${MANAGER_ID}
53    ${HTTP_OK}           /redfish/v1/UpdateService
54
55
56Redfish Login Using Invalid Token
57    [Documentation]  Login to BMCweb with invalid token.
58    [Tags]  Redfish_Login_Using_Invalid_Token
59
60    Create Session  openbmc  ${AUTH_URI}
61
62    # Example: "X-Auth-Token: 3la1JUf1vY4yN2dNOwun"
63    ${headers}=  Create Dictionary  Content-Type=application/json
64    ...  X-Auth-Token=deadbeef
65
66    ${resp}=  GET On Session
67    ...  openbmc  /redfish/v1/SessionService/Sessions  headers=${headers}
68    ...  expected_status=${HTTP_UNAUTHORIZED}
69
70    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_UNAUTHORIZED}
71
72
73Verify Redfish Invalid URL Response Code
74    [Documentation]  Login to BMCweb and verify error response code.
75    [Tags]  Verify_Redfish_Invalid_URL_Response_Code
76
77    Redfish.Login
78    Redfish.Get  /redfish/v1/idontexist  valid_status_codes=[${HTTP_NOT_FOUND}]
79    Redfish.Logout
80
81
82Delete Redfish Session Using Valid Login
83    [Documentation]  Delete a session using valid login.
84    [Tags]  Delete_Redfish_Session_Using_Valid_Login
85
86    Redfish.Login
87    ${session_info}=  Get Redfish Session Info
88
89    Redfish.Login
90
91    # Example o/p:
92    # [{'@odata.id': '/redfish/v1/SessionService/Sessions/bOol3WlCI8'},
93    #  {'@odata.id': '/redfish/v1/SessionService/Sessions/Yu3xFqjZr1'}]
94    ${resp_list}=  Redfish_Utils.List Request
95    ...  /redfish/v1/SessionService/Sessions
96
97    Redfish.Delete  ${session_info["location"]}
98
99    ${resp}=  Redfish_Utils.List Request  /redfish/v1/SessionService/Sessions
100    List Should Not Contain Value  ${resp}  ${session_info["location"]}
101
102
103Redfish Login Via SessionService
104    [Documentation]  Login to BMC via redfish session service.
105    [Tags]   Redfish_Login_Via_SessionService
106
107    Create Session  openbmc  https://${OPENBMC_HOST}
108    ${headers}=  Create Dictionary  Content-Type=application/json
109    ${data}=  Set Variable  {"UserName":"${OPENBMC_USERNAME}", "Password":"${OPENBMC_PASSWORD}"}
110
111    ${resp}=  POST On Session  openbmc  /redfish/v1/SessionService/Sessions  data=${data}  headers=${headers}
112    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_CREATED}
113
114    ${headers}=  Create Dictionary   Content-Type=application/json
115    ...  X-Auth-Token=${resp.headers["X-Auth-Token"]}
116    ${resp}=  DELETE On Session  openbmc  ${REDFISH_SESSION}${/}${resp.json()["Id"]}  headers=${headers}
117    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
118
119
120Verify Redfish Unresponsive URL paths
121    [Documentation]  Verify that all URLs in /redfish/v1 respond.
122    [Tags]   Verify_Redfish_Unresponsive_URL_paths
123
124    Redfish.Login
125    ${resource_list}  ${dead_resources}=  Enumerate Request  /redfish/v1  include_dead_resources=True
126    Redfish.Logout
127    Valid Length  dead_resources  max_length=0
128
129
130*** Keywords ***
131
132GET And Verify Redfish Response
133    [Documentation]  GET given resource and verify response.
134    [Arguments]  ${valid_status_codes}  ${resource_path}
135
136    # Description of argument(s):
137    # valid_status_codes            A comma-separated list of acceptable
138    #                               status codes (e.g. 200).
139    # resource_path                 Redfish resource URL path.
140
141    ${resp}=  Redfish.Get  ${resource_path}
142    ...  valid_status_codes=[${valid_status_codes}]
143