]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-15016] Fix Python 3 compatibility after merge of RM-15451
authorOleh Prypin <oleh@pryp.in>
Wed, 25 May 2016 15:52:09 +0000 (18:52 +0300)
committerOleh Prypin <oleh@pryp.in>
Thu, 9 Jun 2016 12:35:30 +0000 (15:35 +0300)
Signed-off-by: Oleh Prypin <oleh@pryp.in>
ceph_deploy/gatherkeys.py
ceph_deploy/new.py
ceph_deploy/tests/test_gather_keys.py
ceph_deploy/tests/test_gather_keys_missing.py
ceph_deploy/tests/test_gather_keys_with_mon.py
ceph_deploy/tests/test_keys_equivalent.py

index 2eb800ed74a480f8a1f1cc5c144037c719c82dfb..656e89c614eab22c1a25bace02618a9502ee673e 100644 (file)
@@ -23,7 +23,7 @@ def _keyring_equivalent(keyring_one, keyring_two):
         They may have some values in quotes, so a safe way to compare is to
         extract the key.
         """
-        with file(file_path, 'r') as f:
+        with open(file_path) as f:
             for line in f:
                 content = line.strip()
                 if len(content) == 0:
@@ -125,9 +125,9 @@ def gatherkeys_missing(args, distro, rlogger, keypath, keytype, dest_dir):
         return False
     keyring_name_local = keytype_path_to(args, keytype)
     keyring_path_local = os.path.join(dest_dir, keyring_name_local)
-    with file(keyring_path_local, 'w') as f:
+    with open(keyring_path_local, 'wb') as f:
         for line in out:
-            f.write(line + '\n')
+            f.write(line + b'\n')
     return True
 
 
@@ -145,7 +145,7 @@ def gatherkeys_with_mon(args, host, dest_dir):
         return False
     mon_name_local = keytype_path_to(args, "mon")
     mon_path_local = os.path.join(dest_dir, mon_name_local)
-    with file(mon_path_local, 'w') as f:
+    with open(mon_path_local, 'wb') as f:
         f.write(mon_key)
     rlogger = logging.getLogger(host)
     path_asok = ceph_deploy.util.paths.mon.asok(args.cluster, remote_hostname)
@@ -167,7 +167,7 @@ def gatherkeys_with_mon(args, host, dest_dir):
             rlogger.debug(line)
         return False
     try:
-        mon_status = json.loads("".join(out))
+        mon_status = json.loads(b''.join(out).decode('utf-8'))
     except ValueError:
         rlogger.error('"ceph mon_status %s" output was not json', host)
         for line in out:
index fa4e680b4ac9ba772b46e605cafce1ea9ff941db..842117bdbc310139ae2f42c4b01cb6af4d02a494 100644 (file)
@@ -27,7 +27,7 @@ def generate_auth_key():
         0,                 # le32 created: nanoseconds,
         len(key),          # le16: len(key)
     )
-    return base64.b64encode(header + key)
+    return base64.b64encode(header + key).decode('utf-8')
 
 
 def ssh_copy_keys(hostname, username=None):
index 8b2c6249eda4fa2d5a2b8a9edda88c1838062a28..917889bb67b5b31a01054bff42e5a4af99f1a13a 100644 (file)
@@ -8,13 +8,13 @@ import shutil
 
 
 def get_key_static(keytype, key_path):
-    with file(key_path, 'w') as f:
+    with open(key_path, 'w') as f:
         f.write("[%s]\n" % (gatherkeys.keytype_identity(keytype)))
         f.write("key=fred\n")
 
 
 def get_key_dynamic(keytype, key_path):
-    with open(key_path, 'w', 0600) as f:
+    with open(key_path, 'w', 0o600) as f:
         f.write("[%s]\n" % (gatherkeys.keytype_identity(keytype)))
         f.write("key='%s'" % (new.generate_auth_key()))
 
index 84f0af00967e30ac23fb542ccffa3ac95f5bc5a0..523d187fed317c89427cd530799617a5a750376b 100644 (file)
@@ -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.split('\n'), "", 0
+    return out.encode('utf-8').split(b'\n'), [], 0
 
 
 def mock_remoto_process_check_rc_error(conn, args):
-    return [""], ["this failed\n"], 1
+    return [b""], [b"this failed\n"], 1
 
 
 class TestGatherKeysMissing(object):
index 08141f9a707339cac5c4bc0537123e0ec33e62d9..805cc17e465f1a950f28db1d1c2f6a22ce0ee6a3 100644 (file)
@@ -68,7 +68,7 @@ class mock_distro(object):
 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
+    output.conn.remote_module.get_file_result = mon_keyring.encode('utf-8')
     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.split('\n'), "", 0
+    return out.encode('utf-8').split(b'\n'), [], 0
 
 
 def mock_remoto_process_check_rc_error(conn, args):
-    return [""], ["this failed\n"], 1
+    return [b""], [b"this failed\n"], 1
 
 
 def mock_remoto_process_check_out_not_json(conn, args):
-    return ["}bad output{"], [""], 0
+    return [b"}bad output{"], [b""], 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.split('\n'), "", 0
+    return out.encode('utf-8').split(b'\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.split('\n'), "", 0
+    return out.encode('utf-8').split(b'\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.split('\n'), "", 0
+    return out.encode('utf-8').split(b'\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.split('\n'), "", 0
+    return out.encode('utf-8').split(b'\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.split('\n'), "", 0
+    return out.encode('utf-8').split(b'\n'), [], 0
 
 
 class TestGatherKeysWithMon(object):
index 5e0d33fbd1f163b3128f499dc7cda5e464630e8f..c748baf5d68e392c92365ee5a97755f615372283 100644 (file)
@@ -7,25 +7,25 @@ import pytest
 
 def write_key_mon_with_caps(path, secret):
     mon_keyring = '[mon.]\nkey = %s\ncaps mon = allow *\n' % secret
-    with open(path, 'w', 0600) as f:
+    with open(path, 'w', 0o600) as f:
         f.write(mon_keyring)
 
 
 def write_key_mon_with_caps_with_tab(path, secret):
     mon_keyring = '[mon.]\n\tkey = %s\n\tcaps mon = allow *\n' % secret
-    with open(path, 'w', 0600) as f:
+    with open(path, 'w', 0o600) as f:
         f.write(mon_keyring)
 
 
 def write_key_mon_with_caps_with_tab_quote(path, secret):
     mon_keyring = '[mon.]\n\tkey = %s\n\tcaps mon = "allow *"\n' % secret
-    with open(path, 'w', 0600) as f:
+    with open(path, 'w', 0o600) as f:
         f.write(mon_keyring)
 
 
 def write_key_mon_without_caps(path, secret):
     mon_keyring = '[mon.]\nkey = %s\n' % secret
-    with open(path, 'w', 0600) as f:
+    with open(path, 'w', 0o600) as f:
         f.write(mon_keyring)