1*** Settings ***
2Documentation    Test Redfish to verify responses for SessionService and Hypermedia.
3
4Resource         ../../lib/resource.robot
5Resource         ../../lib/bmc_redfish_resource.robot
6Resource         ../../lib/openbmc_ffdc.robot
7
8
9Test Teardown    FFDC On Test Case Fail
10Test Setup       Printn
11
12*** Test Cases ***
13
14Redfish Login And Logout
15    [Documentation]  Login to BMCweb and then logout.
16    [Tags]  Redfish_Login_And_Logout
17
18    Redfish.Login
19    Redfish.Logout
20
21
22GET Redfish Hypermedia Without Login
23    [Documentation]  GET hypermedia URL without login.
24    [Tags]  GET_Redfish_Hypermedia_Without_Login
25    [Setup]  Redfish.Logout
26    [Template]  GET And Verify Redfish Response
27
28    # Expect status      Resource URL Path
29    ${HTTP_OK}           /
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
53    ${HTTP_OK}           /redfish/v1/Chassis/${CHASSIS_ID}
54    ${HTTP_OK}           /redfish/v1/Managers/bmc
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 Request
69    ...  openbmc  /redfish/v1/SessionService/Sessions  headers=${headers}
70
71    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_UNAUTHORIZED}
72
73
74Verify Redfish Invalid URL Response Code
75    [Documentation]  Login to BMCweb and verify error response code.
76    [Tags]  Verify_Redfish_Invalid_URL_Response_Code
77
78    Redfish.Login
79    Redfish.Get  /redfish/v1/idontexist  valid_status_codes=[${HTTP_NOT_FOUND}]
80    Redfish.Logout
81
82
83Delete Redfish Session Using Valid login
84    [Documentation]  Delete a session using valid login.
85    [Tags]  Delete_Redfish_Session_Using_Valid_Login
86
87    Redfish.Login
88    ${session_info}=  Get Redfish Session Info
89
90    Redfish.Login
91
92    # Example o/p:
93    # [{'@odata.id': '/redfish/v1/SessionService/Sessions/bOol3WlCI8'},
94    #  {'@odata.id': '/redfish/v1/SessionService/Sessions/Yu3xFqjZr1'}]
95    ${resp_list}=  Redfish_Utils.List Request
96    ...  /redfish/v1/SessionService/Sessions
97
98    Redfish.Delete  ${session_info["location"]}
99
100    ${resp}=  Redfish_Utils.List Request  /redfish/v1/SessionService/Sessions
101    List Should Not Contain Value  ${resp}  ${session_info["location"]}
102
103
104Redfish Login Via SessionService
105    [Documentation]  Login to BMC via redfish session service.
106    [Tags]   Redfish_Login_Via_SessionService
107
108    Create Session  openbmc  https://${OPENBMC_HOST}
109    ${headers}=  Create Dictionary  Content-Type=application/json
110    ${data}=  Create Dictionary  UserName=${OPENBMC_USERNAME}  Password=${OPENBMC_PASSWORD}
111
112    ${resp}=  Post Request  openbmc  /redfish/v1/SessionService/Sessions  data=${data}  headers=${headers}
113    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_CREATED}
114
115    ${content}=  To JSON  ${resp.content}
116    ${headers}=  Create Dictionary   Content-Type=application/json
117    ...  X-Auth-Token=${resp.headers["X-Auth-Token"]}
118    ${resp}=  Delete Request  openbmc  ${REDFISH_SESSION}${/}${content["Id"]}  headers=${headers}
119    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
120
121
122Verify Redfish Unresponsive URL paths
123    [Documentation]  Verify that all URLs in /redfish/v1 respond.
124    [Tags]   Verify_Redfish_Unresponsive_URL_paths
125
126    Redfish.Login
127    ${resource_list}  ${dead_resources}=  Enumerate Request  /redfish/v1  include_dead_resources=True
128    Redfish.Logout
129    Valid Length  dead_resources  max_length=0
130
131
132*** Keywords ***
133
134GET And Verify Redfish Response
135    [Documentation]  GET given resource and verfiy response.
136    [Arguments]  ${valid_status_codes}  ${resource_path}
137
138    # Description of argument(s):
139    # valid_status_codes            A comma-separated list of acceptable
140    #                               status codes (e.g. 200).
141    # resource_path                 Redfish resource URL path.
142
143    ${resp}=  Redfish.Get  ${resource_path}
144    ...  valid_status_codes=[${valid_status_codes}]
145