Replace ipaddr to netaddr

Remove ipaddr from fuelweb_test/requirements.txt and use netaddr
    in test cases instead of ipaddr

Use string for creation of netaddr instances

Change-Id: Idc86dcaae6f10c13b04095fb11fa9351b130deb8
Closes-bug: #1544148
This commit is contained in:
Dmitry Tyzhnenko 2016-02-29 11:29:51 +00:00
parent 55a1920dc9
commit 7f3fb9da40
7 changed files with 50 additions and 47 deletions

View File

@ -33,8 +33,8 @@ from fuelweb_test.settings import OPENSTACK_RELEASE_UBUNTU
from fuelweb_test.settings import POOLS from fuelweb_test.settings import POOLS
from fuelweb_test.settings import PUBLIC_TEST_IP from fuelweb_test.settings import PUBLIC_TEST_IP
from ipaddr import IPAddress from netaddr import IPAddress
from ipaddr import IPNetwork from netaddr import IPNetwork
from proboscis.asserts import assert_equal from proboscis.asserts import assert_equal
from proboscis.asserts import assert_true from proboscis.asserts import assert_true
@ -603,7 +603,8 @@ def check_stats_private_info(collector_remote, postgres_actions,
# If IP address isn't public and doesn't belong to defined for # If IP address isn't public and doesn't belong to defined for
# deployment pools (e.g. admin, public, storage), then skip it # deployment pools (e.g. admin, public, storage), then skip it
if any(re.search(_r, _match.group()) for _r in _not_public_regex) \ if any(re.search(_r, _match.group()) for _r in _not_public_regex) \
and not any(IPAddress(_match.group()) in IPNetwork(net) for and not any(IPAddress(str(_match.group())) in
IPNetwork(str(net)) for
net in _used_networks): net in _used_networks):
continue continue
logger.debug('Usage statistics with public IP(s):\n {0}'. logger.debug('Usage statistics with public IP(s):\n {0}'.

View File

@ -23,7 +23,7 @@ import os
import posixpath import posixpath
import re import re
import signal import signal
import ipaddr import netaddr
from proboscis import asserts from proboscis import asserts
from proboscis.asserts import assert_true from proboscis.asserts import assert_true
@ -625,8 +625,8 @@ def generate_floating_ranges(start_ip, end_ip, step):
:return: :return:
""" """
ranges = [] ranges = []
ip_start = ipaddr.IPAddress(start_ip) ip_start = netaddr.IPAddress(str(start_ip))
ip_end = ipaddr.IPAddress(end_ip) ip_end = netaddr.IPAddress(str(end_ip))
while ip_end - step > ip_start: while ip_end - step > ip_start:
ranges.append([str(ip_start), str(ip_start + step)]) ranges.append([str(ip_start), str(ip_start + step)])
ip_start += (step + 1) ip_start += (step + 1)

View File

@ -15,6 +15,10 @@
import re import re
import time import time
import traceback import traceback
import yaml
import netaddr
from urllib2 import HTTPError from urllib2 import HTTPError
from devops.error import DevopsCalledProcessError from devops.error import DevopsCalledProcessError
@ -22,16 +26,13 @@ from devops.error import TimeoutError
from devops.helpers.helpers import _wait from devops.helpers.helpers import _wait
from devops.helpers.helpers import wait from devops.helpers.helpers import wait
from devops.models.node import Node from devops.models.node import Node
import ipaddr
from ipaddr import IPNetwork
from netaddr import EUI
from proboscis.asserts import assert_equal from proboscis.asserts import assert_equal
from proboscis.asserts import assert_false from proboscis.asserts import assert_false
from proboscis.asserts import assert_is_not_none from proboscis.asserts import assert_is_not_none
from proboscis.asserts import assert_not_equal from proboscis.asserts import assert_not_equal
from proboscis.asserts import assert_raises from proboscis.asserts import assert_raises
from proboscis.asserts import assert_true from proboscis.asserts import assert_true
import yaml
from fuelweb_test import logger from fuelweb_test import logger
from fuelweb_test import logwrap from fuelweb_test import logwrap
@ -818,10 +819,8 @@ class FuelWebClient(object):
cluster_id)['external_net'])) cluster_id)['external_net']))
ret = [] ret = []
for pool in subnet['allocation_pools']: for pool in subnet['allocation_pools']:
ip = ipaddr.IPv4Address(pool['start']) ret.extend([str(ip) for ip in
while ip <= ipaddr.IPv4Address(pool['end']): netaddr.iter_iprange(pool['start'], pool['end'])])
ret.append(str(ip))
ip += 1
return ret return ret
@logwrap @logwrap
@ -898,7 +897,7 @@ class FuelWebClient(object):
Returns dict with nailgun slave node description if node is Returns dict with nailgun slave node description if node is
registered. Otherwise return None. registered. Otherwise return None.
""" """
d_macs = {EUI(i.mac_address) for i in devops_node.interfaces} d_macs = {netaddr.EUI(i.mac_address) for i in devops_node.interfaces}
logger.debug('Verify that nailgun api is running') logger.debug('Verify that nailgun api is running')
attempts = ATTEMPTS attempts = ATTEMPTS
nodes = [] nodes = []
@ -916,7 +915,8 @@ class FuelWebClient(object):
time.sleep(TIMEOUT) time.sleep(TIMEOUT)
logger.debug('Look for nailgun node by macs %s', d_macs) logger.debug('Look for nailgun node by macs %s', d_macs)
for nailgun_node in nodes: for nailgun_node in nodes:
macs = {EUI(i['mac']) for i in nailgun_node['meta']['interfaces']} macs = {netaddr.EUI(i['mac']) for i in
nailgun_node['meta']['interfaces']}
logger.debug('Look for macs returned by nailgun {0}'.format(macs)) logger.debug('Look for macs returned by nailgun {0}'.format(macs))
# Because our HAproxy may create some interfaces # Because our HAproxy may create some interfaces
if d_macs.issubset(macs): if d_macs.issubset(macs):
@ -947,9 +947,11 @@ class FuelWebClient(object):
:rtype: Devops Node or None :rtype: Devops Node or None
""" """
nailgun_node = self.get_nailgun_node_by_fqdn(fqdn) nailgun_node = self.get_nailgun_node_by_fqdn(fqdn)
macs = {EUI(i['mac']) for i in nailgun_node['meta']['interfaces']} macs = {netaddr.EUI(i['mac']) for i in
nailgun_node['meta']['interfaces']}
for devops_node in devops_nodes: for devops_node in devops_nodes:
devops_macs = {EUI(i.mac_address) for i in devops_node.interfaces} devops_macs = {netaddr.EUI(i.mac_address) for i in
devops_node.interfaces}
if devops_macs == macs: if devops_macs == macs:
return devops_node return devops_node
@ -962,7 +964,7 @@ class FuelWebClient(object):
""" """
for node in self.environment.d_env.nodes(): for node in self.environment.d_env.nodes():
for iface in node.interfaces: for iface in node.interfaces:
if EUI(iface.mac_address) == EUI(mac_address): if netaddr.EUI(iface.mac_address) == netaddr.EUI(mac_address):
return node return node
@logwrap @logwrap
@ -1652,7 +1654,7 @@ class FuelWebClient(object):
baremetal_net = self.environment.d_env.get_network( baremetal_net = self.environment.d_env.get_network(
name='ironic').ip_network name='ironic').ip_network
net_config['gateway'] = str( net_config['gateway'] = str(
list(IPNetwork(baremetal_net))[-2]) list(netaddr.IPNetwork(str(baremetal_net)))[-2])
ip_network = baremetal_net ip_network = baremetal_net
else: else:
ip_network = net_name ip_network = net_name
@ -1662,7 +1664,7 @@ class FuelWebClient(object):
baremetal_net = self.environment.d_env.get_network( baremetal_net = self.environment.d_env.get_network(
name='ironic').ip_network name='ironic').ip_network
net_config['gateway'] = str( net_config['gateway'] = str(
list(IPNetwork(baremetal_net))[-2]) list(netaddr.IPNetwork(str(baremetal_net)))[-2])
ip_network = baremetal_net ip_network = baremetal_net
else: else:
net_config['gateway'] = self.environment.d_env.router(net_name) net_config['gateway'] = self.environment.d_env.router(net_name)
@ -1679,7 +1681,7 @@ class FuelWebClient(object):
net_config['ip_ranges'] = self.get_range(ip_network, -1) net_config['ip_ranges'] = self.get_range(ip_network, -1)
def get_range(self, ip_network, ip_range=0): def get_range(self, ip_network, ip_range=0):
net = list(IPNetwork(ip_network)) net = list(netaddr.IPNetwork(str(ip_network)))
half = len(net) / 2 half = len(net) / 2
if ip_range == 0: if ip_range == 0:
return [[str(net[2]), str(net[-2])]] return [[str(net[2]), str(net[-2])]]
@ -2221,7 +2223,8 @@ class FuelWebClient(object):
for subnet in subnets_list: for subnet in subnets_list:
logger.debug("Check that subnet {0} is part of network {1}" logger.debug("Check that subnet {0} is part of network {1}"
.format(subnet, nailgun_cidr)) .format(subnet, nailgun_cidr))
assert_true(IPNetwork(subnet) in IPNetwork(nailgun_cidr), assert_true(netaddr.IPNetwork(str(subnet)) in
netaddr.IPNetwork(str(nailgun_cidr)),
'Something goes wrong. Seems subnet {0} is out ' 'Something goes wrong. Seems subnet {0} is out '
'of net {1}'.format(subnet, nailgun_cidr)) 'of net {1}'.format(subnet, nailgun_cidr))
@ -2233,7 +2236,8 @@ class FuelWebClient(object):
for subnet1, subnet2 in subnets_pairs: for subnet1, subnet2 in subnets_pairs:
logger.debug("Check if the subnet {0} is part of the subnet {1}" logger.debug("Check if the subnet {0} is part of the subnet {1}"
.format(subnet1, subnet2)) .format(subnet1, subnet2))
assert_true(IPNetwork(subnet1) not in IPNetwork(subnet2), assert_true(netaddr.IPNetwork(str(subnet1)) not in
netaddr.IPNetwork(str(subnet2)),
"Subnet {0} is part of subnet {1}" "Subnet {0} is part of subnet {1}"
.format(subnet1, subnet2)) .format(subnet1, subnet2))
@ -2560,7 +2564,7 @@ class FuelWebClient(object):
for network in networks: for network in networks:
if network['name'] != network_name: if network['name'] != network_name:
continue continue
old_cidr = IPNetwork(network['cidr']) old_cidr = netaddr.IPNetwork(str(network['cidr']))
new_cidr = old_cidr.subnet(1)[0] new_cidr = old_cidr.subnet(1)[0]
assert_not_equal(old_cidr, new_cidr, assert_not_equal(old_cidr, new_cidr,
'Can\t create a subnet using default cidr {0} ' 'Can\t create a subnet using default cidr {0} '

View File

@ -3,9 +3,8 @@ git+git://github.com/openstack/fuel-devops.git@2.9.19
anyjson==0.3.1 anyjson==0.3.1
paramiko paramiko
proboscis==1.2.6.0 proboscis==1.2.6.0
ipaddr
junitxml>=0.7.0 junitxml>=0.7.0
netaddr netaddr>=0.7.12,!=0.7.16
python-glanceclient==0.17.1 python-glanceclient==0.17.1
python-keystoneclient>=0.3.2 python-keystoneclient>=0.3.2
python-novaclient>=2.15.0 python-novaclient>=2.15.0

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from ipaddr import IPAddress
from ipaddr import summarize_address_range
import netaddr import netaddr
import json import json
@ -51,7 +49,7 @@ class TestMultipleClusterNets(TestBasic):
for net in net_dict['networks']: for net in net_dict['networks']:
if net_name in net['name'] and net['group_id'] == group_id: if net_name in net['name'] and net['group_id'] == group_id:
cidr = net['cidr'] cidr = net['cidr']
sliced_list = list(netaddr.IPNetwork(cidr))[5:-5] sliced_list = list(netaddr.IPNetwork(str(cidr)))[5:-5]
return [str(sliced_list[0]), str(sliced_list[-1])] return [str(sliced_list[0]), str(sliced_list[-1])]
@staticmethod @staticmethod
@ -67,7 +65,7 @@ class TestMultipleClusterNets(TestBasic):
asserts.assert_true(len(default_admin_network) == 1, asserts.assert_true(len(default_admin_network) == 1,
"Default 'admin/pxe' network not found " "Default 'admin/pxe' network not found "
"in cluster network configuration!") "in cluster network configuration!")
default_admin_range = [IPAddress(ip) for ip default_admin_range = [netaddr.IPAddress(str(ip)) for ip
in default_admin_network[0]["ip_ranges"][0]] in default_admin_network[0]["ip_ranges"][0]]
new_admin_range = [default_admin_range[0] + number_excluded_ips, new_admin_range = [default_admin_range[0] + number_excluded_ips,
default_admin_range[1]] default_admin_range[1]]
@ -77,9 +75,8 @@ class TestMultipleClusterNets(TestBasic):
@staticmethod @staticmethod
def is_ip_in_range(ip_addr, ip_range_start, ip_range_end): def is_ip_in_range(ip_addr, ip_range_start, ip_range_end):
ip_addr_ranges = summarize_address_range(IPAddress(ip_range_start), return netaddr.IPAddress(str(ip_addr)) in netaddr.iter_iprange(
IPAddress(ip_range_end)) str(ip_range_start), str(ip_range_end))
return any(IPAddress(ip_addr) in iprange for iprange in ip_addr_ranges)
@staticmethod @staticmethod
def is_update_dnsmasq_running(tasks): def is_update_dnsmasq_running(tasks):
@ -659,8 +656,9 @@ class TestMultipleClusterNets(TestBasic):
} }
for k in check: for k in check:
vip = IPAddress(current_settings['vips'][k]['ipaddr']) vip = netaddr.IPAddress(str(current_settings['vips'][k]['ipaddr']))
custom_net = self.env.d_env.get_network(name=check[k]).ip custom_net = netaddr.IPNetwork(
str(self.env.d_env.get_network(name=check[k]).ip))
asserts.assert_true( asserts.assert_true(
vip in custom_net, vip in custom_net,
'{0} is not from {1} network'.format(k, check[k])) '{0} is not from {1} network'.format(k, check[k]))

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from ipaddr import IPAddress import netaddr
from ipaddr import IPNetwork
from proboscis.asserts import assert_equal from proboscis.asserts import assert_equal
from proboscis.asserts import assert_true from proboscis.asserts import assert_true
from proboscis.asserts import fail from proboscis.asserts import fail
@ -55,9 +55,8 @@ class TestNetworkTemplatesBase(TestBasic):
'"{0}", which does not exist!'.format(nodegroup)) '"{0}", which does not exist!'.format(nodegroup))
group_id = [n['id'] for n in nodegroups if group_id = [n['id'] for n in nodegroups if
n['name'] == nodegroup][0] n['name'] == nodegroup][0]
ip_network = IPNetwork(ip_nets[nodegroup]) ip_network = netaddr.IPNetwork(str(ip_nets[nodegroup]))
ip_subnets = ip_network.subnet( ip_subnets = ip_network.subnet(int(ip_prefixlen))
int(ip_prefixlen) - int(ip_network.prefixlen))
for network, interface in networks: for network, interface in networks:
ip_subnet = ip_subnets.pop() ip_subnet = ip_subnets.pop()
networks_data.append( networks_data.append(
@ -147,13 +146,14 @@ class TestNetworkTemplatesBase(TestBasic):
raw_addresses = self.get_interface_ips(remote, iface_name) raw_addresses = self.get_interface_ips(remote, iface_name)
raw_ips = [raw_addr.split('/')[0] for raw_addr in raw_addresses] raw_ips = [raw_addr.split('/')[0] for raw_addr in raw_addresses]
try: try:
ips = [IPAddress(raw_ip) for raw_ip in raw_ips] ips = [netaddr.IPAddress(str(raw_ip)) for raw_ip in raw_ips]
except ValueError: except ValueError:
fail('Device {0} on remote node does not have a valid ' fail('Device {0} on remote node does not have a valid '
'IPv4 address assigned!'.format(iface_name)) 'IPv4 address assigned!'.format(iface_name))
return return
actual_networks = [IPNetwork(raw_addr) for raw_addr in raw_addresses] actual_networks = [netaddr.IPNetwork(str(raw_addr)) for
network = IPNetwork(cidr) raw_addr in raw_addresses]
network = netaddr.IPNetwork(str(cidr))
assert_true(network in actual_networks, assert_true(network in actual_networks,
'Network(s) on {0} device differs than {1}: {2}'.format( 'Network(s) on {0} device differs than {1}: {2}'.format(
iface_name, cidr, raw_addresses)) iface_name, cidr, raw_addresses))

View File

@ -12,9 +12,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from ipaddr import IPAddress
import random import random
import time import time
import netaddr
import traceback import traceback
from devops.helpers import helpers from devops.helpers import helpers
@ -103,7 +103,7 @@ class ServicesReconfiguration(TestBasic):
lambda x: ((x['name'] != 'fuelweb_admin')and lambda x: ((x['name'] != 'fuelweb_admin')and
(x['name'] != 'private')), (x['name'] != 'private')),
networks): networks):
default_range = [IPAddress(ip) for ip default_range = [netaddr.IPAddress(str(ip)) for ip
in default_network["ip_ranges"][0]] in default_network["ip_ranges"][0]]
if cut_from_start: if cut_from_start:
new_range = [default_range[0], new_range = [default_range[0],
@ -1349,7 +1349,8 @@ class ServicesReconfiguration(TestBasic):
service_list = ['neutron-server', 'neutron-dhcp-agent', service_list = ['neutron-server', 'neutron-dhcp-agent',
'neutron-l3-agent', 'neutron-metadata-agent', 'neutron-l3-agent', 'neutron-metadata-agent',
'nova-scheduler', 'nova-novncproxy', 'nova-conductor', 'nova-scheduler', 'nova-novncproxy', 'nova-conductor',
'nova-api', 'nova-consoleauth', 'nova-cert'] 'nova-api', 'nova-consoleauth', 'nova-objectstore',
'nova-cert']
services_uptime = {} services_uptime = {}
for service_name in service_list: for service_name in service_list:
services_uptime[service_name] = self.get_service_uptime( services_uptime[service_name] = self.get_service_uptime(