1*** Settings ***
2Documentation   Test BMC DHCP multiple network interface functionalities.
3
4Resource        ../../lib/resource.robot
5Resource        ../../lib/common_utils.robot
6Resource        ../../lib/connection_client.robot
7Resource        ../../lib/bmc_network_utils.robot
8Resource        ../../lib/openbmc_ffdc.robot
9
10Suite Setup     Suite Setup Execution
11Test Teardown   FFDC On Test Case Fail
12Suite Teardown  Redfish.Logout
13
14*** Variables ***
15
16&{DHCP_ENABLED}           DHCPEnabled=${True}
17&{DHCP_DISABLED}          DHCPEnabled=${False}
18&{ENABLE_DHCP}            DHCPv4=${DHCP_ENABLED}
19&{DISABLE_DHCP}           DHCPv4=${DHCP_DISABLED}
20${ethernet_interface}     eth1
21
22&{dns_enable_dict}                 UseDNSServers=${True}
23&{dns_disable_dict}                UseDNSServers=${False}
24&{ntp_enable_dict}                 UseNTPServers=${True}
25&{ntp_disable_dict}                UseNTPServers=${False}
26&{domain_name_enable_dict}         UseDomainName=${True}
27&{domain_name_disable_dict}        UseDomainName=${False}
28&{enable_multiple_properties}      UseDomainName=${True}
29...                                UseNTPServers=${True}
30...                                UseDNSServers=${True}
31&{disable_multiple_properties}     UseDomainName=${False}
32...                                UseNTPServers=${False}
33...                                UseDNSServers=${False}
34
35Force Tags                         Multiple_Interfaces_DHCP
36
37*** Test Cases ***
38
39Disable DHCP On Eth1 And Verify System Is Accessible By Eth0
40    [Documentation]  Disable DHCP on eth1 using Redfish and verify
41    ...              if system is accessible by eth0.
42    [Tags]  Disable_DHCP_On_Eth1_And_Verify_System_Is_Accessible_By_Eth0
43    [Teardown]  Set DHCPEnabled To Enable Or Disable  True  eth1
44
45    Set DHCPEnabled To Enable Or Disable  False  eth1
46    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
47
48Enable DHCP On Eth1 And Verify System Is Accessible By Eth0
49    [Documentation]  Enable DHCP on eth1 using Redfish and verify if system
50    ...              is accessible by eth0.
51    [Tags]  Enable_DHCP_On_Eth1_And_Verify_System_Is_Accessible_By_Eth0
52    [Setup]  Set DHCPEnabled To Enable Or Disable  False  eth1
53
54    Set DHCPEnabled To Enable Or Disable  True  eth1
55    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
56
57Set Network Property via Redfish And Verify
58   [Documentation]  Set network property via Redfish and verify.
59   [Tags]  Set_Network_Property_via_Redfish_And_Verify
60   [Teardown]  Restore Configuration
61   [Template]  Apply DHCP Config
62
63    # property
64    ${dns_enable_dict}
65    ${dns_disable_dict}
66    ${domain_name_enable_dict}
67    ${domain_name_disable_dict}
68    ${ntp_enable_dict}
69    ${ntp_disable_dict}
70    ${enable_multiple_properties}
71    ${disable_multiple_properties}
72
73Enable DHCP On Eth1 And Check No Impact On Eth0
74    [Documentation]  Enable DHCP On Eth1 And Check No Impact On Eth0.
75    [Tags]  Enable_DHCP_On_Eth1_And_Check_No_Impact_On_Eth0
76    [Setup]  Set DHCPEnabled To Enable Or Disable  False  eth1
77
78    # Getting the eth0 details before enabling DHCP.
79    ${ip_data_before}=  Get BMC IP Info
80
81    # Enable DHCP.
82    Set DHCPEnabled To Enable Or Disable  True  eth1
83
84    # Check the value of DHCPEnabled on eth0 is not impacted.
85    ${DHCPEnabled}=  Get IPv4 DHCP Enabled Status
86    Should Be Equal  ${DHCPEnabled}  ${False}
87
88    # Getting eth0 details after enabling DHCP.
89    ${ip_data_after}=  Get BMC IP Info
90
91    # Before and after IP details must match.
92    Should Be Equal  ${ip_data_before}  ${ip_data_after}
93
94*** Keywords ***
95
96Get IPv4 DHCP Enabled Status
97    [Documentation]  Return IPv4 DHCP enabled status from redfish URI.
98
99    ${active_channel_config}=  Get Active Channel Config
100    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
101    ${resp}=  Redfish.Get Attribute  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  DHCPv4
102    Return From Keyword  ${resp['DHCPEnabled']}
103
104Set DHCPEnabled To Enable Or Disable
105    [Documentation]  Enable or Disable DHCP on the interface.
106    [Arguments]  ${dhcp_enabled}=${False}  ${interface}=${ethernet_interface}
107    ...          ${valid_status_code}=[${HTTP_OK},${HTTP_ACCEPTED}]
108
109    # Description of argument(s):
110    # dhcp_enabled        False for disabling DHCP and True for Enabling DHCP.
111    # interface           eth0 or eth1. Default is eth1.
112    # valid_status_code   Expected valid status code from Patch request.
113    #                     Default is HTTP_OK.
114
115    ${data}=  Set Variable If  ${dhcp_enabled} == ${False}  ${DISABLE_DHCP}  ${ENABLE_DHCP}
116    ${resp}=  Redfish.Patch
117    ...  /redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/${interface}
118    ...  body=${data}  valid_status_codes=${valid_status_code}
119
120Apply DHCP Config
121    [Documentation]  Apply DHCP Config
122    [Arguments]  ${property}
123
124    # Description of Argument(s):
125    # property  DHCP property values.
126
127    ${active_channel_config}=  Get Active Channel Config
128    Redfish.Patch
129    ...  /redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}/
130    ...  body={"DHCPv4":${property}}  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
131
132    ${resp}=  Redfish.Get
133    ...  /redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}
134    Verify Ethernet Config Property  ${property}  ${resp.dict["DHCPv4"]}
135
136
137Verify Ethernet Config Property
138    [Documentation]  verify ethernet config properties.
139    [Arguments]  ${property}  ${response_data}
140
141    # Description of argument(s):
142    # ${property}       DHCP Properties in dictionary.
143    # Example:
144    # property         value
145    # DHCPEnabled      :False
146    # UseDomainName    :True
147    # UseNTPServers    :True
148    # UseDNSServers    :True
149    # ${response_data}  DHCP Response data in dictionary.
150    # Example:
151    # property         value
152    # DHCPEnabled      :False
153    # UseDomainName    :True
154    # UseNTPServers    :True
155    # UseDNSServers    :True
156
157   ${key_map}=  Get Dictionary Items  ${property}
158   FOR  ${key}  ${value}  IN  @{key_map}
159      Should Be Equal As Strings  ${response_data['${key}']}  ${value}
160   END
161
162Restore Configuration
163    [Documentation]  Restore the configuration to Both Static Network
164
165    Run Keyword If  '${CHANNEL_NUMBER}' == '1'  Add IP Address  ${OPENBMC_HOST}  ${eth0_subnet_mask}  ${eth0_gateway}
166    ...  ELSE IF  '${CHANNEL_NUMBER}' == '2'  Add IP Address  ${OPENBMC_HOST_1}  ${eth1_subnet_mask}  ${eth1_gateway}
167
168Get Network Configuration Using Channel Number
169    [Documentation]  Get ethernet interface.
170    [Arguments]  ${channel_number}
171
172    # Description of argument(s):
173    # channel_number   Ethernet channel number, 1 is for eth0 and 2 is for eth1 (e.g. "1").
174
175    ${active_channel_config}=  Get Active Channel Config
176    ${ethernet_interface}=  Set Variable  ${active_channel_config['${channel_number}']['name']}
177    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
178
179    @{network_configurations}=  Get From Dictionary  ${resp.dict}  IPv4StaticAddresses
180    [Return]  @{network_configurations}
181
182Suite Setup Execution
183    [Documentation]  Do suite setup task.
184
185    Ping Host  ${OPENBMC_HOST}
186    Ping Host  ${OPENBMC_HOST_1}
187    Redfish.Login
188
189    # Get the configuration of eth1
190    ${network_configurations}=  Get Network Configuration Using Channel Number  ${2}
191    FOR  ${network_configuration}  IN  @{network_configurations}
192      Run Keyword If  '${network_configuration['Address']}' == '${OPENBMC_HOST_1}'
193      ...  Run Keywords  Set Suite Variable  ${eth1_subnet_mask}  ${network_configuration['SubnetMask']}
194      ...  AND  Set Suite Variable  ${eth1_gateway}  ${network_configuration['Gateway']}
195      ...  AND  Exit For Loop
196    END
197
198    # Get the configuration of eth0
199    ${network_configurations}=  Get Network Configuration Using Channel Number  ${1}
200    FOR  ${network_configuration}  IN  @{network_configurations}
201      Run Keyword If  '${network_configuration['Address']}' == '${OPENBMC_HOST}'
202      ...  Run Keywords  Set Suite Variable  ${eth0_subnet_mask}  ${network_configuration['SubnetMask']}
203      ...  AND  Set Suite Variable  ${eth0_gateway}  ${network_configuration['Gateway']}
204      ...  AND  Exit For Loop
205    END
206
207