diff --git a/example.conf b/example.conf index 2bd2103b9..21c22ae87 100644 --- a/example.conf +++ b/example.conf @@ -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 = # 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 diff --git a/ironic_inspector/conf.py b/ironic_inspector/conf.py index 24da3dc02..a889c6664 100644 --- a/ironic_inspector/conf.py +++ b/ironic_inspector/conf.py @@ -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.'), ] diff --git a/ironic_inspector/test/test_utils.py b/ironic_inspector/test/test_utils.py index ba322b26c..614c2e353 100644 --- a/ironic_inspector/test/test_utils.py +++ b/ironic_inspector/test/test_utils.py @@ -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): diff --git a/ironic_inspector/utils.py b/ironic_inspector/utils.py index 7b5dc401a..d4acd889b 100644 --- a/ironic_inspector/utils.py +++ b/ironic_inspector/utils.py @@ -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: