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
62*c957f57fSSushil SinghFail To Set Client Origin IP
63*c957f57fSSushil Singh    [Documentation]  Fail to set the client origin IP.
64*c957f57fSSushil Singh    [Tags]  Fail_To_Set_Client_Origin_IP
65*c957f57fSSushil Singh    [Template]  Create Session And Fail To Set Client Origin IP
66*c957f57fSSushil Singh
67*c957f57fSSushil Singh    # client_id
68*c957f57fSSushil Singh    12345
69*c957f57fSSushil Singh    EXTERNAL-CLIENT-01
70*c957f57fSSushil Singh
7145d841e3SSushil Singh*** Keywords ***
7245d841e3SSushil Singh
7345d841e3SSushil SinghCreate A Session With ClientID
7445d841e3SSushil Singh    [Documentation]  Create redifish session with client id.
7545d841e3SSushil Singh    [Arguments]  ${client_id}
7645d841e3SSushil Singh
7745d841e3SSushil Singh    # Description of argument(s):
7845d841e3SSushil Singh    # client_id    This client id can contain string value
7945d841e3SSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
8045d841e3SSushil Singh
81889a75e4SSushil Singh    @{session_list}=  Create List
82889a75e4SSushil Singh    &{tmp_dict}=  Create Dictionary
8345d841e3SSushil Singh
84889a75e4SSushil Singh    FOR  ${client}  IN  @{client_id}
85889a75e4SSushil Singh      ${resp}=  Redfish Login  kwargs= "Oem":{"OpenBMC" : {"ClientID":"${client}"}}
86889a75e4SSushil Singh      Append To List  ${session_list}  ${resp}
87889a75e4SSushil Singh    END
88889a75e4SSushil Singh
89889a75e4SSushil Singh    [Return]  ${session_list}
90889a75e4SSushil Singh
91889a75e4SSushil Singh
92889a75e4SSushil SinghGet Session Information By ClientID
93889a75e4SSushil Singh    [Documentation]  Get session information by client id.
94889a75e4SSushil Singh    [Arguments]  ${client_id}  ${session_ids}
95889a75e4SSushil Singh
96889a75e4SSushil Singh    FOR  ${session}  IN  @{session_ids}
97889a75e4SSushil Singh       Return From Keyword If  '${client_id}' == '${session["Oem"]["OpenBMC"]["ClientID"]}'  ${session["Id"]}
98889a75e4SSushil Singh    END
99889a75e4SSushil Singh
100889a75e4SSushil Singh    [Return]  ${EMPTY}
101889a75e4SSushil Singh
10245d841e3SSushil Singh
10345d841e3SSushil SinghVerify A Session Created With ClientID
10445d841e3SSushil Singh    [Documentation]  Verify session created with client id.
105889a75e4SSushil Singh    [Arguments]  ${client_ids}  ${session_ids}
10645d841e3SSushil Singh
10745d841e3SSushil Singh    # Description of argument(s):
10845d841e3SSushil Singh    # client_id    External client name.
10945d841e3SSushil Singh    # session_id   This value is a session id.
11045d841e3SSushil Singh
11145d841e3SSushil Singh    # {
11245d841e3SSushil Singh    #   "@odata.id": "/redfish/v1/SessionService/Sessions/H8q2ZKucSJ",
11345d841e3SSushil Singh    #   "@odata.type": "#Session.v1_0_2.Session",
11445d841e3SSushil Singh    #   "Description": "Manager User Session",
11545d841e3SSushil Singh    #   "Id": "H8q2ZKucSJ",
11645d841e3SSushil Singh    #   "Name": "User Session",
11745d841e3SSushil Singh    #   "Oem": {
11845d841e3SSushil Singh    #   "OpenBMC": {
11945d841e3SSushil Singh    #  "@odata.type": "#OemSession.v1_0_0.Session",
12045d841e3SSushil Singh    #  "ClientID": "",
12145d841e3SSushil Singh    #  "ClientOriginIP": "::ffff:x.x.x.x"
12245d841e3SSushil Singh    #       }
12345d841e3SSushil Singh    #     },
12445d841e3SSushil Singh    #   "UserName": "root"
12545d841e3SSushil Singh    # }
12645d841e3SSushil Singh
127889a75e4SSushil Singh    FOR  ${client}  IN  @{client_ids}
128889a75e4SSushil Singh      ${session_id}=  Get Session Information By ClientID  ${client}  ${session_ids}
129889a75e4SSushil Singh      ${sessions}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions/${session_id}
13045d841e3SSushil Singh      Rprint Vars  sessions
13145d841e3SSushil Singh      @{words} =  Split String  ${sessions["Oem"]["OpenBMC"]["ClientOriginIP"]}  :
13245d841e3SSushil Singh      ${ipaddr}=  Get Running System IP
13345d841e3SSushil Singh      Set Test Variable  ${temp_ipaddr}  ${words}[-1]
134889a75e4SSushil Singh      Valid Value  client  ['${sessions["Oem"]["OpenBMC"]["ClientID"]}']
13545d841e3SSushil Singh      Valid Value  sessions["Id"]  ['${session_id}']
13645d841e3SSushil Singh      Valid Value  temp_ipaddr  ${ipaddr}
137889a75e4SSushil Singh    END
1381384321bSSushil Singh
1391384321bSSushil Singh
1401384321bSSushil SinghCreate And Verify Session ClientID
1411384321bSSushil Singh    [Documentation]  Create redifish session with client id and verify it remain same.
1421384321bSSushil Singh    [Arguments]  ${client_id}  ${reboot_flag}=False
1431384321bSSushil Singh
1441384321bSSushil Singh    # Description of argument(s):
1451384321bSSushil Singh    # client_id    This client id contain string value
1461384321bSSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
1471384321bSSushil Singh    # reboot_flag  Flag is used to run reboot the BMC code.
1481384321bSSushil Singh    #               (e.g. True or False).
1491384321bSSushil Singh
150889a75e4SSushil Singh    ${client_ids}=  Split String  ${client_id}  ,
151889a75e4SSushil Singh    ${session_info}=  Create A Session With ClientID  ${client_ids}
152889a75e4SSushil Singh    Verify A Session Created With ClientID  ${client_ids}  ${session_info}
1531384321bSSushil Singh    Run Keyword If  '${reboot_flag}' == 'True'
154889a75e4SSushil Singh    ...  Run Keywords  Redfish OBMC Reboot (off)  AND
155889a75e4SSushil Singh    ...  Verify A Session Created With ClientID  ${client_ids}  ${session_info}
156*c957f57fSSushil Singh
157*c957f57fSSushil Singh
158*c957f57fSSushil SinghSet Client Origin IP
159*c957f57fSSushil Singh    [Documentation]  Set client origin IP.
160*c957f57fSSushil Singh    [Arguments]  ${client_id}  ${client_ip}  ${status}
161*c957f57fSSushil Singh
162*c957f57fSSushil Singh    # Description of argument(s):
163*c957f57fSSushil Singh    # client_id    This client id contain string value
164*c957f57fSSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
165*c957f57fSSushil Singh    # client_ip    Valid IP address
166*c957f57fSSushil Singh    # status       HTTP status code
167*c957f57fSSushil Singh
168*c957f57fSSushil Singh    ${session}=  Run Keyword And Return Status
169*c957f57fSSushil Singh    ...  Redfish Login
170*c957f57fSSushil Singh    ...  kwargs= "Oem":{"OpenBMC": {"ClientID":"${client_id}", "ClientOriginIP":"${client_ip}"}}
171*c957f57fSSushil Singh    Valid Value  session  [${status}]
172*c957f57fSSushil Singh
173*c957f57fSSushil Singh
174*c957f57fSSushil SinghCreate Session And Fail To Set Client Origin IP
175*c957f57fSSushil Singh    [Documentation]  Create redifish session with client id and fail to set client origin IP.
176*c957f57fSSushil Singh    [Arguments]  ${client_id}
177*c957f57fSSushil Singh
178*c957f57fSSushil Singh    # Description of argument(s):
179*c957f57fSSushil Singh    # client_id    This client id contain string value
180*c957f57fSSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
181*c957f57fSSushil Singh
182*c957f57fSSushil Singh    Set Test Variable  ${client_ip}  10.6.7.8
183*c957f57fSSushil Singh    ${resp}=  Set Client Origin IP  ${client_id}  ${client_ip}  status=False
184