]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: switch to using template files
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 1 Nov 2023 21:58:19 +0000 (17:58 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Fri, 3 Nov 2023 22:51:49 +0000 (18:51 -0400)
Switch off of the embedded template strings to using the recently
added template files.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py
src/cephadm/cephadmlib/templating.py

index 8f189becaa125c7e99f69103c9eb415b7378d597..8b44e1c8f543ba72308a350658386f278f5ea0b4 100755 (executable)
@@ -3387,61 +3387,15 @@ def install_base_units(ctx, fsid):
 """ % (fsid, ' '.join(targets), '|'.join(targets)))
 
 
-_TMPL_DAEMON_UNIT = """# generated by cephadm
-[Unit]
-Description=Ceph %i for {{fsid}}
-
-# According to:
-#   http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget
-# these can be removed once ceph-mon will dynamically change network
-# configuration.
-After=network-online.target local-fs.target time-sync.target{% if has_docker_engine %} docker.service{% endif %}
-Wants=network-online.target local-fs.target time-sync.target
-{%- if has_docker_engine %}
-Requires=docker.service
-{%- endif %}
-
-PartOf=ceph-{{fsid}}.target
-Before=ceph-{{fsid}}.target
-
-[Service]
-LimitNOFILE=1048576
-LimitNPROC=1048576
-EnvironmentFile=-/etc/environment
-ExecStart=/bin/bash {{ctx.data_dir}}/{{fsid}}/%i/unit.run
-ExecStop=-/bin/bash -c 'bash {{ctx.data_dir}}/{{fsid}}/%i/unit.stop'
-ExecStopPost=-/bin/bash {{ctx.data_dir}}/{{fsid}}/%i/unit.poststop
-KillMode=none
-Restart=on-failure
-RestartSec=10s
-TimeoutStartSec=200
-TimeoutStopSec=120
-StartLimitInterval=30min
-StartLimitBurst=5
-{%- if has_podman_engine %}
-ExecStartPre=-/bin/rm -f %t/%n-pid %t/%n-cid
-ExecStopPost=-/bin/rm -f %t/%n-pid %t/%n-cid
-Type=forking
-PIDFile=%t/%n-pid
-{%- if has_podman_split_version %}
-Delegate=yes
-{%- endif %}
-{%- endif %}
-
-[Install]
-WantedBy=ceph-{{fsid}}.target
-"""
-
-
 def get_unit_file(ctx: CephadmContext, fsid: str) -> str:
     has_docker_engine = isinstance(ctx.container_engine, Docker)
     has_podman_engine = isinstance(ctx.container_engine, Podman)
     has_podman_split_version = (
         has_podman_engine and ctx.container_engine.supports_split_cgroups
     )
-    return templating.template_str(
+    return templating.render(
         ctx,
-        _TMPL_DAEMON_UNIT,
+        templating.Templates.ceph_service,
         fsid=fsid,
         has_docker_engine=has_docker_engine,
         has_podman_engine=has_podman_engine,
@@ -3619,23 +3573,9 @@ class CephadmAgent(DaemonForm):
         return ('set -e\n' + f'{py3} {binary_path} agent --fsid {self.fsid} --daemon-id {self.daemon_id} &\n')
 
     def unit_file(self) -> str:
-        ts = """#generated by cephadm
-[Unit]
-Description=cephadm agent for cluster {{agent.fsid}}
-
-PartOf=ceph-{{agent.fsid}}.target
-Before=ceph-{{agent.fsid}}.target
-
-[Service]
-Type=forking
-ExecStart=/bin/bash {{agent.daemon_dir}}/unit.run
-Restart=on-failure
-RestartSec=10s
-
-[Install]
-WantedBy=ceph-{{agent.fsid}}.target
-"""
-        return templating.template_str(self.ctx, ts, agent=self)
+        return templating.render(
+            self.ctx, templating.Templates.agent_service, agent=self
+        )
 
     def shutdown(self) -> None:
         self.stop = True
index b48b5deeaab682c4b136d8f843729d7bf2b03e53..3b7c6f9657e0911f4f67eda0df65218712b426e2 100644 (file)
@@ -65,9 +65,6 @@ class Templater:
 # be used to provide a simple set of methods
 defaultTemplater = Templater()
 
-# (temporary alias) template_str is currently used by the cephadm code
-template_str = defaultTemplater.render_str
-
 # alias methods as module level functions for convenience. most callers do
 # not need to care that these are implemented via a class
 render_str = defaultTemplater.render_str