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
13*889a75e4SSushil 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
25*889a75e4SSushil 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
37*889a75e4SSushil Singh    # client_id           reboot_flag
381384321bSSushil Singh    12345                 True
391384321bSSushil Singh    EXTERNAL-CLIENT-01    True
4045d841e3SSushil Singh
41*889a75e4SSushil Singh
42*889a75e4SSushil SinghCreate A Multiple Session With ClientID And Verify
43*889a75e4SSushil Singh    [Documentation]  Create a multiple session with client id and verify client id is same.
44*889a75e4SSushil Singh    [Tags]  Create_A_Multiple_Session_With_ClientID_And_Verify
45*889a75e4SSushil Singh    [Template]  Create And Verify Session ClientID
46*889a75e4SSushil Singh
47*889a75e4SSushil Singh    # client_id                              reboot_flag
48*889a75e4SSushil Singh    12345,123456                             False
49*889a75e4SSushil Singh    EXTERNAL-CLIENT-01,EXTERNAL-CLIENT-02    False
50*889a75e4SSushil Singh
51*889a75e4SSushil Singh
52*889a75e4SSushil SinghCheck Multiple ClientID Persistency On BMC Reboot
53*889a75e4SSushil Singh    [Documentation]  Create a multiple session with client id and verify client id is same after the reboot.
54*889a75e4SSushil Singh    [Tags]  Check_Multiple_ClientID_Persistency_On_BMC_Reboot
55*889a75e4SSushil Singh    [Template]  Create And Verify Session ClientID
56*889a75e4SSushil Singh
57*889a75e4SSushil Singh    # client_id                              reboot_flag
58*889a75e4SSushil Singh    12345,123456                             True
59*889a75e4SSushil Singh    EXTERNAL-CLIENT-01,EXTERNAL-CLIENT-02    True
60*889a75e4SSushil Singh
61*889a75e4SSushil Singh
6245d841e3SSushil Singh*** Keywords ***
6345d841e3SSushil Singh
6445d841e3SSushil SinghCreate A Session With ClientID
6545d841e3SSushil Singh    [Documentation]  Create redifish session with client id.
6645d841e3SSushil Singh    [Arguments]  ${client_id}
6745d841e3SSushil Singh
6845d841e3SSushil Singh    # Description of argument(s):
6945d841e3SSushil Singh    # client_id    This client id can contain string value
7045d841e3SSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
7145d841e3SSushil Singh
72*889a75e4SSushil Singh    @{session_list}=  Create List
73*889a75e4SSushil Singh    &{tmp_dict}=  Create Dictionary
7445d841e3SSushil Singh
75*889a75e4SSushil Singh    FOR  ${client}  IN  @{client_id}
76*889a75e4SSushil Singh      ${resp}=  Redfish Login  kwargs= "Oem":{"OpenBMC" : {"ClientID":"${client}"}}
77*889a75e4SSushil Singh      Append To List  ${session_list}  ${resp}
78*889a75e4SSushil Singh    END
79*889a75e4SSushil Singh
80*889a75e4SSushil Singh    [Return]  ${session_list}
81*889a75e4SSushil Singh
82*889a75e4SSushil Singh
83*889a75e4SSushil SinghGet Session Information By ClientID
84*889a75e4SSushil Singh    [Documentation]  Get session information by client id.
85*889a75e4SSushil Singh    [Arguments]  ${client_id}  ${session_ids}
86*889a75e4SSushil Singh
87*889a75e4SSushil Singh    FOR  ${session}  IN  @{session_ids}
88*889a75e4SSushil Singh       Return From Keyword If  '${client_id}' == '${session["Oem"]["OpenBMC"]["ClientID"]}'  ${session["Id"]}
89*889a75e4SSushil Singh    END
90*889a75e4SSushil Singh
91*889a75e4SSushil Singh    [Return]  ${EMPTY}
92*889a75e4SSushil Singh
9345d841e3SSushil Singh
9445d841e3SSushil SinghVerify A Session Created With ClientID
9545d841e3SSushil Singh    [Documentation]  Verify session created with client id.
96*889a75e4SSushil Singh    [Arguments]  ${client_ids}  ${session_ids}
9745d841e3SSushil Singh
9845d841e3SSushil Singh    # Description of argument(s):
9945d841e3SSushil Singh    # client_id    External client name.
10045d841e3SSushil Singh    # session_id   This value is a session id.
10145d841e3SSushil Singh
10245d841e3SSushil Singh    # {
10345d841e3SSushil Singh    #   "@odata.id": "/redfish/v1/SessionService/Sessions/H8q2ZKucSJ",
10445d841e3SSushil Singh    #   "@odata.type": "#Session.v1_0_2.Session",
10545d841e3SSushil Singh    #   "Description": "Manager User Session",
10645d841e3SSushil Singh    #   "Id": "H8q2ZKucSJ",
10745d841e3SSushil Singh    #   "Name": "User Session",
10845d841e3SSushil Singh    #   "Oem": {
10945d841e3SSushil Singh    #   "OpenBMC": {
11045d841e3SSushil Singh    #  "@odata.type": "#OemSession.v1_0_0.Session",
11145d841e3SSushil Singh    #  "ClientID": "",
11245d841e3SSushil Singh    #  "ClientOriginIP": "::ffff:x.x.x.x"
11345d841e3SSushil Singh    #       }
11445d841e3SSushil Singh    #     },
11545d841e3SSushil Singh    #   "UserName": "root"
11645d841e3SSushil Singh    # }
11745d841e3SSushil Singh
118*889a75e4SSushil Singh    FOR  ${client}  IN  @{client_ids}
119*889a75e4SSushil Singh      ${session_id}=  Get Session Information By ClientID  ${client}  ${session_ids}
120*889a75e4SSushil Singh      ${sessions}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions/${session_id}
12145d841e3SSushil Singh      Rprint Vars  sessions
12245d841e3SSushil Singh      @{words} =  Split String  ${sessions["Oem"]["OpenBMC"]["ClientOriginIP"]}  :
12345d841e3SSushil Singh      ${ipaddr}=  Get Running System IP
12445d841e3SSushil Singh      Set Test Variable  ${temp_ipaddr}  ${words}[-1]
125*889a75e4SSushil Singh      Valid Value  client  ['${sessions["Oem"]["OpenBMC"]["ClientID"]}']
12645d841e3SSushil Singh      Valid Value  sessions["Id"]  ['${session_id}']
12745d841e3SSushil Singh      Valid Value  temp_ipaddr  ${ipaddr}
128*889a75e4SSushil Singh    END
1291384321bSSushil Singh
1301384321bSSushil Singh
1311384321bSSushil SinghCreate And Verify Session ClientID
1321384321bSSushil Singh    [Documentation]  Create redifish session with client id and verify it remain same.
1331384321bSSushil Singh    [Arguments]  ${client_id}  ${reboot_flag}=False
1341384321bSSushil Singh
1351384321bSSushil Singh    # Description of argument(s):
1361384321bSSushil Singh    # client_id    This client id contain string value
1371384321bSSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
1381384321bSSushil Singh    # reboot_flag  Flag is used to run reboot the BMC code.
1391384321bSSushil Singh    #               (e.g. True or False).
1401384321bSSushil Singh
141*889a75e4SSushil Singh    ${client_ids}=  Split String  ${client_id}  ,
142*889a75e4SSushil Singh    ${session_info}=  Create A Session With ClientID  ${client_ids}
143*889a75e4SSushil Singh    Verify A Session Created With ClientID  ${client_ids}  ${session_info}
1441384321bSSushil Singh    Run Keyword If  '${reboot_flag}' == 'True'
145*889a75e4SSushil Singh    ...  Run Keywords  Redfish OBMC Reboot (off)  AND
146*889a75e4SSushil Singh    ...  Verify A Session Created With ClientID  ${client_ids}  ${session_info}
147