From 2a844e67d75604fbf8fb67f6c778f278d3f5936d Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Wed, 23 Nov 2016 12:13:49 +0000 Subject: [PATCH] Drac: Deprecate drac_host property This patch is deprecating the drac_host property in favor of drac_address. The drivers in the Ironic tree uses the "_address" format for setting the IP address to talk to their BMC except for Drac which used "drac_host" instead. This patch is fixing it. These small incosistencies decrease the UX and make scripting around Ironic harder than it should be. Change-Id: Ia23e8582a398dca9ca11762ee6fe1789fdba9777 Closes-Bug: #1644210 --- ironic/drivers/modules/drac/common.py | 28 ++++++++++++++++-- ironic/tests/unit/db/utils.py | 2 +- .../unit/drivers/modules/drac/test_common.py | 29 +++++++++++++++++-- ...drac_host-deprecated-b181149246eecb47.yaml | 5 ++++ 4 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/drac_host-deprecated-b181149246eecb47.yaml diff --git a/ironic/drivers/modules/drac/common.py b/ironic/drivers/modules/drac/common.py index ead3a88724..275c0f6289 100644 --- a/ironic/drivers/modules/drac/common.py +++ b/ironic/drivers/modules/drac/common.py @@ -15,18 +15,20 @@ Common functionalities shared between different DRAC modules. """ +from oslo_log import log as logging from oslo_utils import importutils from ironic.common import exception -from ironic.common.i18n import _ +from ironic.common.i18n import _, _LW from ironic.common import utils drac_client = importutils.try_import('dracclient.client') drac_constants = importutils.try_import('dracclient.constants') +LOG = logging.getLogger(__name__) REQUIRED_PROPERTIES = { - 'drac_host': _('IP address or hostname of the DRAC card. Required.'), + 'drac_address': _('IP address or hostname of the DRAC card. Required.'), 'drac_username': _('username used for authentication. Required.'), 'drac_password': _('password used for authentication. Required.') } @@ -37,8 +39,13 @@ OPTIONAL_PROPERTIES = { 'drac_protocol': _('protocol used for WS-Man endpoint; one of http, https;' ' default is "https". Optional.'), } +DEPRECATED_PROPERTIES = { + 'drac_host': _('IP address or hostname of the DRAC card. DEPRECATED, ' + 'PLEASE USE "drac_address" INSTEAD.'), +} COMMON_PROPERTIES = REQUIRED_PROPERTIES.copy() COMMON_PROPERTIES.update(OPTIONAL_PROPERTIES) +COMMON_PROPERTIES.update(DEPRECATED_PROPERTIES) def parse_driver_info(node): @@ -56,6 +63,21 @@ def parse_driver_info(node): driver_info = node.driver_info parsed_driver_info = {} + if 'drac_host' in driver_info and 'drac_address' not in driver_info: + LOG.warning(_LW('The driver_info["drac_host"] property is deprecated ' + 'and will be removed in the Pike release. Please ' + 'update the node %s driver_info field to use ' + '"drac_address" instead'), node.uuid) + address = driver_info.pop('drac_host', None) + if address: + driver_info['drac_address'] = address + elif 'drac_host' in driver_info and 'drac_address' in driver_info: + LOG.warning(_LW('Both driver_info["drac_address"] and ' + 'driver_info["drac_host"] properties are ' + 'specified for node %s. Please remove the ' + '"drac_host" property from the node. Ignoring ' + '"drac_host" for now'), node.uuid) + error_msgs = [] for param in REQUIRED_PROPERTIES: try: @@ -104,7 +126,7 @@ def get_drac_client(node): node or on invalid input. """ driver_info = parse_driver_info(node) - client = drac_client.DRACClient(driver_info['drac_host'], + client = drac_client.DRACClient(driver_info['drac_address'], driver_info['drac_username'], driver_info['drac_password'], driver_info['drac_port'], diff --git a/ironic/tests/unit/db/utils.py b/ironic/tests/unit/db/utils.py index 72fe659fa8..74377b5cd0 100644 --- a/ironic/tests/unit/db/utils.py +++ b/ironic/tests/unit/db/utils.py @@ -108,7 +108,7 @@ def get_test_ilo_info(): def get_test_drac_info(): return { - "drac_host": "1.2.3.4", + "drac_address": "1.2.3.4", "drac_port": 443, "drac_path": "/wsman", "drac_protocol": "https", diff --git a/ironic/tests/unit/drivers/modules/drac/test_common.py b/ironic/tests/unit/drivers/modules/drac/test_common.py index 480005feed..e79edc143f 100644 --- a/ironic/tests/unit/drivers/modules/drac/test_common.py +++ b/ironic/tests/unit/drivers/modules/drac/test_common.py @@ -34,18 +34,43 @@ class DracCommonMethodsTestCase(db_base.DbTestCase): driver='fake_drac', driver_info=INFO_DICT) info = drac_common.parse_driver_info(node) - self.assertEqual(INFO_DICT['drac_host'], info['drac_host']) + self.assertEqual(INFO_DICT['drac_address'], info['drac_address']) self.assertEqual(INFO_DICT['drac_port'], info['drac_port']) self.assertEqual(INFO_DICT['drac_path'], info['drac_path']) self.assertEqual(INFO_DICT['drac_protocol'], info['drac_protocol']) self.assertEqual(INFO_DICT['drac_username'], info['drac_username']) self.assertEqual(INFO_DICT['drac_password'], info['drac_password']) + @mock.patch.object(drac_common.LOG, 'warning') + def test_parse_driver_info_drac_host(self, mock_log): + driver_info = db_utils.get_test_drac_info() + driver_info['drac_host'] = '4.5.6.7' + driver_info.pop('drac_address') + node = obj_utils.create_test_node(self.context, + driver='fake_drac', + driver_info=driver_info) + info = drac_common.parse_driver_info(node) + self.assertEqual('4.5.6.7', info['drac_address']) + self.assertNotIn('drac_host', info) + self.assertTrue(mock_log.called) + + @mock.patch.object(drac_common.LOG, 'warning') + def test_parse_driver_info_drac_host_and_drac_address(self, mock_log): + driver_info = db_utils.get_test_drac_info() + driver_info['drac_host'] = '4.5.6.7' + node = obj_utils.create_test_node(self.context, + driver='fake_drac', + driver_info=driver_info) + info = drac_common.parse_driver_info(node) + self.assertEqual('4.5.6.7', driver_info['drac_host']) + self.assertEqual(driver_info['drac_address'], info['drac_address']) + self.assertTrue(mock_log.called) + def test_parse_driver_info_missing_host(self): node = obj_utils.create_test_node(self.context, driver='fake_drac', driver_info=INFO_DICT) - del node.driver_info['drac_host'] + del node.driver_info['drac_address'] self.assertRaises(exception.InvalidParameterValue, drac_common.parse_driver_info, node) diff --git a/releasenotes/notes/drac_host-deprecated-b181149246eecb47.yaml b/releasenotes/notes/drac_host-deprecated-b181149246eecb47.yaml new file mode 100644 index 0000000000..8cb22d1779 --- /dev/null +++ b/releasenotes/notes/drac_host-deprecated-b181149246eecb47.yaml @@ -0,0 +1,5 @@ +--- +deprecations: + - For DRAC drivers, the node's ``driver_info["drac_host"]`` property is + deprecated and will be ignored starting in the Pike release. + Please use ``driver_info["drac_address"]`` instead.