From ce5baa38039fa8e84cd642f23ea1f085546dbf6b Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Wed, 23 Jun 2021 16:58:10 +0200 Subject: [PATCH] Fix handling driver_info[agent_verify_ca] == False Because of using 'or', it will only be respected when verify_ca is also False in the configuration. Change-Id: Ie000463fa8ac2cd739a9d8f256346472fe3f4288 --- ironic/drivers/modules/agent_client.py | 10 ++++++--- .../unit/drivers/modules/test_agent_client.py | 22 +++++++++++++++++++ .../notes/verify-bool-ab3607429e005bed.yaml | 4 ++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/verify-bool-ab3607429e005bed.yaml diff --git a/ironic/drivers/modules/agent_client.py b/ironic/drivers/modules/agent_client.py index 134d997143..3dc64caa01 100644 --- a/ironic/drivers/modules/agent_client.py +++ b/ironic/drivers/modules/agent_client.py @@ -89,9 +89,13 @@ class AgentClient(object): }) def _get_verify(self, node): - value = (node.driver_internal_info.get('agent_verify_ca') - or node.driver_info.get('agent_verify_ca') - or CONF.agent.verify_ca) + # False is a valid value, don't use 'or' + value = node.driver_internal_info.get('agent_verify_ca') + if value is None: + value = node.driver_info.get('agent_verify_ca') + if value is None: + value = CONF.agent.verify_ca + if isinstance(value, str): try: value = strutils.bool_from_string(value, strict=True) diff --git a/ironic/tests/unit/drivers/modules/test_agent_client.py b/ironic/tests/unit/drivers/modules/test_agent_client.py index 1933165761..9396639193 100644 --- a/ironic/tests/unit/drivers/modules/test_agent_client.py +++ b/ironic/tests/unit/drivers/modules/test_agent_client.py @@ -487,6 +487,28 @@ class TestAgentClient(base.TestCase): timeout=60, verify=False) + @mock.patch('os.path.exists', autospec=True, return_value=True) + def test__command_verify_disable_in_driver_info(self, mock_exists): + response_data = {'status': 'ok'} + self.client.session.post.return_value = MockResponse(response_data) + method = 'standby.run_image' + image_info = {'image_id': 'test_image'} + params = {'image_info': image_info} + + self.node.driver_info['agent_verify_ca'] = False + + url = self.client._get_command_url(self.node) + body = self.client._get_command_body(method, params) + + response = self.client._command(self.node, method, params) + self.assertEqual(response, response_data) + self.client.session.post.assert_called_once_with( + url, + data=body, + params={'wait': 'false'}, + timeout=60, + verify=False) + @mock.patch('os.path.exists', autospec=True, return_value=False) def test__command_verify_invalid_file(self, mock_exists): response_data = {'status': 'ok'} diff --git a/releasenotes/notes/verify-bool-ab3607429e005bed.yaml b/releasenotes/notes/verify-bool-ab3607429e005bed.yaml new file mode 100644 index 0000000000..ec67b12d59 --- /dev/null +++ b/releasenotes/notes/verify-bool-ab3607429e005bed.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Fixes overriding ``agent_verify_ca`` with ``False`` via ``driver_info``.