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
This commit is contained in:
Riccardo Pittau 2019-02-04 09:47:52 +01:00
parent a365ff4245
commit d525f8a07f
3 changed files with 7 additions and 2 deletions

View File

@ -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()

View File

@ -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

View File

@ -0,0 +1,5 @@
---
fixes:
- Fixes an issue where the ironic-python-agent is not able to stop when
running with python3.x.