1*** Settings ***
2Documentation   Test BMC multiple network interface functionalities.
3...             Run on setup with both eth0 and eth1 in static mode.
4
5# User input BMC IP for the eth1.
6# Use can input as  -v OPENBMC_HOST_1:xx.xxx.xx from command line.
7Library         ../../lib/bmc_redfish.py  https://${OPENBMC_HOST_1}:${HTTPS_PORT}
8...             ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}  WITH NAME  Redfish1
9
10Resource        ../../lib/resource.robot
11Resource        ../../lib/common_utils.robot
12Resource        ../../lib/connection_client.robot
13Resource        ../../lib/bmc_network_utils.robot
14Resource        ../../lib/openbmc_ffdc.robot
15Resource        ../../lib/bmc_ldap_utils.robot
16Resource        ../../lib/snmp/resource.robot
17Resource        ../../lib/snmp/redfish_snmp_utils.robot
18Resource        ../../lib/certificate_utils.robot
19Resource         ../../lib/protocol_setting_utils.robot
20Library         ../../lib/jobs_processing.py
21Library         OperatingSystem
22
23Suite Setup     Suite Setup Execution
24Test Setup      Run Keywords  Redfish.Login  AND  Redfish1.Login
25Test Teardown   Run Keywords  FFDC On Test Case Fail  AND  Redfish.Logout  AND  Redfish1.Logout
26Suite Teardown  Run Keywords  Redfish1.Logout  AND  Redfish.Logout
27
28*** Variables ***
29
30${cmd_prefix}  ipmitool -I lanplus -C 17 -p 623 -U ${IPMI_USERNAME} -P ${IPMI_PASSWORD}
31${test_ipv4_addr}     10.7.7.7
32${test_ipv4_addr2}    10.7.7.8
33${test_subnet_mask}   255.255.255.0
34
35*** Test Cases ***
36
37Verify Both Interfaces BMC IP Addresses Accessible Via SSH
38    [Documentation]  Verify both interfaces (eth0, eth1) BMC IP addresses accessible via SSH.
39    [Tags]  Verify_Both_Interfaces_BMC_IP_Addresses_Accessible_Via_SSH
40
41    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}  host=${OPENBMC_HOST}
42    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}  host=${OPENBMC_HOST_1}
43    Close All Connections
44
45
46Verify Redfish Works On Both Interfaces
47    [Documentation]  Verify access BMC with both interfaces (eth0, eth1) IP addresses via Redfish.
48    [Tags]  Verify_Redfish_Works_On_Both_Interfaces
49    [Teardown]  Run Keywords
50    ...  Configure Hostname  ${hostname}  AND  Validate Hostname On BMC  ${hostname}
51
52    ${hostname}=  Redfish.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  HostName
53    ${data}=  Create Dictionary  HostName=openbmc
54    Redfish1.patch  ${REDFISH_NW_ETH_IFACE}eth1  body=&{data}
55    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
56
57    Validate Hostname On BMC  openbmc
58
59    ${resp1}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}eth0
60    ${resp2}=  Redfish1.Get  ${REDFISH_NW_ETH_IFACE}eth1
61    Should Be Equal  ${resp1.dict['HostName']}  ${resp2.dict['HostName']}
62
63
64Verify LDAP Login Works When Eth1 IP Is Not Configured
65    [Documentation]  Verify LDAP login works when eth1 IP is erased.
66    [Tags]  Verify_LDAP_Login_Works_When_Eth1_IP_Is_Not_Configured
67    [Setup]  Run Keywords  Set Test Variable  ${CHANNEL_NUMBER}  ${SECONDARY_CHANNEL_NUMBER}
68    ...  AND  Redfish.Login  AND  Delete IP Address  ${OPENBMC_HOST_1}
69    [Teardown]  Run Keywords  Redfish.Logout  AND  Redfish.Login  AND
70    ...  Add IP Address  ${OPENBMC_HOST_1}  ${eth1_subnet_mask}  ${eth1_gateway}
71
72    Create LDAP Configuration
73    Redfish.Logout
74    Sleep   30
75    Redfish.Login  ${LDAP_USER}  ${LDAP_USER_PASSWORD}
76
77
78Verify LDAP Login Works When Both Interfaces Are Configured
79    [Documentation]  Verify LDAP login works when both interfaces are configured.
80    [Tags]  Verify_LDAP_Login_Works_When_Both_Interfaces_Are_Configured
81
82    Create LDAP Configuration
83    Redfish.Logout
84    Sleep   30
85    Redfish.Login  ${LDAP_USER}  ${LDAP_USER_PASSWORD}
86
87
88Verify Secure LDAP Login Works When Both Interfaces Are Configured
89    [Documentation]  Verify Secure LDAP login works when both the interfaces are configured.
90    [Tags]  Verify_Secure_LDAP_Login_Works_When_Both_Interfaces_Are_Configured
91
92    Create LDAP Configuration  ${LDAP_TYPE}  ${LDAP_SERVER_URI_1}  ${LDAP_BIND_DN}
93    ...  ${LDAP_BIND_DN_PASSWORD}  ${LDAP_BASE_DN}
94    Redfish.Logout
95    Sleep   30
96    Redfish.Login  ${LDAP_USER}  ${LDAP_USER_PASSWORD}
97
98
99Verify SNMP Works When Eth1 IP Is Not Configured
100    [Documentation]  Verify SNMP works when eth1 IP is not configured.
101    [Tags]  Verify_SNMP_Works_When_Eth1_IP_Is_Not_Configured
102    [Setup]  Run Keywords  Redfish.Login  AND
103    ...  Set Test Variable  ${CHANNEL_NUMBER}  ${SECONDARY_CHANNEL_NUMBER}
104    ...  AND  Delete IP Address  ${OPENBMC_HOST_1}
105    [Teardown]  Add IP Address  ${OPENBMC_HOST_1}  ${eth1_subnet_mask}  ${eth1_gateway}
106
107    Create Error On BMC And Verify Trap
108
109
110Disable And Enable Eth0 Interface
111    [Documentation]  Disable and Enable eth0 ethernet interface via redfish.
112    [Tags]  Disable_And_Enable_Eth0_Interface
113    [Template]  Set BMC Ethernet Interfaces State
114
115    # interface_ip   interface  enabled
116    ${OPENBMC_HOST}   eth0      ${False}
117    ${OPENBMC_HOST}   eth0      ${True}
118
119
120Verify Both Interfaces Access Concurrently Via Redfish
121    [Documentation]  Verify both interfaces access conurrently via redfish.
122    [Tags]  Verify_Both_Interfaces_Access_Concurrently_Via_Redfish
123
124    ${dict}=  Execute Process Multi Keyword  ${2}
125    ...  Redfish.patch ${REDFISH_NW_ETH_IFACE}eth0 body={'DHCPv4':{'UseDNSServers':${True}}}
126    ...  Redfish1.patch ${REDFISH_NW_ETH_IFACE}eth1 body={'DHCPv4':{'UseDNSServers':${True}}}
127
128    Dictionary Should Not Contain Value  ${dict}  False
129    ...  msg=One or more operations has failed.
130
131    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}eth0
132    ${resp1}=  Redfish1.Get  ${REDFISH_NW_ETH_IFACE}eth1
133
134    Should Be Equal  ${resp.dict["DHCPv4"]['UseDNSServers']}  ${True}
135    Should Be Equal  ${resp1.dict["DHCPv4"]['UseDNSServers']}  ${True}
136
137Able To Access Serial Console Via Both Network Interfaces
138    [Documentation]  Able to access serial console via both network interfaces.
139    [Tags]  Able_To_Access_Serial_Console_Via_Both_Network_Interfaces
140
141    Open Connection And Log In  host=${OPENBMC_HOST}  port=2200
142    Open Connection And Log In  host=${OPENBMC_HOST_1}  port=2200
143    Close All Connections
144
145Verify IPMI Works On Both Network Interfaces
146    [Documentation]  Verify IPMI works on both network interfaces.
147    [Tags]  Verify_IPMI_Works_On_Both_Network_Interfaces
148
149    Run IPMI  ${OPENBMC_HOST_1}  power on
150    ${status1}=  Run IPMI  ${OPENBMC_HOST}  power status
151    ${status2}=  Run IPMI  ${OPENBMC_HOST_1}  power status
152    Should Be Equal  ${status1}  ${status2}
153
154Verify Modifying IP Address Multiple Times On Interface
155    [Documentation]  Verify modifying IP address multiple times on interface.
156    [Tags]  Verify_Modifying_IP_Address_Multiple_Times_On_Interface
157    [Teardown]  Run Keywords
158    ...  Delete IP Address  ${test_ipv4_addr}  AND  Redfish.Logout
159
160    ${test_gateway}=  Get BMC Default Gateway
161    Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
162    Update IP Address  ${test_ipv4_addr}  ${test_ipv4_addr2}  ${test_subnet_mask}  ${test_gateway}
163    Update IP Address  ${test_ipv4_addr2}  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
164    Run Keyword  Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
165    Run Keyword  Wait For Host To Ping  ${OPENBMC_HOST_1}  ${NETWORK_TIMEOUT}
166
167Verify Able To Load Certificates Via Eth1 IP Address
168    [Documentation]  Verify able to load certificates via eth1 IP address.
169    [Tags]  Verify_Able_To_Load_Certificates_Via_Eth1_IP_Address
170    [Template]  Install Certificate Via Redfish And Verify
171
172    # cert_type  cert_format                         expected_status
173    CA           Valid Certificate                   ok
174    Client       Valid Certificate Valid Privatekey  ok
175
176Enable SSH Protocol Via Eth1 And Verify On Both Interfaces
177    [Documentation]  Enable SSH protocol via eth1 and verify on both interfaces.
178    [Tags]  Enable_SSH_Protocol_Via_Eth1_And_Verify_On_Both_Interfaces
179
180    Set SSH Value Via Eth1  ${True}
181    # Check if SSH is really enabled via Redfish via eth1.
182    Verify SSH Protocol State Via Eth1  ${True}
183    # Check if SSH login and commands on SSH session work on both interfaces.
184    Verify SSH Login And Commands Work
185    Verify SSH Login And Commands Work  ${OPENBMC_HOST_1}
186
187Disable SSH Protocol Via Eth1 And Verify On Both Interfaces
188    [Documentation]  Disable SSH protocol via eth1 and verify on both interfaces.
189    [Tags]  Disable_SSH_Protocol_Via_Eth1_And_Verify_On_Both_Interfaces
190    [Teardown]  Set SSH Value Via Eth1  ${True}
191
192    Set SSH Value Via Eth1  ${False}
193    # Check if SSH is really disabled via Redfish via eth1.
194    Verify SSH Protocol State Via Eth1  ${False}
195    # Check if SSH login and commands fail on eth1.
196    ${status}=  Run Keyword And Return Status
197    ...  Verify SSH Login And Commands Work  ${OPENBMC_HOST_1}
198
199    Should Be Equal As Strings  ${status}  False
200    ...  msg=SSH Login and commands are working after disabling SSH via eth1.
201
202    # Check if SSH login and commands fail.
203    ${status}=  Run Keyword And Return Status
204    ...  Verify SSH Login And Commands Work
205
206    Should Be Equal As Strings  ${status}  False
207    ...  msg=SSH Login and commands are working after disabling SSH.
208
209*** Keywords ***
210
211Get Network Configuration Using Channel Number
212    [Documentation]  Get ethernet interface.
213    [Arguments]  ${channel_number}
214
215    # Description of argument(s):
216    # channel_number   Ethernet channel number, 1 is for eth0 and 2 is for eth1 (e.g. "1").
217
218    ${active_channel_config}=  Get Active Channel Config
219    ${ethernet_interface}=  Set Variable  ${active_channel_config['${channel_number}']['name']}
220    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
221
222    @{network_configurations}=  Get From Dictionary  ${resp.dict}  IPv4StaticAddresses
223    RETURN  @{network_configurations}
224
225
226Suite Setup Execution
227    [Documentation]  Do suite setup task.
228
229    Valid Value  OPENBMC_HOST_1
230
231    # Check both interfaces are configured and reachable.
232    Ping Host  ${OPENBMC_HOST}
233    Ping Host  ${OPENBMC_HOST_1}
234
235    ${network_configurations}=  Get Network Configuration Using Channel Number  ${SECONDARY_CHANNEL_NUMBER}
236    FOR  ${network_configuration}  IN  @{network_configurations}
237
238      Run Keyword If  '${network_configuration['Address']}' == '${OPENBMC_HOST_1}'
239      ...  Run Keywords  Set Suite Variable  ${eth1_subnet_mask}  ${network_configuration['SubnetMask']}
240      ...  AND  Set Suite Variable  ${eth1_gateway}  ${network_configuration['Gateway']}
241      ...  AND  Exit For Loop
242
243    END
244
245
246Set BMC Ethernet Interfaces State
247    [Documentation]  Set BMC ethernet interface state.
248    [Arguments]  ${interface_ip}  ${interface}  ${enabled}
249    [Teardown]  Redfish1.Logout
250
251    # Description of argument(s):
252    # interface_ip    IP address of ethernet interface.
253    # interface       The ethernet interface name (eg. eth0 or eth1).
254    # enabled         Indicates interface should be enabled (eg. True or False).
255
256    Redfish1.Login
257
258    ${data}=  Create Dictionary  InterfaceEnabled=${enabled}
259
260    Redfish1.patch  ${REDFISH_NW_ETH_IFACE}${interface}  body=&{data}
261    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
262
263    Sleep  ${NETWORK_TIMEOUT}s
264    ${interface_status}=   Redfish1.Get Attribute  ${REDFISH_NW_ETH_IFACE}${interface}  InterfaceEnabled
265    Should Be Equal  ${interface_status}  ${enabled}
266
267    ${status}=  Run Keyword And Return Status  Ping Host  ${interface_ip}
268
269    Run Keyword If  ${enabled} == ${True}  Should Be Equal  ${status}  ${True}
270    ...  ELSE  Should Be Equal  ${status}  ${False}
271
272
273Run IPMI
274    [Documentation]  Run IPMI command.
275    [Arguments]  ${host}  ${sub_cmd}
276
277    # Description of argument(s):
278    # host         BMC host name or IP address.
279    # sub_cmd      The IPMI command string to be executed.
280
281    ${rc}  ${output}=  Run And Return Rc And Output  ${cmd_prefix} -H ${host} ${sub_cmd}
282    Should Be Equal As Strings  ${rc}  0
283    RETURN  ${output}
284
285
286Install Certificate Via Redfish And Verify
287    [Documentation]  Install and verify certificate using Redfish.
288    [Arguments]  ${cert_type}  ${cert_format}  ${expected_status}  ${delete_cert}=${True}
289    [Teardown]  Remove Directory  certificate_dir  recursive=True
290
291    # Description of argument(s):
292    # cert_type           Certificate type (e.g. "Client" or "CA").
293    # cert_format         Certificate file format
294    #                     (e.g. "Valid_Certificate_Valid_Privatekey").
295    # expected_status     Expected status of certificate replace Redfish
296    #                     request (i.e. "ok" or "error").
297    # delete_cert         Certificate will be deleted before installing if this True.
298
299    Create Directory  certificate_dir
300    # AUTH_URI is a global variable defined in lib/resource.robot
301    Set Test Variable  ${AUTH_URI}  https://${OPENBMC_HOST_1}
302    Run Keyword If  '${cert_type}' == 'CA' and '${delete_cert}' == '${True}'
303    ...  Delete All CA Certificate Via Redfish
304    ...  ELSE IF  '${cert_type}' == 'Client' and '${delete_cert}' == '${True}'
305    ...  Delete Certificate Via BMC CLI  ${cert_type}
306
307    ${cert_file_path}=  Generate Certificate File Via Openssl  ${cert_format}
308    ${bytes}=  OperatingSystem.Get Binary File  ${cert_file_path}
309    ${file_data}=  Decode Bytes To String  ${bytes}  UTF-8
310
311    ${certificate_uri}=  Set Variable If
312    ...  '${cert_type}' == 'Client'  ${REDFISH_LDAP_CERTIFICATE_URI}
313    ...  '${cert_type}' == 'CA'  ${REDFISH_CA_CERTIFICATE_URI}
314
315    ${cert_id}=  Install Certificate File On BMC  ${certificate_uri}  ${expected_status}  data=${file_data}
316    Logging  Installed certificate id: ${cert_id}
317
318    Sleep  30s
319    ${cert_file_content}=  OperatingSystem.Get File  ${cert_file_path}
320    ${bmc_cert_content}=  Run Keyword If  '${expected_status}' == 'ok'  redfish_utils.Get Attribute
321    ...  ${certificate_uri}/${cert_id}  CertificateString
322    Run Keyword If  '${expected_status}' == 'ok'  Should Contain  ${cert_file_content}  ${bmc_cert_content}
323    RETURN  ${cert_id}
324
325Set SSH Value Via Eth1
326    [Documentation]  Enable or disable SSH protocol via Eth1.
327    [Arguments]  ${enable_value}=${True}
328
329    # Description of argument(s}:
330    # enable_value  Enable or disable SSH, e.g. (true, false).
331
332    ${ssh_state}=  Create Dictionary  ProtocolEnabled=${enable_value}
333    ${data}=  Create Dictionary  SSH=${ssh_state}
334
335    Redfish1.Login
336    Redfish1.patch  ${REDFISH_NW_PROTOCOL_URI}  body=&{data}
337    ...  valid_status_codes=[${HTTP_NO_CONTENT}]
338
339    # Wait for timeout for new values to take effect.
340    Sleep  ${NETWORK_TIMEOUT}s
341
342Verify SSH Protocol State Via Eth1
343    [Documentation]  Verify SSH protocol state via eth1.
344    [Arguments]  ${state}=${True}
345
346    # Description of argument(s}:
347    # state  Enable or disable SSH, e.g. (true, false)
348
349    ${resp}=  Redfish1.Get  ${REDFISH_NW_PROTOCOL_URI}
350    Should Be Equal As Strings  ${resp.dict['SSH']['ProtocolEnabled']}  ${state}
351    ...  msg=Protocol states are not matching.
352