Update Honeycomb interface IPv4 test 63/1063/7
authorselias <samelias@cisco.com>
Wed, 11 May 2016 09:42:54 +0000 (11:42 +0200)
committerMatej Klotton <mklotton@cisco.com>
Thu, 12 May 2016 07:33:43 +0000 (07:33 +0000)
 - add verification of ipv4 subnet prefix support
 - modify keywords to allow setting ipv4 address with network prefix
 - fix variable definitions to evaluate numbers as ints, not strings
 - add exception to ipv4 netmask/prefix conversion method

Change-Id: I9343ceb35856ddb33674d7067f1def6d40e99acc
Signed-off-by: selias <samelias@cisco.com>
resources/libraries/python/IPUtil.py
resources/libraries/python/honeycomb/HcAPIKwInterfaces.py
resources/libraries/robot/honeycomb/interfaces.robot
tests/suites/honeycomb/1 - interface_management.robot

index 00a7000..4b6e276 100644 (file)
@@ -43,19 +43,22 @@ class IPUtil(object):
                 dev=interface, ip=addr, h=node['host']))
 
 
                 dev=interface, ip=addr, h=node['host']))
 
 
-def convert_ipv4_netmask_prefix(netmask):
+def convert_ipv4_netmask_prefix(network):
     """Convert network mask to equivalent network prefix length or vice versa.
 
     Example: mask 255.255.0.0 -> prefix length 16
     """Convert network mask to equivalent network prefix length or vice versa.
 
     Example: mask 255.255.0.0 -> prefix length 16
-    :param netmask: network mask or network prefix length.
-    :type netmask: str or int
-    :return: network mask or network prefix length.
+    :param network: Network mask or network prefix length.
+    :type network: str or int
+    :return: Network mask or network prefix length.
     :rtype: str or int
     """
     temp_address = "0.0.0.0"
     :rtype: str or int
     """
     temp_address = "0.0.0.0"
-    net = IPv4Network(u"{0}/{1}".format(temp_address, netmask), False)
+    net = IPv4Network(u"{0}/{1}".format(temp_address, network), False)
 
 
-    if isinstance(netmask, int):
+    if isinstance(network, int) and (0 < network < 33):
         return net.netmask
         return net.netmask
-    elif isinstance(netmask, basestring):
+    elif isinstance(network, basestring):
         return net.prefixlen
         return net.prefixlen
+    else:
+        raise Exception("Value {0} is not a valid ipv4 netmask or network"
+                        " prefix length".format(network))
index 8f6819e..b1dd5b5 100644 (file)
@@ -331,7 +331,7 @@ class InterfaceKeywords(object):
             node, interface, path, value)
 
     @staticmethod
             node, interface, path, value)
 
     @staticmethod
-    def add_first_ipv4_address(node, interface, ip_addr, netmask):
+    def add_first_ipv4_address(node, interface, ip_addr, network):
         """Add the first IPv4 address.
 
         If there are any other addresses configured, they will be removed.
         """Add the first IPv4 address.
 
         If there are any other addresses configured, they will be removed.
@@ -339,39 +339,51 @@ class InterfaceKeywords(object):
         :param node: Honeycomb node.
         :param interface: The name of interface.
         :param ip_addr: IPv4 address to be set.
         :param node: Honeycomb node.
         :param interface: The name of interface.
         :param ip_addr: IPv4 address to be set.
-        :param netmask: Netmask.
+        :param network: Netmask or length of network prefix.
         :type node: dict
         :type interface: str
         :type ip_addr: str
         :type node: dict
         :type interface: str
         :type ip_addr: str
-        :type netmask: str
+        :type network: str or int
         :return: Content of response.
         :rtype: bytearray
         """
 
         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4")
         :return: Content of response.
         :rtype: bytearray
         """
 
         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4")
-        address = {"address": [{"ip": ip_addr, "netmask": netmask}, ]}
+        if isinstance(network, basestring):
+            address = {"address": [{"ip": ip_addr, "netmask": network}, ]}
+        elif isinstance(network, int) and (0 < network < 33):
+            address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]}
+        else:
+            raise HoneycombError("Value {0} is not a valid netmask or network "
+                                 "prefix length.".format(network))
         return InterfaceKeywords._set_interface_properties(
             node, interface, path, address)
 
     @staticmethod
         return InterfaceKeywords._set_interface_properties(
             node, interface, path, address)
 
     @staticmethod
-    def add_ipv4_address(node, interface, ip_addr, netmask):
+    def add_ipv4_address(node, interface, ip_addr, network):
         """Add IPv4 address.
 
         :param node: Honeycomb node.
         :param interface: The name of interface.
         :param ip_addr: IPv4 address to be set.
         """Add IPv4 address.
 
         :param node: Honeycomb node.
         :param interface: The name of interface.
         :param ip_addr: IPv4 address to be set.
-        :param netmask: Netmask.
+        :param network: Netmask or length of network prefix.
         :type node: dict
         :type interface: str
         :type ip_addr: str
         :type node: dict
         :type interface: str
         :type ip_addr: str
-        :type netmask: str
+        :type network: str or int
         :return: Content of response.
         :rtype: bytearray
         """
 
         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
                 "address")
         :return: Content of response.
         :rtype: bytearray
         """
 
         path = ("interfaces", ("interface", "name", interface), "ietf-ip:ipv4",
                 "address")
-        address = [{"ip": ip_addr, "prefix-length": netmask}, ]
+        if isinstance(network, basestring):
+            address = {"address": [{"ip": ip_addr, "netmask": network}, ]}
+        elif isinstance(network, int) and (0 < network < 33):
+            address = {"address": [{"ip": ip_addr, "prefix-length": network}, ]}
+        else:
+            raise HoneycombError("Value {0} is not a valid netmask or network "
+                                 "prefix length.".format(network))
         return InterfaceKeywords._set_interface_properties(
             node, interface, path, address)
 
         return InterfaceKeywords._set_interface_properties(
             node, interface, path, address)
 
index d27aff4..7e2e654 100644 (file)
 | | | interfaceAPI.Configure interface ipv4
 | | | ... | ${node} | ${interface} | ${key} | ${settings['${key}']}
 
 | | | interfaceAPI.Configure interface ipv4
 | | | ... | ${node} | ${interface} | ${key} | ${settings['${key}']}
 
+| Honeycomb sets interface ipv4 address with prefix
+| | [Documentation] | Uses Honeycomb API to assign an ipv4 address to the\
+| | ... | specified interface. Any existing addresses will be removed.
+| | ...
+| | ... | *Arguments:*
+| | ... | - node - information about a DUT node. Type: dictionary
+| | ... | - interface - name of an interface on the specified node. Type: string
+| | ... | - address - IP address to set. Type: string
+| | ... | - prefix - length of address network prefix. Type: int
+| | ...
+| | ... | *Example:*
+| | ...
+| | ... | \| Honeycomb sets interface ipv4 address with prefix \
+| | ... | \| ${nodes['DUT1']} \| GigabitEthernet0/8/0 \| 192.168.0.2 \| 24 \|
+| | [Arguments] | ${node} | ${interface} | ${address} | ${prefix}
+| | interfaceAPI.Add first ipv4 address
+| | ... | ${node} | ${interface} | ${address} | ${prefix}
+
 | IPv4 config from Honeycomb should be
 | | [Documentation] | Retrieves interface ipv4 configuration through Honeycomb\
 | | ... | and compares with state supplied in argument.
 | IPv4 config from Honeycomb should be
 | | [Documentation] | Retrieves interface ipv4 configuration through Honeycomb\
 | | ... | and compares with state supplied in argument.
index 50eaa4e..ae4fec9 100644 (file)
 | ${node}= | ${nodes['DUT1']}
 | ${interface}= | ${node['interfaces'].values()[0]['name']}
 # Configuration which will be set and verified during tests.
 | ${node}= | ${nodes['DUT1']}
 | ${interface}= | ${node['interfaces'].values()[0]['name']}
 # Configuration which will be set and verified during tests.
-| @{ipv4_address}= | 192.168.0.2 | 255.255.255.0
-| @{ipv4_neighbor}= | 192.168.0.3 | 08:00:27:c0:5d:37
-| &{ipv4_settings}= | enabled=${True} | forwarding=${True} | mtu=9000
-| @{ipv6_address}= | 10::10 | 64
+| @{ipv4_address_mask}= | 192.168.0.2 | 255.255.255.0
+| @{ipv4_address_prefix}= | 192.168.0.3 | ${16}
+| @{ipv4_neighbor}= | 192.168.0.4 | 08:00:27:c0:5d:37
+| &{ipv4_settings}= | enabled=${True} | forwarding=${True} | mtu=${9000}
+| @{ipv6_address}= | 10::10 | ${64}
 | @{ipv6_neighbor}= | 10::11 | 08:00:27:c0:5d:37
 | @{ipv6_neighbor}= | 10::11 | 08:00:27:c0:5d:37
-| &{ipv6_settings}= | enabled=${True} | forwarding=${True} | mtu=9000
-| ... | dup-addr-detect-transmits=5
-| &{ethernet}= | mtu=9000
-| &{routing}= | vrf-id=27
-| &{vxlan_settings}= | src=10.0.1.20 | dst=10.0.3.20 | vni=1000
-| ... | encap-vrf-id=1000
+| &{ipv6_settings}= | enabled=${True} | forwarding=${True} | mtu=${9000}
+| ... | dup-addr-detect-transmits=${5}
+| &{ethernet}= | mtu=${9000}
+| &{routing}= | vrf-id=${27}
+| &{vxlan_settings}= | src=10.0.1.20 | dst=10.0.3.20 | vni=${1000}
+| ... | encap-vrf-id=${1000}
 
 *** Settings ***
 | Resource | resources/libraries/robot/default.robot
 
 *** Settings ***
 | Resource | resources/libraries/robot/default.robot
 | | [Documentation] | Check if Honeycomb API can configure interfaces for ipv4.
 | | [Tags] | honeycomb_sanity
 | | When Honeycomb sets interface ipv4 configuration
 | | [Documentation] | Check if Honeycomb API can configure interfaces for ipv4.
 | | [Tags] | honeycomb_sanity
 | | When Honeycomb sets interface ipv4 configuration
-| | ... | ${node} | ${interface} | @{ipv4_address} | @{ipv4_neighbor}
+| | ... | ${node} | ${interface} | @{ipv4_address_mask} | @{ipv4_neighbor}
 | | ... | ${ipv4_settings}
 | | Then IPv4 config from Honeycomb should be
 | | ... | ${ipv4_settings}
 | | Then IPv4 config from Honeycomb should be
-| | ... | ${node} | ${interface} | @{ipv4_address} | @{ipv4_neighbor}
+| | ... | ${node} | ${interface} | @{ipv4_address_mask} | @{ipv4_neighbor}
 | | ... | ${ipv4_settings}
 | | And IPv4 config from VAT should be
 | | ... | ${ipv4_settings}
 | | And IPv4 config from VAT should be
-| | ... | ${node} | ${interface} | @{ipv4_address}
+| | ... | ${node} | ${interface} | @{ipv4_address_mask}
+| | When Honeycomb sets interface ipv4 address with prefix
+| | ... | ${node} | ${interface} | @{ipv4_address_prefix}
+| | Then IPv4 config from Honeycomb should be
+| | ... | ${node} | ${interface} | @{ipv4_address_prefix} | @{ipv4_neighbor}
+| | ... | ${ipv4_settings}
+| | And IPv4 config from VAT should be
+| | ... | ${node} | ${interface} | @{ipv4_address_prefix}
 
 | Honeycomb modifies interface configuration - ipv6
 | | [Documentation] | Check if Honeycomb API can configure interfaces for ipv6.
 
 | Honeycomb modifies interface configuration - ipv6
 | | [Documentation] | Check if Honeycomb API can configure interfaces for ipv6.