diff options
author | Julia Kreger <juliaashleykreger@gmail.com> | 2019-12-05 14:38:09 -0800 |
---|---|---|
committer | Julia Kreger <juliaashleykreger@gmail.com> | 2020-03-09 23:59:21 +0000 |
commit | 3d2d04c84297eff25cd9e51839b639f4a871acf4 (patch) | |
tree | 6bb2bd3bf38e8c3f76e908db9caf09c584bcdb3b | |
parent | 6121fbf1005097e2cfa23725df3e35e91ae4cbf5 (diff) | |
download | ironic-3d2d04c84297eff25cd9e51839b639f4a871acf4.tar.gz |
Send our token back to the agent
Send our token back to the agent so it can authenitcate
that we are actually the ironic deployment it knows about.
Story: 2007025
Task: 37820
Change-Id: Idd0b2b27956867c66e714cd1a00de5514c67e7ae
-rw-r--r-- | ironic/drivers/modules/agent_client.py | 3 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/test_agent_client.py | 22 |
2 files changed, 25 insertions, 0 deletions
diff --git a/ironic/drivers/modules/agent_client.py b/ironic/drivers/modules/agent_client.py index d9d14c380..32427c6e7 100644 --- a/ironic/drivers/modules/agent_client.py +++ b/ironic/drivers/modules/agent_client.py @@ -82,6 +82,9 @@ class AgentClient(object): request_params = { 'wait': str(wait).lower() } + agent_token = node.driver_internal_info.get('agent_secret_token') + if agent_token: + request_params['agent_token'] = agent_token LOG.debug('Executing agent command %(method)s for node %(node)s', {'node': node.uuid, 'method': method}) diff --git a/ironic/tests/unit/drivers/modules/test_agent_client.py b/ironic/tests/unit/drivers/modules/test_agent_client.py index 9d1af1201..a39477f02 100644 --- a/ironic/tests/unit/drivers/modules/test_agent_client.py +++ b/ironic/tests/unit/drivers/modules/test_agent_client.py @@ -346,6 +346,28 @@ class TestAgentClient(base.TestCase): self.node) self.assertFalse(self.client._command.called) + def test__command_agent_client(self): + response_data = {'status': 'ok'} + response_text = json.dumps(response_data) + self.client.session.post.return_value = MockResponse(response_text) + method = 'standby.run_image' + image_info = {'image_id': 'test_image'} + params = {'image_info': image_info} + i_info = self.node.driver_internal_info + i_info['agent_secret_token'] = 'magical' + self.node.driver_internal_info = i_info + 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', + 'agent_token': 'magical'}, + timeout=60) + class TestAgentClientAttempts(base.TestCase): def setUp(self): |