Fix argument type for _sd_notify() on python3
socket.sendall() expects a byte-string as argument but takes its from _sd_notify in a string format causing an exception on python3 Closes-Bug: #1564150 Change-Id: I16de988739b9e37b8b2721fefd3c6be485e5a4c7
This commit is contained in:
parent
9604fc9c43
commit
63c62f201a
@ -53,7 +53,7 @@ def notify():
|
|||||||
For details see
|
For details see
|
||||||
http://www.freedesktop.org/software/systemd/man/sd_notify.html
|
http://www.freedesktop.org/software/systemd/man/sd_notify.html
|
||||||
"""
|
"""
|
||||||
_sd_notify(False, 'READY=1')
|
_sd_notify(False, b'READY=1')
|
||||||
|
|
||||||
|
|
||||||
def notify_once():
|
def notify_once():
|
||||||
@ -64,7 +64,7 @@ def notify_once():
|
|||||||
This method removes the NOTIFY_SOCKET environment variable to ensure
|
This method removes the NOTIFY_SOCKET environment variable to ensure
|
||||||
notification is sent only once.
|
notification is sent only once.
|
||||||
"""
|
"""
|
||||||
_sd_notify(True, 'READY=1')
|
_sd_notify(True, b'READY=1')
|
||||||
|
|
||||||
|
|
||||||
def onready(notify_socket, timeout):
|
def onready(notify_socket, timeout):
|
||||||
@ -86,7 +86,7 @@ def onready(notify_socket, timeout):
|
|||||||
msg = sock.recv(512)
|
msg = sock.recv(512)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
return 2
|
return 2
|
||||||
if 'READY=1' in msg:
|
if b'READY=1' == msg:
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
return 1
|
return 1
|
||||||
|
@ -45,7 +45,7 @@ class SystemdTestCase(test_base.BaseTestCase):
|
|||||||
self.closed = True
|
self.closed = True
|
||||||
|
|
||||||
def sendall(fs, data):
|
def sendall(fs, data):
|
||||||
if data == 'READY=1':
|
if data == b'READY=1':
|
||||||
self.ready = True
|
self.ready = True
|
||||||
|
|
||||||
with mock.patch.object(socket, 'socket', new=FakeSocket):
|
with mock.patch.object(socket, 'socket', new=FakeSocket):
|
||||||
@ -67,7 +67,7 @@ class SystemdTestCase(test_base.BaseTestCase):
|
|||||||
|
|
||||||
@mock.patch("socket.socket")
|
@mock.patch("socket.socket")
|
||||||
def test_onready(self, sock_mock):
|
def test_onready(self, sock_mock):
|
||||||
recv_results = ['READY=1', '', socket.timeout]
|
recv_results = [b'READY=1', '', socket.timeout]
|
||||||
expected_results = [0, 1, 2]
|
expected_results = [0, 1, 2]
|
||||||
for recv, expected in zip(recv_results, expected_results):
|
for recv, expected in zip(recv_results, expected_results):
|
||||||
if recv == socket.timeout:
|
if recv == socket.timeout:
|
||||||
|
Loading…
Reference in New Issue
Block a user