xref: /openbmc/openbmc-test-automation/lib/external_intf/management_console_utils.robot (revision 5166ebd57a8b5559829fc41873df780c9906d24e)
1c5e9ebc6SSushil Singh*** Settings ***
2c5e9ebc6SSushil SinghDocumentation    Management console utilities keywords.
3c5e9ebc6SSushil Singh
487e984c8SSushil SinghResource         ../../lib/bmc_redfish_utils.robot
5c5e9ebc6SSushil SinghLibrary          ../../lib/gen_robot_valid.py
6c5e9ebc6SSushil SinghLibrary          Collections
7c5e9ebc6SSushil SinghLibrary          ../../lib/bmc_ssh_utils.py
8c5e9ebc6SSushil SinghLibrary          SSHLibrary
9c5e9ebc6SSushil Singh
10c5e9ebc6SSushil Singh*** Variables ***
11c5e9ebc6SSushil Singh&{daemon_command}  start=systemctl start avahi-daemon
12c5e9ebc6SSushil Singh                  ...  stop=systemctl stop avahi-daemon
13c5e9ebc6SSushil Singh                  ...  status=systemctl status avahi-daemon -l
14c5e9ebc6SSushil Singh&{daemon_message}  start=Active: active (running)
15c5e9ebc6SSushil Singh                  ...  stop=Active: inactive (dead)
16c5e9ebc6SSushil Singh
17c5e9ebc6SSushil Singh*** Keywords ***
18c5e9ebc6SSushil Singh
19c5e9ebc6SSushil SinghSet AvahiDaemon Service
20c5e9ebc6SSushil Singh    [Documentation]  To enable or disable avahi service.
21c5e9ebc6SSushil Singh    [Arguments]  ${command}
22c5e9ebc6SSushil Singh
23c5e9ebc6SSushil Singh    # Description of argument(s):
241faaa460SGeorge Keishing    # command  Get command from dictionary.
25c5e9ebc6SSushil Singh
26c5e9ebc6SSushil Singh    ${service_command}=  Get From Dictionary  ${daemon_command}  ${command}
27c5e9ebc6SSushil Singh    ${resp}  ${stderr}  ${rc}=  BMC Execute Command  ${service_command}  print_out=1
28c5e9ebc6SSushil Singh    Should Be Equal As Integers  ${rc}  0
29c5e9ebc6SSushil Singh
30c5e9ebc6SSushil Singh
31c5e9ebc6SSushil SinghVerify AvahiDaemon Service Status
32c5e9ebc6SSushil Singh    [Documentation]  To check for avahi service.
33c5e9ebc6SSushil Singh    [Arguments]  ${message}
34c5e9ebc6SSushil Singh
35c5e9ebc6SSushil Singh    # Description of argument(s):
361faaa460SGeorge Keishing    # message  Get status message from dictionary.
37c5e9ebc6SSushil Singh
38c5e9ebc6SSushil Singh    ${service_command}=  Get From Dictionary  ${daemon_command}  status
39c5e9ebc6SSushil Singh    ${service_message}=  Get From Dictionary  ${daemon_message}  ${message}
40c5e9ebc6SSushil Singh    ${resp}  ${stderr}  ${rc}=  BMC Execute Command  ${service_command}  print_out=1
41c5e9ebc6SSushil Singh    Should Contain  ${resp}  ${service_message}
42d03f2ce1SSushil Singh
43d03f2ce1SSushil Singh
4487e984c8SSushil SinghCreate Session With ClientID
4587e984c8SSushil Singh    [Documentation]  Create redifish session with client id.
4687e984c8SSushil Singh    [Arguments]  ${client_id}
4787e984c8SSushil Singh
4887e984c8SSushil Singh    # Description of argument(s):
4987e984c8SSushil Singh    # client_id    This client id can contain string value
5087e984c8SSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
5187e984c8SSushil Singh
5287e984c8SSushil Singh    ${session_info}=  Create Dictionary
5387e984c8SSushil Singh    ${session_resp}=  Redfish Login  kwargs= "Oem":{"OpenBMC" : {"ClientID":"${client_id}"}}
5487e984c8SSushil Singh
5587e984c8SSushil Singh    Set To Dictionary  ${session_info}  SessionIDs  ${session_resp['Id']}
5687e984c8SSushil Singh    Set To Dictionary  ${session_info}  ClientID  ${session_resp["Oem"]["OpenBMC"]["ClientID"]}
5787e984c8SSushil Singh    Set To Dictionary  ${session_info}  SessionToken  ${XAUTH_TOKEN}
5887e984c8SSushil Singh    Set To Dictionary  ${session_info}  SessionResp  ${session_resp}
5987e984c8SSushil Singh
6087e984c8SSushil Singh    [Return]  ${session_info}
6187e984c8SSushil Singh
6287e984c8SSushil Singh
6387e984c8SSushil SinghCreate Session With List Of ClientID
6487e984c8SSushil Singh    [Documentation]  Create redifish session with client id.
6587e984c8SSushil Singh    [Arguments]  ${client_id}
6687e984c8SSushil Singh
6787e984c8SSushil Singh    # Description of argument(s):
6887e984c8SSushil Singh    # client_id    This client id can contain string value
6987e984c8SSushil Singh    #              (e.g. 12345, "EXTERNAL-CLIENT").
7087e984c8SSushil Singh
7187e984c8SSushil Singh    @{session_dict_list}=  Create List
7287e984c8SSushil Singh    &{session_dict}=  Create Dictionary
7387e984c8SSushil Singh
7487e984c8SSushil Singh    FOR  ${client}  IN  @{client_id}
7587e984c8SSushil Singh      ${session_dict}=  Create Session With ClientID  ${client}
7687e984c8SSushil Singh      Append To List  ${session_dict_list}  ${session_dict}
7787e984c8SSushil Singh    END
7887e984c8SSushil Singh
7987e984c8SSushil Singh    [Return]  ${session_dict_list}
8087e984c8SSushil Singh
8187e984c8SSushil Singh
8287e984c8SSushil SinghVerify A Session Created With ClientID
83*5166ebd5SSushil Singh    [Documentation]  Verify the session is created.
8487e984c8SSushil Singh    [Arguments]  ${client_id}  ${session_ids}
8587e984c8SSushil Singh
8687e984c8SSushil Singh    # Description of argument(s):
8787e984c8SSushil Singh    # client_id    External client name.
8887e984c8SSushil Singh    # session_id   This value is a session id.
8987e984c8SSushil Singh
9087e984c8SSushil Singh    # {
9187e984c8SSushil Singh    #   "@odata.id": "/redfish/v1/SessionService/Sessions/H8q2ZKucSJ",
9287e984c8SSushil Singh    #   "@odata.type": "#Session.v1_0_2.Session",
9387e984c8SSushil Singh    #   "Description": "Manager User Session",
9487e984c8SSushil Singh    #   "Id": "H8q2ZKucSJ",
9587e984c8SSushil Singh    #   "Name": "User Session",
9687e984c8SSushil Singh    #   "Oem": {
9787e984c8SSushil Singh    #   "OpenBMC": {
9887e984c8SSushil Singh    #  "@odata.type": "#OemSession.v1_0_0.Session",
9987e984c8SSushil Singh    #  "ClientID": "",
10087e984c8SSushil Singh    #  "ClientOriginIP": "::ffff:x.x.x.x"
10187e984c8SSushil Singh    #       }
10287e984c8SSushil Singh    #     },
10387e984c8SSushil Singh    #   "UserName": "root"
10487e984c8SSushil Singh    # }
10587e984c8SSushil Singh
10687e984c8SSushil Singh    FOR  ${client}  ${session}  IN ZIP  ${client_id}  ${session_ids}
10787e984c8SSushil Singh      ${session_resp}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions/${session["SessionIDs"]}
10887e984c8SSushil Singh      Rprint Vars  session_resp
10987e984c8SSushil Singh      @{words} =  Split String  ${session_resp["ClientOriginIPAddress"]}  :
11087e984c8SSushil Singh      ${ip_address}=  Get Running System IP
11187e984c8SSushil Singh      Set Test Variable  ${temp_ipaddr}  ${words}[-1]
11287e984c8SSushil Singh      Valid Value  client  ['${session_resp["Oem"]["OpenBMC"]["ClientID"]}']
11387e984c8SSushil Singh      Valid Value  session["SessionIDs"]  ['${session_resp["Id"]}']
11487e984c8SSushil Singh      Valid Value  temp_ipaddr  ${ip_address}
11587e984c8SSushil Singh    END
11687e984c8SSushil Singh
11787e984c8SSushil Singh
118d03f2ce1SSushil SinghGet Lock Resource Information
119d03f2ce1SSushil Singh    [Documentation]  Get lock resource information.
120d03f2ce1SSushil Singh
121d03f2ce1SSushil Singh    ${code_base_dir_path}=  Get Code Base Dir Path
122d03f2ce1SSushil Singh    ${resource_lock_json}=  Evaluate
123d03f2ce1SSushil Singh    ...  json.load(open('${code_base_dir_path}data/resource_lock_table.json'))  modules=json
124d03f2ce1SSushil Singh    Rprint Vars  resource_lock_json
125d03f2ce1SSushil Singh
126d03f2ce1SSushil Singh    [Return]  ${resource_lock_json}
127