1*** Settings ***
2Documentation          DHCP Network to test suite functionality.
3
4Resource               ../lib/openbmc_ffdc.robot
5Resource               ../lib/bmc_network_utils.robot
6Library                ../lib/ipmi_utils.py
7Library                ../lib/bmc_network_utils.py
8
9Suite Setup            Suite Setup Execution
10Suite Teardown         Redfish.Logout
11
12*** Variables ***
13
14&{dhcp_enable_dict}                DHCPEnabled=${True}
15&{dhcp_disable_dict}               DHCPEnabled=${False}
16
17&{dns_enable_dict}                 UseDNSServers=${True}
18&{dns_disable_dict}                UseDNSServers=${False}
19
20&{ntp_enable_dict}                 UseNTPServers=${True}
21&{ntp_disable_dict}                UseNTPServers=${False}
22
23&{domain_name_enable_dict}         UseDomainName=${True}
24&{domain_name_disable_dict}        UseDomainName=${False}
25
26&{enable_multiple_properties}      UseDomainName=${True}
27...                                UseNTPServers=${True}
28...                                UseDNSServers=${True}
29
30&{disable_multiple_properties}     UseDomainName=${False}
31...                                UseNTPServers=${False}
32...                                UseDNSServers=${False}
33
34*** Test Cases ***
35
36Set Network Property via Redfish And Verify
37   [Documentation]  Set network property via Redfish and verify.
38   [Tags]  Set_Network_Property_via_Redfish_And_Verify
39   [Template]  Apply Ethernet Config
40
41    # property
42    ${dhcp_enable_dict}
43    ${dhcp_disable_dict}
44    ${dns_enable_dict}
45    ${dns_disable_dict}
46    ${domain_name_enable_dict}
47    ${domain_name_disable_dict}
48    ${ntp_enable_dict}
49    ${ntp_disable_dict}
50    ${enable_multiple_properties}
51    ${disable_multiple_properties}
52
53
54*** Keywords ***
55
56Suite Setup Execution
57    [Documentation]  Suite Setup Execution.
58
59    Redfish.Login
60
61    Redfish Power On
62    # This keyword should login to host OS.
63    Run Inband IPMI Standard Command
64    ...  lan set ${CHANNEL_NUMBER} ipsrc static  login_host=${1}
65
66    ${host_name}  ${ip_address}=  Get Host Name IP  host=${OPENBMC_HOST}
67
68    Set Suite Variable  ${ip_address}
69
70    @{network_configurations}=  Get Network Configuration
71    FOR  ${network_configuration}  IN  @{network_configurations}
72      Run Keyword If  '${network_configuration['Address']}' == '${ip_address}'
73      ...  Set Suite Variable  ${subnet_mask}  ${network_configuration['SubnetMask']}
74    END
75
76    ${initial_lan_config}=  Get LAN Print Dict  ${CHANNEL_NUMBER}  ipmi_cmd_type=inband
77    Set Suite Variable  ${initial_lan_config}
78
79
80Set IPMI Inband Network Configuration
81    [Documentation]  Run sequence of standard in-band IPMI command and set
82    ...              the IP configuration.
83    [Arguments]  ${ip}  ${netmask}  ${gateway}
84
85    # Description of argument(s):
86    # ip       The IP address to be set using ipmitool-inband.
87    # netmask  The Netmask to be set using ipmitool-inband.
88    # gateway  The Gateway address to be set using ipmitool-inband.
89    # login    Indicates that this keyword should login to host OS.
90
91    Run Inband IPMI Standard Command
92    ...  lan set ${CHANNEL_NUMBER} ipaddr ${ip}  login_host=${0}
93    Run Inband IPMI Standard Command
94    ...  lan set ${CHANNEL_NUMBER} netmask ${netmask}  login_host=${0}
95    Run Inband IPMI Standard Command
96    ...  lan set ${CHANNEL_NUMBER} defgw ipaddr ${gateway}  login_host=${0}
97
98
99Restore Configuration
100    [Documentation]  Restore the configuration to its pre-test state.
101
102    ${length}=  Get Length  ${initial_lan_config}
103    Return From Keyword If  ${length} == ${0}
104
105    Set IPMI Inband Network Configuration  ${ip_address}  ${subnet_mask}
106    ...  ${initial_lan_config['Default Gateway IP']}
107
108
109Apply Ethernet Config
110    [Documentation]  Set the given Ethernet config property.
111    [Arguments]  ${property}
112    [Teardown]  Run Keywords  Restore Configuration  AND
113    ...  Set Global Variable  ${TEST_STATUS}  ${KEYWORD STATUS}  AND  FFDC On Test Case Fail
114
115    # Description of argument(s):
116    # property   Ethernet property to be set..
117
118    ${active_channel_config}=  Get Active Channel Config
119    Redfish.Patch
120    ...  /redfish/v1/Managers/bmc/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}/
121    ...  body={"DHCPv4":${property}}  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
122
123    ${resp}=  Redfish.Get
124    ...  /redfish/v1/Managers/bmc/EthernetInterfaces/${active_channel_config['${CHANNEL_NUMBER}']['name']}
125    Verify Ethernet Config Property  ${property}  ${resp.dict["DHCPv4"]}
126
127
128Verify Ethernet Config Property
129    [Documentation]  verify ethernet config properties.
130    [Arguments]  ${property}  ${response_data}
131
132    # Description of argument(s):
133    # ${property}       DHCP Properties in dictionary.
134    # Example:
135    # property         value
136    # DHCPEnabled      :False
137    # UseDomainName    :True
138    # UseNTPServers    :True
139    # UseDNSServers    :True
140    # ${response_data}  DHCP Response data in dictionary.
141    # Example:
142    # property         value
143    # DHCPEnabled      :False
144    # UseDomainName    :True
145    # UseNTPServers    :True
146    # UseDNSServers    :True
147
148   ${key_map}=  Get Dictionary Items  ${property}
149   FOR  ${key}  ${value}  IN  @{key_map}
150      Should Be Equal As Strings  ${response_data['${key}']}  ${value}
151   END
152
153