]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add a utilty method for type checking DaemonSubIdentity types
authorJohn Mulligan <jmulligan@redhat.com>
Sun, 1 Oct 2023 16:49:59 +0000 (12:49 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 2 Jan 2024 14:30:20 +0000 (09:30 -0500)
Add a `must` method that ensures a DaemonIdentity is a DaemonSubIdentity
in a single call.

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

index 4d83ec8f9bfa16872a4ca2a293f91ad39391f8a5..aa47f2815d4959c93791190eefa01ad23a8a244c 100644 (file)
@@ -5,7 +5,7 @@ import os
 import pathlib
 import re
 
-from typing import Union
+from typing import Union, Optional
 
 from .context import CephadmContext
 
@@ -169,3 +169,12 @@ class DaemonSubIdentity(DaemonIdentity):
             parent.daemon_id,
             subcomponent,
         )
+
+    @classmethod
+    def must(cls, value: Optional[DaemonIdentity]) -> 'DaemonSubIdentity':
+        """Helper to assert value is of the correct type.  Mostly to make mypy
+        happy.
+        """
+        if not isinstance(value, cls):
+            raise TypeError(f'{value!r} is not a {cls}')
+        return value