Skip to content

Commit

Permalink
mgr/cephadm: serve.py: put _write_client_files into it's own method
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
  • Loading branch information
sebastian-philipp committed Nov 29, 2021
1 parent fb2321e commit 018807e
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/pybind/mgr/cephadm/serve.py
Expand Up @@ -257,28 +257,7 @@ def refresh(host: str) -> None:
self.log.debug(f"autotuning memory for {host}")
self._autotune_host_memory(host)

# client files
updated_files = False
old_files = self.mgr.cache.get_host_client_files(host).copy()
for path, m in client_files.get(host, {}).items():
mode, uid, gid, content, digest = m
if path in old_files:
match = old_files[path] == (digest, mode, uid, gid)
del old_files[path]
if match:
continue
self.log.info(f'Updating {host}:{path}')
self.mgr.ssh.write_remote_file(host, path, content, mode, uid, gid)
self.mgr.cache.update_client_file(host, path, digest, mode, uid, gid)
updated_files = True
for path in old_files.keys():
self.log.info(f'Removing {host}:{path}')
cmd = ['rm', '-f', path]
self.mgr.ssh.check_execute_command(host, cmd)
updated_files = True
self.mgr.cache.removed_client_file(host, path)
if updated_files:
self.mgr.cache.save_host(host)
self._write_client_files(client_files, host)

refresh(self.mgr.cache.get_hosts())

Expand Down Expand Up @@ -1038,6 +1017,31 @@ def _calc_client_files(self) -> Dict[str, Dict[str, Tuple[int, int, int, bytes,
f'unable to calc client keyring {ks.entity} placement {ks.placement}: {e}')
return client_files

def _write_client_files(self,
client_files: Dict[str, Dict[str, Tuple[int, int, int, bytes, str]]],
host: str) -> None:
updated_files = False
old_files = self.mgr.cache.get_host_client_files(host).copy()
for path, m in client_files.get(host, {}).items():
mode, uid, gid, content, digest = m
if path in old_files:
match = old_files[path] == (digest, mode, uid, gid)
del old_files[path]
if match:
continue
self.log.info(f'Updating {host}:{path}')
self.mgr.ssh.write_remote_file(host, path, content, mode, uid, gid)
self.mgr.cache.update_client_file(host, path, digest, mode, uid, gid)
updated_files = True
for path in old_files.keys():
self.log.info(f'Removing {host}:{path}')
cmd = ['rm', '-f', path]
self.mgr.ssh.check_execute_command(host, cmd)
updated_files = True
self.mgr.cache.removed_client_file(host, path)
if updated_files:
self.mgr.cache.save_host(host)

async def _create_daemon(self,
daemon_spec: CephadmDaemonDeploySpec,
reconfig: bool = False,
Expand Down

0 comments on commit 018807e

Please sign in to comment.