Make list of ipmi_address-alike driver fields configurable

Add cimc_address approved as part of
http://specs.openstack.org/openstack/ironic-specs/specs/approved/cisco-imc-pxe-driver.html

Change-Id: Id16e0e253eb21def26a089063a528308262d5a01
Closes-Bug: #1488525
This commit is contained in:
Dmitry Tantsur 2015-08-28 16:36:16 +02:00
parent 4484b1fc17
commit 5831723eb6
4 changed files with 32 additions and 15 deletions

View File

@ -59,6 +59,10 @@
# affected by introspection_delay setting. (string value)
#introspection_delay_drivers = ^.*_ssh$
# Ironic driver_info fields that are equivalent to ipmi_address. (list
# value)
#ipmi_address_fields = ilo_address,drac_host,cimc_address
#
# From oslo.log
#
@ -106,8 +110,9 @@
# (Optional) Enables or disables syslog rfc5424 format for logging. If
# enabled, prefixes the MSG part of the syslog message with APP-NAME
# (RFC5424). The format without the APP-NAME is deprecated in K, and
# will be removed in M, along with this option. (boolean value)
# (RFC5424). The format without the APP-NAME is deprecated in Kilo,
# and will be removed in Mitaka, along with this option. (boolean
# value)
# This option is deprecated for removal.
# Its value may be silently ignored in the future.
#use_syslog_rfc_format = true
@ -590,7 +595,7 @@
#node_not_found_hook = <None>
# Method for storing introspection data. If set to 'none',
# introspection data will not be stored (string value)
# introspection data will not be stored. (string value)
# Allowed values: none, swift
#store_data = none

View File

@ -238,6 +238,10 @@ SERVICE_OPTS = [
default='^.*_ssh$',
help='Only node with drivers matching this regular expression '
'will be affected by introspection_delay setting.'),
cfg.ListOpt('ipmi_address_fields',
default=['ilo_address', 'drac_host', 'cimc_address'],
help='Ironic driver_info fields that are equivalent '
'to ipmi_address.'),
]

View File

@ -139,30 +139,38 @@ class TestCheckAuth(base.BaseTest):
utils.check_auth(request)
@mock.patch('ironic_inspector.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'
def test_ipv4_in_resolves(self):
node = mock.Mock(spec=['driver_info', 'uuid'],
driver_info={'ipmi_address': '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'
def test_good_hostname_resolves(self, mock_socket):
node = mock.Mock(spec=['driver_info', 'uuid'],
driver_info={'ipmi_address': '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')
@mock.patch('socket.gethostbyname')
def test_bad_hostname_errors(self, mock_socket, mock_node):
def test_bad_hostname_errors(self, mock_socket):
node = mock.Mock(spec=['driver_info', 'uuid'],
driver_info={'ipmi_address': 'meow'})
mock_socket.side_effect = socket.gaierror('Boom')
node = mock_node.return_value
node.driver_info.get.return_value = 'meow'
self.assertRaises(utils.Error, utils.get_ipmi_address, node)
def test_additional_fields(self):
node = mock.Mock(spec=['driver_info', 'uuid'],
driver_info={'foo': '192.168.1.1'})
self.assertIsNone(utils.get_ipmi_address(node))
CONF.set_override('ipmi_address_fields', ['foo', 'bar', 'baz'])
ip = utils.get_ipmi_address(node)
self.assertEqual(ip, '192.168.1.1')
class TestCapabilities(unittest.TestCase):

View File

@ -155,8 +155,8 @@ def get_auth_strategy():
def get_ipmi_address(node):
# All these are kind-of-ipmi
for name in ('ipmi_address', 'ilo_address', 'drac_host'):
ipmi_fields = ['ipmi_address'] + CONF.ipmi_address_fields
for name in ipmi_fields:
value = node.driver_info.get(name)
if value:
try: