diff options
Diffstat (limited to 'resources/libraries')
-rw-r--r-- | resources/libraries/python/Dhcp.py | 18 | ||||
-rw-r--r-- | resources/libraries/python/honeycomb/DHCP.py | 109 | ||||
-rw-r--r-- | resources/libraries/robot/honeycomb/dhcp.robot | 94 |
3 files changed, 220 insertions, 1 deletions
diff --git a/resources/libraries/python/Dhcp.py b/resources/libraries/python/Dhcp.py index 93a9180972..5f76e434ec 100644 --- a/resources/libraries/python/Dhcp.py +++ b/resources/libraries/python/Dhcp.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016 Cisco and/or its affiliates. +# Copyright (c) 2017 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: @@ -73,3 +73,19 @@ class DhcpProxy(object): if output["retval"] != 0: raise RuntimeError('Unable to set DHCP proxy on node {}' .format(vpp_node)) + + @staticmethod + def vpp_get_dhcp_proxy(node, ip_version): + """Retrieve DHCP relay configuration. + + :param node: VPP node. + :param ip_version: IP protocol version: ipv4 or ipv6. + :type node: dict + :type ip_version: str + :returns: DHCP relay data. + :rtype: list + """ + + return VatExecutor.cmd_from_template( + node, "dhcp_proxy_dump.vat", + ipv6="ipv6" if ip_version == "ipv6" else "") diff --git a/resources/libraries/python/honeycomb/DHCP.py b/resources/libraries/python/honeycomb/DHCP.py new file mode 100644 index 0000000000..3c03b1405f --- /dev/null +++ b/resources/libraries/python/honeycomb/DHCP.py @@ -0,0 +1,109 @@ +# Copyright (c) 2017 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. + +"""Keywords to manipulate NAT configuration using Honeycomb REST API.""" + +from resources.libraries.python.HTTPRequest import HTTPCodes +from resources.libraries.python.honeycomb.HoneycombSetup import HoneycombError +from resources.libraries.python.honeycomb.HoneycombUtil \ + import DataRepresentation +from resources.libraries.python.honeycomb.HoneycombUtil \ + import HoneycombUtil as HcUtil + + +class DHCPRelayKeywords(object): + """Keywords for NAT configuration.""" + + def __init__(self): + pass + + @staticmethod + def _set_dhcp_relay_properties(node, path, data=None): + """Set DHCP relay properties and check the return code. + + :param node: Honeycomb node. + :param path: Path which is added to the base path to identify the data. + :param data: The new data to be set. If None, the item will be removed. + :type node: dict + :type path: str + :type data: dict + :return: Content of response. + :rtype: bytearray + :raises HoneycombError: If the status code in response is not + 200 = OK or 201 = ACCEPTED. + """ + + if data: + status_code, resp = HcUtil. \ + put_honeycomb_data(node, "config_dhcp_relay", data, path, + data_representation=DataRepresentation.JSON) + else: + status_code, resp = HcUtil. \ + delete_honeycomb_data(node, "config_dhcp_relay", path) + + if status_code not in (HTTPCodes.OK, HTTPCodes.ACCEPTED): + raise HoneycombError( + "The configuration of DHCP relay was not successful. " + "Status code: {0}.".format(status_code)) + return resp + + @staticmethod + def add_dhcp_relay(node, data, ip_version, entry_id): + """Add a DHCP relay entry to the list on entries. + + :param node: Honeycomb node. + :param data: Configuration for the relay entry. + :param ip_version: IP protocol version, ipv4 or ipv6. + :param entry_id: Numeric ID. + :type node: dict + :type data: dict + :type ip_version: str + :type entry_id: int + :returns: Content of response. + :rtype: bytearray + """ + + path = "/relay/dhcp:{0}/{1}".format(ip_version, entry_id) + + return DHCPRelayKeywords._set_dhcp_relay_properties(node, path, data) + + @staticmethod + def clear_dhcp_relay_configuration(node): + """Remove all DHCP relay configuration from the node. + + :param node: Honeycomb node. + :type node: dict + :returns: Content of response. + :rtype: bytearray + """ + return DHCPRelayKeywords._set_dhcp_relay_properties(node, "") + + @staticmethod + def get_dhcp_relay_oper_data(node): + """Get operational data about the DHCP relay feature. + + :param node: Honeycomb node. + :type node: dict + :returns: Content of response. + :rtype: bytearray + :raises HoneycombError: If the status code in response is not 200 = OK. + """ + + status_code, resp = HcUtil. \ + get_honeycomb_data(node, "config_dhcp_relay") + + if status_code != HTTPCodes.OK: + raise HoneycombError( + "Could not retrieve DHCP relay configuration. " + "Status code: {0}.".format(status_code)) + return resp diff --git a/resources/libraries/robot/honeycomb/dhcp.robot b/resources/libraries/robot/honeycomb/dhcp.robot new file mode 100644 index 0000000000..d3fe942668 --- /dev/null +++ b/resources/libraries/robot/honeycomb/dhcp.robot @@ -0,0 +1,94 @@ +# Copyright (c) 2017 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. + +*** Settings *** +| Library | resources.libraries.python.honeycomb.DHCP.DHCPRelayKeywords +| Library | resources.libraries.python.Dhcp.DhcpProxy +| Documentation | Keywords used to test Honeycomb DHCP features. + +*** Keywords *** +| DHCP relay configuration from Honeycomb should be empty +| | [Documentation] | Uses Honeycomb API to retrieve DHCP relay configuration\ +| | ... | and expects to fail. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| DHCP relay configuration from Honeycomb should be empty \ +| | ... | \| ${nodes['DUT1']} \| +| | [Arguments] | ${node} +| | Run keyword and expect error | *Status code: 404* +| | ... | Get DHCP relay oper data | ${node} + +| Log DHCP relay configuration from VAT +| | [Documentation] | Uses VAT to retrieve DHCP relay configuration from VPP. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - ip_version - IP protocol version, ipv4 or ipv6. Type: string +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Log DHCP relay configuration from VAT \ +| | ... | \| ${nodes['DUT1']} \| ipv4 \| +| | [Arguments] | ${node} | ${ip_version} +| | VPP get DHCP proxy | ${node} | ${ip_version} + +| Honeycomb configures DHCP relay +| | [Documentation] | Uses Honeycomb API to configure DHCP relay. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - data - settings for the DHCP relay. Type: dictionary +| | ... | - ip_version - IP protocol version, ipv4 or ipv6. Type: string +| | ... | - vrf - vrf ID to configure DHCP on. Type: integer +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Honeycomb configures DHCP relay \| ${nodes['DUT1']} \| ${data} \ +| | ... | \| ipv4 \| ${0} \| +| | [Arguments] | ${node} | ${data} | ${ip_version} | ${vrf} +| | Add DHCP relay | ${node} | ${data} | ${ip_version} | ${vrf} + +| Honeycomb clears DHCP relay configuration +| | [Documentation] | Uses Honeycomb API to delete all configured DHCP relays. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| Honeycomb clears DHCP relay configuration \| ${nodes['DUT1']} \| +| | [Arguments] | ${node} +| | Clear DHCP relay configuration | ${node} + +| DHCP relay configuration from Honeycomb should contain +| | [Documentation] | Retrieves oper data for DHCP relay and compares\ +| | ... | with provided values. +| | ... +| | ... | *Arguments:* +| | ... | - node - information about a DUT node. Type: dictionary +| | ... | - data - expected DHCP relay settings. Type dictionary +| | ... +| | ... | *Example:* +| | ... +| | ... | \| DHCP relay configuration from Honeycomb should contain \ +| | ... | \| ${nodes['DUT1']} \| ${data} \| +| | [Arguments] | ${node} | ${data} +| | ${oper_data}= | Get DHCP relay oper data | ${node} +| | ${oper_data}= | Set Variable | ${oper_data['relays']['relay'][0]} +| | Sort List | ${oper_data['server']} +| | Sort List | ${data['server']} +| | Should be equal | ${oper_data} | ${data} |