From d30aa3a0c0e64682266b0fbf5c8506952e39e414 Mon Sep 17 00:00:00 2001 From: selias Date: Fri, 17 Mar 2017 14:44:27 +0100 Subject: [PATCH] CSIT-526 HC test: DHCP relay Change-Id: I00d841bee1e5139a4530ce97d8bda17780caa0f1 Signed-off-by: selias --- resources/libraries/python/Dhcp.py | 18 ++- resources/libraries/python/honeycomb/DHCP.py | 109 ++++++++++++++++++ resources/libraries/robot/honeycomb/dhcp.robot | 94 ++++++++++++++++ .../templates/honeycomb/config_dhcp_relay.url | 1 + resources/templates/vat/dhcp_proxy_dump.vat | 1 + resources/test_data/honeycomb/dhcp_relay.py | 122 +++++++++++++++++++++ .../mgmt-cfg-dhcp-apihc-apivat-func.robot | 119 ++++++++++++++++++++ 7 files changed, 463 insertions(+), 1 deletion(-) create mode 100644 resources/libraries/python/honeycomb/DHCP.py create mode 100644 resources/libraries/robot/honeycomb/dhcp.robot create mode 100644 resources/templates/honeycomb/config_dhcp_relay.url create mode 100644 resources/templates/vat/dhcp_proxy_dump.vat create mode 100644 resources/test_data/honeycomb/dhcp_relay.py create mode 100644 tests/func/honeycomb/mgmt-cfg-dhcp-apihc-apivat-func.robot diff --git a/resources/libraries/python/Dhcp.py b/resources/libraries/python/Dhcp.py index 93a9180972..5f76e434ec 100644 --- a/resources/libraries/python/Dhcp.py +++ b/resources/libraries/python/Dhcp.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016 Cisco and/or its affiliates. +# Copyright (c) 2017 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -73,3 +73,19 @@ class DhcpProxy(object): if output["retval"] != 0: raise RuntimeError('Unable to set DHCP proxy on node {}' .format(vpp_node)) + + @staticmethod + def vpp_get_dhcp_proxy(node, ip_version): + """Retrieve DHCP relay configuration. + + :param node: VPP node. + :param ip_version: IP protocol version: ipv4 or ipv6. + :type node: dict + :type ip_version: str + :returns: DHCP relay data. + :rtype: list + """ + + return VatExecutor.cmd_from_template( + node, "dhcp_proxy_dump.vat", + ipv6="ipv6" if ip_version == "ipv6" else "") diff --git a/resources/libraries/python/honeycomb/DHCP.py b/resources/libraries/python/honeycomb/DHCP.py new file mode 100644 index 0000000000..3c03b1405f --- /dev/null +++ b/resources/libraries/python/honeycomb/DHCP.py @@ -0,0 +1,109 @@ +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Keywords to manipulate NAT configuration using Honeycomb REST API.""" + +from resources.libraries.python.HTTPRequest import HTTPCodes +from resources.libraries.python.honeycomb.HoneycombSetup import HoneycombError +from resources.libraries.python.honeycomb.HoneycombUtil \ + import DataRepresentation +from resources.libraries.python.honeycomb.HoneycombUtil \ + import HoneycombUtil as HcUtil + + +class DHCPRelayKeywords(object): + """Keywords for NAT configuration.""" + + def __init__(self): + pass + + @staticmethod + def _set_dhcp_relay_properties(node, path, data=None): + """Set DHCP relay properties and check the return code. + + :param node: Honeycomb node. + :param path: Path which is added to the base path to identify the data. + :param data: The new data to be set. If None, the item will be removed. + :type node: dict + :type path: str + :type data: dict + :return: Content of response. + :rtype: bytearray + :raises HoneycombError: If the status code in response is not + 200 = OK or 201 = ACCEPTED. + """ + + if data: + status_code, resp = HcUtil. \ + put_honeycomb_data(node, "config_dhcp_relay", data, path, + data_representation=DataRepresentation.JSON) + else: + status_code, resp = HcUtil. \ + delete_honeycomb_data(node, "config_dhcp_relay", path) + + if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): + raise HoneycombError( + "The configuration of DHCP relay was not successful. " + "Status code: {0}.".format(status_code)) + return resp + + @staticmethod + def add_dhcp_relay(node, data, ip_version, entry_id): + """Add a DHCP relay entry to the list on entries. + + :param node: Honeycomb node. + :param data: Configuration for the relay entry. + :param ip_version: IP protocol version, ipv4 or ipv6. + :param entry_id: Numeric ID. + :type node: dict + :type data: dict + :type ip_version: str + :type entry_id: int + :returns: Content of response. + :rtype: bytearray + """ + + path = "/relay/dhcp:{0}/{1}".format(ip_version, entry_id) + + return DHCPRelayKeywords._set_dhcp_relay_properties(node, path, data) + + @staticmethod + def clear_dhcp_relay_configuration(node): + """Remove all DHCP relay configuration from the node. + + :param node: Honeycomb node. + :type node: dict + :returns: Content of response. + :rtype: bytearray + """ + return DHCPRelayKeywords._set_dhcp_relay_properties(node, "") + + @staticmethod + def get_dhcp_relay_oper_data(node): + """Get operational data about the DHCP relay feature. + + :param node: Honeycomb node. + :type node: dict + :returns: Content of response. + :rtype: bytearray + :raises HoneycombError: If the status code in response is not 200 = OK. + """ + + status_code, resp = HcUtil. \ + get_honeycomb_data(node, "config_dhcp_relay") + + if status_code != HTTPCodes.OK: + raise HoneycombError( + "Could not retrieve DHCP relay configuration. " + "Status code: {0}.".format(status_code)) + return resp diff --git a/resources/libraries/robot/honeycomb/dhcp.robot b/resources/libraries/robot/honeycomb/dhcp.robot new file mode 100644 index 0000000000..d3fe942668 --- /dev/null +++ b/resources/libraries/robot/honeycomb/dhcp.robot @@ -0,0 +1,94 @@ +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +*** Settings *** +| Library | resources.libraries.python.honeycomb.DHCP.DHCPRelayKeywords +| Library | resources.libraries.python.Dhcp.DhcpProxy +| Documentation | Keywords used to test Honeycomb DHCP features. + +*** Keywords *** +| DHCP relay configuration from Honeycomb should be empty +| | [Documentation] | Uses Honeycomb API to retrieve DHCP relay configuration\ +| | ... | and expects to fail. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| DHCP relay configuration from Honeycomb should be empty \ +| | ... | \| ${nodes['DUT1']} \| +| | [Arguments] | ${node} +| | Run keyword and expect error | *Status code: 404* +| | ... | Get DHCP relay oper data | ${node} + +| Log DHCP relay configuration from VAT +| | [Documentation] | Uses VAT to retrieve DHCP relay configuration from VPP. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - ip_version - IP protocol version, ipv4 or ipv6. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Log DHCP relay configuration from VAT \ +| | ... | \| ${nodes['DUT1']} \| ipv4 \| +| | [Arguments] | ${node} | ${ip_version} +| | VPP get DHCP proxy | ${node} | ${ip_version} + +| Honeycomb configures DHCP relay +| | [Documentation] | Uses Honeycomb API to configure DHCP relay. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - data - settings for the DHCP relay. Type: dictionary +| | ... | - ip_version - IP protocol version, ipv4 or ipv6. Type: string +| | ... | - vrf - vrf ID to configure DHCP on. Type: integer +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Honeycomb configures DHCP relay \| ${nodes['DUT1']} \| ${data} \ +| | ... | \| ipv4 \| ${0} \| +| | [Arguments] | ${node} | ${data} | ${ip_version} | ${vrf} +| | Add DHCP relay | ${node} | ${data} | ${ip_version} | ${vrf} + +| Honeycomb clears DHCP relay configuration +| | [Documentation] | Uses Honeycomb API to delete all configured DHCP relays. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Honeycomb clears DHCP relay configuration \| ${nodes['DUT1']} \| +| | [Arguments] | ${node} +| | Clear DHCP relay configuration | ${node} + +| DHCP relay configuration from Honeycomb should contain +| | [Documentation] | Retrieves oper data for DHCP relay and compares\ +| | ... | with provided values. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - data - expected DHCP relay settings. Type dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| DHCP relay configuration from Honeycomb should contain \ +| | ... | \| ${nodes['DUT1']} \| ${data} \| +| | [Arguments] | ${node} | ${data} +| | ${oper_data}= | Get DHCP relay oper data | ${node} +| | ${oper_data}= | Set Variable | ${oper_data['relays']['relay'][0]} +| | Sort List | ${oper_data['server']} +| | Sort List | ${data['server']} +| | Should be equal | ${oper_data} | ${data} diff --git a/resources/templates/honeycomb/config_dhcp_relay.url b/resources/templates/honeycomb/config_dhcp_relay.url new file mode 100644 index 0000000000..81ab02e46d --- /dev/null +++ b/resources/templates/honeycomb/config_dhcp_relay.url @@ -0,0 +1 @@ +/restconf/config{odl_url_part}/dhcp:dhcp/relays \ No newline at end of file diff --git a/resources/templates/vat/dhcp_proxy_dump.vat b/resources/templates/vat/dhcp_proxy_dump.vat new file mode 100644 index 0000000000..584a58b5c6 --- /dev/null +++ b/resources/templates/vat/dhcp_proxy_dump.vat @@ -0,0 +1 @@ +dhcp_proxy_dump {ipv6} diff --git a/resources/test_data/honeycomb/dhcp_relay.py b/resources/test_data/honeycomb/dhcp_relay.py new file mode 100644 index 0000000000..f5cb4a128c --- /dev/null +++ b/resources/test_data/honeycomb/dhcp_relay.py @@ -0,0 +1,122 @@ +# Copyright (c) 2016 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Test variables for DHCP relay test suite.""" + +# IPv4 addresses used in traffic tests +dut_to_tg_if1_ip = "172.16.0.1" +dut_to_tg_if2_ip = "192.168.0.1" +dhcp_server1_ip = "192.168.0.100" +dhcp_server2_ip = "192.168.0.101" +client_ip = "172.16.0.2" +prefix_length = 24 + +# IPv6 addresses used in traffic tests +dut_to_tg_if1_ip6 = "3ffe:62::1" +dut_to_tg_if2_ip6 = "3ffe:63::1" +dhcp_server_ip6 = "3ffe:63::2" +client_ip6 = "3ffe:62::2" +prefix_length_v6 = 64 + +# DHCP relay configuration +relay1 = { + "relay": [ + { + "address-type": "ipv4", + "rx-vrf-id": 0, + "gateway-address": dut_to_tg_if1_ip, + "server": [ + { + "vrf-id": 0, + "address": dhcp_server1_ip + }, + ] + } + ] +} + +relay1_oper = { + "address-type": "dhcp:ipv4", + "rx-vrf-id": 0, + "gateway-address": dut_to_tg_if1_ip, + "server": [ + { + "vrf-id": 0, + "address": dhcp_server1_ip + } + ] +} + +relay2 = { + "relay": [ + { + "address-type": "ipv4", + "rx-vrf-id": 0, + "gateway-address": dut_to_tg_if1_ip, + "server": [ + { + "vrf-id": 0, + "address": dhcp_server1_ip + }, + { + "vrf-id": 0, + "address": dhcp_server2_ip + }, + ] + } + ] +} + +relay2_oper = { + "address-type": "dhcp:ipv4", + "rx-vrf-id": 0, + "gateway-address": dut_to_tg_if1_ip, + "server": [ + { + "vrf-id": 0, + "address": dhcp_server1_ip + }, + { + "vrf-id": 0, + "address": dhcp_server2_ip + } + ] +} + +relay_v6 = { + "relay": [ + { + "address-type": "ipv6", + "rx-vrf-id": 0, + "gateway-address": dut_to_tg_if1_ip6, + "server": [ + { + "vrf-id": 0, + "address": dhcp_server_ip6 + }, + ] + } + ] +} + +relay_v6_oper = { + "address-type": "dhcp:ipv6", + "rx-vrf-id": 0, + "gateway-address": dut_to_tg_if1_ip6, + "server": [ + { + "vrf-id": 0, + "address": dhcp_server_ip6 + } + ] +} diff --git a/tests/func/honeycomb/mgmt-cfg-dhcp-apihc-apivat-func.robot b/tests/func/honeycomb/mgmt-cfg-dhcp-apihc-apivat-func.robot new file mode 100644 index 0000000000..4405da11e6 --- /dev/null +++ b/tests/func/honeycomb/mgmt-cfg-dhcp-apihc-apivat-func.robot @@ -0,0 +1,119 @@ +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +*** Settings *** +| Resource | resources/libraries/robot/default.robot +| Resource | resources/libraries/robot/testing_path.robot +| Resource | resources/libraries/robot/dhcp_proxy.robot +| Resource | resources/libraries/robot/honeycomb/honeycomb.robot +| Resource | resources/libraries/robot/honeycomb/interfaces.robot +| Resource | resources/libraries/robot/honeycomb/dhcp.robot +| Library | resources.libraries.python.Trace +| Library | resources.libraries.python.IPv4Setup +| Library | resources.libraries.python.IPv6Setup +| Library | resources.libraries.python.IPv6Util +| Library | resources.libraries.python.Routing +| Variables | resources/test_data/honeycomb/dhcp_relay.py +| Documentation | *Honeycomb DHCP relay test suite.* +| Test Setup | Clear Packet Trace on All DUTs | ${nodes} +| Suite Teardown | Restart Honeycomb and VPP | ${node} +| Force Tags | honeycomb_sanity | honeycomb_odl + +*** Test Cases *** +| TC01: Honeycomb can configure DHCP relay entry +| | [Documentation] +| | ... | [Top] TG=DUT1=TG. +| | ... | [Enc] Eth-IPv4-DHCP. +| | ... | [Cfg] (Using Honeycomb API) On DUT1 configure IP addresses\ +| | ... | neighbors and configure DHCP relay. +| | ... | [Ver] Send DHCP packets from TG interface to DUT. Receive all packets\ +| | ... | on the second TG interface and verify required fields. +| | [Teardown] | Run Keywords | Show Packet Trace on All DUTs | ${nodes} +| | ... | AND | Log DHCP relay configuration from VAT | ${node} | ipv4 +| | Given DHCP relay configuration from Honeycomb should be empty | ${node} +| | When Honeycomb configures DHCP relay | ${node} | ${relay1} | ipv4 | ${0} +| | Then DHCP relay configuration from Honeycomb should contain +| | ... | ${node} | ${relay1_oper} +| | When DHCP relay test setup +| | Then Send DHCP Messages | ${tg_node} | ${tg_to_dut_if1} | ${tg_to_dut_if2} +| | ... | ${dhcp_server1_ip} | ${tg_to_dut_if2_mac} | ${client_ip} +| | ... | ${tg_to_dut_if1_mac} | ${dut_to_tg_if1_ip} + +| TC02: Honeycomb can remove DHCP relay entry +| | [Documentation] | Remove DHCP relay configuration, and verify that\ +| | ... | it was removed. +| | Given DHCP relay configuration from Honeycomb should contain +| | ... | ${node} | ${relay1_oper} +| | When Honeycomb clears DHCP relay configuration | ${node} +| | Then DHCP relay configuration from Honeycomb should be empty | ${node} + +| TC03: Honeycomb can configure multiple DHCP relay servers. +| | [Documentation] | Configure multiple DHCP relay servers and verify\ +| | ... | their configuration using operational data. +| | [Teardown] | Honeycomb clears DHCP relay configuration | ${node} +| | Given DHCP relay configuration from Honeycomb should be empty | ${node} +| | And Honeycomb configures DHCP relay | ${node} | ${relay2} | ipv4 | ${0} +| | Then DHCP relay configuration from Honeycomb should contain +| | ... | ${node} | ${relay2_oper} + +| TC04: Honeycomb can configure DHCP relay entry with ipv6 +| | [Documentation] +| | ... | [Top] TG=DUT1=TG. +| | ... | [Enc] Eth-IPv6-DHCPv6. +| | ... | [Cfg] (Using Honeycomb API) On DUT1 configure IP addresses\ +| | ... | neighbors and configure DHCP relay. +| | ... | [Ver] Send DHCPv6 packets from TG interface to DUT. Receive all\ +| | ... | packets on the second TG interface and verify required fields. +| | [Teardown] | Run Keywords | Show Packet Trace on All DUTs | ${nodes} +| | ... | AND | Log DHCP relay configuration from VAT | ${node} | ipv6 +| | ... | AND | Honeycomb clears DHCP relay configuration | ${node} +| | Given DHCP relay configuration from Honeycomb should be empty | ${node} +| | When Honeycomb configures DHCP relay | ${node} | ${relay_v6} | ipv6 | ${0} +| | Then DHCP relay configuration from Honeycomb should contain +| | ... | ${node} | ${relay_v6_oper} +| | When DHCP relay test setup IPv6 +| | Then Send DHCPv6 Messages | ${tg_node} | ${tg_to_dut_if1} | ${tg_to_dut_if2} +| | ... | ${dut_to_tg_if1_ip6} | ${dut_to_tg_if1_mac} | ${dhcp_server_ip6} +| | ... | ${tg_to_dut_if2_mac} | ${tg_to_dut_if1_mac} | ${dut_to_tg_if2_mac} + +*** Keywords *** +| DHCP relay test setup +| | Path for 2-node testing is set +| | ... | ${nodes['TG']} | ${nodes['DUT1']} | ${nodes['TG']} +| | Honeycomb sets interface state | ${dut_node} | ${dut_to_tg_if1} | up +| | Honeycomb sets interface state | ${dut_node} | ${dut_to_tg_if2} | up +| | Honeycomb sets interface ipv4 address with prefix | ${dut_node} +| | ... | ${dut_to_tg_if1} | ${dut_to_tg_if1_ip} | ${prefix_length} +| | Honeycomb sets interface ipv4 address with prefix | ${dut_node} +| | ... | ${dut_to_tg_if2} | ${dut_to_tg_if2_ip} | ${prefix_length} +| | Add ARP on DUT +| | ... | ${dut_node} | ${dut_to_tg_if2} | ${dhcp_server1_ip} | ${tg_to_dut_if2_mac} +| | Add ARP on DUT +| | ... | ${dut_node} | ${dut_to_tg_if2} | ${dhcp_server2_ip} | ${tg_to_dut_if2_mac} +| | And VPP Route Add | ${dut_node} | 255.255.255.255 | 32 | ${NONE} | local +| | ... | ${FALSE} | ${NONE} + +| DHCP relay test setup IPv6 +| | Path for 2-node testing is set +| | ... | ${nodes['TG']} | ${nodes['DUT1']} | ${nodes['TG']} +| | Honeycomb sets interface state | ${dut_node} | ${dut_to_tg_if1} | up +| | Honeycomb sets interface state | ${dut_node} | ${dut_to_tg_if2} | up +| | And Vpp All Ra Suppress Link Layer | ${nodes} +| | Honeycomb sets interface ipv6 address | ${dut_node} +| | ... | ${dut_to_tg_if1} | ${dut_to_tg_if1_ip6} | ${prefix_length_v6} +| | Honeycomb sets interface ipv6 address | ${dut_node} +| | ... | ${dut_to_tg_if2} | ${dut_to_tg_if2_ip6} | ${prefix_length_v6} +| | And Add IP Neighbor | ${dut_node} | ${dut_to_tg_if2} | ${dhcp_server_ip6} +| | ... | ${tg_to_dut_if2_mac} +| | And VPP Route Add | ${dut_node} | ff02::1:2 | 128 | ${NONE} | local +| | ... | ${FALSE} | ${NONE} -- 2.16.6