summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Mulligan <jmulligan@redhat.com>2023-11-20 22:43:52 +0100
committerJohn Mulligan <jmulligan@redhat.com>2023-11-20 22:50:25 +0100
commit7d48e8aa259266dcdc06f11a4ad67a764108b6b1 (patch)
tree6cb2cad270fede6b90981ac0eb9fa610d20edd61
parentMerge pull request #54486 from pdvian/wip-app-release (diff)
downloadceph-7d48e8aa259266dcdc06f11a4ad67a764108b6b1.tar.xz
ceph-7d48e8aa259266dcdc06f11a4ad67a764108b6b1.zip
cephadm: add a custom template not found exception with diagnostic info
Add a new exception based on jinja2's template not found exception for the case where the template was not found in the zip(app). We've been having sporadic failures with this in CI & testing and hopefully the additional information will help pinpoint the cause. Signed-off-by: John Mulligan <jmulligan@redhat.com>
-rw-r--r--src/cephadm/cephadmlib/templating.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/cephadm/cephadmlib/templating.py b/src/cephadm/cephadmlib/templating.py
index e6e8d5e0ea2..ceef32ff9fe 100644
--- a/src/cephadm/cephadmlib/templating.py
+++ b/src/cephadm/cephadmlib/templating.py
@@ -29,6 +29,34 @@ class Templates(str, enum.Enum):
return repr(self.value)
+class TemplateNotFoundInZipApp(jinja2.TemplateNotFound):
+ def __init__(
+ self,
+ template: str,
+ *,
+ path: str = '',
+ relative_path: str = '',
+ archive_norm_path: str = '',
+ archive_path: str = ''
+ ) -> None:
+ super().__init__(template)
+ self.path = path
+ self.relative_path = relative_path
+ self.archive_norm_path = archive_norm_path
+ self.archive_path = archive_path
+
+ def __str__(self) -> str:
+ msg = self.message
+ msg2 = ''
+ if self.path or self.relative_path:
+ msg2 += f' path [{self.path!r}, rel={self.relative_path!r}] not found'
+ if self.archive_norm_path or self.archive_path:
+ msg2 += f' in [{self.archive_norm_path!r}, orig={self.archive_path!r}]'
+ if msg2:
+ msg2 = ':' + msg2
+ return f'{msg}{msg2}'
+
+
class _PackageLoader(jinja2.PackageLoader):
"""Workaround for PackageLoader when using cephadm with relative paths.
@@ -71,7 +99,14 @@ class _PackageLoader(jinja2.PackageLoader):
try:
source = cast(bytes, self._loader.get_data(arelpath))
except OSError as e:
- raise jinja2.TemplateNotFound(template) from e
+ not_found = TemplateNotFoundInZipApp(
+ template,
+ path=path,
+ relative_path=arelpath,
+ archive_norm_path=archive_path,
+ archive_path=self._loader.archive,
+ )
+ raise not_found from e
return source.decode(self.encoding), path, None