From d525f8a07f2b223f7c7455a8fa4c8aad9b914d9b Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Mon, 4 Feb 2019 09:47:52 +0100 Subject: [PATCH] Making ironic-python-agent able to stop with python 3.x The agent stop function will write a byte string 'a' to the pipe as a signal for the run function to end process. The run function is expecting a literal string. In python 2.x the byte string will automatically be converted to literal, while python 3.x won't do the conversion, causing the process to never stop. This patch will fix that behavior, allowing the IPA to correctly stop using python 3.x. Story: 2004928 Task: 29308 Change-Id: Iad16e8bed2436d961dea8ddaec1c2724225b4097 --- ironic_python_agent/agent.py | 2 +- ironic_python_agent/tests/unit/test_agent.py | 2 +- .../notes/fix-agent-unable-to-stop-py3-6c210793476968d1.yaml | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/fix-agent-unable-to-stop-py3-6c210793476968d1.yaml diff --git a/ironic_python_agent/agent.py b/ironic_python_agent/agent.py index 819bb91c8..c4b42f76a 100644 --- a/ironic_python_agent/agent.py +++ b/ironic_python_agent/agent.py @@ -111,7 +111,7 @@ class IronicPythonAgentHeartbeater(threading.Thread): try: while True: if p.poll(interval * 1000): - if os.read(self.reader, 1) == 'a': + if os.read(self.reader, 1).decode() == 'a': break self.do_heartbeat() diff --git a/ironic_python_agent/tests/unit/test_agent.py b/ironic_python_agent/tests/unit/test_agent.py index 3a9024c83..ba529bae4 100644 --- a/ironic_python_agent/tests/unit/test_agent.py +++ b/ironic_python_agent/tests/unit/test_agent.py @@ -111,7 +111,7 @@ class TestHeartbeater(ironic_agent_base.IronicAgentTest): expected_poll_calls.append(mock.call(1000 * 25.0)) # Stop now poll_responses.append(True) - mock_read.return_value = 'a' + mock_read.return_value = b'a' # Hook it up and run it mock_time.side_effect = time_responses diff --git a/releasenotes/notes/fix-agent-unable-to-stop-py3-6c210793476968d1.yaml b/releasenotes/notes/fix-agent-unable-to-stop-py3-6c210793476968d1.yaml new file mode 100644 index 000000000..784c134fe --- /dev/null +++ b/releasenotes/notes/fix-agent-unable-to-stop-py3-6c210793476968d1.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - Fixes an issue where the ironic-python-agent is not able to stop when + running with python3.x. +