aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
authorTibor Frank <tifrank@cisco.com>2016-05-26 14:11:09 +0200
committerMatej Klotton <mklotton@cisco.com>2016-06-01 12:54:26 +0000
commit036f36181c177e4c77f22cdbdcb87fb2f94df3bf (patch)
tree74b3240035629298861b75b711eb8c9eb4d00587 /resources/libraries/python
parentdeb6fdb6a59f5c02b8cacaa9c0e6043562e53646 (diff)
Add Honeycomb sub-interface and VLAN tests
JIRA: CSIT-94 JIRA: CSIT-48 - add Honeycomb sub-interface tests - add Honeycomb VLAN tests - add keywords for sub-interface tests - add keywords for VLAN tests Change-Id: I89cd3b41dd9c60bfd946e24567d0ff93e5ea9fff Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/InterfaceUtil.py12
-rw-r--r--resources/libraries/python/honeycomb/HcAPIKwInterfaces.py118
-rw-r--r--resources/libraries/python/honeycomb/HoneycombUtil.py2
3 files changed, 125 insertions, 7 deletions
diff --git a/resources/libraries/python/InterfaceUtil.py b/resources/libraries/python/InterfaceUtil.py
index 838ba3bb69..35077d8268 100644
--- a/resources/libraries/python/InterfaceUtil.py
+++ b/resources/libraries/python/InterfaceUtil.py
@@ -190,15 +190,15 @@ class InterfaceUtil(object):
if interface is not None:
if isinstance(interface, basestring):
- sw_if_index = Topology.get_interface_sw_index(node, interface)
+ param = "interface_name"
+ elif isinstance(interface, int):
+ param = "sw_if_index"
else:
- sw_if_index = interface
-
+ raise TypeError
for data_if in data:
- if data_if["sw_if_index"] == sw_if_index:
-
+ if data_if[param] == interface:
return data_if
-
+ return dict()
return data
@staticmethod
diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py
index 3f9e9d16a5..c143b069db 100644
--- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py
+++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py
@@ -26,6 +26,7 @@ from resources.libraries.python.honeycomb.HoneycombUtil \
# pylint: disable=too-many-public-methods
+# pylint: disable=too-many-lines
class InterfaceKeywords(object):
"""Keywords for Interface manipulation.
@@ -34,7 +35,7 @@ class InterfaceKeywords(object):
"""
INTF_PARAMS = ("name", "description", "type", "enabled",
- "link-up-down-trap-enable")
+ "link-up-down-trap-enable", "v3po:l2")
IPV4_PARAMS = ("enabled", "forwarding", "mtu")
IPV6_PARAMS = ("enabled", "forwarding", "mtu", "dup-addr-detect-transmits")
IPV6_AUTOCONF_PARAMS = ("create-global-addresses",
@@ -46,8 +47,22 @@ class InterfaceKeywords(object):
VXLAN_PARAMS = ("src", "dst", "vni", "encap-vrf-id")
L2_PARAMS = ("bridge-domain", "split-horizon-group",
"bridged-virtual-interface")
+ L2_REWRITE_TAG_PARAMS = ("rewrite-operation",
+ "first-pushed",
+ "tag1",
+ "tag2")
TAP_PARAMS = ("tap-name", "mac", "device-instance")
VHOST_USER_PARAMS = ("socket", "role")
+ SUB_INTF_PARAMS = ("super-interface",
+ "identifier",
+ "vlan-type",
+ "number-of-tags",
+ "outer-id",
+ "inner-id",
+ "match-any-outer-id",
+ "match-any-inner-id",
+ "exact-match",
+ "default-subif")
def __init__(self):
pass
@@ -931,3 +946,104 @@ class InterfaceKeywords(object):
new_vhost_structure = [new_vhost, ]
return InterfaceKeywords._set_interface_properties(
node, interface, path, new_vhost_structure)
+
+ @staticmethod
+ def create_sub_interface(node, super_interface, identifier, **kwargs):
+ """Create a new sub-interface.
+
+ :param node: Honeycomb node.
+ :param super_interface: The name of super interface.
+ :param identifier: sub-interface identifier.
+ :param kwargs: Parameters and their values. The accepted parameters are
+ defined in InterfaceKeywords.SUB_INTF_PARAMS.
+ :type node: dict
+ :type super_interface: str
+ :type identifier: int
+ :type kwargs: dict
+ :return: Content of response.
+ :rtype: bytearray
+ :raises HoneycombError: If the parameter is not valid.
+ """
+
+ # These parameters are empty types (in JSON represented as empty
+ # dictionary) but ODL internally represents them as Booleans. If the
+ # value is an empty dictionary, it is True, if the parameter is
+ # missing, it is False.
+ empty_types = ("match-any-outer-id",
+ "match-any-inner-id",
+ "exact-match",
+ "default-subif")
+
+ sub_interface_name = "{0}.{1}".format(super_interface, str(identifier))
+ new_sub_interface = {
+ "name": sub_interface_name,
+ "type": "v3po:sub-interface",
+ "enabled": "false",
+ "sub-interface": {
+ "super-interface": super_interface,
+ "identifier": identifier
+ }
+ }
+ for param, value in kwargs.items():
+ if param in InterfaceKeywords.INTF_PARAMS:
+ new_sub_interface[param] = value
+ elif param in InterfaceKeywords.SUB_INTF_PARAMS:
+ if param in empty_types:
+ if value:
+ new_sub_interface["sub-interface"][param] = dict()
+ else:
+ new_sub_interface["sub-interface"][param] = value
+ else:
+ raise HoneycombError("The parameter {0} is invalid.".
+ format(param))
+
+ path = ("interfaces", "interface")
+ new_sub_interface_structure = [new_sub_interface, ]
+ return InterfaceKeywords._set_interface_properties(
+ node, sub_interface_name, path, new_sub_interface_structure)
+
+ @staticmethod
+ def add_vlan_tag_rewrite_to_sub_interface(node, sub_interface, **kwargs):
+ """Add vlan tag rewrite to a sub-interface.
+
+ :param node: Honeycomb node.
+ :param sub_interface: The name of sub-interface.
+ :param kwargs: Parameters and their values. The accepted parameters are
+ defined in InterfaceKeywords.L2_REWRITE_TAG_PARAMS.
+ :type node: dict
+ :type sub_interface: str
+ :type kwargs: dict
+ :return: Content of response.
+ :rtype: bytearray
+ :raises HoneycombError: If the parameter is not valid.
+ """
+
+ new_rewrite = dict()
+ for param, value in kwargs.items():
+ if param in InterfaceKeywords.L2_REWRITE_TAG_PARAMS:
+ new_rewrite[param] = value
+ else:
+ raise HoneycombError("The parameter {0} is invalid.".
+ format(param))
+
+ path = ("interfaces", ("interface", "name", sub_interface), "v3po:l2",
+ "vlan-tag-rewrite")
+ return InterfaceKeywords._set_interface_properties(
+ node, sub_interface, path, new_rewrite)
+
+ @staticmethod
+ def remove_vlan_tag_rewrite_from_sub_interface(node, sub_interface):
+ """Remove vlan tag rewrite from a sub-interface.
+
+ :param node: Honeycomb node.
+ :param sub_interface: The name of sub-interface.
+ :type node: dict
+ :type sub_interface: str
+ :rtype: bytearray
+ :raises HoneycombError: If the parameter is not valid.
+ """
+
+ path = ("interfaces", ("interface", "name", sub_interface), "v3po:l2",
+ "vlan-tag-rewrite")
+ return InterfaceKeywords._set_interface_properties(
+ node, sub_interface, path, None)
diff --git a/resources/libraries/python/honeycomb/HoneycombUtil.py b/resources/libraries/python/honeycomb/HoneycombUtil.py
index 644cf62c43..2f8392ecb5 100644
--- a/resources/libraries/python/honeycomb/HoneycombUtil.py
+++ b/resources/libraries/python/honeycomb/HoneycombUtil.py
@@ -330,6 +330,8 @@ class HoneycombUtil(object):
if data_representation == DataRepresentation.JSON:
data = dumps(data)
+ logger.trace(data)
+
path = HoneycombUtil.read_path_from_url_file(url_file)
return HTTPRequest.put(node=node, path=path, headers=header,
payload=data)