]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add a custom template not found exception with diagnostic info 54582/head
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 20 Nov 2023 21:43:52 +0000 (16:43 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Mon, 20 Nov 2023 21:50:25 +0000 (16:50 -0500)
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>
src/cephadm/cephadmlib/templating.py

index e6e8d5e0ea2c2a82863107c2a39b1ebe45489e2f..ceef32ff9fedd64a9266be8537e7d45ec61b43dc 100644 (file)
@@ -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