1*** Settings ***
2Documentation    Test Redfish user account.
3
4Resource         ../../lib/resource.robot
5Resource         ../../lib/bmc_redfish_resource.robot
6Resource         ../../lib/openbmc_ffdc.robot
7
8Test Setup       Test Setup Execution
9Test Teardown    Test Teardown Execution
10
11
12** Test Cases **
13
14Verify AccountService Available
15    [Documentation]  Verify Redfish account service is available.
16    [Tags]  Verify_AccountService_Available
17
18    ${resp} =  Redfish_utils.Get Attribute  /redfish/v1/AccountService  ServiceEnabled
19    Should Be Equal As Strings  ${resp}  ${True}
20
21Redfish Create and Verify Users
22    [Documentation]  Create Redfish users with various roles
23    [Tags]  Redfish_Create_and_Verify_Users
24    [Template]  Redfish Create And Verify User
25
26     # username       password    role_id         enabled
27       admin_user     TestPwd123  Administrator   ${True}
28       operator_user  TestPwd123  Operator        ${True}
29       user_user      TestPwd123  User            ${True}
30       callback_user  TestPwd123  Callback        ${True}
31
32*** Keywords ***
33
34Test Setup Execution
35    [Documentation]  Do test case setup tasks.
36
37    Redfish.Login
38
39
40Test Teardown Execution
41    [Documentation]  Do the post test teardown.
42
43    FFDC On Test Case Fail
44    Redfish.Logout
45
46Redfish Create And Verify User
47    [Documentation]  Redfish create and verify user.
48    [Arguments]   ${username}  ${password}  ${role_id}  ${enabled}
49
50    # Description of argument(s):
51    # Username            The username to be created
52    # Password            The password to be assigned
53    # Roleid              The role id of the user to be created
54    # Enabled             The decision if it should be enabled
55
56    # Example:
57    #{
58    #"@odata.context": "/redfish/v1/$metadata#ManagerAccount.ManagerAccount",
59    #"@odata.id": "/redfish/v1/AccountService/Accounts/test1",
60    #"@odata.type": "#ManagerAccount.v1_0_3.ManagerAccount",
61    #"Description": "User Account",
62    #"Enabled": true,
63    #"Id": "test1",
64    #"Links": {
65    #  "Role": {
66    #    "@odata.id": "/redfish/v1/AccountService/Roles/Administrator"
67    #  }
68    #},
69
70    # Delete if the user exist.
71    Run Keyword And Ignore Error
72    ...  Redfish.Delete  /redfish/v1/AccountService/Accounts/${userName}
73
74    # Create specified user.
75    ${payload}=  Create Dictionary
76    ...  UserName=${username}  Password=${password}  RoleId=${role_id}  Enabled=${enabled}
77    Redfish.Post  /redfish/v1/AccountService/Accounts  body=&{payload}
78    ...  valid_status_codes=[${HTTP_CREATED}]
79
80    Redfish.Logout
81
82    # Login with created user.
83    Redfish.Login  ${username}  ${password}
84
85    # Validate Role Id of created user.
86    ${role_config}=  Redfish_Utils.Get Attribute
87    ...  /redfish/v1/AccountService/Accounts/${userName}  RoleId
88    Should Be Equal  ${role_id}  ${role_config}
89
90    Redfish.Get  /redfish/v1/AccountService/Accounts/${userName}
91
92    # Delete Specified User
93    Redfish.Delete  /redfish/v1/AccountService/Accounts/${userName}
94