145d841e3SSushil Singh*** Settings ***
245d841e3SSushil Singh
345d841e3SSushil SinghDocumentation     Test client identifier feature on BMC.
445d841e3SSushil Singh
545d841e3SSushil SinghResource          ../../lib/rest_client.robot
645d841e3SSushil SinghResource          ../../lib/openbmc_ffdc.robot
745d841e3SSushil SinghResource          ../../lib/resource.robot
845d841e3SSushil SinghResource          ../../lib/bmc_redfish_utils.robot
945d841e3SSushil SinghLibrary           ../../lib/bmc_network_utils.py
1045d841e3SSushil SinghLibrary           ../../lib/gen_robot_valid.py
1145d841e3SSushil Singh
1245d841e3SSushil SinghSuite Setup       Redfish.Login
13889a75e4SSushil SinghSuite Teardown    Run Keyword And Ignore Error  Delete All Redfish Sessions
1445d841e3SSushil SinghTest Setup        Printn
1545d841e3SSushil SinghTest Teardown     FFDC On Test Case Fail
1645d841e3SSushil Singh
1745d841e3SSushil Singh
1845d841e3SSushil Singh*** Test Cases ***
1945d841e3SSushil Singh
2045d841e3SSushil SinghCreate A Session With ClientID And Verify
2145d841e3SSushil Singh    [Documentation]  Create a session with client id and verify client id is same.
2245d841e3SSushil Singh    [Tags]  Create_A_Session_With_ClientID_And_Verify
231384321bSSushil Singh    [Template]  Create And Verify Session ClientID
2445d841e3SSushil Singh
25889a75e4SSushil Singh    # client_id           reboot_flag
261384321bSSushil Singh    12345                 False
271384321bSSushil Singh    123456                False
281384321bSSushil Singh    EXTERNAL-CLIENT-01    False
291384321bSSushil Singh    EXTERNAL-CLIENT-02    False
301384321bSSushil Singh
311384321bSSushil Singh
321384321bSSushil SinghCheck ClientID Persistency On BMC Reboot
331384321bSSushil Singh    [Documentation]  Create a session with client id and verify client id is same after the reboot.
341384321bSSushil Singh    [Tags]  Check_ClientID_Persistency_On_BMC_Reboot
351384321bSSushil Singh    [Template]  Create And Verify Session ClientID
361384321bSSushil Singh
37889a75e4SSushil Singh    # client_id           reboot_flag
381384321bSSushil Singh    12345                 True
391384321bSSushil Singh    EXTERNAL-CLIENT-01    True
4045d841e3SSushil Singh
41889a75e4SSushil Singh
42889a75e4SSushil SinghCreate A Multiple Session With ClientID And Verify
43889a75e4SSushil Singh    [Documentation]  Create a multiple session with client id and verify client id is same.
44889a75e4SSushil Singh    [Tags]  Create_A_Multiple_Session_With_ClientID_And_Verify
45889a75e4SSushil Singh    [Template]  Create And Verify Session ClientID
46889a75e4SSushil Singh
47889a75e4SSushil Singh    # client_id                              reboot_flag
48889a75e4SSushil Singh    12345,123456                             False
49889a75e4SSushil Singh    EXTERNAL-CLIENT-01,EXTERNAL-CLIENT-02    False
50889a75e4SSushil Singh
51889a75e4SSushil Singh
52889a75e4SSushil SinghCheck Multiple ClientID Persistency On BMC Reboot
53889a75e4SSushil Singh    [Documentation]  Create a multiple session with client id and verify client id is same after the reboot.
54889a75e4SSushil Singh    [Tags]  Check_Multiple_ClientID_Persistency_On_BMC_Reboot
55889a75e4SSushil Singh    [Template]  Create And Verify Session ClientID
56889a75e4SSushil Singh
57889a75e4SSushil Singh    # client_id                              reboot_flag
58889a75e4SSushil Singh    12345,123456                             True
59889a75e4SSushil Singh    EXTERNAL-CLIENT-01,EXTERNAL-CLIENT-02    True
60889a75e4SSushil Singh
61889a75e4SSushil Singh
62c957f57fSSushil SinghFail To Set Client Origin IP
63c957f57fSSushil Singh    [Documentation]  Fail to set the client origin IP.
64c957f57fSSushil Singh    [Tags]  Fail_To_Set_Client_Origin_IP
65c957f57fSSushil Singh    [Template]  Create Session And Fail To Set Client Origin IP
66c957f57fSSushil Singh
67c957f57fSSushil Singh    # client_id
68c957f57fSSushil Singh    12345
69c957f57fSSushil Singh    EXTERNAL-CLIENT-01
70c957f57fSSushil Singh
714ec68ba8SSushil Singh
724ec68ba8SSushil SinghCreate Session For Non Admin User
734ec68ba8SSushil Singh    [Documentation]  Create Session for non-admin user.
744ec68ba8SSushil Singh    [Tags]  Create_Session_For_Non_Admin_User
754ec68ba8SSushil Singh    [Template]  Non Admin User To Create Session
764ec68ba8SSushil Singh
774ec68ba8SSushil Singh    # client_id    username         password      role_id
784ec68ba8SSushil Singh    12345          operator_user    TestPwd123    Operator
794ec68ba8SSushil Singh
804ec68ba8SSushil Singh
8145d841e3SSushil Singh*** Keywords ***
8245d841e3SSushil Singh
8345d841e3SSushil SinghCreate A Session With ClientID
8445d841e3SSushil Singh    [Documentation]  Create redifish session with client id.
8545d841e3SSushil Singh    [Arguments]  ${client_id}
8645d841e3SSushil Singh
8745d841e3SSushil Singh    # Description of argument(s):
8845d841e3SSushil Singh    # client_id    This client id can contain string value
8945d841e3SSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
9045d841e3SSushil Singh
91889a75e4SSushil Singh    @{session_list}=  Create List
92889a75e4SSushil Singh    &{tmp_dict}=  Create Dictionary
9345d841e3SSushil Singh
94889a75e4SSushil Singh    FOR  ${client}  IN  @{client_id}
95889a75e4SSushil Singh      ${resp}=  Redfish Login  kwargs= "Oem":{"OpenBMC" : {"ClientID":"${client}"}}
96889a75e4SSushil Singh      Append To List  ${session_list}  ${resp}
97889a75e4SSushil Singh    END
98889a75e4SSushil Singh
99889a75e4SSushil Singh    [Return]  ${session_list}
100889a75e4SSushil Singh
101889a75e4SSushil Singh
102889a75e4SSushil SinghGet Session Information By ClientID
103889a75e4SSushil Singh    [Documentation]  Get session information by client id.
104889a75e4SSushil Singh    [Arguments]  ${client_id}  ${session_ids}
105889a75e4SSushil Singh
106889a75e4SSushil Singh    FOR  ${session}  IN  @{session_ids}
107889a75e4SSushil Singh       Return From Keyword If  '${client_id}' == '${session["Oem"]["OpenBMC"]["ClientID"]}'  ${session["Id"]}
108889a75e4SSushil Singh    END
109889a75e4SSushil Singh
110889a75e4SSushil Singh    [Return]  ${EMPTY}
111889a75e4SSushil Singh
11245d841e3SSushil Singh
11345d841e3SSushil SinghVerify A Session Created With ClientID
11445d841e3SSushil Singh    [Documentation]  Verify session created with client id.
115889a75e4SSushil Singh    [Arguments]  ${client_ids}  ${session_ids}
11645d841e3SSushil Singh
11745d841e3SSushil Singh    # Description of argument(s):
11845d841e3SSushil Singh    # client_id    External client name.
11945d841e3SSushil Singh    # session_id   This value is a session id.
12045d841e3SSushil Singh
12145d841e3SSushil Singh    # {
12245d841e3SSushil Singh    #   "@odata.id": "/redfish/v1/SessionService/Sessions/H8q2ZKucSJ",
12345d841e3SSushil Singh    #   "@odata.type": "#Session.v1_0_2.Session",
12445d841e3SSushil Singh    #   "Description": "Manager User Session",
12545d841e3SSushil Singh    #   "Id": "H8q2ZKucSJ",
12645d841e3SSushil Singh    #   "Name": "User Session",
12745d841e3SSushil Singh    #   "Oem": {
12845d841e3SSushil Singh    #   "OpenBMC": {
12945d841e3SSushil Singh    #  "@odata.type": "#OemSession.v1_0_0.Session",
13045d841e3SSushil Singh    #  "ClientID": "",
13145d841e3SSushil Singh    #  "ClientOriginIP": "::ffff:x.x.x.x"
13245d841e3SSushil Singh    #       }
13345d841e3SSushil Singh    #     },
13445d841e3SSushil Singh    #   "UserName": "root"
13545d841e3SSushil Singh    # }
13645d841e3SSushil Singh
137889a75e4SSushil Singh    FOR  ${client}  IN  @{client_ids}
138889a75e4SSushil Singh      ${session_id}=  Get Session Information By ClientID  ${client}  ${session_ids}
139889a75e4SSushil Singh      ${sessions}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions/${session_id}
14045d841e3SSushil Singh      Rprint Vars  sessions
14124e32afaSSushil Singh      @{words} =  Split String  ${sessions["ClientOriginIPAddress"]}  :
14207297f8bSSushil Singh      ${ip_address}=  Get Running System IP
14345d841e3SSushil Singh      Set Test Variable  ${temp_ipaddr}  ${words}[-1]
144889a75e4SSushil Singh      Valid Value  client  ['${sessions["Oem"]["OpenBMC"]["ClientID"]}']
14545d841e3SSushil Singh      Valid Value  sessions["Id"]  ['${session_id}']
14607297f8bSSushil Singh      Valid Value  temp_ipaddr  ${ip_address}
147889a75e4SSushil Singh    END
1481384321bSSushil Singh
1491384321bSSushil Singh
1501384321bSSushil SinghCreate And Verify Session ClientID
1511384321bSSushil Singh    [Documentation]  Create redifish session with client id and verify it remain same.
1521384321bSSushil Singh    [Arguments]  ${client_id}  ${reboot_flag}=False
1531384321bSSushil Singh
1541384321bSSushil Singh    # Description of argument(s):
1551384321bSSushil Singh    # client_id    This client id contain string value
1561384321bSSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
1571384321bSSushil Singh    # reboot_flag  Flag is used to run reboot the BMC code.
1581384321bSSushil Singh    #               (e.g. True or False).
1591384321bSSushil Singh
160889a75e4SSushil Singh    ${client_ids}=  Split String  ${client_id}  ,
161*87e984c8SSushil Singh    ${session_info}=  Create Session With List Of ClientID  ${client_ids}
162889a75e4SSushil Singh    Verify A Session Created With ClientID  ${client_ids}  ${session_info}
1631384321bSSushil Singh    Run Keyword If  '${reboot_flag}' == 'True'
164889a75e4SSushil Singh    ...  Run Keywords  Redfish OBMC Reboot (off)  AND
165889a75e4SSushil Singh    ...  Verify A Session Created With ClientID  ${client_ids}  ${session_info}
166*87e984c8SSushil Singh    Redfish Delete List Of Session  ${session_info}
167c957f57fSSushil Singh
168c957f57fSSushil Singh
169c957f57fSSushil SinghSet Client Origin IP
170c957f57fSSushil Singh    [Documentation]  Set client origin IP.
171c957f57fSSushil Singh    [Arguments]  ${client_id}  ${client_ip}  ${status}
172c957f57fSSushil Singh
173c957f57fSSushil Singh    # Description of argument(s):
174c957f57fSSushil Singh    # client_id    This client id contain string value
175c957f57fSSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
176c957f57fSSushil Singh    # client_ip    Valid IP address
177c957f57fSSushil Singh    # status       HTTP status code
178c957f57fSSushil Singh
179c957f57fSSushil Singh    ${session}=  Run Keyword And Return Status
180c957f57fSSushil Singh    ...  Redfish Login
181c957f57fSSushil Singh    ...  kwargs= "Oem":{"OpenBMC": {"ClientID":"${client_id}", "ClientOriginIP":"${client_ip}"}}
182c957f57fSSushil Singh    Valid Value  session  [${status}]
183c957f57fSSushil Singh
184c957f57fSSushil Singh
185c957f57fSSushil SinghCreate Session And Fail To Set Client Origin IP
186c957f57fSSushil Singh    [Documentation]  Create redifish session with client id and fail to set client origin IP.
187c957f57fSSushil Singh    [Arguments]  ${client_id}
188c957f57fSSushil Singh
189c957f57fSSushil Singh    # Description of argument(s):
190c957f57fSSushil Singh    # client_id    This client id contain string value
191c957f57fSSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
192c957f57fSSushil Singh
193c957f57fSSushil Singh    Set Test Variable  ${client_ip}  10.6.7.8
194c957f57fSSushil Singh    ${resp}=  Set Client Origin IP  ${client_id}  ${client_ip}  status=False
1954ec68ba8SSushil Singh
1964ec68ba8SSushil Singh
1974ec68ba8SSushil SinghCreate A Non Admin Session With ClientID
1984ec68ba8SSushil Singh    [Documentation]  Create redifish session with client id.
1994ec68ba8SSushil Singh    [Arguments]  ${client_id}  ${username}  ${password}
2004ec68ba8SSushil Singh
2014ec68ba8SSushil Singh    # Description of argument(s):
2024ec68ba8SSushil Singh    # client_id    This client id can contain string value
2034ec68ba8SSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
2044ec68ba8SSushil Singh
2054ec68ba8SSushil Singh    @{session_list}=  Create List
2064ec68ba8SSushil Singh    &{tmp_dict}=  Create Dictionary
2074ec68ba8SSushil Singh
2084ec68ba8SSushil Singh    FOR  ${client}  IN  @{client_id}
2094ec68ba8SSushil Singh      ${resp}=  Redfish Login  rest_username=${username}  rest_password=${password}  kwargs= "Oem":{"OpenBMC" : {"ClientID":"${client}"}}
2104ec68ba8SSushil Singh      Append To List  ${session_list}  ${resp}
2114ec68ba8SSushil Singh    END
2124ec68ba8SSushil Singh
2134ec68ba8SSushil Singh    [Return]  ${session_list}
2144ec68ba8SSushil Singh
2154ec68ba8SSushil Singh
2164ec68ba8SSushil SinghVerify A Non Admin Session Created With ClientID
2174ec68ba8SSushil Singh    [Documentation]  Verify session created with client id.
2184ec68ba8SSushil Singh    [Arguments]  ${client_ids}  ${session_ids}
2194ec68ba8SSushil Singh
2204ec68ba8SSushil Singh    # Description of argument(s):
221*87e984c8SSushil Singh    # client_ids    External client name.
222*87e984c8SSushil Singh    # session_ids   This value is a session id.
2234ec68ba8SSushil Singh
2244ec68ba8SSushil Singh    # {
2254ec68ba8SSushil Singh    #   "@odata.id": "/redfish/v1/SessionService/Sessions/H8q2ZKucSJ",
2264ec68ba8SSushil Singh    #   "@odata.type": "#Session.v1_0_2.Session",
2274ec68ba8SSushil Singh    #   "Description": "Manager User Session",
2284ec68ba8SSushil Singh    #   "Id": "H8q2ZKucSJ",
2294ec68ba8SSushil Singh    #   "Name": "User Session",
2304ec68ba8SSushil Singh    #   "Oem": {
2314ec68ba8SSushil Singh    #   "OpenBMC": {
2324ec68ba8SSushil Singh    #  "@odata.type": "#OemSession.v1_0_0.Session",
2334ec68ba8SSushil Singh    #  "ClientID": "",
2344ec68ba8SSushil Singh    #  "ClientOriginIP": "::ffff:x.x.x.x"
2354ec68ba8SSushil Singh    #       }
2364ec68ba8SSushil Singh    #     },
2374ec68ba8SSushil Singh    #   "UserName": "root"
2384ec68ba8SSushil Singh    # }
2394ec68ba8SSushil Singh
240*87e984c8SSushil Singh    FOR  ${client}  ${session}  IN ZIP  ${client_ids}  ${session_ids}
241*87e984c8SSushil Singh      ${resp}=  Redfish Get Request  /redfish/v1/SessionService/Sessions/${session["Id"]}
2424ec68ba8SSushil Singh      ${sessions}=     To Json    ${resp.content}
2434ec68ba8SSushil Singh      Rprint Vars  sessions
24424e32afaSSushil Singh      @{words} =  Split String  ${sessions["ClientOriginIPAddress"]}  :
2454ec68ba8SSushil Singh      ${ip_address}=  Get Running System IP
2464ec68ba8SSushil Singh      Set Test Variable  ${temp_ipaddr}  ${words}[-1]
2474ec68ba8SSushil Singh      Valid Value  client  ['${sessions["Oem"]["OpenBMC"]["ClientID"]}']
248*87e984c8SSushil Singh      Valid Value  session["Id"]  ['${sessions["Id"]}']
2494ec68ba8SSushil Singh      Valid Value  temp_ipaddr  ${ip_address}
2504ec68ba8SSushil Singh    END
2514ec68ba8SSushil Singh
2524ec68ba8SSushil Singh
2534ec68ba8SSushil SinghNon Admin User To Create Session
2544ec68ba8SSushil Singh    [Documentation]  Non Admin user create a session and verify the session is created.
2554ec68ba8SSushil Singh    [Arguments]  ${client_id}  ${username}  ${password}  ${role}  ${enabled}=${True}
2564ec68ba8SSushil Singh
2574ec68ba8SSushil Singh    # Description of argument(s):
2584ec68ba8SSushil Singh    # client_id    This client id contain string value
2594ec68ba8SSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
2604ec68ba8SSushil Singh    # username     Username.
2614ec68ba8SSushil Singh    # password     Password.
2624ec68ba8SSushil Singh    # role         Role of user.
2634ec68ba8SSushil Singh    # enabled      Value can be True or False.
2644ec68ba8SSushil Singh
2654ec68ba8SSushil Singh    Redfish.Login
2664ec68ba8SSushil Singh    Redfish Create User  ${username}  ${password}  ${role}  ${enabled}
2674ec68ba8SSushil Singh    Delete All Sessions
2684ec68ba8SSushil Singh    Redfish.Logout
2694ec68ba8SSushil Singh    Initialize OpenBMC  rest_username=${username}  rest_password=${password}
2704ec68ba8SSushil Singh    ${client_ids}=  Split String  ${client_id}  ,
2714ec68ba8SSushil Singh    ${session_info}=  Create A Non Admin Session With ClientID  ${client_ids}  ${username}  ${password}
2724ec68ba8SSushil Singh    Verify A Non Admin Session Created With ClientID  ${client_ids}  ${session_info}
273