diff options
Diffstat (limited to 'resources')
-rw-r--r-- | resources/libraries/python/Classify.py | 43 | ||||
-rw-r--r-- | resources/libraries/python/InterfaceUtil.py | 23 | ||||
-rw-r--r-- | resources/libraries/python/honeycomb/HcAPIKwInterfaces.py | 25 | ||||
-rw-r--r-- | resources/libraries/robot/honeycomb/access_control_lists.robot | 339 | ||||
-rw-r--r-- | resources/templates/vat/classify_interface_table.vat | 1 | ||||
-rw-r--r-- | resources/templates/vat/classify_session_dump.vat | 1 | ||||
-rw-r--r-- | resources/templates/vat/classify_table_info.vat | 1 |
7 files changed, 425 insertions, 8 deletions
diff --git a/resources/libraries/python/Classify.py b/resources/libraries/python/Classify.py index d955a9cc8c..dfa5c3377d 100644 --- a/resources/libraries/python/Classify.py +++ b/resources/libraries/python/Classify.py @@ -280,3 +280,46 @@ class Classify(object): # base value of classify hex table for IPv6 TCP/UDP ports else: raise ValueError("Invalid IP version!") + + @staticmethod + def get_classify_table_data(node, table_index): + """Retrieve settings for classify table by ID. + + :param node: VPP node to retrieve classify data from. + :param table_index: Index of a specific classify table. + :type node: dict + :type table_index: int + :return: Classify table settings. + :rtype: dict + """ + with VatTerminal(node) as vat: + data = vat.vat_terminal_exec_cmd_from_template( + "classify_table_info.vat", + table_id=table_index + ) + return data[0] + + @staticmethod + def get_classify_session_data(node, table_index, session_index=None): + """Retrieve settings for all classify sessions in a table, + or for a specific classify session. + + :param node: VPP node to retrieve classify data from. + :param table_index: Index of a classify table. + :param session_index: Index of a specific classify session. (Optional) + :type node: dict + :type table_index: int + :type session_index: int + :return: List of classify session settings, or a dictionary of settings + for a specific classify session. + :rtype: list or dict + """ + with VatTerminal(node) as vat: + data = vat.vat_terminal_exec_cmd_from_template( + "classify_session_dump.vat", + table_id=table_index + ) + if session_index is not None: + return data[0][session_index] + else: + return data[0] diff --git a/resources/libraries/python/InterfaceUtil.py b/resources/libraries/python/InterfaceUtil.py index a16a02fbe8..69d0a59680 100644 --- a/resources/libraries/python/InterfaceUtil.py +++ b/resources/libraries/python/InterfaceUtil.py @@ -713,6 +713,29 @@ class InterfaceUtil(object): table_index=table_index) @staticmethod + def get_interface_classify_table(node, interface): + """Get name of classify table for the given interface. + + :param node: VPP node to get data from. + :param interface: Name or sw_if_index of a specific interface. + :type node: dict + :type interface: str or int + :return: Classify table name. + :rtype: str + """ + if isinstance(interface, basestring): + sw_if_index = InterfaceUtil.get_sw_if_index(node, interface) + else: + sw_if_index = interface + + with VatTerminal(node) as vat: + data = vat.vat_terminal_exec_cmd_from_template( + "classify_interface_table.vat", + sw_if_index=sw_if_index + ) + return data[0] + + @staticmethod def get_sw_if_index(node, interface_name): """Get sw_if_index for the given interface from actual interface dump. diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py index ff1589f217..4eaef11bdb 100644 --- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py +++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py @@ -307,8 +307,8 @@ class InterfaceKeywords(object): :param node: Honeycomb node. :param interface: The name of interface. - :type interface: str :type node: dict + :type interface: str :return: Operational data about bridge domain settings in the interface. :rtype: dict @@ -1224,27 +1224,36 @@ class InterfaceKeywords(object): node, super_interface, path, None) @staticmethod - def compare_data_structures(data, ref): + def compare_data_structures(data, ref, ignore=()): """Checks if data obtained from UUT is as expected. :param data: Data to be checked. :param ref: Referential data used for comparison. + :param ignore: Dictionary keys to be ignored. :type data: dict :type ref: dict + :type ignore: iterable :raises HoneycombError: If a parameter from referential data is not present in operational data or if it has different value. """ + errors = "" + for key, item in ref.items(): + if key in ignore: + continue try: if data[key] != item: - raise HoneycombError("The value of parameter '{0}' is " - "incorrect. It should be " - "'{1}' but it is '{2}'". - format(key, item, data[key])) + errors += ("\nThe value of parameter '{0}' is " + "incorrect. It should be " + "'{1}' but it is '{2}'". + format(key, item, data[key])) except KeyError: - raise HoneycombError("The parameter '{0}' is not present in " - "operational data".format(key)) + errors += ("\nThe parameter '{0}' is not present in " + "operational data".format(key)) + + if errors: + raise HoneycombError(errors) @staticmethod def compare_interface_lists(list1, list2): diff --git a/resources/libraries/robot/honeycomb/access_control_lists.robot b/resources/libraries/robot/honeycomb/access_control_lists.robot new file mode 100644 index 0000000000..0fd1c7ef86 --- /dev/null +++ b/resources/libraries/robot/honeycomb/access_control_lists.robot @@ -0,0 +1,339 @@ +# Copyright (c) 2016 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*** Variables *** +#TODO: update based on resolution of bug https://jira.fd.io/browse/HONEYCOMB-119 +| @{hc_table_ignore}= | memory_size + +*** Settings *** +| Library | resources.libraries.python.Classify +| Library | resources.libraries.python.InterfaceUtil +| Library | resources.libraries.python.honeycomb.HcAPIKwACL.ACLKeywords +| Library | resources.libraries.python.honeycomb.HcAPIKwInterfaces.InterfaceKeywords +| ... | WITH NAME | InterfaceAPI +| Documentation | Keywords used to manage ACLs. + +*** Keywords *** +| Honeycomb creates ACL table +| | [Documentation] | Uses Honeycomb API to create an ACL table. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - settings - ACL table settings. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Honeycomb creates ACL table \| ${nodes['DUT1']} \ +| | ... | \| ${settings} \| +| | [Arguments] | ${node} | ${settings} +| | Add classify table | ${node} | ${settings} + +| Honeycomb removes ACL table +| | [Documentation] | Uses Honeycomb API to remove and existing ACL table. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - table_name - name of an ACL table. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Honeycomb removes ACL table \| ${nodes['DUT1']} \| table0 \| +| | [Arguments] | ${node} | ${table_name} +| | Remove classify table | ${node} | ${table_name} + +| Honeycomb adds ACL session +| | [Documentation] | Uses Honeycomb API to create an ACL session. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - table_name - name of an ACL table. Type: string +| | ... | - settings - ACL session settings. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Honeycomb adds ACL session \| ${nodes['DUT1']} \ +| | ... | \| table0 \| ${settings} \| +| | [Arguments] | ${node} | ${table_name} | ${settings} +| | Add classify session | ${node} | ${table_name} | ${settings} + +| Honeycomb removes ACL session +| | [Documentation] | Uses Honeycomb API to remove an ACL session. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - table_name - name of an ACL table. Type: string +| | ... | - match - ACL session match setting. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Honeycomb removes ACL session \| ${nodes['DUT1']} \ +| | ... | \| table0 \| 00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00 \| +| | [Arguments] | ${node} | ${table_name} | ${match} +| | Remove classify session | ${node} | ${table_name} | ${match} + +| Honeycomb enables ACL on interface +| | [Documentation] | Uses Honeycomb API to enable ACL on an interface. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - interface - name of an interface on the specified node. Type: string +| | ... | - table_name - name of an ACL table. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Honeycomb enables ACL on interface \| ${nodes['DUT1']} \ +| | ... | \| GigabithEthernet0/8/0 \| table0 \| +| | [Arguments] | ${node} | ${interface} | ${table_name} +| | InterfaceAPI.Enable ACL on interface +| | ... | ${node} | ${interface} | ${table_name} + +| Honeycomb disables ACL on interface +| | [Documentation] | Uses Honeycomb API to disable ACL on an interface. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - interface - name of an interface on the specified node. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Honeycomb disables ACL on interface \| ${nodes['DUT1']} \ +| | ... | \| GigabithEthernet0/8/0 \| +| | [Arguments] | ${node} | ${interface} +| | InterfaceAPI.Disable ACL on interface | ${node} | ${interface} + +| ACL table from Honeycomb should be +| | [Documentation] | Retrieves ACL table information from Honeycomb\ +| | ... | and compares with expected settings. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - settings - expected ACL table settings. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| ACL table from Honeycomb should be \| ${nodes['DUT1']} \ +| | ... | \| ${settings} \| +| | [Arguments] | ${node} | ${settings} +| | ${data}= | Get classify table oper data | ${node} | ${settings['name']} +| | Compare data structures | ${data} | ${settings} | ignore=${hc_table_ignore} + +| ACL table from VAT should be +| | [Documentation] | Retrieves ACL table information from VAT\ +| | ... | and compares with expected settings. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - table_index - VPP internal index of an ACL table. Type: integer +| | ... | - settings - expected ACL table settings. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| ACL session from VAT should be \| ${nodes['DUT1']} \ +| | ... | \| ${0} \| ${settings} \| +| | [Arguments] | ${node} | ${table_index} | ${settings} +| | ${data}= | Get classify table data | ${node} | ${table_index} +| | Compare data structures | ${data} | ${settings} + +| ACL table from Honeycomb should not exist +| | [Documentation] | Retrieves ACL table information from Honeycomb\ +| | ... | and expects to fail. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - table_name - name of an ACL table. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| ACL table from Honeycomb should not exist \| ${nodes['DUT1']} \ +| | ... | \| table0 \| +| | [Arguments] | ${node} | ${table_name} +| | Run keyword and expect error | ValueError: No JSON object could be decoded +| | ... | Get classify table oper data | ${node} | ${table_name} + +| ACL table from VAT should not exist +| | [Documentation] | Retrieves ACL table information from VAT\ +| | ... | and expects to fail. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - table_index - VPP internal index of an ACL table. Type: integer +| | ... +| | ... | *Example:* +| | ... +| | ... | \| ACL table from VAT should not exist \| ${nodes['DUT1']} \ +| | ... | \| ${0} \| +| | [Arguments] | ${node} | ${table_index} +| | Run keyword and expect error | No JSON data. +| | ... | Get classify table data | ${node} | ${table_index} + +| ACL session from Honeycomb should be +| | [Documentation] | Retrieves ACL session information from Honeycomb\ +| | ... | and compares with expected settings. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - table_name - name of an ACL table. Type: string +| | ... | - settings - expected ACL session settings. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| ACL session from Honeycomb should be \| ${nodes['DUT1']} \ +| | ... | \| table0 \| ${settings} \| +| | [Arguments] | ${node} | ${table_name} | ${settings} +| | ${data}= | Get classify session oper data +| | ... | ${node} | ${table_name} | ${settings['match']} +| | Compare data structures | ${data} | ${settings} + +| ACL session from VAT should be +| | [Documentation] | Retrieves ACL session information from VAT\ +| | ... | and compares with expected settings. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - table_index - VPP internal index of an ACL table. Type: integer +| | ... | - session_index - VPP internal index of an ACL session. Type: integer +| | ... | - settings - expected ACL session settings. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| ACL session from VAT should be \| ${nodes['DUT1']} \ +| | ... | \| ${0} \| ${0} \| ${settings} \| +| | [Arguments] | ${node} | ${table_index} | ${session_index} | ${settings} +| | ${data}= | Get classify session data +| | ... | ${node} | ${table_index} | ${session_index} +| | Compare data structures | ${data} | ${settings} + +| ACL session from Honeycomb should not exist +| | [Documentation] | Retrieves ACL session information from Honeycomb\ +| | ... | and expects to fail. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - table_name - name of an ACL table. Type: string +| | ... | - session_match - ACL session match setting. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| ACL session from Honeycomb should not exist \| ${nodes['DUT1']} \ +| | ... | \| table0 \| 00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00 \| +| | [Arguments] | ${node} | ${table_name} | ${session_match} +| | Run keyword and expect error | *HoneycombError: *Status code: 404. +| | ... | Get classify session oper data +| | ... | ${node} | ${table_name} | ${session_match} + +| ACL session from VAT should not exist +| | [Documentation] | Retrieves ACL session information from VAT\ +| | ... | and compares with expected settings. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - table_index - VPP internal index of an ACL table. Type: integer +| | ... | - session_index - VPP internal index of an ACL session. Type: integer +| | ... +| | ... | *Example:* +| | ... +| | ... | \| ACL session from VAT should not exist \| ${nodes['DUT1']} \ +| | ... | \| ${0} \| ${0} \| +| | [Arguments] | ${node} | ${table_index} | ${session_index} +| | Run keyword if | ${session_index} == 0 +| | ... | Run keyword and expect error +| | ... | ValueError: No JSON object could be decoded +| | ... | Get classify session data +| | ... | ${node} | ${table_index} | ${session_index} +| | Run keyword if | ${session_index} > 0 +| | ... | Run keyword and expect error +| | ... | IndexError: list index out of range +| | ... | Get classify session data +| | ... | ${node} | ${table_index} | ${session_index} + +| Interface ACL settings from Honeycomb should be +| | [Documentation] | Retrieves ACL interface settings from Honeycomb\ +| | ... | and compares with expected settings. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - interface - name of an interface on the specified node. Type: string +| | ... | - table_name - expected ACL table name. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Interface ACL settings from Honeycomb should be \ +| | ... | \| ${nodes['DUT1']} \| GigabithEthernet0/8/0 \| table0 \| +| | [Arguments] | ${node} | ${interface} | ${table_name} +| | ${data}= | InterfaceAPI.Get interface oper data | ${node} | ${interface} +| | Should be equal +| | ... | ${table_name} | ${data['v3po:acl']['l2-acl']['classify-table']} + +| Interface ACL settings from VAT should be +| | [Documentation] | Retrieves ACL interface settings from VAT\ +| | ... | and compares with expected settings. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - interface - name of an interface on the specified node. Type: string +| | ... | - table_index - VPP internal index of an ACL table. Type: integer +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Interface ACL settings from VAT should be \| ${nodes['DUT1']} \ +| | ... | \| GigabithEthernet0/8/0 \| ${0} \| +| | [Arguments] | ${node} | ${interface} | ${table_index} +| | ${data}= | Get interface classify table | ${node} | ${interface} +| | Should be equal | ${table_index} | ${data['l2_table_id']} +| | Should be equal | ${table_index} | ${data['ip4_table_id']} + +| Interface ACL settings from Honeycomb should be empty +| | [Documentation] | Retrieves ACL interface settings from Honeycomb\ +| | ... | and expects to fail. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - interface - name of an interface on the specified node. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Interface ACL settings from Honeycomb should be empty \ +| | ... | \| ${nodes['DUT1']} \| GigabithEthernet0/8/0 \| +| | [Arguments] | ${node} | ${interface} +| | ${data}= | InterfaceAPI.Get interface oper data | ${node} | ${interface} +| | Run keyword and expect error | *KeyError: 'v3po:acl' +| | ... | Set Variable | ${data['v3po:acl']['l2-acl']['classify-table']} + +| Interface ACL settings from VAT should be empty +| | [Documentation] | Retrieves ACL interface settings from VAT\ +| | ... | and expects to fail. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - interface - name of an interface on the specified node. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Interface ACL settings from Honeycomb should be empty \ +| | ... | \| ${nodes['DUT1']} \| GigabithEthernet0/8/0 \| +| | [Arguments] | ${node} | ${interface} +| | ${data}= | Get interface classify table | ${node} | ${interface} +| | Should be equal | ${data['l2_table_id']} | ${-1} +| | Should be equal | ${data['ip4_table_id']} | ${-1} + +| Clear all ACL settings +| | [Documentation] | Removes all ACL sessions and tables from Honeycomb\ +| | ... | configuration. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Clear all ACL settings \| ${nodes['DUT1']} \| +| | [Arguments] | ${node} +| | Remove all classify tables | ${node} diff --git a/resources/templates/vat/classify_interface_table.vat b/resources/templates/vat/classify_interface_table.vat new file mode 100644 index 0000000000..f12af78e1c --- /dev/null +++ b/resources/templates/vat/classify_interface_table.vat @@ -0,0 +1 @@ +classify_table_by_interface sw_if_index {sw_if_index}
\ No newline at end of file diff --git a/resources/templates/vat/classify_session_dump.vat b/resources/templates/vat/classify_session_dump.vat new file mode 100644 index 0000000000..f76ecbbb4b --- /dev/null +++ b/resources/templates/vat/classify_session_dump.vat @@ -0,0 +1 @@ +classify_session_dump table_id {table_id}
\ No newline at end of file diff --git a/resources/templates/vat/classify_table_info.vat b/resources/templates/vat/classify_table_info.vat new file mode 100644 index 0000000000..2e8fe5ae72 --- /dev/null +++ b/resources/templates/vat/classify_table_info.vat @@ -0,0 +1 @@ +classify_table_info table_id {table_id}
\ No newline at end of file |