From 93ad2993bdd4a6701badc729b3e52e93f6ca384a Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Sat, 4 Nov 2023 18:19:57 -0400 Subject: [PATCH] cephadm: add customize_container_binds method to custom container Add a customize_container_binds function to the CustomContainer daemon type class and use it from the common get_container_binds function. Signed-off-by: John Mulligan --- src/cephadm/cephadm.py | 13 +++++++++---- src/cephadm/tests/test_custom_container.py | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index d01619cb5aff2..7d6855778afae 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -1854,7 +1854,7 @@ class CustomContainer(ContainerDaemonForm): mounts[source] = destination return mounts - def get_container_binds(self, data_dir: str) -> List[List[str]]: + def _get_container_binds(self, data_dir: str) -> List[List[str]]: """ Get the bind mounts. Relative `source=...` paths will be located below `/var/lib/ceph//`. @@ -1882,6 +1882,12 @@ class CustomContainer(ContainerDaemonForm): data_dir, match.group(1))) return binds + def customize_container_binds( + self, ctx: CephadmContext, binds: List[List[str]] + ) -> None: + data_dir = self.identity.data_dir(ctx.data_dir) + binds.extend(self._get_container_binds(data_dir)) + # Cache the container so we don't need to rebuild it again when calling # into init_containers _container: Optional[CephContainer] = None @@ -2563,9 +2569,8 @@ def get_container_binds( nvmeof = CephNvmeof.create(ctx, ident) nvmeof.customize_container_binds(ctx, binds) elif ident.daemon_type == CustomContainer.daemon_type: - cc = CustomContainer.init(ctx, ident.fsid, ident.daemon_id) - data_dir = ident.data_dir(ctx.data_dir) - binds.extend(cc.get_container_binds(data_dir)) + cc = CustomContainer.create(ctx, ident) + cc.customize_container_binds(ctx, binds) return binds diff --git a/src/cephadm/tests/test_custom_container.py b/src/cephadm/tests/test_custom_container.py index c0f2a7966c44c..0c020732cc7d5 100644 --- a/src/cephadm/tests/test_custom_container.py +++ b/src/cephadm/tests/test_custom_container.py @@ -79,7 +79,10 @@ class TestCustomContainer(unittest.TestCase): }) def test_get_container_binds(self): - result = self.cc.get_container_binds('/xyz') + # TODO: get_container_binds was made private. test the private func for + # now. in the future update to test base class fune + # customize_container_binds + result = self.cc._get_container_binds('/xyz') self.assertEqual(result, [ [ 'type=bind', -- 2.39.5