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