1*** Settings ***
2Documentation    Management console utilities keywords.
3
4Resource         ../../lib/bmc_redfish_utils.robot
5Resource         ../../lib/common_utils.robot
6Library          ../../lib/gen_robot_valid.py
7Library          Collections
8Library          ../../lib/bmc_ssh_utils.py
9Library          SSHLibrary
10
11*** Variables ***
12&{daemon_command}  start=systemctl start avahi-daemon
13                  ...  stop=systemctl stop avahi-daemon
14                  ...  status=systemctl status avahi-daemon -l
15&{daemon_message}  start=Active: active (running)
16                  ...  stop=Active: inactive (dead)
17
18*** Keywords ***
19
20Set AvahiDaemon Service
21    [Documentation]  To enable or disable avahi service.
22    [Arguments]  ${command}
23
24    # Description of argument(s):
25    # command  Get command from dictionary.
26
27    ${service_command}=  Get From Dictionary  ${daemon_command}  ${command}
28    ${resp}  ${stderr}  ${rc}=  BMC Execute Command  ${service_command}  print_out=1
29    Should Be Equal As Integers  ${rc}  0
30
31
32Verify AvahiDaemon Service Status
33    [Documentation]  To check for avahi service.
34    [Arguments]  ${message}
35
36    # Description of argument(s):
37    # message  Get status message from dictionary.
38
39    ${service_command}=  Get From Dictionary  ${daemon_command}  status
40    ${service_message}=  Get From Dictionary  ${daemon_message}  ${message}
41    ${resp}  ${stderr}  ${rc}=  BMC Execute Command  ${service_command}  print_out=1
42    Should Contain  ${resp}  ${service_message}
43
44
45Create Session With ClientID
46    [Documentation]  Create redifish session with client id.
47    [Arguments]  ${client_id}
48
49    # Description of argument(s):
50    # client_id    This client id can contain string value
51    #              (e.g. 12345, "EXTERNAL-CLIENT").
52
53    ${session_info}=  Create Dictionary
54
55    ${session_resp}=  Redfish Login  kwargs="Context":"${client_id}"
56
57    Set To Dictionary  ${session_info}  SessionIDs  ${session_resp['Id']}
58    Set To Dictionary  ${session_info}  ClientID  ${session_resp["Context"]}
59    Set To Dictionary  ${session_info}  SessionToken  ${XAUTH_TOKEN}
60    Set To Dictionary  ${session_info}  SessionResp  ${session_resp}
61
62    [Return]  ${session_info}
63
64
65Create Session With List Of ClientID
66    [Documentation]  Create redifish session with client id.
67    [Arguments]  ${client_id}
68
69    # Description of argument(s):
70    # client_id    This client id can contain string value
71    #              (e.g. 12345, "EXTERNAL-CLIENT").
72
73    @{session_dict_list}=  Create List
74    &{session_dict}=  Create Dictionary
75
76    FOR  ${client}  IN  @{client_id}
77      ${session_dict}=  Create Session With ClientID  ${client}
78      Append To List  ${session_dict_list}  ${session_dict}
79    END
80
81    [Return]  ${session_dict_list}
82
83
84Verify A Session Created With ClientID
85    [Documentation]  Verify the session is created.
86    [Arguments]  ${client_id}  ${session_ids}
87
88    # Description of argument(s):
89    # client_id    External client name.
90    # session_id   This value is a session id.
91
92    # {
93    #   "@odata.id": "/redfish/v1/SessionService/Sessions/H8q2ZKucSJ",
94    #   "@odata.type": "#Session.v1_0_2.Session",
95    #   "Description": "Manager User Session",
96    #   "Id": "H8q2ZKucSJ",
97    #   "Name": "User Session",
98    #   "Oem": {
99    #   "OpenBMC": {
100    #  "@odata.type": "#OemSession.v1_0_0.Session",
101    #  "ClientID": "",
102    #  "ClientOriginIP": "::ffff:x.x.x.x"
103    #       }
104    #     },
105    #   "UserName": "root"
106    # }
107
108    FOR  ${client}  ${session}  IN ZIP  ${client_id}  ${session_ids}
109      ${session_resp}=  Redfish.Get Properties  /redfish/v1/SessionService/Sessions/${session["SessionIDs"]}
110      Rprint Vars  session_resp
111
112      ${ip_address}=  Get Running System IP
113
114      Set Test Variable  ${temp_ipaddr}  ${session_resp["ClientOriginIPAddress"]}
115      Valid Value  client  ['${session_resp["Context"]}']
116      Valid Value  session["SessionIDs"]  ['${session_resp["Id"]}']
117      Valid Value  temp_ipaddr  ${ip_address}
118    END
119
120
121Get Lock Resource Information
122    [Documentation]  Get lock resource information.
123
124    ${code_base_dir_path}=  Get Code Base Dir Path
125    ${resource_lock_json}=  Evaluate
126    ...  json.load(open('${code_base_dir_path}data/resource_lock_table.json'))  modules=json
127    Rprint Vars  resource_lock_json
128
129    [Return]  ${resource_lock_json}
130
131