1*** Settings ***
2Documentation        Test to discover the BMC. Before running suit,
3...                  check BMC and Avahi browse machine should be in same subnet.
4
5Variables            ../../data/variables.py
6Library              SSHLibrary
7Library              ../../lib/external_intf/management_console_utils.py
8Library              ../../lib/gen_robot_print.py
9Library              ../../lib/gen_print.py
10Library              ../../lib/gen_misc.py
11Resource             ../../lib/external_intf/management_console_utils.robot
12Resource             ../../lib/redfish_code_update_utils.robot
13Resource             ../../lib/boot_utils.robot
14Resource             ../../lib/os_utilities.robot
15Resource             ../../lib/code_update_utils.robot
16
17Suite Setup          Suite Setup Execution
18Suite Teardown       Redfish.Logout
19Test Setup           Printn
20Test Teardown        FFDC On Test Case Fail
21
22*** Test Cases ***
23
24Discover BMC With Different Service Type
25    [Documentation]  Discover all the BMC with different service type support.
26    [Tags]  Discover_BMC_With_Different_Service_Type
27    [Template]  Discover BMC With Service Type
28
29    # Service type
30    _obmc_rest._tcp
31    _obmc_redfish._tcp
32
33
34Discover BMC Pre And Post Reboot
35    [Documentation]  Discover BMC before and after reboot.
36    [Tags]  Discover_BMC_Pre_And_Post_Reboot
37    [Template]  Set Daemon And Discover BMC After Reboot
38
39    # Service type
40    _obmc_rest._tcp
41    _obmc_redfish._tcp
42
43
44Disable AvahiDaemon And Discover BMC After Reboot
45    [Documentation]  BMC should be discoverable in next reboot even after disabling Avahi daemon.
46    [Tags]  Disable_AvahiDaemon_And_Discover_BMC_After_Reboot
47    [Template]  Set Daemon And Discover BMC After Reboot
48
49    # Service type       skip
50    _obmc_rest._tcp      True
51    _obmc_redfish._tcp   True
52
53
54Discover BMC Pre And Post Firmware Update Of Same Release
55    [Documentation]  Discover BMC, when firmware update occurs for same release.
56    [Tags]  Discover_BMC_Pre_And_Post_Firmware_Update_Of_Same_Release
57    [Template]  Discover BMC Pre And Post Firmware Update
58
59    # Service type   Service type        status
60    _obmc_rest._tcp  _obmc_redfish._tcp  True
61
62
63Discover BMC Pre And Post Firmware Update Of Different Release
64    [Documentation]  Discover BMC, when firmware update occurs for different release.
65    [Tags]  Discover_BMC_Pre_And_Post_Firmware_Update_Of_Different_Release
66    [Template]  Discover BMC Pre And Post Firmware Update
67
68    # Service type   Service type        status
69    _obmc_rest._tcp  _obmc_redfish._tcp  True
70
71
72Discover BMC Fail After Firmware Update Of Different Release
73    [Documentation]  Discover BMC fail, when firmware update occurs for different release.
74    [Tags]  Discover_BMC_Fail_After_Firmware_Update_Of_Different_Release
75    [Template]  Discover BMC Pre And Post Firmware Update
76
77    # Service type   Service type        status
78    _obmc_rest._tcp  _obmc_redfish._tcp  False
79
80
81Discover BMC Pre And Post When Host Boot InProgress
82    [Documentation]  Discover BMC, when Host boot in progress.
83    [Tags]  Discover_BMC_Pre_And_Post_When_Host_Boot_InProgress
84    [Template]  Discover BMC Pre And Post When Host Boot
85
86    # Service type   Service type
87    _obmc_rest._tcp  _obmc_redfish._tcp
88
89*** Keywords ***
90
91Suite Setup Execution
92    [Documentation]  Do the suite setup.
93
94    Should Not Be Empty  ${AVAHI_CLIENT}
95    Should Not Be Empty  ${AVAHI_CLIENT_USERNAME}
96    Should Not Be Empty  ${AVAHI_CLIENT_PASSWORD}
97    Login To OS  ${AVAHI_CLIENT}  ${AVAHI_CLIENT_USERNAME}  ${AVAHI_CLIENT_PASSWORD}
98    Check Avahi Package
99    Redfish.Login
100
101
102Check Avahi Package
103    [Documentation]  To check for avahi-tools package.
104
105    # Expected command output as below.
106    # avahi-tools-0.6.31-19.el7.x86_64
107
108    ${command}=  Set Variable  rpm -qa | grep avahi-tools
109    ${resp_rpm}  ${stderr}=  Execute Command  ${command}  return_stderr=True
110    Should Be Empty  ${stderr}
111    Should Contain  ${resp_rpm}  avahi-tools  ignore_case=True  msg=avahi-tools is not available.
112
113
114Discover BMC With Service Type
115    [Documentation]  To get the discoverd BMC list.
116    [Arguments]  ${service_type}
117
118    # Description of argument(s):
119    # service_type  BMC service type e.g.
120    #               (REST Service = _obmc_rest._tcp, Redfish Service = _obmc_redfish._tcp).
121
122    # bmc_list:
123    # [1]:
124    #    [service]:          _obmc_XXXX._tcp
125    #    [hostname]:         System Name
126    #    [address]:          XXX.XXX.XXX.XXX
127    #    [port]:             XXX
128    #    [txt]:
129    # [2]:
130    #    [service]:          _obmc_XXXX._tcp
131    #    [hostname]:         System Name
132    #    [address]:          XXX.XXX.XXX.XXX
133    #    [port]:             XXX
134    #    [txt]:
135
136    ${resp_service}  ${stderr}=  Execute Command  avahi-browse -rt ${service_type}  return_stderr=True
137    ${bmc_list}  ${exc_msg}=  Get BMC Records  ${service_type}  ${resp_service}
138    Print Timen  Exception message is ${exc_msg}
139    Should Not Be Empty  ${bmc_list}
140    Rprint Vars  bmc_list
141    RETURN  ${bmc_list}
142
143
144Verify Existence Of BMC Record From List
145    [Documentation]  Verify the existence of BMC record from list of BMC records.
146    [Arguments]  ${service_type}
147
148    # Description of argument(s):
149    # service_type  BMC service type e.g.
150    #               (REST Service = _obmc_rest._tcp, Redfish Service = _obmc_redfish._tcp).
151
152    ${bmc_list}=  Discover BMC With Service Type  ${service_type}
153    ${openbmc_host_name}  ${openbmc_ip}=  Get Host Name IP  host=${OPENBMC_HOST}
154    ${resp}=  Check BMC Record Exists  ${bmc_list}  ${openbmc_ip}
155    Should Be True  'True' == '${resp}'
156
157
158Set Daemon And Discover BMC After Reboot
159    [Documentation]  Discover BMC After reboot.
160    [Arguments]  ${service_type}  ${skip}=False
161
162    # Description of argument(s):
163    # service_type  BMC service type e.g.
164    #               (REST Service = _obmc_rest._tcp, Redfish Service = _obmc_redfish._tcp).
165    # skip          Default value set to False.
166    #               If the value is True, Disable the AvahiDaemon.
167    #               If the value is False, skip the step to disable the AvahiDaemon.
168
169    Verify Existence Of BMC Record From List  ${service_type}
170    Run Keyword If  '${skip}' == 'True'  Set AvahiDaemon Service  command=stop
171    Redfish OBMC Reboot (off)
172    Verify AvahiDaemon Service Status  message=start
173    Login To OS  ${AVAHI_CLIENT}  ${AVAHI_CLIENT_USERNAME}  ${AVAHI_CLIENT_PASSWORD}
174    Wait Until Keyword Succeeds  2 min  30 sec
175    ...  Verify Existence Of BMC Record From List  ${service_type}
176
177
178Redfish Update Firmware
179    [Documentation]  Update the BMC firmware via redfish interface and verify the bmc version
180    ...              and apply time.
181    [Arguments]  ${apply_time}
182
183    # Description of argument(s):
184    # apply_time    ApplyTime allowed values (e.g. "OnReset", "Immediate").
185
186    ${post_code_update_actions}=  Get Post Boot Action
187    ${state}=  Get Pre Reboot State
188    Rprint Vars  state
189    Set ApplyTime  policy=${apply_Time}
190    Redfish Upload Image And Check Progress State
191    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
192    Redfish.Login
193    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
194    Verify Get ApplyTime  ${apply_time}
195
196
197Discover BMC Pre And Post Firmware Update
198    [Documentation]  Discover BMC, After code update.
199    [Arguments]  ${service_type1}  ${service_type2}  ${status}
200
201    # Description of argument(s):
202    # service_type     BMC service type e.g.
203    #                  (REST Service = _obmc_rest._tcp, Redfish Service = _obmc_redfish._tcp).
204    # status           True or False
205
206    Valid File Path  IMAGE_FILE_PATH
207    Verify Existence Of BMC Record From List  ${service_type1}
208    Verify Existence Of BMC Record From List  ${service_type2}
209    Redfish Update Firmware  apply_time=Immediate
210    ${keyword_status}=  Run Keyword And Return Status
211    ...  Verify Existence Of BMC Record From List  ${service_type1}
212    Should Be Equal  '${status}'  '${keyword_status}'
213    ${keyword_status}=  Run Keyword And Return Status
214    ...  Verify Existence Of BMC Record From List  ${service_type2}
215    Should Be Equal  '${status}'  '${keyword_status}'
216
217
218Discover BMC Pre And Post When Host Boot
219    [Documentation]  Discover BMC, when host boot in progress.
220    [Arguments]  ${service_type1}  ${service_type2}
221
222    # Description of argument(s):
223    # service_type     BMC service type e.g.
224    #                  (REST Service = _obmc_rest._tcp, Redfish Service = _obmc_redfish._tcp).
225
226    Verify Existence Of BMC Record From List  ${service_type1}
227    Verify Existence Of BMC Record From List  ${service_type2}
228    Redfish Power Off  stack_mode=skip
229    Get Host Power State
230    Redfish Power Operation  reset_type=On
231    Sleep  15s
232    Login To OS  ${AVAHI_CLIENT}  ${AVAHI_CLIENT_USERNAME}  ${AVAHI_CLIENT_PASSWORD}
233    FOR  ${index}  IN RANGE  10
234        Sleep  3s
235        Verify Existence Of BMC Record From List  ${service_type1}
236        Verify Existence Of BMC Record From List  ${service_type2}
237    END
238    Wait Until Keyword Succeeds  10 min  10 sec  Is OS Booted
239