Remove resolve_hostname
Remove the resolve_hostname function since the resolve_hostname in cinder.utils does the exact same thing so we can reuse it. Change-Id: I3fcdaf8c9d91845bada9d2bff8967b04ab700992 Signed-off-by: Chuck Short <chucks@redhat.com> Signed-off-by: zhu.boxiang <zhu.boxiang@99cloud.net>
This commit is contained in:
parent
80b3bfb91e
commit
fe421fe4bf
|
@ -1055,7 +1055,7 @@ class NetAppCmodeClientTestCase(test.TestCase):
|
|||
mock.call('qos-policy-group-delete-iter', api_args, False)])
|
||||
self.assertEqual(1, mock_log.call_count)
|
||||
|
||||
@mock.patch('cinder.volume.drivers.netapp.utils.resolve_hostname',
|
||||
@mock.patch('cinder.utils.resolve_hostname',
|
||||
return_value='192.168.1.101')
|
||||
def test_get_if_info_by_ip_not_found(self, mock_resolve_hostname):
|
||||
fake_ip = '192.168.1.101'
|
||||
|
@ -1070,7 +1070,7 @@ class NetAppCmodeClientTestCase(test.TestCase):
|
|||
self.assertRaises(exception.NotFound, self.client.get_if_info_by_ip,
|
||||
fake_ip)
|
||||
|
||||
@mock.patch('cinder.volume.drivers.netapp.utils.resolve_hostname',
|
||||
@mock.patch('cinder.utils.resolve_hostname',
|
||||
return_value='192.168.1.101')
|
||||
def test_get_if_info_by_ip(self, mock_resolve_hostname):
|
||||
fake_ip = '192.168.1.101'
|
||||
|
|
|
@ -651,7 +651,7 @@ class NetAppNfsDriverTestCase(test.TestCase):
|
|||
fake.NFS_SHARE)
|
||||
|
||||
def test_get_share_mount_and_vol_from_vol_ref(self):
|
||||
self.mock_object(na_utils, 'resolve_hostname',
|
||||
self.mock_object(utils, 'resolve_hostname',
|
||||
return_value='10.12.142.11')
|
||||
self.mock_object(os.path, 'isfile', return_value=True)
|
||||
self.driver._mounted_shares = [self.fake_nfs_export_1]
|
||||
|
@ -669,7 +669,7 @@ class NetAppNfsDriverTestCase(test.TestCase):
|
|||
self.assertEqual('test_file_name', file_path)
|
||||
|
||||
def test_get_share_mount_and_vol_from_vol_ref_with_bad_ref(self):
|
||||
self.mock_object(na_utils, 'resolve_hostname',
|
||||
self.mock_object(utils, 'resolve_hostname',
|
||||
return_value='10.12.142.11')
|
||||
self.driver._mounted_shares = [self.fake_nfs_export_1]
|
||||
vol_ref = {'source-id': '1234546'}
|
||||
|
@ -683,7 +683,7 @@ class NetAppNfsDriverTestCase(test.TestCase):
|
|||
vol_ref)
|
||||
|
||||
def test_get_share_mount_and_vol_from_vol_ref_where_not_found(self):
|
||||
self.mock_object(na_utils, 'resolve_hostname',
|
||||
self.mock_object(utils, 'resolve_hostname',
|
||||
return_value='10.12.142.11')
|
||||
self.driver._mounted_shares = [self.fake_nfs_export_1]
|
||||
vol_path = "%s/%s" % (self.fake_nfs_export_2, 'test_file_name')
|
||||
|
@ -698,7 +698,7 @@ class NetAppNfsDriverTestCase(test.TestCase):
|
|||
vol_ref)
|
||||
|
||||
def test_get_share_mount_and_vol_from_vol_ref_where_is_dir(self):
|
||||
self.mock_object(na_utils, 'resolve_hostname',
|
||||
self.mock_object(utils, 'resolve_hostname',
|
||||
return_value='10.12.142.11')
|
||||
self.driver._mounted_shares = [self.fake_nfs_export_1]
|
||||
vol_ref = {'source-name': self.fake_nfs_export_2}
|
||||
|
|
|
@ -307,7 +307,7 @@ class NetAppCmodeNfsDriverTestCase(test.TestCase):
|
|||
self.driver.zapi_client, 'get_operational_lif_addresses',
|
||||
return_value=[fake.SHARE_IP])
|
||||
mock_resolve_hostname = self.mock_object(
|
||||
na_utils, 'resolve_hostname', return_value=fake.SHARE_IP)
|
||||
utils, 'resolve_hostname', return_value=fake.SHARE_IP)
|
||||
mock_get_flexvol = self.mock_object(
|
||||
self.driver.zapi_client, 'get_flexvol',
|
||||
return_value={'name': fake.NETAPP_VOLUME})
|
||||
|
@ -330,7 +330,7 @@ class NetAppCmodeNfsDriverTestCase(test.TestCase):
|
|||
self.mock_object(self.driver.zapi_client,
|
||||
'get_operational_lif_addresses',
|
||||
return_value=[])
|
||||
self.mock_object(na_utils,
|
||||
self.mock_object(utils,
|
||||
'resolve_hostname',
|
||||
return_value=fake.SHARE_IP)
|
||||
|
||||
|
@ -344,7 +344,7 @@ class NetAppCmodeNfsDriverTestCase(test.TestCase):
|
|||
self.mock_object(self.driver.zapi_client,
|
||||
'get_operational_lif_addresses',
|
||||
return_value=[fake.SHARE_IP])
|
||||
self.mock_object(na_utils,
|
||||
self.mock_object(utils,
|
||||
'resolve_hostname',
|
||||
return_value=fake.SHARE_IP)
|
||||
side_effect = exception.VolumeBackendAPIException(data='fake_data')
|
||||
|
|
|
@ -21,6 +21,7 @@ import mock
|
|||
import socket
|
||||
|
||||
from cinder import exception
|
||||
from cinder import utils as cinder_utils
|
||||
from cinder.volume import configuration as conf
|
||||
|
||||
from cinder.tests.unit.volume.drivers.netapp.eseries import fakes as \
|
||||
|
@ -344,7 +345,7 @@ class NetAppESeriesDriverTestCase(object):
|
|||
configuration = self._set_config(self.create_configuration())
|
||||
configuration.netapp_controller_ips = '987.65.43.21'
|
||||
driver = common.NetAppDriver(configuration=configuration)
|
||||
self.mock_object(na_utils, 'resolve_hostname',
|
||||
self.mock_object(cinder_utils, 'resolve_hostname',
|
||||
side_effect=socket.gaierror)
|
||||
|
||||
self.assertRaises(
|
||||
|
@ -355,7 +356,7 @@ class NetAppESeriesDriverTestCase(object):
|
|||
configuration = self._set_config(self.create_configuration())
|
||||
configuration.netapp_controller_ips = '987.65.43.21,127.0.0.1'
|
||||
driver = common.NetAppDriver(configuration=configuration)
|
||||
self.mock_object(na_utils, 'resolve_hostname',
|
||||
self.mock_object(cinder_utils, 'resolve_hostname',
|
||||
side_effect=socket.gaierror)
|
||||
|
||||
self.assertRaises(
|
||||
|
@ -366,7 +367,7 @@ class NetAppESeriesDriverTestCase(object):
|
|||
configuration = self._set_config(self.create_configuration())
|
||||
configuration.netapp_controller_ips = '127.0.0.1,987.65.43.21'
|
||||
driver = common.NetAppDriver(configuration=configuration)
|
||||
self.mock_object(na_utils, 'resolve_hostname',
|
||||
self.mock_object(cinder_utils, 'resolve_hostname',
|
||||
side_effect=socket.gaierror)
|
||||
|
||||
self.assertRaises(
|
||||
|
@ -377,7 +378,7 @@ class NetAppESeriesDriverTestCase(object):
|
|||
configuration = self._set_config(self.create_configuration())
|
||||
configuration.netapp_controller_ips = '564.124.1231.1,987.65.43.21'
|
||||
driver = common.NetAppDriver(configuration=configuration)
|
||||
self.mock_object(na_utils, 'resolve_hostname',
|
||||
self.mock_object(cinder_utils, 'resolve_hostname',
|
||||
side_effect=socket.gaierror)
|
||||
|
||||
self.assertRaises(
|
||||
|
|
|
@ -668,7 +668,7 @@ class Client(client_base.Client):
|
|||
net_if_iter.add_child_elem(query)
|
||||
query.add_node_with_children(
|
||||
'net-interface-info',
|
||||
**{'address': na_utils.resolve_hostname(ip)})
|
||||
**{'address': utils.resolve_hostname(ip)})
|
||||
result = self.connection.invoke_successfully(net_if_iter, True)
|
||||
num_records = result.get_child_content('num-records')
|
||||
if num_records and int(num_records) >= 1:
|
||||
|
|
|
@ -744,7 +744,7 @@ class NetAppNfsDriver(driver.ManageableVD,
|
|||
try:
|
||||
if conn:
|
||||
host = conn.split(':')[0]
|
||||
ip = na_utils.resolve_hostname(host)
|
||||
ip = utils.resolve_hostname(host)
|
||||
share_candidates = []
|
||||
for sh in self._mounted_shares:
|
||||
sh_exp = sh.split(':')[-1]
|
||||
|
@ -910,7 +910,7 @@ class NetAppNfsDriver(driver.ManageableVD,
|
|||
# First strip out share and convert to IP format.
|
||||
share_split = vol_ref.rsplit(':', 1)
|
||||
|
||||
vol_ref_share_ip = na_utils.resolve_hostname(share_split[0])
|
||||
vol_ref_share_ip = utils.resolve_hostname(share_split[0])
|
||||
|
||||
# Now place back into volume reference.
|
||||
vol_ref_share = vol_ref_share_ip + ':' + share_split[1]
|
||||
|
|
|
@ -327,7 +327,7 @@ class NetAppCmodeNfsDriver(nfs_base.NetAppNfsDriver,
|
|||
for share in self._mounted_shares:
|
||||
host, junction_path = na_utils.get_export_host_junction_path(share)
|
||||
|
||||
address = na_utils.resolve_hostname(host)
|
||||
address = utils.resolve_hostname(host)
|
||||
|
||||
if address not in vserver_addresses:
|
||||
LOG.warning('Address not found for NFS share %s.', share)
|
||||
|
@ -463,7 +463,7 @@ class NetAppCmodeNfsDriver(nfs_base.NetAppNfsDriver,
|
|||
|
||||
def _get_ip_verify_on_cluster(self, host):
|
||||
"""Verifies if host on same cluster and returns ip."""
|
||||
ip = na_utils.resolve_hostname(host)
|
||||
ip = utils.resolve_hostname(host)
|
||||
vserver = self._get_vserver_for_ip(ip)
|
||||
if not vserver:
|
||||
raise exception.NotFound(_("Unable to locate an SVM that is "
|
||||
|
|
|
@ -260,7 +260,7 @@ class NetAppESeriesLibrary(object):
|
|||
"""Does validity checks for storage system registry and health."""
|
||||
def _resolve_host(host):
|
||||
try:
|
||||
ip = na_utils.resolve_hostname(host)
|
||||
ip = cinder_utils.resolve_hostname(host)
|
||||
return ip
|
||||
except socket.gaierror as e:
|
||||
LOG.error('Error resolving host %(host)s. Error - %(e)s.',
|
||||
|
@ -272,7 +272,7 @@ class NetAppESeriesLibrary(object):
|
|||
ips = self.configuration.netapp_controller_ips
|
||||
ips = [i.strip() for i in ips.split(",")]
|
||||
ips = [x for x in ips if _resolve_host(x)]
|
||||
host = na_utils.resolve_hostname(
|
||||
host = cinder_utils.resolve_hostname(
|
||||
self.configuration.netapp_server_hostname)
|
||||
if host in ips:
|
||||
LOG.info('Embedded mode detected.')
|
||||
|
|
|
@ -26,7 +26,6 @@ NetApp drivers to achieve the desired functionality.
|
|||
import decimal
|
||||
import platform
|
||||
import re
|
||||
import socket
|
||||
|
||||
from oslo_concurrency import processutils as putils
|
||||
from oslo_log import log as logging
|
||||
|
@ -148,13 +147,6 @@ def trace_filter_func_api(all_args):
|
|||
return re.match(API_TRACE_PATTERN, api_name) is not None
|
||||
|
||||
|
||||
def resolve_hostname(hostname):
|
||||
"""Resolves host name to IP address."""
|
||||
res = socket.getaddrinfo(hostname, None)[0]
|
||||
family, socktype, proto, canonname, sockaddr = res
|
||||
return sockaddr[0]
|
||||
|
||||
|
||||
def round_down(value, precision='0.00'):
|
||||
return float(decimal.Decimal(six.text_type(value)).quantize(
|
||||
decimal.Decimal(precision), rounding=decimal.ROUND_DOWN))
|
||||
|
|
Loading…
Reference in New Issue