]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: document ResourceEntry base class methods better
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 2 Jul 2025 17:10:26 +0000 (13:10 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 2 Jul 2025 17:10:26 +0000 (13:10 -0400)
Add docstrings to many previously undocumented methods.
Add a real exception instead of an assert when getting a real
resource object.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/internal.py

index 5846a4742df6e747a01179ca313bf98d160cccbd..36de2d51002ba76ddde4ef2c33ab6e327e8088ff 100644 (file)
@@ -53,20 +53,31 @@ class ResourceEntry:
 
     @property
     def uri(self) -> str:
+        """Return a unique URI for this store entry."""
         return self.config_entry.uri
 
     def get(self) -> SMBResource:
+        """Fetch a single smb resource object from the underlying store."""
         return one(resources.load(self.config_entry.get()))
 
     def get_resource_type(self, cls: Type[T]) -> T:
+        """Fetch an smb resource matching the supplied type from the
+        underlying store.
+        """
         obj = self.get()
-        assert isinstance(obj, cls), f"{obj!r} is not a {cls}"
+        if not isinstance(obj, cls):
+            raise TypeError(f"{obj!r} is not a {cls}")
         return obj
 
     def set(self, resource: Simplifiable) -> None:
+        """Given a serializable resource object, save it to the store."""
         self.config_entry.set(resource.to_simplified())
 
     def create_or_update(self, resource: Simplifiable) -> State:
+        """Given a serializable resource object, save it to the store,
+        returning a state value indicating if the object was created
+        or updated.
+        """
         try:
             previous = self.config_entry.get()
         except KeyError:
@@ -78,23 +89,33 @@ class ResourceEntry:
         return State.CREATED if previous is None else State.UPDATED
 
     def remove(self) -> bool:
+        """Remove an object from the underlying store."""
         return self.config_entry.remove()
 
     @classmethod
     def ids(
         cls, store: ConfigStoreListing
     ) -> Union[Collection[str], Collection[Tuple[str, str]]]:
+        """Return a collection of id values representing all entries
+        in a particular namespace within the store.
+        """
         raise NotImplementedError()
 
     @classmethod
     def from_store_by_key(
         cls, store: ConfigStore, key: Union[str, ResourceKey]
     ) -> Self:
+        """Return a new resource entry object bound to the given store
+        and identified by the given key.
+        """
         _key = str(key)
         return cls(_key, store[str(cls.namespace), _key])
 
     @classmethod
     def to_key(cls, resource: SMBResource) -> ResourceKey:
+        """Return a key object uniquely identifiying a resource within a
+        particular namespace.
+        """
         raise NotImplementedError()