xref: /openbmc/openbmc-test-automation/redfish/managers/test_multiple_interfaces_dhcp.robot (revision 94041a34a992d9b5f6418a43e1cd5273a6d9f9b2)
1*** Settings ***
2Documentation   Test BMC DHCP multiple network interface functionalities.
3                ...  Run on setup eth0 in static and eth1 in DHCP.
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
10
11Suite Setup     Suite Setup Execution
12Test Teardown   FFDC On Test Case Fail
13Suite Teardown  Redfish.Logout
14
15Test Tags       Multiple_Interfaces_DHCP
16
17*** Variables ***
18
19&{DHCP_ENABLED}           DHCPEnabled=${True}
20&{DHCP_DISABLED}          DHCPEnabled=${False}
21&{ENABLE_DHCP}            DHCPv4=${DHCP_ENABLED}
22&{DISABLE_DHCP}           DHCPv4=${DHCP_DISABLED}
23${ethernet_interface}     eth1
24
25&{dns_enable_dict}                 UseDNSServers=${True}
26&{dns_disable_dict}                UseDNSServers=${False}
27&{ntp_enable_dict}                 UseNTPServers=${True}
28&{ntp_disable_dict}                UseNTPServers=${False}
29&{domain_name_enable_dict}         UseDomainName=${True}
30&{domain_name_disable_dict}        UseDomainName=${False}
31&{enable_multiple_properties}      UseDomainName=${True}
32...                                UseNTPServers=${True}
33...                                UseDNSServers=${True}
34&{disable_multiple_properties}     UseDomainName=${False}
35...                                UseNTPServers=${False}
36...                                UseDNSServers=${False}
37
38*** Test Cases ***
39
40Disable DHCP On Eth1 And Verify System Is Accessible By Eth0
41    [Documentation]  Disable DHCP on eth1 using Redfish and verify
42    ...              if system is accessible by eth0.
43    [Tags]  Disable_DHCP_On_Eth1_And_Verify_System_Is_Accessible_By_Eth0
44    [Teardown]  Set DHCPEnabled To Enable Or Disable  True  eth1
45
46    Set DHCPEnabled To Enable Or Disable  False  eth1
47    ${DHCPEnabled}=  Get IPv4 DHCP Enabled Status  ${2}
48    Should Be Equal  ${DHCPEnabled}  ${False}
49    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
50
51Enable DHCP On Eth1 And Verify System Is Accessible By Eth0
52    [Documentation]  Enable DHCP on eth1 using Redfish and verify if system
53    ...              is accessible by eth0.
54    [Tags]  Enable_DHCP_On_Eth1_And_Verify_System_Is_Accessible_By_Eth0
55    [Setup]  Set DHCPEnabled To Enable Or Disable  False  eth1
56
57    Set DHCPEnabled To Enable Or Disable  True  eth1
58    ${DHCPEnabled}=  Get IPv4 DHCP Enabled Status  ${2}
59    Should Be Equal  ${DHCPEnabled}  ${True}
60    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
61
62Set Network Property via Redfish And Verify
63   [Documentation]  Set network property via Redfish and verify.
64   [Tags]  Set_Network_Property_via_Redfish_And_Verify
65   [Template]  Apply DHCP Config
66
67    # property
68    ${dns_enable_dict}
69    ${dns_disable_dict}
70    ${domain_name_enable_dict}
71    ${domain_name_disable_dict}
72    ${ntp_enable_dict}
73    ${ntp_disable_dict}
74    ${enable_multiple_properties}
75    ${disable_multiple_properties}
76
77Set Network Property For DHCPv6 via Redfish And Verify
78   [Documentation]  Set network property for DHCPv6 via Redfish and verify.
79   [Tags]  Set_Network_Property_For_DHCPv6_via_Redfish_And_Verify
80   [Template]  Apply DHCPv6 Config And Verify
81
82    # property
83    ${dns_enable_dict}
84    ${dns_disable_dict}
85    ${domain_name_enable_dict}
86    ${domain_name_disable_dict}
87    ${ntp_enable_dict}
88    ${ntp_disable_dict}
89    ${enable_multiple_properties}
90    ${disable_multiple_properties}
91
92Enable DHCP On Eth1 And Check No Impact On Eth0
93    [Documentation]  Enable DHCP On Eth1 And Check No Impact On Eth0.
94    [Tags]  Enable_DHCP_On_Eth1_And_Check_No_Impact_On_Eth0
95    [Setup]  Set DHCPEnabled To Enable Or Disable  False  eth1
96
97    # Getting the eth0 details before enabling DHCP.
98    ${ip_data_before}=  Get BMC IP Info
99
100    # Enable DHCP on eth1.
101    Set DHCPEnabled To Enable Or Disable  True  eth1
102
103    # Check the value of DHCPEnabled on eth0 is not impacted.
104    ${DHCPEnabled}=  Get IPv4 DHCP Enabled Status  ${1}
105    Should Be Equal  ${DHCPEnabled}  ${False}
106
107    # Getting eth0 details after enabling DHCP.
108    ${ip_data_after}=  Get BMC IP Info
109
110    # Before and after IP details must match.
111    Should Be Equal  ${ip_data_before}  ${ip_data_after}
112
113Enable DHCP On Eth1 And Check Persistency On Reboot
114    [Documentation]  Enable DHCP on Eth1 and check persistency
115    ...  on reboot and should not switch to static.
116    [Tags]  Enable_DHCP_On_Eth1_And_Check_Persistency_On_Reboot
117    [Setup]  Set DHCPEnabled To Enable Or Disable  False  eth1
118
119    Set DHCPEnabled To Enable Or Disable  True  eth1
120    Redfish OBMC Reboot (off)  stack_mode=skip
121    ${DHCPEnabled}=  Get IPv4 DHCP Enabled Status  ${2}
122    Should Be Equal  ${DHCPEnabled}  ${True}
123
124Switch Between DHCP And Static
125    [Documentation]  Switch between DHCP and static.
126    [Tags]  Switch_Between_DHCP_And_Static
127    [Teardown]  Set DHCPEnabled To Enable Or Disable  True  eth1
128
129    # Fetch the IP details before.
130    ${ip_addr_before}  ${gateway_before}  ${subnetmask_before}  Get DHCP IP Info
131
132    # Switch Between Static and DHCP.
133    FOR  ${i}  IN RANGE  ${10}
134      Set DHCPEnabled To Enable Or Disable  False  eth1
135      Set DHCPEnabled To Enable Or Disable  True  eth1
136    END
137    Sleep  5s
138
139    # Fetch the IP details after.
140    ${ip_addr_after}  ${gateway_after}  ${subnetmask_after}  Get DHCP IP Info
141
142    # DHCP Details must be the same before and after.
143    Should Be Equal  ${ip_addr_before}  ${ip_addr_after}
144    Should Be Equal  ${gateway_before}  ${gateway_after}
145    Should Be Equal  ${subnetmask_before}  ${subnetmask_after}
146
147Disable DHCP On Eth1 And Verify DHCP IP Erased
148    [Documentation]  Disable DHCP on Eth1 and verify DHCP IP erased.
149    [Tags]  Disable_DHCP_On_Eth1_And_Verify_DHCP_IP_Erased
150    [Teardown]  Set DHCPEnabled To Enable Or Disable  True  eth1
151
152    Set DHCPEnabled To Enable Or Disable  False  eth1
153    ${DHCPEnabled}=  Get IPv4 DHCP Enabled Status  ${2}
154    Should Be Equal  ${DHCPEnabled}  ${False}
155
156    ${dhcp_ip_list}=  Get Network Configuration Using Channel Number  ${2}
157
158    Should Be Empty  ${dhcp_ip_list}
159    ...  msg=From switching from DHCP to Static DHCP IP is not erased.
160
161*** Keywords ***
162
163Set DHCPEnabled To Enable Or Disable
164    [Documentation]  Enable or Disable DHCP on the interface.
165    [Arguments]  ${dhcp_enabled}=${False}  ${interface}=${ethernet_interface}
166    ...          ${valid_status_code}=[${HTTP_OK},${HTTP_ACCEPTED},${HTTP_NO_CONTENT}]
167
168    # Description of argument(s):
169    # dhcp_enabled        False for disabling DHCP and True for Enabling DHCP.
170    # interface           eth0 or eth1. Default is eth1.
171    # valid_status_code   Expected valid status code from Patch request.
172    #                     Default is HTTP_OK.
173
174    ${data}=  Set Variable If  ${dhcp_enabled} == ${False}  ${DISABLE_DHCP}  ${ENABLE_DHCP}
175    ${resp}=  Redfish.Patch
176    ...  /redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/${interface}
177    ...  body=${data}  valid_status_codes=${valid_status_code}
178
179Apply DHCP Config
180    [Documentation]  Apply DHCP Config
181    [Arguments]  ${property}
182
183    # Description of Argument(s):
184    # property  DHCP property values.
185
186    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
187    ...  body={"DHCPv4":${property}}  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
188
189    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
190    Verify Ethernet Config Property  ${property}  ${resp.dict["DHCPv4"]}
191
192Apply DHCPv6 Config And Verify
193    [Documentation]  Apply DHCPv6 config and verify.
194    [Arguments]  ${property}
195
196    # Description of Argument(s):
197    # property  DHCPv6 property values.
198
199    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
200    ...  body={"DHCPv6":${property}}  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
201    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
202
203    Verify Ethernet Config Property  ${property}  ${resp.dict["DHCPv6"]}
204
205Verify Ethernet Config Property
206    [Documentation]  verify ethernet config properties.
207    [Arguments]  ${property}  ${response_data}
208
209    # Description of argument(s):
210    # property         DHCP Properties in dictionary.
211    #   Example:
212    #   property         value
213    #   DHCPEnabled      :False
214    #   UseDomainName    :True
215    #   UseNTPServers    :True
216    #   UseDNSServers    :True
217    # response_data    DHCP Response data in dictionary.
218    #   Example:
219    #   property         value
220    #   DHCPEnabled      :False
221    #   UseDomainName    :True
222    #   UseNTPServers    :True
223    #   UseDNSServers    :True
224
225   ${key_map}=  Get Dictionary Items  ${property}
226   FOR  ${key}  ${value}  IN  @{key_map}
227      Should Be Equal As Strings  ${response_data['${key}']}  ${value}
228   END
229
230Restore Configuration
231    [Documentation]  Restore the configuration to Both Static Network
232
233    IF  '${CHANNEL_NUMBER}' == '${1}'
234        Add IP Address  ${OPENBMC_HOST}  ${eth0_subnet_mask}  ${eth0_gateway}
235    ELSE IF  '${CHANNEL_NUMBER}' == '{2}'
236        Add IP Address  ${OPENBMC_HOST_ETH1}  ${eth1_subnet_mask}  ${eth1_gateway}
237    END
238
239Get Network Configuration Using Channel Number
240    [Documentation]  Get ethernet interface.
241    [Arguments]  ${channel_number}
242
243    # Description of argument(s):
244    # channel_number   Ethernet channel number, 1 is for eth0 and 2 is for eth1 (e.g. "1").
245
246    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
247
248    @{network_configurations}=  Get From Dictionary  ${resp.dict}  IPv4StaticAddresses
249    RETURN  @{network_configurations}
250
251Suite Setup Execution
252    [Documentation]  Do suite setup task.
253
254    Ping Host  ${OPENBMC_HOST}
255    Redfish.Login
256
257    ${active_channel_config}=  Get Active Channel Config
258    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
259
260    # Get the configuration of eth1
261    ${network_configurations}=  Get Network Configuration Using Channel Number  ${2}
262    FOR  ${network_configuration}  IN  @{network_configurations}
263        IF  '${network_configuration['Address']}' == '${OPENBMC_HOST_ETH1}'
264            Set Suite Variable  ${eth1_subnet_mask}  ${network_configuration['SubnetMask']}
265            Set Suite Variable  ${eth1_gateway}  ${network_configuration['Gateway']}
266            BREAK
267        END
268    END
269
270    # Get the configuration of eth0
271    ${network_configurations}=  Get Network Configuration Using Channel Number  ${1}
272    FOR  ${network_configuration}  IN  @{network_configurations}
273        IF  '${network_configuration['Address']}' == '${OPENBMC_HOST}'
274            Set Suite Variable  ${eth0_subnet_mask}  ${network_configuration['SubnetMask']}
275            Set Suite Variable  ${eth0_gateway}  ${network_configuration['Gateway']}
276            BREAK
277        END
278    END
279