import ceph_module # noqa
-from typing import cast, Tuple, Any, Dict, Generic, Optional, Callable, List, \
- Mapping, NamedTuple, Sequence, Union, Set, TYPE_CHECKING
+from typing import (
+ Any,
+ Callable,
+ Dict,
+ Generic,
+ Iterator,
+ List,
+ Mapping,
+ NamedTuple,
+ Optional,
+ Sequence,
+ Set,
+ TYPE_CHECKING,
+ Tuple,
+ Union,
+ cast,
+)
if TYPE_CHECKING:
import sys
if sys.version_info >= (3, 8):
import subprocess
import threading
from collections import defaultdict
+from contextlib import contextmanager
from enum import IntEnum, Enum
import os
import rados
raise MgrDBNotReady()
return self._db
+ @contextmanager
+ def exclusive_db_access(self) -> Iterator[sqlite3.Connection]:
+ """Context manager that grants exclusive access to the manager module sqlite3
+ db connection, while establishing a new db transaction.
+ """
+ with self._db_lock, self.db:
+ yield self.db
+
+ @contextmanager
+ def exclusive_db_cursor(self) -> Iterator[sqlite3.Cursor]:
+ """Context manager that yields a db cursor after getting exclusive
+ access to the manager module sqlite3 connection and a new db
+ transaction.
+ """
+ with self.exclusive_db_access() as db:
+ yield db.cursor()
+
@property
def release_name(self) -> str:
"""