]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: write config files as utf-8 41463/head
authorSage Weil <sage@newdream.net>
Tue, 18 May 2021 12:23:36 +0000 (08:23 -0400)
committerSage Weil <sage@newdream.net>
Thu, 20 May 2021 23:17:58 +0000 (18:17 -0500)
If we don't specify the encoding, python may use something like 'latin-1',
which cannot handle unicode characters.

Signed-off-by: Sage Weil <sage@newdream.net>
(cherry picked from commit fa2cf2987cccea9f152c04862fc684e146c4692e)

src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 9766256d34700a37da31960fab5c9828f08feb5c..b025fe9867586b14ed73cc78eee560fe58458d2c 100755 (executable)
@@ -363,7 +363,7 @@ def populate_files(config_dir, config_files, uid, gid):
         config_file = os.path.join(config_dir, fname)
         config_content = dict_get_join(config_files, fname)
         logger.info('Write file: %s' % (config_file))
-        with open(config_file, 'w') as f:
+        with open(config_file, 'w', encoding='utf-8') as f:
             os.fchown(f.fileno(), uid, gid)
             os.fchmod(f.fileno(), 0o600)
             f.write(config_content)
@@ -2219,7 +2219,7 @@ def create_daemon_dirs(ctx, fsid, daemon_type, daemon_id, uid, gid,
                     fpath = os.path.join(data_dir_root, fname.lstrip(os.path.sep))
                 else:
                     fpath = os.path.join(data_dir_root, config_dir, fname)
-                with open(fpath, 'w') as f:
+                with open(fpath, 'w', encoding='utf-8') as f:
                     os.fchown(f.fileno(), uid, gid)
                     os.fchmod(f.fileno(), 0o600)
                     f.write(content)
index 75e8936049bf7502ef30469a7c33fc119bab001e..ae857955cabdd510b8b815477988b3ca9cf4998c 100644 (file)
@@ -1004,8 +1004,10 @@ class TestMonitoring(object):
             daemon_id=daemon_id
         )
         assert _open.call_args_list == [
-            call('{}/etc/prometheus/prometheus.yml'.format(prefix), 'w'),
-            call('{}/etc/prometheus/alerting/ceph_alerts.yml'.format(prefix), 'w'),
+            call('{}/etc/prometheus/prometheus.yml'.format(prefix), 'w',
+                 encoding='utf-8'),
+            call('{}/etc/prometheus/alerting/ceph_alerts.yml'.format(prefix), 'w',
+                 encoding='utf-8'),
         ]
         assert call().__enter__().write('foo') in _open.mock_calls
         assert call().__enter__().write('bar') in _open.mock_calls