diff options
author | jan.hradil <jan.hradil@pantheon.tech> | 2017-04-11 09:28:07 +0200 |
---|---|---|
committer | Tibor Frank <tifrank@cisco.com> | 2017-04-25 09:31:18 +0000 |
commit | 2659bfa861fd129b22b4769a9ed402517ef3db44 (patch) | |
tree | d2f76a9167db3e100199dfd10d4eb32e3197d717 /resources/libraries/python | |
parent | b4a288b19aa838825eff803207d1fedd82cb62f3 (diff) |
CSIT-534 HC Test: policer tests
Added empty lines where needed
Repaired Phrasese "Given" --> "And" where necessary in mgmt-cfg-policer-apihc-func.robot
Corrected English in mgmt-cfg-policer-apihc-func.robot - in TC07 Documentation
Change-Id: Id99d7fd04d8f2dcae1820baa208ce338fad3a290
Signed-off-by: jan.hradil <jan.hradil@pantheon.tech>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r-- | resources/libraries/python/honeycomb/HcAPIKwInterfaces.py | 63 | ||||
-rw-r--r-- | resources/libraries/python/honeycomb/Routing.py | 57 |
2 files changed, 120 insertions, 0 deletions
diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py index 19ce8f26c8..d57f93913f 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py +++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py @@ -1512,6 +1512,69 @@ class InterfaceKeywords(object): return resp @staticmethod + def enable_policer_on_interface(node, interface, table_name): + """Enable Policer on the given interface. + + :param node: Honeycomb node. + :param interface: The interface where policer will be enabled. + :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 + successful. + """ + interface = Topology.convert_interface_reference( + node, interface, "name") + interface = interface.replace("/", "%2F") + + data = { + "interface-policer:policer": { + "ip4-table": table_name + } + } + + path = "/interface/" + interface + "/interface-policer:policer" + 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( + "The configuration of interface '{0}' was not successful. " + "Status code: {1}.".format(interface, status_code)) + return resp + + @staticmethod + def disable_policer_on_interface(node, interface): + """Disable Policer on the given interface. + + :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 + successful. + """ + interface = Topology.convert_interface_reference( + node, interface, "name") + interface = interface.replace("/", "%2F") + + path = "/interface/" + interface + "/interface-policer:policer" + status_code, resp = HcUtil.\ + delete_honeycomb_data(node, "config_vpp_interfaces", path) + if status_code != HTTPCodes.OK: + raise HoneycombError( + "The configuration of interface '{0}' was not successful. " + "Status code: {1}.".format(interface, status_code)) + return resp + + @staticmethod def disable_acl_on_interface(node, interface): """Disable ACL on the given interface. diff --git a/resources/libraries/python/honeycomb/Routing.py b/resources/libraries/python/honeycomb/Routing.py index c39031d920..a4d606bd5d 100644 --- a/resources/libraries/python/honeycomb/Routing.py +++ b/resources/libraries/python/honeycomb/Routing.py @@ -273,3 +273,60 @@ class RoutingKeywords(object): return {k: str(v) for k, v in dict_of_str.items()} except (KeyError, TypeError): return {} + + @staticmethod + def configure_policer(node, policy_name, policer_data=None): + """Configure Policer on the specified node. + + :param node: Honeycomb node. + :param policer_data: Dictionary of configurations to apply. \ + If it is None then the existing configuration is removed. + :type node: dict + :type policer_data: dict + :returns: Content of response. + :rtype: bytearray + :raises HoneycombError: If policer could not be configured. + """ + + path = '/' + policy_name + + if not policer_data: + status_code, _ = HcUtil.delete_honeycomb_data( + node, 'config_policer', path) + else: + data = { + 'policer': policer_data + } + + status_code, _ = HcUtil.put_honeycomb_data( + node, 'config_policer', data, path) + + if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): + raise HoneycombError( + 'Configuring policer failed. Status code:{0}'\ + .format(status_code)) + + @staticmethod + def get_policer_oper_data(node, policy_name): + """Get operational data about Policer on the node. + + :param node: Honeycomb node. + :type node: dict + :returns: dict of Policer operational data. + :rtype: dict + :raises HoneycombError: If status code differs from successful. + """ + + path = '/' + policy_name + + status_code, resp = HcUtil.\ + get_honeycomb_data(node, "oper_policer", path) + + if status_code != HTTPCodes.OK: + raise HoneycombError( + "Not possible to get operational information about Policer. " + "Status code: {0}.".format(status_code)) + try: + return resp['policer'] + except (KeyError, TypeError): + return {} |