From dbb0c187f8024023d437474541e9b8e7f2c167e3 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Wed, 17 Apr 2024 15:44:30 -0400 Subject: [PATCH] pybind/mgr: add killpoint for sqlite3 database setup To catch unintentional autocommit by sqlite3. Signed-off-by: Patrick Donnelly (cherry picked from commit fdd0dde62bbc4d84c6d77247315a5cf8eabfa13c) --- src/pybind/mgr/mgr_module.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 15939a2628009..aa05ba9602bcd 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -18,6 +18,7 @@ import subprocess import threading from collections import defaultdict from enum import IntEnum, Enum +import os import rados import re import socket @@ -857,6 +858,8 @@ class MgrStandbyModule(ceph_module.BaseMgrStandbyModule, MgrModuleLoggingMixin): 'warning', ''])) cls.MODULE_OPTIONS.append( Option(name='log_to_file', type='bool', default=False, runtime=True)) + cls.MODULE_OPTIONS.append( + Option(name='sqlite3_killpoint', level=OptionLevel.DEV, type='int', default=0, runtime=True)) if not [x for x in cls.MODULE_OPTIONS if x['name'] == 'log_to_cluster']: cls.MODULE_OPTIONS.append( Option(name='log_to_cluster', type='bool', default=False, @@ -1062,6 +1065,8 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): 'warning', ''])) cls.MODULE_OPTIONS.append( Option(name='log_to_file', type='bool', default=False, runtime=True)) + cls.MODULE_OPTIONS.append( + Option(name='sqlite3_killpoint', level=OptionLevel.DEV, type='int', default=0, runtime=True)) if not [x for x in cls.MODULE_OPTIONS if x['name'] == 'log_to_cluster']: cls.MODULE_OPTIONS.append( Option(name='log_to_cluster', type='bool', default=False, @@ -1229,13 +1234,20 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): SELECT value FROM MgrModuleKV WHERE key = '__version'; """ + kv = self.get_module_option('sqlite3_killpoint') with db: self.create_skeleton_schema(db) + if kv == 1: + os._exit(120) cur = db.execute(SQL) row = cur.fetchone() self.maybe_upgrade(db, int(row['value'])) assert cur.fetchone() is None cur.close() + if kv == 2: + os._exit(120) + if kv == 3: + os._exit(120) def configure_db(self, db: sqlite3.Connection) -> None: db.execute('PRAGMA FOREIGN_KEYS = 1') -- 2.39.5