Change utils.get_ipmi_address(node) to always return IPv4 address
It is possible for ipmi_address, ilo_address, or drac_host to be hostnames. However, we need an IPv4 address. Closes-Bug: #1415040 Change-Id: I221e63ffe8881ad26f512fb29328ffcad8e26b45
This commit is contained in:
parent
9d4006e186
commit
3d1715a8ab
@ -44,6 +44,29 @@ class TestCheckIsAdmin(base.BaseTest):
|
|||||||
utils.check_is_admin, 'token')
|
utils.check_is_admin, 'token')
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch('ironic_discoverd.node_cache.NodeInfo')
|
||||||
|
class TestGetIpmiAddress(base.BaseTest):
|
||||||
|
def test_ipv4_in_resolves(self, mock_node):
|
||||||
|
node = mock_node.return_value
|
||||||
|
node.driver_info.get.return_value = '192.168.1.1'
|
||||||
|
ip = utils.get_ipmi_address(node)
|
||||||
|
self.assertEqual(ip, '192.168.1.1')
|
||||||
|
|
||||||
|
@mock.patch('socket.gethostbyname')
|
||||||
|
def test_good_hostname_resolves(self, mock_socket, mock_node):
|
||||||
|
node = mock_node.return_value
|
||||||
|
node.driver_info.get.return_value = 'www.example.com'
|
||||||
|
mock_socket.return_value = '192.168.1.1'
|
||||||
|
ip = utils.get_ipmi_address(node)
|
||||||
|
mock_socket.assert_called_once_with('www.example.com')
|
||||||
|
self.assertEqual(ip, '192.168.1.1')
|
||||||
|
|
||||||
|
def test_bad_hostname_errors(self, mock_node):
|
||||||
|
node = mock_node.return_value
|
||||||
|
node.driver_info.get.return_value = 'meow'
|
||||||
|
self.assertRaises(utils.Error, utils.get_ipmi_address, node)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch.object(eventlet.greenthread, 'sleep', lambda _: None)
|
@mock.patch.object(eventlet.greenthread, 'sleep', lambda _: None)
|
||||||
class TestRetryOnConflict(unittest.TestCase):
|
class TestRetryOnConflict(unittest.TestCase):
|
||||||
def test_retry_on_conflict(self):
|
def test_retry_on_conflict(self):
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
from ironicclient import client
|
from ironicclient import client
|
||||||
@ -76,7 +77,12 @@ def get_ipmi_address(node):
|
|||||||
for name in ('ipmi_address', 'ilo_address', 'drac_host'):
|
for name in ('ipmi_address', 'ilo_address', 'drac_host'):
|
||||||
value = node.driver_info.get(name)
|
value = node.driver_info.get(name)
|
||||||
if value:
|
if value:
|
||||||
return value
|
try:
|
||||||
|
ip = socket.gethostbyname(value)
|
||||||
|
return ip
|
||||||
|
except socket.gaierror:
|
||||||
|
msg = ('Failed to resolve the hostname (%s) for node %s')
|
||||||
|
raise Error(msg % (value, node.uuid))
|
||||||
|
|
||||||
|
|
||||||
def retry_on_conflict(call, *args, **kwargs):
|
def retry_on_conflict(call, *args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user