From 10221e9f946a262c9a59ca2f29c5e865e0bf1cd5 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Wed, 1 May 2019 10:52:37 -0400 Subject: [PATCH] tests: update to avoid binary/decode issues Signed-off-by: Alfredo Deza Resolves: rm#39489 --- ceph_deploy/tests/test_gather_keys_missing.py | 6 +++--- .../tests/test_gather_keys_with_mon.py | 20 +++++++++---------- ceph_deploy/tests/test_mon.py | 4 +++- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ceph_deploy/tests/test_gather_keys_missing.py b/ceph_deploy/tests/test_gather_keys_missing.py index 0369aa8..36b2654 100644 --- a/ceph_deploy/tests/test_gather_keys_missing.py +++ b/ceph_deploy/tests/test_gather_keys_missing.py @@ -26,11 +26,11 @@ class mock_rlogger(object): def mock_remoto_process_check_success(conn, args): secret = new.generate_auth_key() out = '[mon.]\nkey = %s\ncaps mon = allow *\n' % secret - return out.encode('utf-8').split(b'\n'), [], 0 + return out.split('\n'), [], 0 def mock_remoto_process_check_rc_error(conn, args): - return [b""], [b"this failed\n"], 1 + return [""], ["this failed\n"], 1 class TestGatherKeysMissing(object): @@ -102,7 +102,7 @@ class TestGatherKeysMissing(object): keyname = gatherkeys.keytype_path_to(self.args, keytype) keypath_gen = os.path.join(self.test_dir, keyname) assert os.path.isfile(keypath_gen) - + @mock.patch('ceph_deploy.lib.remoto.process.check', mock_remoto_process_check_success) def test_success_osd(self): keytype = 'osd' diff --git a/ceph_deploy/tests/test_gather_keys_with_mon.py b/ceph_deploy/tests/test_gather_keys_with_mon.py index 805cc17..e7d1ada 100644 --- a/ceph_deploy/tests/test_gather_keys_with_mon.py +++ b/ceph_deploy/tests/test_gather_keys_with_mon.py @@ -63,12 +63,12 @@ class mock_conn(object): class mock_distro(object): def __init__(self): self.conn = mock_conn() - + def mock_hosts_get_file_key_content(host, **kwargs): output = mock_distro() mon_keyring = '[mon.]\nkey = %s\ncaps mon = allow *\n' % new.generate_auth_key() - output.conn.remote_module.get_file_result = mon_keyring.encode('utf-8') + output.conn.remote_module.get_file_result = mon_keyring output.conn.remote_module.longhostname = host return output @@ -90,50 +90,50 @@ def mock_gatherkeys_missing_fail(args, distro, rlogger, path_keytype_mon, keytyp def mock_remoto_process_check_success(conn, args): out = json.dumps(remoto_process_check_success_output,sort_keys=True, indent=4) - return out.encode('utf-8').split(b'\n'), [], 0 + return out.split('\n'), [], 0 def mock_remoto_process_check_rc_error(conn, args): - return [b""], [b"this failed\n"], 1 + return [""], ["this failed\n"], 1 def mock_remoto_process_check_out_not_json(conn, args): - return [b"}bad output{"], [b""], 0 + return ["}bad output{"], [""], 0 def mock_remoto_process_check_out_missing_quorum(conn, args): outdata = copy.deepcopy(remoto_process_check_success_output) del outdata["quorum"] out = json.dumps(outdata,sort_keys=True, indent=4) - return out.encode('utf-8').split(b'\n'), [], 0 + return out.split('\n'), [], 0 def mock_remoto_process_check_out_missing_quorum_1(conn, args): outdata = copy.deepcopy(remoto_process_check_success_output) del outdata["quorum"][1] out = json.dumps(outdata,sort_keys=True, indent=4) - return out.encode('utf-8').split(b'\n'), [], 0 + return out.split('\n'), [], 0 def mock_remoto_process_check_out_missing_monmap(conn, args): outdata = copy.deepcopy(remoto_process_check_success_output) del outdata["monmap"] out = json.dumps(outdata,sort_keys=True, indent=4) - return out.encode('utf-8').split(b'\n'), [], 0 + return out.split('\n'), [], 0 def mock_remoto_process_check_out_missing_mons(conn, args): outdata = copy.deepcopy(remoto_process_check_success_output) del outdata["monmap"]["mons"] out = json.dumps(outdata,sort_keys=True, indent=4) - return out.encode('utf-8').split(b'\n'), [], 0 + return out.split('\n'), [], 0 def mock_remoto_process_check_out_missing_monmap_host1(conn, args): outdata = copy.deepcopy(remoto_process_check_success_output) del outdata["monmap"]["mons"][1] out = json.dumps(outdata,sort_keys=True, indent=4) - return out.encode('utf-8').split(b'\n'), [], 0 + return out.split('\n'), [], 0 class TestGatherKeysWithMon(object): diff --git a/ceph_deploy/tests/test_mon.py b/ceph_deploy/tests/test_mon.py index 585aa41..7e73cad 100644 --- a/ceph_deploy/tests/test_mon.py +++ b/ceph_deploy/tests/test_mon.py @@ -11,8 +11,10 @@ def make_fake_conf(): # and make it even more generic def make_fake_conn(receive_returns=None): - receive_returns = receive_returns or ([b'{}'], [], 0) + receive_returns = receive_returns or (['{}'], [], 0) conn = Mock() + conn.cmd = lambda x: x + conn.sudo = '' conn.return_value = conn conn.execute = conn conn.receive = Mock(return_value=receive_returns) -- 2.47.3