1*** Settings ***
2Documentation          DHCP Network to test suite functionality.
3
4Resource               ../lib/openbmc_ffdc.robot
5Resource               ../lib/bmc_network_utils.robot
6Library                ../lib/bmc_network_utils.py
7
8Suite Setup            Suite Setup Execution
9Suite Teardown         Run Keywords  Restore Configuration  AND Redfish.Logout
10
11Force Tags             BMC_DHCP_Conf
12
13*** Variables ***
14
15&{dhcp_enable_dict}                DHCPEnabled=${True}
16&{dhcp_disable_dict}               DHCPEnabled=${False}
17
18&{dns_enable_dict}                 UseDNSServers=${True}
19&{dns_disable_dict}                UseDNSServers=${False}
20
21&{ntp_enable_dict}                 UseNTPServers=${True}
22&{ntp_disable_dict}                UseNTPServers=${False}
23
24&{domain_name_enable_dict}         UseDomainName=${True}
25&{domain_name_disable_dict}        UseDomainName=${False}
26
27&{enable_multiple_properties}      UseDomainName=${True}
28...                                UseNTPServers=${True}
29...                                UseDNSServers=${True}
30
31&{disable_multiple_properties}     UseDomainName=${False}
32...                                UseNTPServers=${False}
33...                                UseDNSServers=${False}
34
35*** Test Cases ***
36
37Set Network Property via Redfish And Verify
38   [Documentation]  Set network property via Redfish and verify.
39   [Tags]  Set_Network_Property_via_Redfish_And_Verify
40   [Template]  Apply Ethernet Config
41
42    # property
43    ${dhcp_enable_dict}
44    ${dhcp_disable_dict}
45    ${dns_enable_dict}
46    ${dns_disable_dict}
47    ${domain_name_enable_dict}
48    ${domain_name_disable_dict}
49    ${ntp_enable_dict}
50    ${ntp_disable_dict}
51    ${enable_multiple_properties}
52    ${disable_multiple_properties}
53
54
55*** Keywords ***
56
57Suite Setup Execution
58    [Documentation]  Suite Setup Execution.
59
60    Ping Host  ${OPENBMC_HOST}
61    Ping Host  ${OPENBMC_HOST_1}
62    Redfish.Login
63
64    ${network_configurations}=  Get Network Configuration Using Channel Number  ${2}
65    FOR  ${network_configuration}  IN  @{network_configurations}
66      Run Keyword If  '${network_configuration['Address']}' == '${OPENBMC_HOST_1}'
67      ...  Run Keywords  Set Suite Variable  ${eth1_subnet_mask}  ${network_configuration['SubnetMask']}
68      ...  AND  Set Suite Variable  ${eth1_gateway}  ${network_configuration['Gateway']}
69      ...  AND  Exit For Loop
70    END
71
72    ${network_configurations}=  Get Network Configuration Using Channel Number  ${1}
73    FOR  ${network_configuration}  IN  @{network_configurations}
74      Run Keyword If  '${network_configuration['Address']}' == '${OPENBMC_HOST}'
75      ...  Run Keywords  Set Suite Variable  ${eth0_subnet_mask}  ${network_configuration['SubnetMask']}
76      ...  AND  Set Suite Variable  ${eth0_gateway}  ${network_configuration['Gateway']}
77      ...  AND  Exit For Loop
78    END
79
80Get Network Configuration Using Channel Number
81    [Documentation]  Get ethernet interface.
82    [Arguments]  ${channel_number}
83
84    # Description of argument(s):
85    # channel_number   Ethernet channel number, 1 is for eth0 and 2 is for eth1 (e.g. "1").
86
87    ${active_channel_config}=  Get Active Channel Config
88    ${ethernet_interface}=  Set Variable  ${active_channel_config['${channel_number}']['name']}
89    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
90
91    @{network_configurations}=  Get From Dictionary  ${resp.dict}  IPv4StaticAddresses
92    [Return]  @{network_configurations}
93
94Apply Ethernet Config
95    [Documentation]  Set the given Ethernet config property.
96    [Arguments]  ${property}
97
98    # Description of argument(s):
99    # property   Ethernet property to be set..
100
101    ${active_channel_config}=  Get Active Channel Config
102    Redfish.Patch
103    ...  /redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}/
104    ...  body={"DHCPv4":${property}}  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
105
106    ${resp}=  Redfish.Get
107    ...  /redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}
108    Verify Ethernet Config Property  ${property}  ${resp.dict["DHCPv4"]}
109
110Restore Configuration
111    [Documentation]  Restore the configuration to Both Static Network
112
113    Run Keyword If  '${CHANNEL_NUMBER}' == '1'  Add IP Address  ${OPENBMC_HOST}  ${eth0_subnet_mask}  ${eth0_gateway}
114    ...  ELSE IF  '${CHANNEL_NUMBER}' == '2'  Add IP Address  ${OPENBMC_HOST_1}  ${eth1_subnet_mask}  ${eth1_gateway}
115
116Verify Ethernet Config Property
117    [Documentation]  verify ethernet config properties.
118    [Arguments]  ${property}  ${response_data}
119
120    # Description of argument(s):
121    # ${property}       DHCP Properties in dictionary.
122    # Example:
123    # property         value
124    # DHCPEnabled      :False
125    # UseDomainName    :True
126    # UseNTPServers    :True
127    # UseDNSServers    :True
128    # ${response_data}  DHCP Response data in dictionary.
129    # Example:
130    # property         value
131    # DHCPEnabled      :False
132    # UseDomainName    :True
133    # UseNTPServers    :True
134    # UseDNSServers    :True
135
136   ${key_map}=  Get Dictionary Items  ${property}
137   FOR  ${key}  ${value}  IN  @{key_map}
138      Should Be Equal As Strings  ${response_data['${key}']}  ${value}
139   END
140
141