def _init_db(self): def connect_db(): conn = sqlite.connect(self.db_file, 5.0) conn.row_factory = sqlite.Row conn.text_factory = sqlite.OptimizedUnicode return conn if not os.path.exists(self.db_file) or not os.stat( self.db_file).st_size: LOG.debug('Creating SQLite database') conn = connect_db() try: with open(os.path.join(self.share_path, 'db.sql')) as fp: conn.executescript(fp.read()) conn.commit() finally: conn.close() # Configure database connection pool LOG.debug('Initializing database connection') t = sqlite_server.SQLiteServerThread(connect_db) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) bus.db = t.connection
def _init_db(file=None): logger = logging.getLogger(__name__) cnf = bus.cnf # Check that database exists (after rebundle for example) db_file = file or cnf.private_path(DB_NAME) if not os.path.exists(db_file) or not os.stat(db_file).st_size: logger.debug("Database doesn't exist, creating new one from script") _create_db(file) # XXX(marat) Added here cause postinst script sometimes failed and we get # OperationalError: table p2pmessage has no column named format conn = _db_connect() cur = conn.cursor() cur.execute('pragma table_info(p2p_message)') if not any(filter(lambda row: row[1] == 'format', cur.fetchall())): cur.execute( "alter table p2p_message add column format TEXT default 'xml'") conn.commit() cur.close() conn.close() # Configure database connection pool t = sqlite_server.SQLiteServerThread(_db_connect) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) bus.db = t.connection
def _init_db(file=None): logger = logging.getLogger(__name__) cnf = bus.cnf # Check that database exists (after rebundle for example) db_file = file or cnf.private_path(DB_NAME) if not os.path.exists(db_file) or not os.stat(db_file).st_size: logger.debug("Database doesn't exist, creating new one from script") _create_db(file) # XXX(marat) Added here cause postinst script sometimes failed and we get # OperationalError: table p2pmessage has no column named format conn = _db_connect() cur = conn.cursor() cur.execute('pragma table_info(p2p_message)') if not any(filter(lambda row: row[1] == 'format', cur.fetchall())): cur.execute("alter table p2p_message add column format TEXT default 'xml'") conn.commit() cur.close() conn.close() # Configure database connection pool t = sqlite_server.SQLiteServerThread(_db_connect) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) bus.db = t.connection
def setup(): global CONN, SQLITE3, SERVER_THREAD SQLITE3 = which('sqlite3') def creator(): return sqlite3.Connection(database=DATABASE) t = sqlite_server.SQLiteServerThread(creator) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) CONN = t.connection
def setup(): global CONN, SQLITE3, SERVER_THREAD SQLITE3 = which('sqlite3') def creator(): return sqlite3.Connection(database=DATABASE) t = sqlite_server.SQLiteServerThread(creator) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) CONN = t.connection
def setUp(): remove_db() create_db() t = sqlite_server.SQLiteServerThread(connect_db) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) bollard.bus.db = t.connection bollard.__node__ = mock.MagicMock() bollard.__node__['platform'].get_access_data = mock.MagicMock(return_value=None) bollard.bus.cnf = mock.MagicMock() key = 'YWZsZztzamRmZ2RscztmZ2pkc2w7ZmpnbDtkamd3O2xlanJnbDtzZGpncnR3ZXI2NDdlZ3NkNGdq\n' bollard.bus.cnf.read_key.return_value = key
def _init_db(file=None): logger = logging.getLogger(__name__) cnf = bus.cnf # Check that database exists (after rebundle for example) db_file = file or cnf.private_path(DB_NAME) if not os.path.exists(db_file) or not os.stat(db_file).st_size: logger.debug("Database doesn't exist, creating new one from script") _create_db(file) # Configure database connection pool t = sqlite_server.SQLiteServerThread(_db_connect) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) bus.db = t.connection
def _init_db(self): def connect_db(): conn = sqlite.connect(self.db_file, 5.0) conn.row_factory = sqlite.Row conn.text_factory = sqlite.OptimizedUnicode return conn if not os.path.exists(self.db_file) or not os.stat(self.db_file).st_size: LOG.debug("Creating SQLite database") conn = connect_db() try: with open(os.path.join(self.share_path, "db.sql")) as fp: conn.executescript(fp.read()) conn.commit() finally: conn.close() # Configure database connection pool LOG.debug("Initializing database connection") t = sqlite_server.SQLiteServerThread(connect_db) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) bus.db = t.connection
def start_sqlite_server(): t = sqlite_server.SQLiteServerThread(connect_db) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) bollard.bus.db = t.connection
except sqlite.OperationalError, e: if 'database schema has changed' not in str(e): # This caused by UpdateClient paralled startup. # # By initial plan, Scalarizr should be started by UpdateClient, # but old Ubuntu 10.04 roles don't have UpdateClient. # Whereas it's installed during migration, but scalr-upd-client init script added to rc2.d # in run time never executed and migration to latest Scalarizr fails. raise # Configure database connection pool t = sqlite_server.SQLiteServerThread(_db_connect) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) bus.db = t.connection def _create_db(db_file=None, script_file=None): logger = logging.getLogger(__name__) #conn = bus.db #logger.debug('conn: %s', conn) conn = _db_connect() conn.executescript( open(script_file or os.path.join(bus.share_path, DB_SCRIPT)).read()) conn.commit() conn.close() #conn.commit() if linux.os['family'] != 'Windows':
except sqlite.OperationalError, e: if 'database schema has changed' not in str(e): # This caused by UpdateClient paralled startup. # # By initial plan, Scalarizr should be started by UpdateClient, # but old Ubuntu 10.04 roles don't have UpdateClient. # Whereas it's installed during migration, but scalr-upd-client init script added to rc2.d # in run time never executed and migration to latest Scalarizr fails. raise # Configure database connection pool t = sqlite_server.SQLiteServerThread(_db_connect) t.setDaemon(True) t.start() sqlite_server.wait_for_server_thread(t) bus.db = t.connection def _create_db(db_file=None, script_file=None): logger = logging.getLogger(__name__) #conn = bus.db #logger.debug('conn: %s', conn) conn = _db_connect() conn.executescript(open(script_file or os.path.join(bus.share_path, DB_SCRIPT)).read()) conn.commit() conn.close() #conn.commit() if linux.os['family'] != 'Windows':