From: Adam King Date: Fri, 26 Jan 2024 16:09:10 +0000 (-0500) Subject: cephadm: rewrite NodeProxy class for reef X-Git-Tag: testing/wip-pdonnell-testing-20240430.123648-reef-debug~291^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=f518138e464a4c9c2334f7f9c5aeb7a4deb7ff79;p=ceph-ci.git cephadm: rewrite NodeProxy class for reef Since we don't have some refactoring work in reef that we have in main that allowed writing these daemon classes in a more standard way Signed-off-by: Adam King --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index e882428ccb5..1c32845d47f 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -700,8 +700,7 @@ class Monitoring(object): ################################## -@register_daemon_form -class NodeProxy(ContainerDaemonForm): +class NodeProxy(object): """Defines a node-proxy container""" daemon_type = 'node-proxy' @@ -713,18 +712,17 @@ class NodeProxy(ContainerDaemonForm): def for_daemon_type(cls, daemon_type: str) -> bool: return cls.daemon_type == daemon_type - def __init__( - self, - ctx: CephadmContext, - ident: DaemonIdentity, - config_json: Dict, - image: str = DEFAULT_IMAGE, - ): + def __init__(self, + ctx: CephadmContext, + fsid: str, + daemon_id: Union[str, int], + config_json: Dict[Any, Any], + image: str = DEFAULT_IMAGE) -> None: self.ctx = ctx - self._identity = ident + self.fsid = fsid + self.daemon_id = daemon_id self.image = image - # config-json options config = dict_get(config_json, 'node-proxy.json', {}) self.files = {'node-proxy.json': config} @@ -732,45 +730,23 @@ class NodeProxy(ContainerDaemonForm): self.validate() @classmethod - def init( - cls, ctx: CephadmContext, fsid: str, daemon_id: str - ) -> 'NodeProxy': - return cls.create( - ctx, DaemonIdentity(fsid, cls.daemon_type, daemon_id) - ) - - @classmethod - def create( - cls, ctx: CephadmContext, ident: DaemonIdentity - ) -> 'NodeProxy': - return cls(ctx, ident, fetch_configs(ctx), ctx.image) - - @property - def identity(self) -> DaemonIdentity: - return self._identity + def init(cls, ctx: CephadmContext, fsid: str, daemon_id: Union[int, str]) -> 'NodeProxy': + return cls(ctx, fsid, daemon_id, + fetch_configs(ctx), ctx.image) - @property - def fsid(self) -> str: - return self._identity.fsid + @staticmethod + def get_container_mounts(data_dir, log_dir): + # type: (str, str) -> Dict[str, str] + mounts = dict() + mounts[os.path.join(data_dir, 'node-proxy.json')] = '/usr/share/ceph/node-proxy.json:z' + return mounts - @property - def daemon_id(self) -> str: - return self._identity.daemon_id - - def customize_container_mounts( - self, ctx: CephadmContext, mounts: Dict[str, str] - ) -> None: - data_dir = self.identity.data_dir(ctx.data_dir) - # TODO: update this when we have the actual location - # in the ceph container we are going to keep node-proxy - mounts.update({os.path.join(data_dir, 'node-proxy.json'): '/usr/share/ceph/node-proxy.json:z'}) - - def customize_process_args(self, ctx: CephadmContext, args: List[str]) -> None: + def get_daemon_args(self) -> List[str]: # TODO: this corresponds with the mount location of # the config in _get_container_mounts above. They # will both need to be updated when we have a proper # location in the container for node-proxy - args.extend(['/usr/share/ceph/ceph_node_proxy/main.py', '--config', '/usr/share/ceph/node-proxy.json']) + return ['/usr/share/ceph/ceph_node_proxy/main.py', '--config', '/usr/share/ceph/node-proxy.json'] def validate(self): # type: () -> None @@ -809,12 +785,6 @@ class NodeProxy(ContainerDaemonForm): # populate files from the config-json populate_files(data_dir, self.files, uid, gid) - def container(self, ctx: CephadmContext) -> CephContainer: - # So the container can modprobe iscsi_target_mod and have write perms - # to configfs we need to make this a privileged container. - ctr = daemon_to_container(ctx, self, privileged=True, envs=['PYTHONPATH=$PYTHONPATH:/usr/share/ceph']) - return to_deployment_container(ctx, ctr) - def config_and_keyring( self, ctx: CephadmContext ) -> Tuple[Optional[str], Optional[str]]: @@ -823,9 +793,6 @@ class NodeProxy(ContainerDaemonForm): def uid_gid(self, ctx: CephadmContext) -> Tuple[int, int]: return extract_uid_gid(ctx) - def default_entrypoint(self) -> str: - return self.entrypoint - @contextmanager def write_new( @@ -3216,6 +3183,9 @@ def get_daemon_args(ctx, fsid, daemon_type, daemon_id): elif daemon_type == SNMPGateway.daemon_type: sc = SNMPGateway.init(ctx, fsid, daemon_id) r.extend(sc.get_daemon_args()) + elif daemon_type == NodeProxy.daemon_type: + node_proxy = NodeProxy.init(ctx, fsid, daemon_id) + r.extend(node_proxy.get_daemon_args()) return r @@ -3663,6 +3633,12 @@ def get_container_mounts(ctx, fsid, daemon_type, daemon_id, data_dir = get_data_dir(fsid, ctx.data_dir, daemon_type, daemon_id) mounts.update(cc.get_container_mounts(data_dir)) + if daemon_type == NodeProxy.daemon_type: + assert daemon_id + data_dir = get_data_dir(fsid, ctx.data_dir, daemon_type, daemon_id) + log_dir = get_log_dir(fsid, ctx.log_dir) + mounts.update(NodeProxy.get_container_mounts(data_dir, log_dir)) + # Modifications podman makes to /etc/hosts causes issues with # certain daemons (specifically referencing "host.containers.internal" entry # being added to /etc/hosts in this case). To avoid that, but still @@ -3793,6 +3769,9 @@ def get_container(ctx: CephadmContext, host_network = False envs.extend(cc.get_container_envs()) container_args.extend(cc.get_container_args()) + elif daemon_type == NodeProxy.daemon_type: + entrypoint = NodeProxy.entrypoint + name = '%s.%s' % (daemon_type, daemon_id) if daemon_type in Monitoring.components: uid, gid = extract_uid_gid_monitoring(ctx, daemon_type) @@ -6929,6 +6908,15 @@ def _dispatch_deploy( deployment_type=deployment_type, endpoints=daemon_endpoints) + elif daemon_type == NodeProxy.daemon_type: + config, keyring = get_config_and_keyring(ctx) + uid, gid = extract_uid_gid(ctx) + c = get_deployment_container(ctx, ctx.fsid, daemon_type, daemon_id) + deploy_daemon(ctx, ctx.fsid, daemon_type, daemon_id, c, uid, gid, + config=config, keyring=keyring, + deployment_type=deployment_type, + endpoints=daemon_endpoints) + elif daemon_type == CephadmAgent.daemon_type: # get current user gid and uid uid = os.getuid() diff --git a/src/cephadm/tests/test_agent.py b/src/cephadm/tests/test_agent.py index c90d0385f3d..182c1f661cf 100644 --- a/src/cephadm/tests/test_agent.py +++ b/src/cephadm/tests/test_agent.py @@ -412,7 +412,7 @@ def test_agent_get_ls(_ls_subset, _ls, cephadm_fs): @mock.patch("threading.Event.clear") @mock.patch("threading.Event.wait") @mock.patch("urllib.request.Request.__init__") -@mock.patch("cephadmlib.agent.urlopen") +@mock.patch("cephadm.urlopen") @mock.patch("cephadm.list_networks") @mock.patch("cephadm.HostFacts.dump") @mock.patch("cephadm.HostFacts.__init__", lambda _, __: None)