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
9ca49ced3SSushil SinghResource          ../../lib/external_intf/management_console_utils.robot
10f90fd656SSushil SinghResource          ../../lib/utils.robot
1145d841e3SSushil SinghLibrary           ../../lib/bmc_network_utils.py
1245d841e3SSushil SinghLibrary           ../../lib/gen_robot_valid.py
1345d841e3SSushil Singh
14f90fd656SSushil Singh
1545d841e3SSushil SinghSuite Setup       Redfish.Login
16889a75e4SSushil SinghSuite Teardown    Run Keyword And Ignore Error  Delete All Redfish Sessions
1745d841e3SSushil SinghTest Setup        Printn
1845d841e3SSushil SinghTest Teardown     FFDC On Test Case Fail
1945d841e3SSushil Singh
20*6fb70d98SMatt FischerTest Tags        Client_Identifier
2145d841e3SSushil Singh
2245d841e3SSushil Singh*** Test Cases ***
2345d841e3SSushil Singh
2445d841e3SSushil SinghCreate A Session With ClientID And Verify
2545d841e3SSushil Singh    [Documentation]  Create a session with client id and verify client id is same.
2645d841e3SSushil Singh    [Tags]  Create_A_Session_With_ClientID_And_Verify
271384321bSSushil Singh    [Template]  Create And Verify Session ClientID
2845d841e3SSushil Singh
29889a75e4SSushil Singh    # client_id           reboot_flag
301384321bSSushil Singh    12345                 False
311384321bSSushil Singh    123456                False
321384321bSSushil Singh    EXTERNAL-CLIENT-01    False
331384321bSSushil Singh    EXTERNAL-CLIENT-02    False
341384321bSSushil Singh
351384321bSSushil Singh
361384321bSSushil SinghCheck ClientID Persistency On BMC Reboot
371384321bSSushil Singh    [Documentation]  Create a session with client id and verify client id is same after the reboot.
381384321bSSushil Singh    [Tags]  Check_ClientID_Persistency_On_BMC_Reboot
391384321bSSushil Singh    [Template]  Create And Verify Session ClientID
401384321bSSushil Singh
41889a75e4SSushil Singh    # client_id           reboot_flag
421384321bSSushil Singh    12345                 True
431384321bSSushil Singh    EXTERNAL-CLIENT-01    True
4445d841e3SSushil Singh
45889a75e4SSushil Singh
46889a75e4SSushil SinghCreate A Multiple Session With ClientID And Verify
47889a75e4SSushil Singh    [Documentation]  Create a multiple session with client id and verify client id is same.
48889a75e4SSushil Singh    [Tags]  Create_A_Multiple_Session_With_ClientID_And_Verify
49889a75e4SSushil Singh    [Template]  Create And Verify Session ClientID
50889a75e4SSushil Singh
51889a75e4SSushil Singh    # client_id                              reboot_flag
52889a75e4SSushil Singh    12345,123456                             False
53889a75e4SSushil Singh    EXTERNAL-CLIENT-01,EXTERNAL-CLIENT-02    False
54889a75e4SSushil Singh
55889a75e4SSushil Singh
56889a75e4SSushil SinghCheck Multiple ClientID Persistency On BMC Reboot
57889a75e4SSushil Singh    [Documentation]  Create a multiple session with client id and verify client id is same after the reboot.
58889a75e4SSushil Singh    [Tags]  Check_Multiple_ClientID_Persistency_On_BMC_Reboot
59889a75e4SSushil Singh    [Template]  Create And Verify Session ClientID
60889a75e4SSushil Singh
61889a75e4SSushil Singh    # client_id                              reboot_flag
62889a75e4SSushil Singh    12345,123456                             True
63889a75e4SSushil Singh    EXTERNAL-CLIENT-01,EXTERNAL-CLIENT-02    True
64889a75e4SSushil Singh
65889a75e4SSushil Singh
66c957f57fSSushil SinghFail To Set Client Origin IP
67c957f57fSSushil Singh    [Documentation]  Fail to set the client origin IP.
68c957f57fSSushil Singh    [Tags]  Fail_To_Set_Client_Origin_IP
69c957f57fSSushil Singh    [Template]  Create Session And Fail To Set Client Origin IP
70c957f57fSSushil Singh
71c957f57fSSushil Singh    # client_id
72c957f57fSSushil Singh    12345
73c957f57fSSushil Singh    EXTERNAL-CLIENT-01
74c957f57fSSushil Singh
754ec68ba8SSushil Singh
764ec68ba8SSushil SinghCreate Session For Non Admin User
774ec68ba8SSushil Singh    [Documentation]  Create Session for non-admin user.
784ec68ba8SSushil Singh    [Tags]  Create_Session_For_Non_Admin_User
794ec68ba8SSushil Singh    [Template]  Non Admin User To Create Session
804ec68ba8SSushil Singh
814ec68ba8SSushil Singh    # client_id    username         password      role_id
824ec68ba8SSushil Singh    12345          operator_user    TestPwd123    Operator
834ec68ba8SSushil Singh
844ec68ba8SSushil Singh
8545d841e3SSushil Singh*** Keywords ***
8645d841e3SSushil Singh
871384321bSSushil SinghCreate And Verify Session ClientID
881384321bSSushil Singh    [Documentation]  Create redifish session with client id and verify it remain same.
891384321bSSushil Singh    [Arguments]  ${client_id}  ${reboot_flag}=False
901384321bSSushil Singh
911384321bSSushil Singh    # Description of argument(s):
921384321bSSushil Singh    # client_id    This client id contain string value
931384321bSSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
941384321bSSushil Singh    # reboot_flag  Flag is used to run reboot the BMC code.
951384321bSSushil Singh    #               (e.g. True or False).
961384321bSSushil Singh
97889a75e4SSushil Singh    ${client_ids}=  Split String  ${client_id}  ,
9887e984c8SSushil Singh    ${session_info}=  Create Session With List Of ClientID  ${client_ids}
99889a75e4SSushil Singh    Verify A Session Created With ClientID  ${client_ids}  ${session_info}
100f90fd656SSushil Singh
101f90fd656SSushil Singh    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
102f90fd656SSushil Singh
1031384321bSSushil Singh    Run Keyword If  '${reboot_flag}' == 'True'
104f90fd656SSushil Singh    ...  Run Keywords  Redfish BMC Reset Operation  AND
105f90fd656SSushil Singh    ...  Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}  AND
106f90fd656SSushil Singh    ...  Is BMC Standby  AND
107889a75e4SSushil Singh    ...  Verify A Session Created With ClientID  ${client_ids}  ${session_info}
108f90fd656SSushil Singh
10987e984c8SSushil Singh    Redfish Delete List Of Session  ${session_info}
110c957f57fSSushil Singh
111c957f57fSSushil Singh
112c957f57fSSushil SinghSet Client Origin IP
113c957f57fSSushil Singh    [Documentation]  Set client origin IP.
114c957f57fSSushil Singh    [Arguments]  ${client_id}  ${client_ip}  ${status}
115c957f57fSSushil Singh
116c957f57fSSushil Singh    # Description of argument(s):
117c957f57fSSushil Singh    # client_id    This client id contain string value
118c957f57fSSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
119c957f57fSSushil Singh    # client_ip    Valid IP address
120c957f57fSSushil Singh    # status       HTTP status code
121c957f57fSSushil Singh
122c957f57fSSushil Singh    ${session}=  Run Keyword And Return Status
123c957f57fSSushil Singh    ...  Redfish Login
12410dba42fSSushil Singh    ...  kwargs= {"Context": "${client_id}", "ClientOriginIP":"${client_ip}"}}
125c957f57fSSushil Singh    Valid Value  session  [${status}]
126c957f57fSSushil Singh
127c957f57fSSushil Singh
128c957f57fSSushil SinghCreate Session And Fail To Set Client Origin IP
129c957f57fSSushil Singh    [Documentation]  Create redifish session with client id and fail to set client origin IP.
130c957f57fSSushil Singh    [Arguments]  ${client_id}
131c957f57fSSushil Singh
132c957f57fSSushil Singh    # Description of argument(s):
133c957f57fSSushil Singh    # client_id    This client id contain string value
134c957f57fSSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
135c957f57fSSushil Singh
136c957f57fSSushil Singh    Set Test Variable  ${client_ip}  10.6.7.8
137c957f57fSSushil Singh    ${resp}=  Set Client Origin IP  ${client_id}  ${client_ip}  status=False
1384ec68ba8SSushil Singh
1394ec68ba8SSushil Singh
1404ec68ba8SSushil SinghCreate A Non Admin Session With ClientID
1414ec68ba8SSushil Singh    [Documentation]  Create redifish session with client id.
1424ec68ba8SSushil Singh    [Arguments]  ${client_id}  ${username}  ${password}
1434ec68ba8SSushil Singh
1444ec68ba8SSushil Singh    # Description of argument(s):
1454ec68ba8SSushil Singh    # client_id    This client id can contain string value
1464ec68ba8SSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
1474ec68ba8SSushil Singh
1484ec68ba8SSushil Singh    @{session_list}=  Create List
1494ec68ba8SSushil Singh    &{tmp_dict}=  Create Dictionary
1504ec68ba8SSushil Singh
1514ec68ba8SSushil Singh    FOR  ${client}  IN  @{client_id}
152b78bca24SGeorge Keishing      ${resp}=  Redfish Login  rest_username=${username}  rest_password=${password}
15310dba42fSSushil Singh      ...  kwargs="Context": "${client_id}"
1544ec68ba8SSushil Singh      Append To List  ${session_list}  ${resp}
1554ec68ba8SSushil Singh    END
1564ec68ba8SSushil Singh
157409df05dSGeorge Keishing    RETURN  ${session_list}
1584ec68ba8SSushil Singh
1594ec68ba8SSushil Singh
1604ec68ba8SSushil SinghVerify A Non Admin Session Created With ClientID
1614ec68ba8SSushil Singh    [Documentation]  Verify session created with client id.
1624ec68ba8SSushil Singh    [Arguments]  ${client_ids}  ${session_ids}
1634ec68ba8SSushil Singh
1644ec68ba8SSushil Singh    # Description of argument(s):
16587e984c8SSushil Singh    # client_ids    External client name.
16687e984c8SSushil Singh    # session_ids   This value is a session id.
1674ec68ba8SSushil Singh
1684ec68ba8SSushil Singh    # {
1694ec68ba8SSushil Singh    #   "@odata.id": "/redfish/v1/SessionService/Sessions/H8q2ZKucSJ",
1704ec68ba8SSushil Singh    #   "@odata.type": "#Session.v1_0_2.Session",
1714ec68ba8SSushil Singh    #   "Description": "Manager User Session",
1724ec68ba8SSushil Singh    #   "Id": "H8q2ZKucSJ",
1734ec68ba8SSushil Singh    #   "Name": "User Session",
1744ec68ba8SSushil Singh    #   "Oem": {
1754ec68ba8SSushil Singh    #   "OpenBMC": {
1764ec68ba8SSushil Singh    #  "@odata.type": "#OemSession.v1_0_0.Session",
1774ec68ba8SSushil Singh    #  "ClientID": "",
1784ec68ba8SSushil Singh    #  "ClientOriginIP": "::ffff:x.x.x.x"
1794ec68ba8SSushil Singh    #       }
1804ec68ba8SSushil Singh    #     },
1814ec68ba8SSushil Singh    #   "UserName": "root"
1824ec68ba8SSushil Singh    # }
1834ec68ba8SSushil Singh
18487e984c8SSushil Singh    FOR  ${client}  ${session}  IN ZIP  ${client_ids}  ${session_ids}
18587e984c8SSushil Singh      ${resp}=  Redfish Get Request  /redfish/v1/SessionService/Sessions/${session["Id"]}
186fbd67007SGeorge Keishing      Rprint Vars  resp.json()
187fbd67007SGeorge Keishing      @{words} =  Split String  ${resp.json()["ClientOriginIPAddress"]}  :
1884ec68ba8SSushil Singh      ${ip_address}=  Get Running System IP
1894ec68ba8SSushil Singh      Set Test Variable  ${temp_ipaddr}  ${words}[-1]
190fbd67007SGeorge Keishing      Valid Value  client  ['${resp.json()["Oem"]["OpenBMC"]["ClientID"]}']
191fbd67007SGeorge Keishing      Valid Value  session["Id"]  ['${resp.json()["Id"]}']
1924ec68ba8SSushil Singh      Valid Value  temp_ipaddr  ${ip_address}
1934ec68ba8SSushil Singh    END
1944ec68ba8SSushil Singh
1954ec68ba8SSushil Singh
1964ec68ba8SSushil SinghNon Admin User To Create Session
1974ec68ba8SSushil Singh    [Documentation]  Non Admin user create a session and verify the session is created.
1984ec68ba8SSushil Singh    [Arguments]  ${client_id}  ${username}  ${password}  ${role}  ${enabled}=${True}
1994ec68ba8SSushil Singh
2004ec68ba8SSushil Singh    # Description of argument(s):
2014ec68ba8SSushil Singh    # client_id    This client id contain string value
2024ec68ba8SSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
2034ec68ba8SSushil Singh    # username     Username.
2044ec68ba8SSushil Singh    # password     Password.
2054ec68ba8SSushil Singh    # role         Role of user.
2064ec68ba8SSushil Singh    # enabled      Value can be True or False.
2074ec68ba8SSushil Singh
2084ec68ba8SSushil Singh    Redfish.Login
2094ec68ba8SSushil Singh    Redfish Create User  ${username}  ${password}  ${role}  ${enabled}
2104ec68ba8SSushil Singh    Delete All Sessions
2114ec68ba8SSushil Singh    Redfish.Logout
2124ec68ba8SSushil Singh    Initialize OpenBMC  rest_username=${username}  rest_password=${password}
2134ec68ba8SSushil Singh    ${client_ids}=  Split String  ${client_id}  ,
2144ec68ba8SSushil Singh    ${session_info}=  Create A Non Admin Session With ClientID  ${client_ids}  ${username}  ${password}
2154ec68ba8SSushil Singh    Verify A Non Admin Session Created With ClientID  ${client_ids}  ${session_info}
216