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