X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Fhoneycomb%2FHcAPIKwInterfaces.py;h=3a32cbe5ff1c0bc26978b894c17bd1d6529c3c6b;hp=01a2eba0ada87da678362af1c664f68ccca9b03e;hb=e3171449c75d948461ac24b0df7212e8a2ca45f9;hpb=4f70ebf481d496f91d2b1ec27361c9898b19c451 diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py index 01a2eba0ad..3a32cbe5ff 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py +++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py @@ -27,8 +27,6 @@ from resources.libraries.python.honeycomb.HoneycombUtil \ import HoneycombUtil as HcUtil -# pylint: disable=too-many-public-methods -# pylint: disable=too-many-lines class InterfaceKeywords(object): """Keywords for Interface manipulation. @@ -46,7 +44,7 @@ class InterfaceKeywords(object): "temporary-valid-lifetime", "temporary-preferred-lifetime") ETH_PARAMS = ("mtu", ) - ROUTING_PARAMS = ("vrf-id", ) + ROUTING_PARAMS = ("ipv4-vrf-id", "ipv6-vrf-id") VXLAN_PARAMS = ("src", "dst", "vni", "encap-vrf-id") L2_PARAMS = ("bridge-domain", "split-horizon-group", "bridged-virtual-interface") @@ -515,9 +513,9 @@ class InterfaceKeywords(object): path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4", "address") if isinstance(network, basestring): - address = {"address": [{"ip": ip_addr, "netmask": network}, ]} + address = [{"ip": ip_addr, "netmask": network}] elif isinstance(network, int) and (0 < network < 33): - address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]} + address = [{"ip": ip_addr, "prefix-length": network}] else: raise HoneycombError("Value {0} is not a valid netmask or network " "prefix length.".format(network)) @@ -1145,7 +1143,7 @@ class InterfaceKeywords(object): path = ("interfaces", ("interface", "name", super_interface), "vpp-vlan:sub-interfaces", - ("sub-interface", "identifier", identifier), + ("sub-interface", "identifier", int(identifier)), "enabled") return InterfaceKeywords._set_interface_properties( @@ -1250,8 +1248,8 @@ class InterfaceKeywords(object): "information about the tag-rewrite.") @staticmethod - def add_ipv4_address_to_sub_interface(node, super_interface, identifier, - ip_addr, network): + def add_ip_address_to_sub_interface(node, super_interface, identifier, + ip_addr, network, ip_version): """Add an ipv4 address to the specified sub-interface, with the provided netmask or network prefix length. Any existing ipv4 addresses on the sub-interface will be replaced. @@ -1261,11 +1259,13 @@ class InterfaceKeywords(object): :param identifier: The ID of sub-interface. :param ip_addr: IPv4 address to be set. :param network: Network mask or network prefix length. + :param ip_version: ipv4 or ipv6 :type node: dict :type super_interface: str :type identifier: int :type ip_addr: str :type network: str or int + :type ip_version: string :returns: Content of response. :rtype: bytearray :raises HoneycombError: If the provided netmask or prefix is not valid. @@ -1275,9 +1275,9 @@ class InterfaceKeywords(object): ("interface", "name", super_interface), "vpp-vlan:sub-interfaces", ("sub-interface", "identifier", int(identifier)), - "ipv4") + ip_version.lower()) - if isinstance(network, basestring): + if isinstance(network, basestring) and ip_version.lower() == "ipv4": address = {"address": [{"ip": ip_addr, "netmask": network}, ]} elif isinstance(network, int) and 0 < network < 33: @@ -1291,16 +1291,18 @@ class InterfaceKeywords(object): node, super_interface, path, address) @staticmethod - def remove_all_ipv4_addresses_from_sub_interface(node, super_interface, # pylint: disable=invalid-name - identifier): + def remove_all_ip_addresses_from_sub_interface(node, super_interface, + identifier, ip_version): """Remove all ipv4 addresses from the specified sub-interface. :param node: Honeycomb node. :param super_interface: Super interface. :param identifier: The ID of sub-interface. + :param ip_version: ipv4 or ipv6 :type node: dict :type super_interface: str :type identifier: int + :type ip_version: string :returns: Content of response. :rtype: bytearray """ @@ -1309,49 +1311,79 @@ class InterfaceKeywords(object): ("interface", "name", super_interface), "vpp-vlan:sub-interfaces", ("sub-interface", "identifier", int(identifier)), - "ipv4", "address") + str(ip_version), "address") return InterfaceKeywords._set_interface_properties( node, super_interface, path, None) @staticmethod - def compare_data_structures(data, ref, ignore=(), list_order=True): - """Checks if data obtained from UUT is as expected. + def compare_data_structures(data, ref, _path=''): + """Checks if data obtained from UUT is as expected. If it is not, + proceeds down the list/dictionary tree and finds the point of mismatch. :param data: Data to be checked. :param ref: Referential data used for comparison. - :param ignore: Dictionary keys to be ignored. - :param list_order: Whether to consider the order of list items\ - in comparison. + :param _path: Used in recursive calls, stores the path taken down + the JSON tree. :type data: dict :type ref: dict - :type ignore: iterable - :type list_order: bool + :type _path: str - :raises HoneycombError: If a parameter from referential data is not - present in operational data or if it has different value. + :raises HoneycombError: If the data structures do not match in some way, + or if they are not in deserialized JSON format. """ - errors = "" - - for key, item in ref.items(): - if key in ignore: - continue - try: - if data[key] != item: - if not list_order and sorted(data[key]) == sorted(item): - pass + if data == ref: + return True + + elif isinstance(data, dict) and isinstance(ref, dict): + for key in ref: + if key not in data: + raise HoneycombError( + "Key {key} is not present in path {path}. Keys in path:" + "{data_keys}".format( + key=key, + path=_path, + data_keys=data.keys())) + + if data[key] != ref[key]: + if isinstance(data[key], list) \ + or isinstance(data[key], dict): + InterfaceKeywords.compare_data_structures( + data[key], ref[key], + _path + '[{0}]'.format(key)) else: - errors += ("\nThe value of parameter '{0}' is " - "incorrect. It should be " - "'{1}' but it is '{2}'". - format(key, item, data[key])) - except KeyError: - errors += ("\nThe parameter '{0}' is not present in " - "operational data".format(key)) + raise HoneycombError( + "Data mismatch, key {key} in path {path} has value" + " {data}, but should be {ref}".format( + key=key, + path=_path, + data=data[key], + ref=ref[key])) + + elif isinstance(data, list) and isinstance(ref, list): + for item in ref: + if item not in data: + if isinstance(item, dict): + InterfaceKeywords.compare_data_structures( + data[0], item, + _path + '[{0}]'.format(ref.index(item))) + else: + raise HoneycombError( + "Data mismatch, list item {index} in path {path}" + " has value {data}, but should be {ref}".format( + index=ref.index(item), + path=_path, + data=data[0], + ref=item)) - if errors: - raise HoneycombError(errors) + else: + raise HoneycombError( + "Unexpected data type {data_type} in path {path}, reference" + " type is {ref_type}. Must be list or dictionary.".format( + data_type=type(data), + ref_type=type(ref), + path=_path)) @staticmethod def compare_interface_lists(list1, list2):