def initialize(): global _db _db = database_connection.DatabaseConnection('AUTOTEST_WEB') _db.connect(db_type='django') notify_statuses_list = global_config.global_config.get_config_value( scheduler_config.CONFIG_SECTION, "notify_email_statuses", default='') global _notify_email_statuses _notify_email_statuses = [ status for status in re.split(r'[\s,;:]', notify_statuses_list.lower()) if status ] # AUTOTEST_WEB.base_url is still a supported config option as some people # may wish to override the entire url. global _base_url config_base_url = global_config.global_config.get_config_value( scheduler_config.CONFIG_SECTION, 'base_url', default='') if config_base_url: _base_url = config_base_url else: # For the common case of everything running on a single server you # can just set the hostname in a single place in the config file. server_name = global_config.global_config.get_config_value( 'SERVER', 'hostname') if not server_name: logging.critical('[SERVER] hostname missing from the config file.') sys.exit(1) _base_url = 'http://%s/afe/' % server_name initialize_globals()
def open_connection(cls): """Open a new database connection. @return: An instance of the newly opened connection. """ db = database_connection.DatabaseConnection(DB_CONFIG_SECTION) db.connect(db_type='django') return db
def get_migration_manager(db_name, debug, force): """Creates a MigrationManager object. @param db_name: The database name. @param debug: Whether to print debug messages. @param force: Whether to force migration without asking for confirmation. @return A created MigrationManager object. """ database = database_connection.DatabaseConnection(db_name) database.debug = debug database.reconnect_enabled = False database.connect() return MigrationManager(database, force=force)
def _get_database_connection(self, config_section=_CONFIG_SECTION): if config_section == _CONFIG_SECTION: self._override_config() db = database_connection.DatabaseConnection(config_section) self._fake_backend = self.god.create_mock_class( database_connection._GenericBackend, 'fake_backend') for exception in database_connection._DB_EXCEPTIONS: setattr(self._fake_backend, exception, FakeDatabaseError) self._fake_backend.rowcount = 0 def get_fake_backend(db_type): self._db_type = db_type return self._fake_backend self.god.stub_with(db, '_get_backend', get_fake_backend) db.reconnect_delay_sec = _RECONNECT_DELAY return db
def run(self): """Connects to SQL DB and calculates DUT usage given args.""" # Force the database connection to use the read the readonly options. database_connection._GLOBAL_CONFIG_NAMES.update({ 'username': '******', 'password': '******', }) self._database_connection = database_connection.DatabaseConnection( global_config_section='AUTOTEST_WEB') self._database_connection.connect() durations = self.find_all_durations() if not durations: print 'Query returned no results.' else: self.calculate_usage(durations) self._database_connection.disconnect()
def get_migration_manager(db_name, debug, force): database = database_connection.DatabaseConnection(db_name) database.debug = debug database.reconnect_enabled = False database.connect() return MigrationManager(database, force=force)