From 54021405af918f9b6ee2fc8c0d531903f579e930 Mon Sep 17 00:00:00 2001 From: selias Date: Thu, 18 May 2017 18:07:46 +0200 Subject: CSIT-610 HC Test: add test cases for unnumbered interface - add interface and sub-interface tests with unnumbered config - modify interface IPv4 address assignment to handle custom interfaces and sub-interfaces - pylint and style fixes Change-Id: Ic39df1655b4d44f0025a2acef9f7f968929aeff5 Signed-off-by: selias --- .../python/honeycomb/HcAPIKwInterfaces.py | 103 +++++++-- .../libraries/python/honeycomb/HoneycombSetup.py | 2 +- resources/libraries/python/honeycomb/Lisp.py | 4 +- resources/libraries/python/honeycomb/ProxyARP.py | 232 +++++++++++++++++++++ resources/libraries/python/honeycomb/proxyARP.py | 232 --------------------- 5 files changed, 325 insertions(+), 248 deletions(-) create mode 100644 resources/libraries/python/honeycomb/ProxyARP.py delete mode 100644 resources/libraries/python/honeycomb/proxyARP.py (limited to 'resources/libraries/python') diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py index e78696cd15..1e0b1a5d14 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py +++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py @@ -483,22 +483,32 @@ class InterfaceKeywords(object): :type network: str or int :returns: Content of response. :rtype: bytearray - :raises HoneycombError: If the provided netmask or prefix is not valid. + :raises ValueError: If the provided netmask or prefix is not valid. + :raises HoneycombError: If the operation fails. """ - interface = Topology.convert_interface_reference( - node, interface, "name") + interface = InterfaceKeywords.handle_interface_reference( + node, interface) - path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4") + path = "/interface/{0}/ietf-ip:ipv4".format(interface) if isinstance(network, basestring): - address = {"address": [{"ip": ip_addr, "netmask": network}, ]} + data = { + "ietf-ip:ipv4": { + "address": [{"ip": ip_addr, "netmask": network}, ]}} elif isinstance(network, int) and (0 < network < 33): - address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]} + data = { + "ietf-ip:ipv4": { + "address": [{"ip": ip_addr, "prefix-length": network}, ]}} else: - raise HoneycombError("Value {0} is not a valid netmask or network " - "prefix length.".format(network)) - return InterfaceKeywords._set_interface_properties( - node, interface, path, address) + raise ValueError("Value {0} is not a valid netmask or network " + "prefix length.".format(network)) + status_code, _ = HcUtil.put_honeycomb_data( + node, "config_vpp_interfaces", data, path) + + if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): + raise HoneycombError( + "Configuring IPv4 address failed. " + "Status code:{0}".format(status_code)) @staticmethod def add_ipv4_address(node, interface, ip_addr, network): @@ -1555,10 +1565,8 @@ class InterfaceKeywords(object): :param node: Honeycomb node. :param interface: The interface where policer will be disabled. - :param table_name: Name of the classify table. :type node: dict :type interface: str - :type table_name: str :returns: Content of response. :rtype: bytearray :raises HoneycombError: If the configuration of interface is not @@ -1780,7 +1788,7 @@ class InterfaceKeywords(object): for src_interface in src_interfaces: src_interface["iface-ref"] = Topology. \ convert_interface_reference( - node, src_interface["iface-ref"], "name") + node, src_interface["iface-ref"], "name") data = { "span": { "mirrored-interfaces": { @@ -1809,3 +1817,72 @@ class InterfaceKeywords(object): local0_key = Topology.add_new_port(node, "localzero") Topology.update_interface_sw_if_index(node, local0_key, 0) Topology.update_interface_name(node, local0_key, "local0") + + @staticmethod + def configure_interface_unnumbered(node, interface, interface_src=None): + """Configure the specified interface as unnumbered. The interface + borrows IP address from the specified source interface. If not source + interface is provided, unnumbered configuration will be removed. + + :param node: Honeycomb node. + :param interface: Name, link name or sw_if_index of an interface. + :param interface_src: Name of source interface. + :type node: dict + :type interface: str or int + :type interface_src: str + :raises HoneycombError: If the configuration fails. + """ + + interface = InterfaceKeywords.handle_interface_reference( + node, interface) + + path = "/interface/{0}/unnumbered-interfaces:unnumbered"\ + .format(interface) + + if interface_src: + data = { + "unnumbered": { + "use": interface_src + } + } + status_code, _ = HcUtil.put_honeycomb_data( + node, "config_vpp_interfaces", data, path) + else: + status_code, _ = HcUtil.delete_honeycomb_data( + node, "config_vpp_interfaces", path) + + if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): + raise HoneycombError( + "Configuring unnumbered interface failed. " + "Status code:{0}".format(status_code)) + + @staticmethod + def handle_interface_reference(node, interface): + """Convert any interface reference to interface name used by Honeycomb. + + :param node: Honeycomb node. + :param interface: Name, link name or sw_if_index of an interface, + name of a custom interface or name of a sub-interface. + :type node: Honeycomb node. + :type interface: str or int + :returns: Name of interface that can be used in Honeycomb requests. + :rtype: str + """ + + try: + interface = Topology.convert_interface_reference( + node, interface, "name") + interface = interface.replace("/", "%2F") + except RuntimeError: + # interface is not in topology + if "." in interface: + # Assume it's the name of a sub-interface + interface, index = interface.split(".") + interface = interface.replace("/", "%2F") + interface = "{0}/vpp-vlan:sub-interfaces/sub-interface/{1}".\ + format(interface, index) + else: + # Assume it's the name of a custom interface (pbb, vxlan, etc.) + interface = interface.replace("/", "%2F") + + return interface diff --git a/resources/libraries/python/honeycomb/HoneycombSetup.py b/resources/libraries/python/honeycomb/HoneycombSetup.py index aecb022314..5026cb4868 100644 --- a/resources/libraries/python/honeycomb/HoneycombSetup.py +++ b/resources/libraries/python/honeycomb/HoneycombSetup.py @@ -438,7 +438,7 @@ class HoneycombSetup(object): "node {0}, {1}".format(node, stderr)) @staticmethod - def setup_odl_client(node, odl_name): + def configure_odl_client(node, odl_name): """Start ODL client on the specified node. Karaf should be located in /mnt/common, and VPP and Honeycomb should diff --git a/resources/libraries/python/honeycomb/Lisp.py b/resources/libraries/python/honeycomb/Lisp.py index 8c124d194c..f89ffed0b9 100644 --- a/resources/libraries/python/honeycomb/Lisp.py +++ b/resources/libraries/python/honeycomb/Lisp.py @@ -148,7 +148,7 @@ class LispKeywords(object): if ret_code == HTTPCodes.OK: data["lisp"]["enable"] = bool(state) elif ret_code == HTTPCodes.NOT_FOUND: - data = {"lisp": {"enable": bool(state)}} + data = {"lisp": {"enable": bool(state)}} else: raise HoneycombError("Unexpected return code when getting existing" " Lisp configuration.") @@ -340,7 +340,7 @@ class LispKeywords(object): data = { "map-request-mode": { "mode": "source-destination" if src_dst - else "target-destination" + else "target-destination" } } diff --git a/resources/libraries/python/honeycomb/ProxyARP.py b/resources/libraries/python/honeycomb/ProxyARP.py new file mode 100644 index 0000000000..9696bf4238 --- /dev/null +++ b/resources/libraries/python/honeycomb/ProxyARP.py @@ -0,0 +1,232 @@ +# 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. + +"""This module implements keywords to configure proxyARP 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 HoneycombUtil as HcUtil +from resources.libraries.python.honeycomb.HoneycombUtil \ + import DataRepresentation +from resources.libraries.python.topology import Topology + + +class ProxyARPKeywords(object): + """Implementation of keywords which make it possible to: + - configure proxyARP behaviour + - enable/disable proxyARP on individual interfaces + """ + + def __init__(self): + """Initializer.""" + pass + + @staticmethod + def configure_proxyarp(node, data): + """Configure the proxyARP feature and check the return code. + + :param node: Honeycomb node. + :param data: Configuration to use. + :type node: dict + :type data: dict + :returns: Content of response. + :rtype: bytearray + :raises HoneycombError: If the status code in response to PUT is not + 200 = OK or 201 = ACCEPTED. + """ + + data = { + "proxy-ranges": { + "proxy-range": [ + data, + ] + } + } + + status_code, resp = HcUtil.\ + put_honeycomb_data(node, "config_proxyarp_ranges", data, + data_representation=DataRepresentation.JSON) + + if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): + raise HoneycombError( + "proxyARP configuration unsuccessful. " + "Status code: {0}.".format(status_code)) + else: + return resp + + @staticmethod + def remove_proxyarp_configuration(node): + """Delete the proxyARP node, removing all of its configuration. + + :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. \ + delete_honeycomb_data(node, "config_proxyarp_ranges") + + if status_code != HTTPCodes.OK: + raise HoneycombError( + "proxyARP removal unsuccessful. " + "Status code: {0}.".format(status_code)) + else: + return resp + + @staticmethod + def get_proxyarp_operational_data(node): + """Retrieve proxyARP properties from Honeycomb operational data. + Note: The proxyARP feature has no operational data available. + + :param node: Honeycomb node. + :type node: dict + :returns: proxyARP operational data. + :rtype: bytearray + """ + + raise NotImplementedError("Not supported in VPP.") + + @staticmethod + def set_proxyarp_interface_config(node, interface, state): + """Enable or disable the proxyARP feature on the specified interface. + + :param node: Honeycomb node. + :param interface: Name or sw_if_index of an interface on the node. + :param state: Desired proxyARP state: enable, disable. + :type node: dict + :type interface: str + :type state: str + :raises ValueError: If the state argument is incorrect. + :raises HoneycombError: If the status code in response is not + 200 = OK or 201 = ACCEPTED. + """ + + interface = Topology.convert_interface_reference( + node, interface, "name") + interface = interface.replace("/", "%2F") + + path = "/interface/{0}/proxy-arp".format(interface) + + if state == "disable": + status_code, _ = HcUtil.delete_honeycomb_data( + node, "config_vpp_interfaces", path) + elif state == "enable": + data = {"proxy-arp": {}} + status_code, _ = HcUtil.put_honeycomb_data( + node, "config_vpp_interfaces", data, path) + else: + raise ValueError("State argument has to be enable or disable.") + + if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): + raise HoneycombError( + "Interface proxyARP configuration on node {0} was not" + " successful.".format(node["host"])) + + @staticmethod + def get_proxyarp_interface_assignment(node, interface): + """Read the status of proxyARP feature on the specified interface. + Note: The proxyARP feature has no operational data available. + + :param node: Honeycomb node. + :param interface: Name or sw_if_index of an interface on the node. + :type node: dict + :type interface: str + :returns: Content of response. + :rtype: bytearray + """ + + raise NotImplementedError("Not supported in VPP.") + + +class IPv6NDProxyKeywords(object): + """Keywords for IPv6 Neighbor Discovery proxy configuration.""" + + def __init__(self): + pass + + @staticmethod + def configure_ipv6nd(node, interface, addresses=None): + """Configure IPv6 Neighbor Discovery proxy on the specified interface, + or remove/replace an existing configuration. + + :param node: Honeycomb node. + :param interface: Name of an interface on the node. + :param addresses: IPv6 addresses to configure ND proxy with. If no + address is provided, ND proxy configuration will be removed. + :type node: dict + :type interface: str + :type addresses: list + :returns: Content of response. + :rtype: bytearray + :raises HoneycombError: If the operation fails. + """ + + interface = Topology.convert_interface_reference( + node, interface, "name") + interface = interface.replace("/", "%2F") + + path = "/interface/{0}/ietf-ip:ipv6/nd-proxies".format(interface) + + if addresses is None: + status_code, resp = HcUtil. \ + delete_honeycomb_data(node, "config_vpp_interfaces", path) + else: + data = { + "nd-proxies": { + "nd-proxy": [{"address": x} for x in addresses] + } + } + + status_code, resp = HcUtil. \ + put_honeycomb_data(node, "config_vpp_interfaces", data, path, + data_representation=DataRepresentation.JSON) + + if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): + raise HoneycombError( + "IPv6 ND proxy configuration unsuccessful. " + "Status code: {0}.".format(status_code)) + else: + return resp + + @staticmethod + def get_ipv6nd_configuration(node, interface): + """Read IPv6 Neighbor Discovery proxy configuration on the specified + interface. + + :param node: Honeycomb node. + :param interface: Name of an interface on the node. + :type node: dict + :type interface: str + :returns: Content of response. + :rtype: bytearray + :raises HoneycombError: If the configuration could not be read. + """ + + interface = Topology.convert_interface_reference( + node, interface, "name") + interface = interface.replace("/", "%2F") + + path = "/interface/{0}/ietf-ip:ipv6/nd-proxies".format(interface) + + status_code, resp = HcUtil.get_honeycomb_data( + node, "config_vpp_interfaces", path) + if status_code != HTTPCodes.OK: + raise HoneycombError( + "Could not read IPv6 ND proxy configuration. " + "Status code: {0}.".format(status_code)) + else: + return resp diff --git a/resources/libraries/python/honeycomb/proxyARP.py b/resources/libraries/python/honeycomb/proxyARP.py deleted file mode 100644 index 9696bf4238..0000000000 --- a/resources/libraries/python/honeycomb/proxyARP.py +++ /dev/null @@ -1,232 +0,0 @@ -# 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. - -"""This module implements keywords to configure proxyARP 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 HoneycombUtil as HcUtil -from resources.libraries.python.honeycomb.HoneycombUtil \ - import DataRepresentation -from resources.libraries.python.topology import Topology - - -class ProxyARPKeywords(object): - """Implementation of keywords which make it possible to: - - configure proxyARP behaviour - - enable/disable proxyARP on individual interfaces - """ - - def __init__(self): - """Initializer.""" - pass - - @staticmethod - def configure_proxyarp(node, data): - """Configure the proxyARP feature and check the return code. - - :param node: Honeycomb node. - :param data: Configuration to use. - :type node: dict - :type data: dict - :returns: Content of response. - :rtype: bytearray - :raises HoneycombError: If the status code in response to PUT is not - 200 = OK or 201 = ACCEPTED. - """ - - data = { - "proxy-ranges": { - "proxy-range": [ - data, - ] - } - } - - status_code, resp = HcUtil.\ - put_honeycomb_data(node, "config_proxyarp_ranges", data, - data_representation=DataRepresentation.JSON) - - if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): - raise HoneycombError( - "proxyARP configuration unsuccessful. " - "Status code: {0}.".format(status_code)) - else: - return resp - - @staticmethod - def remove_proxyarp_configuration(node): - """Delete the proxyARP node, removing all of its configuration. - - :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. \ - delete_honeycomb_data(node, "config_proxyarp_ranges") - - if status_code != HTTPCodes.OK: - raise HoneycombError( - "proxyARP removal unsuccessful. " - "Status code: {0}.".format(status_code)) - else: - return resp - - @staticmethod - def get_proxyarp_operational_data(node): - """Retrieve proxyARP properties from Honeycomb operational data. - Note: The proxyARP feature has no operational data available. - - :param node: Honeycomb node. - :type node: dict - :returns: proxyARP operational data. - :rtype: bytearray - """ - - raise NotImplementedError("Not supported in VPP.") - - @staticmethod - def set_proxyarp_interface_config(node, interface, state): - """Enable or disable the proxyARP feature on the specified interface. - - :param node: Honeycomb node. - :param interface: Name or sw_if_index of an interface on the node. - :param state: Desired proxyARP state: enable, disable. - :type node: dict - :type interface: str - :type state: str - :raises ValueError: If the state argument is incorrect. - :raises HoneycombError: If the status code in response is not - 200 = OK or 201 = ACCEPTED. - """ - - interface = Topology.convert_interface_reference( - node, interface, "name") - interface = interface.replace("/", "%2F") - - path = "/interface/{0}/proxy-arp".format(interface) - - if state == "disable": - status_code, _ = HcUtil.delete_honeycomb_data( - node, "config_vpp_interfaces", path) - elif state == "enable": - data = {"proxy-arp": {}} - status_code, _ = HcUtil.put_honeycomb_data( - node, "config_vpp_interfaces", data, path) - else: - raise ValueError("State argument has to be enable or disable.") - - if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): - raise HoneycombError( - "Interface proxyARP configuration on node {0} was not" - " successful.".format(node["host"])) - - @staticmethod - def get_proxyarp_interface_assignment(node, interface): - """Read the status of proxyARP feature on the specified interface. - Note: The proxyARP feature has no operational data available. - - :param node: Honeycomb node. - :param interface: Name or sw_if_index of an interface on the node. - :type node: dict - :type interface: str - :returns: Content of response. - :rtype: bytearray - """ - - raise NotImplementedError("Not supported in VPP.") - - -class IPv6NDProxyKeywords(object): - """Keywords for IPv6 Neighbor Discovery proxy configuration.""" - - def __init__(self): - pass - - @staticmethod - def configure_ipv6nd(node, interface, addresses=None): - """Configure IPv6 Neighbor Discovery proxy on the specified interface, - or remove/replace an existing configuration. - - :param node: Honeycomb node. - :param interface: Name of an interface on the node. - :param addresses: IPv6 addresses to configure ND proxy with. If no - address is provided, ND proxy configuration will be removed. - :type node: dict - :type interface: str - :type addresses: list - :returns: Content of response. - :rtype: bytearray - :raises HoneycombError: If the operation fails. - """ - - interface = Topology.convert_interface_reference( - node, interface, "name") - interface = interface.replace("/", "%2F") - - path = "/interface/{0}/ietf-ip:ipv6/nd-proxies".format(interface) - - if addresses is None: - status_code, resp = HcUtil. \ - delete_honeycomb_data(node, "config_vpp_interfaces", path) - else: - data = { - "nd-proxies": { - "nd-proxy": [{"address": x} for x in addresses] - } - } - - status_code, resp = HcUtil. \ - put_honeycomb_data(node, "config_vpp_interfaces", data, path, - data_representation=DataRepresentation.JSON) - - if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): - raise HoneycombError( - "IPv6 ND proxy configuration unsuccessful. " - "Status code: {0}.".format(status_code)) - else: - return resp - - @staticmethod - def get_ipv6nd_configuration(node, interface): - """Read IPv6 Neighbor Discovery proxy configuration on the specified - interface. - - :param node: Honeycomb node. - :param interface: Name of an interface on the node. - :type node: dict - :type interface: str - :returns: Content of response. - :rtype: bytearray - :raises HoneycombError: If the configuration could not be read. - """ - - interface = Topology.convert_interface_reference( - node, interface, "name") - interface = interface.replace("/", "%2F") - - path = "/interface/{0}/ietf-ip:ipv6/nd-proxies".format(interface) - - status_code, resp = HcUtil.get_honeycomb_data( - node, "config_vpp_interfaces", path) - if status_code != HTTPCodes.OK: - raise HoneycombError( - "Could not read IPv6 ND proxy configuration. " - "Status code: {0}.".format(status_code)) - else: - return resp -- cgit 1.2.3-korg