aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
authorTibor Frank <tifrank@cisco.com>2016-06-16 09:05:45 +0200
committerJan Gelety <jgelety@cisco.com>2016-06-23 12:53:58 +0000
commit95253bdf705a06ec01c2a04f437bae2ef23355c3 (patch)
tree0c8ac3978d87b29dd705fe817d38ebf7346223b5 /resources/libraries/python
parent33e58e512b91d57f0ccab05d6e57de11d7c9fd37 (diff)
Add tests for Honeycomb L2 FIB support
JIRA: CSIT-168 - add tests for Honeycomb L2 FIB support - add keywords for Honeycomb L2 FIB support - fix typos Change-Id: I81292c10e26e7ad05725034c1db1db0a81d29283 Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/L2Util.py75
-rw-r--r--resources/libraries/python/honeycomb/HcAPIKwBridgeDomain.py152
-rw-r--r--resources/libraries/python/honeycomb/HcAPIKwInterfaces.py23
3 files changed, 250 insertions, 0 deletions
diff --git a/resources/libraries/python/L2Util.py b/resources/libraries/python/L2Util.py
index e44a6b360a..db550f0640 100644
--- a/resources/libraries/python/L2Util.py
+++ b/resources/libraries/python/L2Util.py
@@ -307,3 +307,78 @@ class L2Util(object):
tag_rewrite_method=
tag_rewrite_method,
tag1_optional=tag1_id)
+
+ @staticmethod
+ def delete_bridge_domain_vat(node, bd_id):
+ """Delete the specified bridge domain from the node.
+
+ :param node: VPP node to delete a bridge domain from.
+ :param bd_id: Bridge domain ID.
+ :type node: dict
+ :type bd_id: int
+ """
+
+ with VatTerminal(node) as vat:
+ vat.vat_terminal_exec_cmd_from_template(
+ "l2_bridge_domain_delete.vat", bd_id=bd_id)
+
+ @staticmethod
+ def delete_l2_fib_entry(node, bd_id, mac):
+ """Delete the specified L2 FIB entry.
+
+ :param node: VPP node.
+ :param bd_id: Bridge domain ID.
+ :param mac: MAC address used as the key in L2 FIB entry.
+ :type node: dict
+ :type bd_id: int
+ :type mac: str
+ """
+
+ with VatTerminal(node) as vat:
+ vat.vat_terminal_exec_cmd_from_template("l2_fib_entry_delete.vat",
+ mac=mac,
+ bd_id=bd_id)
+
+ @staticmethod
+ def get_l2_fib_table_vat(node, bd_index):
+ """Retrieves the L2 FIB table using VAT.
+
+ :param node: VPP node.
+ :param bd_index: Index of the bridge domain.
+ :type node: dict
+ :type bd_index: int
+ :return: L2 FIB table.
+ :rtype: list
+ """
+
+ bd_data = L2Util.vpp_get_bridge_domain_data(node)
+ bd_id = bd_data[bd_index-1]["bd_id"]
+
+ try:
+ with VatTerminal(node) as vat:
+ table = vat.vat_terminal_exec_cmd_from_template(
+ "l2_fib_table_dump.vat", bd_id=bd_id)
+
+ return table[0]
+ except ValueError:
+ return []
+
+ @staticmethod
+ def get_l2_fib_entry_vat(node, bd_index, mac):
+ """Retrieves the L2 FIB entry specified by MAC address using VAT.
+
+ :param node: VPP node.
+ :param bd_index: Index of the bridge domain.
+ :param mac: MAC address used as the key in L2 FIB data structure.
+ :type node: dict
+ :type bd_index: int
+ :type mac: str
+ :return: L2 FIB entry
+ :rtype: dict
+ """
+
+ table = L2Util.get_l2_fib_table_vat(node, bd_index)
+ for entry in table:
+ if entry["mac"] == mac:
+ return entry
+ return {}
diff --git a/resources/libraries/python/honeycomb/HcAPIKwBridgeDomain.py b/resources/libraries/python/honeycomb/HcAPIKwBridgeDomain.py
index 0906d5c762..e3fd6fb4fc 100644
--- a/resources/libraries/python/honeycomb/HcAPIKwBridgeDomain.py
+++ b/resources/libraries/python/honeycomb/HcAPIKwBridgeDomain.py
@@ -99,6 +99,7 @@ class BridgeDomainKeywords(object):
new_data = HcUtil.set_item_value(resp, path, new_value)
else:
new_data = HcUtil.remove_item(resp, path)
+
return BridgeDomainKeywords._configure_bd(node, bd_name, new_data)
@staticmethod
@@ -328,3 +329,154 @@ class BridgeDomainKeywords(object):
path = ("bridge-domains", ("bridge-domain", "name", bd_name), param)
return BridgeDomainKeywords.\
_set_bd_properties(node, bd_name, path, value)
+
+ @staticmethod
+ def add_l2_fib_entry(node, bd_name, l2_fib_entry):
+ """Add an L2 FIB entry to the bridge domain's list of L2 FIB entries.
+
+ :param node: Honeycomb node.
+ :param bd_name: Bridge domain's name.
+ :param l2_fib_entry: L2 FIB entry to be added to the L2 FIB table.
+ :type node: dict
+ :type bd_name: str
+ :type l2_fib_entry: dict
+ :return: Content of response.
+ :rtype: bytearray
+ """
+
+ path = ("bridge-domains",
+ ("bridge-domain", "name", bd_name),
+ "l2-fib-table",
+ "l2-fib-entry")
+
+ new_l2_fib_entry = [l2_fib_entry, ]
+ return BridgeDomainKeywords._set_bd_properties(
+ node, bd_name, path, new_l2_fib_entry)
+
+ @staticmethod
+ def modify_l2_fib_entry(node, bd_name, mac, param, value):
+ """Modify an existing L2 FIB entry in the bridge domain's L2 FIB table.
+ The L2 FIB entry is specified by MAC address.
+
+ :param node: Honeycomb node.
+ :param bd_name: Bridge domain's name.
+ :param mac: MAC address used as the key in L2 FIB data structure.
+ :param param: The parameter to be modified.
+ :param value: The new value of the parameter.
+ :type node: dict
+ :type bd_name: str
+ :type mac: str
+ :type param: str
+ :type value: str or int
+ :return: Content of response.
+ :rtype: bytearray
+ """
+
+ path = ("bridge-domains",
+ ("bridge-domain", "name", bd_name),
+ "l2-fib-table",
+ ("l2-fib-entry", "phys-address", mac),
+ param)
+
+ return BridgeDomainKeywords._set_bd_properties(
+ node, bd_name, path, value)
+
+ @staticmethod
+ def remove_l2_fib_entry(node, bd_name, mac):
+ """Remove an L2 FIB entry from bridge domain's L2 FIB table. The
+ entry is specified by MAC address.
+
+ :param node: Honeycomb node.
+ :param bd_name: Bridge domain's name.
+ :param mac: MAC address used as the key in L2 FIB data structure.
+ :type node: dict
+ :type bd_name: str
+ :type mac: str
+ :return: Content of response.
+ :rtype: bytearray
+ :raises HoneycombError: If it is not possible to remove the specified
+ entry.
+ """
+
+ path = ("bridge-domains",
+ ("bridge-domain", "name", bd_name),
+ "l2-fib-table",
+ ("l2-fib-entry", "phys-address", str(mac)))
+
+ status_code, resp = HcUtil.\
+ get_honeycomb_data(node, "config_bridge_domain")
+ if status_code != HTTPCodes.OK:
+ raise HoneycombError("Not possible to get configuration information"
+ " about the L2 FIB entry {0} from bridge "
+ "domain {1}. Status code: {2}.".
+ format(mac, bd_name, status_code))
+
+ new_data = HcUtil.remove_item(resp, path)
+ status_code, resp = HcUtil.\
+ put_honeycomb_data(node, "config_bridge_domain", new_data)
+ if status_code != HTTPCodes.OK:
+ raise HoneycombError("Not possible to remove L2 FIB entry {0} from "
+ "bridge domain {1}. Status code: {2}.".
+ format(mac, bd_name, status_code))
+ return resp
+
+
+ @staticmethod
+ def remove_all_l2_fib_entries(node, bd_name):
+ """Remove all entries from the bridge domain's L2 FIB table.
+
+ :param node: Honeycomb node.
+ :param bd_name: Bridge domain's name.
+ :type node: dict
+ :type bd_name: str
+ :return: Content of response.
+ :rtype: bytearray
+ """
+
+ path = ("bridge-domains",
+ ("bridge-domain", "name", bd_name),
+ "l2-fib-table")
+
+ return BridgeDomainKeywords._set_bd_properties(
+ node, bd_name, path, None)
+
+ @staticmethod
+ def get_all_l2_fib_entries(node, bd_name):
+ """Retrieves all entries from the bridge domain's L2 FIB table.
+
+ :param node: Honeycomb node.
+ :param bd_name: Bridge domain's name.
+ :type node: dict
+ :type bd_name: str
+ :return: Bridge domain's L2 FIB table or empty list if the table does
+ not exist or it is empty.
+ :rtype: list
+ """
+
+ bd_data = BridgeDomainKeywords.get_bd_oper_data(node, bd_name)
+ try:
+ return bd_data["l2-fib-table"]["l2-fib-entry"]
+ except KeyError:
+ return []
+
+ @staticmethod
+ def get_l2_fib_entry(node, bd_name, mac):
+ """Retrieves an entry from bridge domain's L2 FIB table. The entry is
+ specified by MAC address.
+
+ :param node: Honeycomb node.
+ :param bd_name: Bridge domain's name.
+ :param mac: MAC address used as the key in L2 FIB data structure.
+ :type node: dict
+ :type bd_name: str
+ :type mac: str
+ :return: The requested entry from bridge domain's L2 FIB table or empty
+ dictionary if it does not exist in the L2 FIB table.
+ :rtype: dict
+ """
+
+ l2_fib = BridgeDomainKeywords.get_all_l2_fib_entries(node, bd_name)
+ for entry in l2_fib:
+ if entry["phys-address"] == mac:
+ return entry
+ return {}
diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py
index e2be81e877..afd6076c7b 100644
--- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py
+++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py
@@ -301,6 +301,29 @@ class InterfaceKeywords(object):
node, interface, path, v3po_l2)
@staticmethod
+ def get_bd_oper_data_from_interface(node, interface):
+ """Returns operational data about bridge domain settings in the
+ interface.
+
+ :param node: Honeycomb node.
+ :param interface: The name of interface.
+ :type interface: str
+ :type param: str
+ :return: Operational data about bridge domain settings in the
+ interface.
+ :rtype: dict
+ """
+
+ if_data = InterfaceKeywords.get_interface_oper_data(node, interface)
+
+ if if_data:
+ try:
+ return if_data["v3po:l2"]
+ except KeyError:
+ return {}
+ return {}
+
+ @staticmethod
def configure_interface_base(node, interface, param, value):
"""Configure the base parameters of interface.