aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'resources/libraries')
-rw-r--r--resources/libraries/python/IPUtil.py17
-rw-r--r--resources/libraries/python/honeycomb/HcAPIKwInterfaces.py28
-rw-r--r--resources/libraries/robot/honeycomb/interfaces.robot18
3 files changed, 48 insertions, 15 deletions
diff --git a/resources/libraries/python/IPUtil.py b/resources/libraries/python/IPUtil.py
index 00a7000c65..4b6e2766d8 100644
--- a/resources/libraries/python/IPUtil.py
+++ b/resources/libraries/python/IPUtil.py
@@ -43,19 +43,22 @@ class IPUtil(object):
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
- :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"
- 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
- elif isinstance(netmask, basestring):
+ elif isinstance(network, basestring):
return net.prefixlen
+ else:
+ raise Exception("Value {0} is not a valid ipv4 netmask or network"
+ " prefix length".format(network))
diff --git a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py
index 8f6819ef5e..b1dd5b5dd1 100644
--- a/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py
+++ b/resources/libraries/python/honeycomb/HcAPIKwInterfaces.py
@@ -331,7 +331,7 @@ class InterfaceKeywords(object):
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.
@@ -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 netmask: Netmask.
+ :param network: Netmask or length of network prefix.
: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 = {"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
- 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.
- :param netmask: Netmask.
+ :param network: Netmask or length of network prefix.
: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")
- 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)
diff --git a/resources/libraries/robot/honeycomb/interfaces.robot b/resources/libraries/robot/honeycomb/interfaces.robot
index d27aff4175..7e2e654bba 100644
--- a/resources/libraries/robot/honeycomb/interfaces.robot
+++ b/resources/libraries/robot/honeycomb/interfaces.robot
@@ -120,6 +120,24 @@
| | | 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.