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