1*** Settings ***
2Documentation  Connections and authentication module stability tests.
3
4Resource  ../lib/bmc_redfish_resource.robot
5Resource  ../lib/bmc_network_utils.robot
6Resource  ../lib/openbmc_ffdc.robot
7Resource  ../lib/resource.robot
8Resource  ../lib/utils.robot
9Resource  ../lib/connection_client.robot
10Library   ../lib/bmc_network_utils.py
11
12Library   SSHLibrary
13Library   OperatingSystem
14Library   Collections
15
16*** Variables ***
17
18${iterations}         10000
19${hostname}           test_hostname
20${MAX_UNAUTH_PER_IP}  ${5}
21
22*** Test Cases ***
23
24Test Patch Without Auth Token Fails
25    [Documentation]  Send patch method without auth token and verify it throws an error.
26    [Tags]   Test_Patch_Without_Auth_Token_Fails
27
28    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}  body={'HostName': '${hostname}'}
29    ...  valid_status_codes=[${HTTP_UNAUTHORIZED}, ${HTTP_FORBIDDEN}]
30
31
32Flood Patch Without Auth Token And Check Stability Of BMC
33    [Documentation]  Flood patch method without auth token and check BMC stability.
34    [Tags]  Flood_Patch_Without_Auth_Token_And_Check_Stability_Of_BMC
35    @{status_list}=  Create List
36
37    FOR  ${i}  IN RANGE  ${1}  ${iterations}
38        Log To Console  ${i}th iteration
39        Run Keyword And Ignore Error
40        ...  Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}  body={'HostName': '${hostname}'}
41
42        # Every 100th iteration, check BMC allows patch with auth token.
43        ${status}=  Run Keyword If  ${i} % 100 == 0  Run Keyword And Return Status
44        ...  Login And Configure Hostname
45        Run Keyword If  ${status} == False  Append To List  ${status_list}  ${status}
46    END
47    ${verify_count}=  Evaluate  ${iterations}/100
48    ${fail_count}=  Get Length  ${status_list}
49
50    Should Be Equal  ${fail_count}  0  msg=Patch operation failed ${fail_count} times in ${verify_count} attempts
51
52
53Verify Uer Cannot Login After 5 Non-Logged In Sessions
54    [Documentation]  User should not be able to login when there
55    ...  are 5 non-logged in sessions.
56    [Tags]  Verify_User_Cannot_Login_After_5_Non-Logged_In_Sessions
57
58    FOR  ${i}  IN RANGE  ${0}  ${MAX_UNAUTH_PER_IP}
59       SSHLibrary.Open Connection  ${OPENBMC_HOST}
60       Start Process  ssh ${OPENBMC_USERNAME}@${OPENBMC_HOST}  shell=True
61    END
62
63    SSHLibrary.Open Connection  ${OPENBMC_HOST}
64    ${status}=   Run Keyword And Return Status  SSHLibrary.Login  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
65
66    Should Be Equal  ${status}  ${False}
67
68
69Test Post Without Auth Token Fails
70    [Documentation]  Send post method without auth token and verify it throws an error.
71    [Tags]   Test_Post_Without_Auth_Token_Fails
72
73    ${user_info}=  Create Dictionary  UserName=test_user  Password=TestPwd123  RoleId=Operator  Enabled=${True}
74    Redfish.Post  /redfish/v1/AccountService/Accounts/  body=&{user_info}
75    ...  valid_status_codes=[${HTTP_UNAUTHORIZED}, ${HTTP_FORBIDDEN}]
76
77
78Flood Post Without Auth Token And Check Stability Of BMC
79    [Documentation]  Flood post method without auth token and check BMC stability.
80    [Tags]  Flood_Post_Without_Auth_Token_And_Check_Stability_Of_BMC
81
82    @{status_list}=  Create List
83    ${user_info}=  Create Dictionary  UserName=test_user  Password=TestPwd123  RoleId=Operator  Enabled=${True}
84
85    FOR  ${i}  IN RANGE  ${1}  ${iterations}
86        Log To Console  ${i}th iteration
87        Run Keyword And Ignore Error
88        ...  Redfish.Post   /redfish/v1/AccountService/Accounts/  body=&{user_info}
89
90        # Every 100th iteration, check BMC allows post with auth token.
91        ${status}=  Run Keyword If  ${i} % 100 == 0  Run Keyword And Return Status
92        ...  Login And Create User
93        Run Keyword If  ${status} == False  Append To List  ${status_list}  ${status}
94    END
95    ${verify_count}=  Evaluate  ${iterations}/100
96    ${fail_count}=  Get Length  ${status_list}
97
98    Should Be Equal  ${fail_count}  0  msg=Post operation failed ${fail_count} times in ${verify_count} attempts
99
100
101*** Keywords ***
102
103Login And Configure Hostname
104    [Documentation]  Login and configure hostname
105
106    [Teardown]  Redfish.Logout
107
108    Redfish.Login
109
110    Redfish.patch  ${REDFISH_NW_PROTOCOL_URI}  body={'HostName': '${hostname}'}
111    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
112
113
114Login And Create User
115    [Documentation]  Login and create user
116
117    [Teardown]  Redfish.Logout
118
119    Redfish.Login
120
121    ${user_info}=  Create Dictionary  UserName=test_user  Password=TestPwd123  RoleId=Operator  Enabled=${True}
122    Redfish.Post  /redfish/v1/AccountService/Accounts/  body=&{user_info}  valid_status_codes=[${HTTP_OK}]
123