1*** Settings ***
2
3Documentation     Test client identifier feature on BMC.
4
5Resource          ../../lib/rest_client.robot
6Resource          ../../lib/openbmc_ffdc.robot
7Resource          ../../lib/resource.robot
8Resource          ../../lib/bmc_redfish_utils.robot
9Resource          ../../lib/external_intf/management_console_utils.robot
10Library           ../../lib/bmc_network_utils.py
11Library           ../../lib/gen_robot_valid.py
12
13Suite Setup       Redfish.Login
14Suite Teardown    Run Keyword And Ignore Error  Delete All Redfish Sessions
15Test Setup        Printn
16Test Teardown     FFDC On Test Case Fail
17
18
19*** Test Cases ***
20
21Create A Session With ClientID And Verify
22    [Documentation]  Create a session with client id and verify client id is same.
23    [Tags]  Create_A_Session_With_ClientID_And_Verify
24    [Template]  Create And Verify Session ClientID
25
26    # client_id           reboot_flag
27    12345                 False
28    123456                False
29    EXTERNAL-CLIENT-01    False
30    EXTERNAL-CLIENT-02    False
31
32
33Check ClientID Persistency On BMC Reboot
34    [Documentation]  Create a session with client id and verify client id is same after the reboot.
35    [Tags]  Check_ClientID_Persistency_On_BMC_Reboot
36    [Template]  Create And Verify Session ClientID
37
38    # client_id           reboot_flag
39    12345                 True
40    EXTERNAL-CLIENT-01    True
41
42
43Create A Multiple Session With ClientID And Verify
44    [Documentation]  Create a multiple session with client id and verify client id is same.
45    [Tags]  Create_A_Multiple_Session_With_ClientID_And_Verify
46    [Template]  Create And Verify Session ClientID
47
48    # client_id                              reboot_flag
49    12345,123456                             False
50    EXTERNAL-CLIENT-01,EXTERNAL-CLIENT-02    False
51
52
53Check Multiple ClientID Persistency On BMC Reboot
54    [Documentation]  Create a multiple session with client id and verify client id is same after the reboot.
55    [Tags]  Check_Multiple_ClientID_Persistency_On_BMC_Reboot
56    [Template]  Create And Verify Session ClientID
57
58    # client_id                              reboot_flag
59    12345,123456                             True
60    EXTERNAL-CLIENT-01,EXTERNAL-CLIENT-02    True
61
62
63Fail To Set Client Origin IP
64    [Documentation]  Fail to set the client origin IP.
65    [Tags]  Fail_To_Set_Client_Origin_IP
66    [Template]  Create Session And Fail To Set Client Origin IP
67
68    # client_id
69    12345
70    EXTERNAL-CLIENT-01
71
72
73Create Session For Non Admin User
74    [Documentation]  Create Session for non-admin user.
75    [Tags]  Create_Session_For_Non_Admin_User
76    [Template]  Non Admin User To Create Session
77
78    # client_id    username         password      role_id
79    12345          operator_user    TestPwd123    Operator
80
81
82*** Keywords ***
83
84Create And Verify Session ClientID
85    [Documentation]  Create redifish session with client id and verify it remain same.
86    [Arguments]  ${client_id}  ${reboot_flag}=False
87
88    # Description of argument(s):
89    # client_id    This client id contain string value
90    #              (e.g. 12345, "EXTERNAL-CLIENT").
91    # reboot_flag  Flag is used to run reboot the BMC code.
92    #               (e.g. True or False).
93
94    ${client_ids}=  Split String  ${client_id}  ,
95    ${session_info}=  Create Session With List Of ClientID  ${client_ids}
96    Verify A Session Created With ClientID  ${client_ids}  ${session_info}
97    Run Keyword If  '${reboot_flag}' == 'True'
98    ...  Run Keywords  Redfish OBMC Reboot (off)  AND
99    ...  Verify A Session Created With ClientID  ${client_ids}  ${session_info}
100    Redfish Delete List Of Session  ${session_info}
101
102
103Set Client Origin IP
104    [Documentation]  Set client origin IP.
105    [Arguments]  ${client_id}  ${client_ip}  ${status}
106
107    # Description of argument(s):
108    # client_id    This client id contain string value
109    #              (e.g. 12345, "EXTERNAL-CLIENT").
110    # client_ip    Valid IP address
111    # status       HTTP status code
112
113    ${session}=  Run Keyword And Return Status
114    ...  Redfish Login
115    ...  kwargs= "Oem":{"OpenBMC": {"ClientID":"${client_id}", "ClientOriginIP":"${client_ip}"}}
116    Valid Value  session  [${status}]
117
118
119Create Session And Fail To Set Client Origin IP
120    [Documentation]  Create redifish session with client id and fail to set client origin IP.
121    [Arguments]  ${client_id}
122
123    # Description of argument(s):
124    # client_id    This client id contain string value
125    #              (e.g. 12345, "EXTERNAL-CLIENT").
126
127    Set Test Variable  ${client_ip}  10.6.7.8
128    ${resp}=  Set Client Origin IP  ${client_id}  ${client_ip}  status=False
129
130
131Create A Non Admin Session With ClientID
132    [Documentation]  Create redifish session with client id.
133    [Arguments]  ${client_id}  ${username}  ${password}
134
135    # Description of argument(s):
136    # client_id    This client id can contain string value
137    #              (e.g. 12345, "EXTERNAL-CLIENT").
138
139    @{session_list}=  Create List
140    &{tmp_dict}=  Create Dictionary
141
142    FOR  ${client}  IN  @{client_id}
143      ${resp}=  Redfish Login  rest_username=${username}  rest_password=${password}  kwargs= "Oem":{"OpenBMC" : {"ClientID":"${client}"}}
144      Append To List  ${session_list}  ${resp}
145    END
146
147    [Return]  ${session_list}
148
149
150Verify A Non Admin Session Created With ClientID
151    [Documentation]  Verify session created with client id.
152    [Arguments]  ${client_ids}  ${session_ids}
153
154    # Description of argument(s):
155    # client_ids    External client name.
156    # session_ids   This value is a session id.
157
158    # {
159    #   "@odata.id": "/redfish/v1/SessionService/Sessions/H8q2ZKucSJ",
160    #   "@odata.type": "#Session.v1_0_2.Session",
161    #   "Description": "Manager User Session",
162    #   "Id": "H8q2ZKucSJ",
163    #   "Name": "User Session",
164    #   "Oem": {
165    #   "OpenBMC": {
166    #  "@odata.type": "#OemSession.v1_0_0.Session",
167    #  "ClientID": "",
168    #  "ClientOriginIP": "::ffff:x.x.x.x"
169    #       }
170    #     },
171    #   "UserName": "root"
172    # }
173
174    FOR  ${client}  ${session}  IN ZIP  ${client_ids}  ${session_ids}
175      ${resp}=  Redfish Get Request  /redfish/v1/SessionService/Sessions/${session["Id"]}
176      ${sessions}=     To Json    ${resp.content}
177      Rprint Vars  sessions
178      @{words} =  Split String  ${sessions["ClientOriginIPAddress"]}  :
179      ${ip_address}=  Get Running System IP
180      Set Test Variable  ${temp_ipaddr}  ${words}[-1]
181      Valid Value  client  ['${sessions["Oem"]["OpenBMC"]["ClientID"]}']
182      Valid Value  session["Id"]  ['${sessions["Id"]}']
183      Valid Value  temp_ipaddr  ${ip_address}
184    END
185
186
187Non Admin User To Create Session
188    [Documentation]  Non Admin user create a session and verify the session is created.
189    [Arguments]  ${client_id}  ${username}  ${password}  ${role}  ${enabled}=${True}
190
191    # Description of argument(s):
192    # client_id    This client id contain string value
193    #              (e.g. 12345, "EXTERNAL-CLIENT").
194    # username     Username.
195    # password     Password.
196    # role         Role of user.
197    # enabled      Value can be True or False.
198
199    Redfish.Login
200    Redfish Create User  ${username}  ${password}  ${role}  ${enabled}
201    Delete All Sessions
202    Redfish.Logout
203    Initialize OpenBMC  rest_username=${username}  rest_password=${password}
204    ${client_ids}=  Split String  ${client_id}  ,
205    ${session_info}=  Create A Non Admin Session With ClientID  ${client_ids}  ${username}  ${password}
206    Verify A Non Admin Session Created With ClientID  ${client_ids}  ${session_info}
207