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