From 481744b2732ab840a00129bacb5994baa19e125c Mon Sep 17 00:00:00 2001 From: selias Date: Wed, 11 May 2016 11:42:54 +0200 Subject: Update Honeycomb interface IPv4 test - add verification of ipv4 subnet prefix support - modify keywords to allow setting ipv4 address with network prefix - fix variable definitions to evaluate numbers as ints, not strings - add exception to ipv4 netmask/prefix conversion method Change-Id: I9343ceb35856ddb33674d7067f1def6d40e99acc Signed-off-by: selias --- .../python/honeycomb/HcAPIKwInterfaces.py | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'resources/libraries/python/honeycomb/HcAPIKwInterfaces.py') diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py index 8f6819ef5e..b1dd5b5dd1 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py +++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py @@ -331,7 +331,7 @@ class InterfaceKeywords(object): node, interface, path, value) @staticmethod - def add_first_ipv4_address(node, interface, ip_addr, netmask): + def add_first_ipv4_address(node, interface, ip_addr, network): """Add the first IPv4 address. If there are any other addresses configured, they will be removed. @@ -339,39 +339,51 @@ class InterfaceKeywords(object): :param node: Honeycomb node. :param interface: The name of interface. :param ip_addr: IPv4 address to be set. - :param netmask: Netmask. + :param network: Netmask or length of network prefix. :type node: dict :type interface: str :type ip_addr: str - :type netmask: str + :type network: str or int :return: Content of response. :rtype: bytearray """ path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4") - address = {"address": [{"ip": ip_addr, "netmask": netmask}, ]} + if isinstance(network, basestring): + address = {"address": [{"ip": ip_addr, "netmask": network}, ]} + elif isinstance(network, int) and (0 < network < 33): + address = {"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) @staticmethod - def add_ipv4_address(node, interface, ip_addr, netmask): + def add_ipv4_address(node, interface, ip_addr, network): """Add IPv4 address. :param node: Honeycomb node. :param interface: The name of interface. :param ip_addr: IPv4 address to be set. - :param netmask: Netmask. + :param network: Netmask or length of network prefix. :type node: dict :type interface: str :type ip_addr: str - :type netmask: str + :type network: str or int :return: Content of response. :rtype: bytearray """ path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4", "address") - address = [{"ip": ip_addr, "prefix-length": netmask}, ] + if isinstance(network, basestring): + address = {"address": [{"ip": ip_addr, "netmask": network}, ]} + elif isinstance(network, int) and (0 < network < 33): + address = {"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) -- cgit 1.2.3-korg