]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: use _write_remote_file for ceph.conf
authorSage Weil <sage@newdream.net>
Tue, 20 Apr 2021 22:19:00 +0000 (18:19 -0400)
committerSage Weil <sage@newdream.net>
Tue, 4 May 2021 16:22:12 +0000 (11:22 -0500)
Signed-off-by: Sage Weil <sage@newdream.net>
(cherry picked from commit 67718f53d189a9afa5fc48016df7c3acdbea5899)

src/pybind/mgr/cephadm/serve.py
src/pybind/mgr/cephadm/tests/test_cephadm.py

index cf722a8fc54dbbe5ab7329d3ba696d6b4413f24c..29589c26d0bec11e700cc496fd7f0f77d6e0898d 100644 (file)
@@ -386,22 +386,10 @@ class CephadmServe:
         config = self.mgr.get_minimal_ceph_conf()
 
         try:
-            with self._remote_connection(host) as tpl:
-                conn, connr = tpl
-                out, err, code = remoto.process.check(
-                    conn,
-                    ['mkdir', '-p', '/etc/ceph'])
-                if code:
-                    return f'failed to create /etc/ceph on {host}: {err}'
-                out, err, code = remoto.process.check(
-                    conn,
-                    ['dd', 'of=/etc/ceph/ceph.conf'],
-                    stdin=config.encode('utf-8')
-                )
-                if code:
-                    return f'failed to create /etc/ceph/ceph.conf on {host}: {err}'
-                self.mgr.cache.update_last_etc_ceph_ceph_conf(host)
-                self.mgr.cache.save_host(host)
+            self._write_remote_file(host, '/etc/ceph/ceph.conf',
+                                    config.encode('utf-8'), 0o644, 0, 0)
+            self.mgr.cache.update_last_etc_ceph_ceph_conf(host)
+            self.mgr.cache.save_host(host)
         except OrchestratorError as e:
             return f'failed to create /etc/ceph/ceph.conf on {host}: {str(e)}'
         return None
index eaba801a030e383a0c69c6723c722b34b852d8ad..ab37d9ead6349e2b81566b695af62db36eb63f44 100644 (file)
@@ -1,6 +1,5 @@
 import json
 from contextlib import contextmanager
-from unittest.mock import ANY
 
 import pytest
 
@@ -1059,9 +1058,11 @@ class TestCephadm(object):
 
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
     @mock.patch("remoto.process.check")
-    def test_etc_ceph(self, _check, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmServe._write_remote_file")
+    def test_etc_ceph(self, _write_file, _check, _get_connection, cephadm_module):
         _get_connection.return_value = mock.Mock(), mock.Mock()
         _check.return_value = '{}', '', 0
+        _write_file.return_value = None
 
         assert cephadm_module.manage_etc_ceph_ceph_conf is False
 
@@ -1074,15 +1075,16 @@ class TestCephadm(object):
             assert cephadm_module.manage_etc_ceph_ceph_conf is True
 
             CephadmServe(cephadm_module)._refresh_hosts_and_daemons()
-            _check.assert_called_with(ANY, ['dd', 'of=/etc/ceph/ceph.conf'], stdin=b'')
+            _write_file.assert_called_with('test', '/etc/ceph/ceph.conf', b'',
+                                           0o644, 0, 0)
 
             assert not cephadm_module.cache.host_needs_new_etc_ceph_ceph_conf('test')
 
             # set extra config and expect that we deploy another ceph.conf
             cephadm_module._set_extra_ceph_conf('[mon]\nk=v')
             CephadmServe(cephadm_module)._refresh_hosts_and_daemons()
-            _check.assert_called_with(
-                ANY, ['dd', 'of=/etc/ceph/ceph.conf'], stdin=b'\n\n[mon]\nk=v\n')
+            _write_file.assert_called_with('test', '/etc/ceph/ceph.conf',
+                                           b'\n\n[mon]\nk=v\n', 0o644, 0, 0)
 
             # reload
             cephadm_module.cache.last_etc_ceph_ceph_conf = {}