From eebd2d4e33f3b38533b24530183c3afde973d9e9 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 24 Jan 2017 13:07:32 -0800 Subject: [PATCH] Fix active/standby under python3 Changes in diskimage-builder switched the amphora image to use python3. The active/standby code was not python3 compatible. This patch corrects that issue. Change-Id: I81db0e52f1a21d1e3ceea6a4ec2467145f761e55 Closes-Bug: #1659116 --- octavia/amphorae/backends/agent/api_server/keepalived.py | 2 +- octavia/cmd/haproxy_vrrp_check.py | 4 ++-- .../amphorae/backend/agent/api_server/test_server.py | 2 +- octavia/tests/unit/cmd/test_haproxy_vrrp_check.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/octavia/amphorae/backends/agent/api_server/keepalived.py b/octavia/amphorae/backends/agent/api_server/keepalived.py index 14bdac28bf..26c5bd7774 100644 --- a/octavia/amphorae/backends/agent/api_server/keepalived.py +++ b/octavia/amphorae/backends/agent/api_server/keepalived.py @@ -50,7 +50,7 @@ class Keepalived(object): flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC # mode 00644 mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH - with os.fdopen(os.open(conf_file, flags, mode), 'w') as f: + with os.fdopen(os.open(conf_file, flags, mode), 'wb') as f: b = stream.read(BUFFER) while b: f.write(b) diff --git a/octavia/cmd/haproxy_vrrp_check.py b/octavia/cmd/haproxy_vrrp_check.py index 7dccfe96ab..9d5da57b51 100644 --- a/octavia/cmd/haproxy_vrrp_check.py +++ b/octavia/cmd/haproxy_vrrp_check.py @@ -29,8 +29,8 @@ def get_status(sock_address): s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.settimeout(SOCKET_TIMEOUT) s.connect(sock_address) - s.send('show stat -1 -1 -1\n') - data = '' + s.send(b'show stat -1 -1 -1\n') + data = b'' while True: x = s.recv(1024) if not x: diff --git a/octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py b/octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py index 1478f35d90..3bf8fd29c7 100644 --- a/octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py +++ b/octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py @@ -1450,7 +1450,7 @@ class TestServerTestCase(base.TestCase): mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH mock_open.assert_called_with(cfg_path, flags, mode) - mock_fdopen.assert_called_with(123, 'w') + mock_fdopen.assert_called_with(123, 'wb') self.assertEqual(200, rv.status_code) mock_exists.return_value = False diff --git a/octavia/tests/unit/cmd/test_haproxy_vrrp_check.py b/octavia/tests/unit/cmd/test_haproxy_vrrp_check.py index a391614e6e..6f5e45b0b6 100644 --- a/octavia/tests/unit/cmd/test_haproxy_vrrp_check.py +++ b/octavia/tests/unit/cmd/test_haproxy_vrrp_check.py @@ -28,7 +28,7 @@ class TestHAproxyVRRPCheckCMD(base.TestCase): socket_mock = mock.MagicMock() mock_socket.return_value = socket_mock recv_mock = mock.MagicMock() - recv_mock.side_effect = ['1', Exception('BREAK')] + recv_mock.side_effect = [b'1', Exception('BREAK')] socket_mock.recv = recv_mock self.assertRaisesRegexp(Exception, 'BREAK',