def test_set_defaults(self): conf = cfg.ConfigOpts() options.set_defaults(conf, connection='sqlite:///:memory:') self.assertTrue(len(conf.database.items()) > 1) self.assertEqual('sqlite:///:memory:', conf.database.connection)
def _setup_database(self): sql_connection = 'sqlite:////%s/tests.sqlite' % self.test_dir options.set_defaults(CONF, connection=sql_connection, sqlite_db='glance.sqlite') glance.db.sqlalchemy.api.clear_db_env() glance_db_env = 'GLANCE_DB_TEST_SQLITE_FILE' if glance_db_env in os.environ: # use the empty db created and cached as a tempfile # instead of spending the time creating a new one db_location = os.environ[glance_db_env] test_utils.execute('cp %s %s/tests.sqlite' % (db_location, self.test_dir)) else: migration.db_sync() # copy the clean db to a temp location so that it # can be reused for future tests (osf, db_location) = tempfile.mkstemp() os.close(osf) test_utils.execute('cp %s/tests.sqlite %s' % (self.test_dir, db_location)) os.environ[glance_db_env] = db_location # cleanup the temp file when the test suite is # complete def _delete_cached_db(): try: os.remove(os.environ[glance_db_env]) except Exception: glance_tests.logger.exception( "Error cleaning up the file %s" % os.environ[glance_db_env]) atexit.register(_delete_cached_db)
def setUp(self): super(IsolatedUnitTest, self).setUp() self.test_dir = self.useFixture(fixtures.TempDir()).path policy_file = self._copy_data_file('policy.json', self.test_dir) options.set_defaults(CONF, connection='sqlite://', sqlite_db='glance.sqlite') self.config(verbose=False, debug=False, policy_file=policy_file, lock_path=os.path.join(self.test_dir)) self.config(default_store='filesystem', filesystem_store_datadir=os.path.join(self.test_dir), group="glance_store") store.create_stores() stubs.stub_out_registry_and_store_server(self.stubs, self.test_dir, registry=self.registry) # clear context left-over from any previous test executions if hasattr(local.store, 'context'): delattr(local.store, 'context')
def test_set_defaults(self): conf = cfg.ConfigOpts() options.set_defaults(conf, connection="sqlite:///:memory:") self.assertTrue(len(conf.database.items()) > 1) self.assertEqual("sqlite:///:memory:", conf.database.connection)
def initialize(): """Initialize the module.""" db_options.set_defaults( CONF, connection="sqlite:///keystone.db", sqlite_db="keystone.db")
def parse_args(argv, default_config_files=None): db_options.set_defaults(cfg.CONF, sqlite_db='tuskar.sqlite') cfg.CONF(argv[1:], project='tuskar', version=version.version_info.release_string(), default_config_files=default_config_files)
def initialize_sql_session(): # Make sure the DB is located in the correct location, in this case set # the default value, as this should be able to be overridden in some # test cases. db_options.set_defaults( CONF, connection=tests.IN_MEM_DB_CONN_STRING)
def parse_args(argv,default_config_files=None): options.set_defaults(CONF,connection=_DEFAULT_SQL_CONNECTION, sqlite_db='ev.sqlite') CONF(argv[1:], project='ev', version=version.version_string(), default_config_files=default_config_files)
def parse_args(argv, default_config_files=None): options.set_defaults(CONF, connection=_DEFAULT_SQL_CONNECTION, sqlite_db='nova.sqlite') rpc.set_defaults(control_exchange='nova') debugger.register_cli_opts() CONF(argv[1:], project='nova', version=version.version_string(), default_config_files=default_config_files) rpc.init(CONF)
def main(): command_opt = cfg.SubCommandOpt('command', title='Command', help='Available commands', handler=add_command_parsers) CONF.register_cli_opt(command_opt) # set_defaults() is called to register the db options. options.set_defaults(CONF) CONF(project='solum') CONF.command.func(get_manager())
def setUp(self): super(IsolatedUnitTest, self).setUp() self.test_dir = self.useFixture(fixtures.TempDir()).path policy_file = self._copy_data_file('policy.json', self.test_dir) options.set_defaults(CONF, connection='sqlite://', sqlite_db='glance.sqlite') self.config(verbose=False, debug=False, default_store='filesystem', filesystem_store_datadir=os.path.join(self.test_dir), policy_file=policy_file, lock_path=os.path.join(self.test_dir)) stubs.stub_out_registry_and_store_server(self.stubs, self.test_dir, registry=self.registry)
def setUp(self): super(IsolatedUnitTest, self).setUp() options.set_defaults(CONF, connection='sqlite://', sqlite_db='glance.sqlite') lockutils.set_defaults(os.path.join(self.test_dir)) self.config(verbose=False, debug=False) self.config(default_store='filesystem', filesystem_store_datadir=os.path.join(self.test_dir), group="glance_store") store.create_stores() stubs.stub_out_registry_and_store_server(self.stubs, self.test_dir, registry=self.registry) # clear context left-over from any previous test executions if hasattr(local.store, 'context'): delattr(local.store, 'context')
:connection: string specifying the sqlalchemy connection to use, like: `sqlite:///var/lib/cinder/cinder.sqlite`. :enable_new_services: when adding a new service to the database, is it in the pool of available hardware (Default: True) """ from oslo.config import cfg from oslo.db import api as db_api from oslo.db import options as db_options CONF = cfg.CONF db_options.set_defaults(CONF, connection="sqlite:////tmp/rally.sqlite", sqlite_db="rally.sqlite") _BACKEND_MAPPING = {'sqlalchemy': 'rally.db.sqlalchemy.api'} IMPL = db_api.DBAPI.from_config(CONF, backend_mapping=_BACKEND_MAPPING) def db_cleanup(): """Recreate engine.""" IMPL.db_cleanup() def db_create(): """Initialize DB. This method will drop existing database.""" IMPL.db_create()
def get_db(config): options.set_defaults(CONF, connection='sqlite://') config(data_api='glance.db.registry.api') return glance.db.get_api()
from oslo.db.sqlalchemy import session from oslo.db import options as db_options from oslo.config import cfg _FACADE = None db_options.set_defaults( cfg.CONF, connection='sqlite:///$state_path/rumster.db') def _create_facade_lazily(): global _FACADE if _FACADE is None: _FACADE = session.EngineFacade.from_config(cfg.CONF, sqlite_fk=True) return _FACADE def get_engine(): """Helper method to grab engine.""" facade = _create_facade_lazily() return facade.get_engine() def get_session(autocommit=True, expire_on_commit=False): """Helper method to grab session.""" facade = _create_facade_lazily() return facade.get_session(autocommit=autocommit, expire_on_commit=expire_on_commit)
def configure(self): options.cfg.set_defaults(options.database_opts, sqlite_synchronous=False) options.set_defaults(cfg.CONF, connection='sqlite:///%s' % self.db_file, sqlite_db=self.db_file)
def setup_dummy_db(): options.cfg.set_defaults(options.database_opts, sqlite_synchronous=False) options.set_defaults(cfg.CONF, connection="sqlite://", sqlite_db='heat.db') engine = get_engine() models.BASE.metadata.create_all(engine) engine.connect()
def __init__(self): options.set_defaults(CONF)
:sql_connection: string specifying the sqlalchemy connection to use, like: `sqlite:///var/lib/sahara/sahara.sqlite`. """ from oslo.config import cfg from oslo.db import api as db_api from oslo.db import options from sahara.openstack.common import log as logging CONF = cfg.CONF options.set_defaults(CONF) _BACKEND_MAPPING = { 'sqlalchemy': 'sahara.db.sqlalchemy.api', } IMPL = db_api.DBAPI.from_config(CONF, backend_mapping=_BACKEND_MAPPING) LOG = logging.getLogger(__name__) def setup_db(): """Set up database, create tables, etc. Return True on success, False otherwise """ return IMPL.setup_db()
def initialize_sql_session(): # Make sure the DB is located in the correct location, in this case set # the default value, as this should be able to be overridden in some # test cases. db_options.set_defaults(CONF, connection=tests.IN_MEM_DB_CONN_STRING)
# License for the specific language governing permissions and limitations # under the License. """Session management functions.""" import threading from oslo.db import options from oslo.db.sqlalchemy import session as db_session from murano.common import config from murano.openstack.common import log as logging LOG = logging.getLogger(__name__) CONF = config.CONF options.set_defaults(CONF) _FACADE = None _LOCK = threading.Lock() def _create_facade_lazily(): global _LOCK, _FACADE if _FACADE is None: with _LOCK: if _FACADE is None: _FACADE = db_session.EngineFacade.from_config(CONF, sqlite_fk=True) return _FACADE
default=None, help='The connection string used to connect to the meteting ' 'database. (if unset, connection is used)'), cfg.StrOpt('alarm_connection', default=None, help='The connection string used to connect to the alarm ' 'database. (if unset, connection is used)'), cfg.StrOpt('event_connection', default=None, help='The connection string used to connect to the event ' 'database. (if unset, connection is used)'), ] cfg.CONF.register_opts(OPTS, group='database') db_options.set_defaults(cfg.CONF) cfg.CONF.import_opt('connection', 'oslo.db.options', group='database') class StorageBadVersion(Exception): """Error raised when the storage backend version is not good enough.""" class StorageBadAggregate(Exception): """Error raised when an aggregate is unacceptable to storage backend.""" code = 400 def get_connection_from_config(conf, purpose=None): if conf.database_connection: conf.set_override('connection', conf.database_connection,
def setup_dummy_db(): options.cfg.set_defaults(options.database_opts, sqlite_synchronous=False) options.set_defaults(cfg.CONF, connection="sqlite://", sqlite_db='heat.db') engine = get_engine() db_api.db_sync(engine) engine.connect()
`sqlite:///var/lib/cinder/cinder.sqlite`. :enable_new_services: when adding a new service to the database, is it in the pool of available hardware (Default: True) """ from oslo.config import cfg from oslo.db import api as db_api from oslo.db import options as db_options CONF = cfg.CONF db_options.set_defaults(CONF, connection="sqlite:////tmp/rally.sqlite", sqlite_db="rally.sqlite") _BACKEND_MAPPING = {'sqlalchemy': 'rally.db.sqlalchemy.api'} IMPL = db_api.DBAPI.from_config(CONF, backend_mapping=_BACKEND_MAPPING) def db_cleanup(): """Recreate engine.""" IMPL.db_cleanup() def db_create(): """Initialize DB. This method will drop existing database.""" IMPL.db_create()
from sqlalchemy.types import TypeDecorator, TEXT from ironic.common import paths sql_opts = [ cfg.StrOpt('mysql_engine', default='InnoDB', help='MySQL engine to use.') ] _DEFAULT_SQL_CONNECTION = 'sqlite:///' + paths.state_path_def('ironic.sqlite') cfg.CONF.register_opts(sql_opts, 'database') db_options.set_defaults(cfg.CONF, _DEFAULT_SQL_CONNECTION, 'ironic.sqlite') def table_args(): engine_name = urlparse.urlparse(cfg.CONF.database.connection).scheme if engine_name == 'mysql': return {'mysql_engine': cfg.CONF.database.mysql_engine, 'mysql_charset': "utf8"} return None class JsonEncodedType(TypeDecorator): """Abstract base type serialized as json-encoded string in db.""" type = None impl = TEXT
from sqlalchemy.sql.expression import literal_column from sqlalchemy.sql import func from sds.common import sqlalchemyutils from sds.db.sqlalchemy import models from sds.common import exception from sds.i18n import _ from sds.openstack.common import log as logging from sds.openstack.common import timeutils from sds.openstack.common import uuidutils CONF = cfg.CONF CONF.import_group("profiler", "sds.service") LOG = logging.getLogger(__name__) options.set_defaults(CONF, connection='sqlite:///$state_path/sds.sqlite') _LOCK = threading.Lock() _FACADE = None def _create_facade_lazily(): global _LOCK with _LOCK: global _FACADE if _FACADE is None: _FACADE = db_session.EngineFacade( CONF.database.connection, **dict(CONF.database.iteritems())) if CONF.profiler.profiler_enabled: if CONF.profiler.trace_sqlalchemy:
from oslo.messaging import opts # noqa state_opts = [ cfg.StrOpt('backend', default='cloudkitty.backend.file.FileBackend', help='Backend for the state manager.'), cfg.StrOpt('basepath', default='/var/lib/cloudkitty/states/', help='Storage directory for the file state backend.'), ] output_opts = [ cfg.StrOpt('backend', default='cloudkitty.backend.file.FileBackend', help='Backend for the output manager.'), cfg.StrOpt('basepath', default='/var/lib/cloudkitty/states/', help='Storage directory for the file output backend.'), cfg.ListOpt('pipeline', default=['osrf'], help='Output pipeline'), ] cfg.CONF.register_opts(state_opts, 'state') cfg.CONF.register_opts(output_opts, 'output') # oslo.db defaults db_options.set_defaults( cfg.CONF, connection='sqlite:////var/lib/cloudkitty/cloudkitty.sqlite')
# See the License for the specific language governing permissions and # limitations under the License. from oslo.config import cfg from oslo.db import options from oslo.db.sqlalchemy import session as db_session from highlander.db.sqlalchemy import sqlite_lock from highlander import exceptions as exc from highlander.openstack.common import log as logging from highlander import utils LOG = logging.getLogger(__name__) # Note(dzimine): sqlite only works for basic testing. options.set_defaults(cfg.CONF, connection="sqlite:///highlander.sqlite") _DB_SESSION_THREAD_LOCAL_NAME = "db_sql_alchemy_session" _facade = None def _get_facade(): global _facade if not _facade: _facade = db_session.EngineFacade(cfg.CONF.database.connection, sqlite_fk=True, autocommit=False, **dict( cfg.CONF.database.iteritems()))
default=True, help='Services to be added to the available pool on create'), cfg.StrOpt('volume_name_template', default='volume-%s', help='Template string to be used to generate volume names'), cfg.StrOpt('snapshot_name_template', default='snapshot-%s', help='Template string to be used to generate snapshot names'), cfg.StrOpt('backup_name_template', default='backup-%s', help='Template string to be used to generate backup names'), ] CONF = cfg.CONF CONF.register_opts(db_opts) db_options.set_defaults(CONF) CONF.set_default('sqlite_db', 'cinder.sqlite', group='database') _BACKEND_MAPPING = {'sqlalchemy': 'cinder.db.sqlalchemy.api'} IMPL = db_concurrency.TpoolDbapiWrapper(CONF, _BACKEND_MAPPING) ################### def service_destroy(context, service_id): """Destroy the service or raise if it does not exist.""" return IMPL.service_destroy(context, service_id) def service_get(context, service_id):
default=True, help='Services to be added to the available pool on create'), cfg.StrOpt('volume_name_template', default='volume-%s', help='Template string to be used to generate volume names'), cfg.StrOpt('snapshot_name_template', default='snapshot-%s', help='Template string to be used to generate snapshot names'), cfg.StrOpt('backup_name_template', default='backup-%s', help='Template string to be used to generate backup names'), ] CONF = cfg.CONF CONF.register_opts(db_opts) db_options.set_defaults(CONF) CONF.set_default('sqlite_db', 'cinder.sqlite', group='database') _BACKEND_MAPPING = {'sqlalchemy': 'cinder.db.sqlalchemy.api'} IMPL = db_concurrency.TpoolDbapiWrapper(CONF, _BACKEND_MAPPING) ################### def service_destroy(context, service_id): """Destroy the service or raise if it does not exist.""" return IMPL.service_destroy(context, service_id)
default=None, help='The connection string used to connect to the meteting ' 'database. (if unset, connection is used)'), cfg.StrOpt('alarm_connection', default=None, help='The connection string used to connect to the alarm ' 'database. (if unset, connection is used)'), cfg.StrOpt('event_connection', default=None, help='The connection string used to connect to the event ' 'database. (if unset, connection is used)'), ] cfg.CONF.register_opts(STORAGE_OPTS, group='database') db_options.set_defaults(cfg.CONF) cfg.CONF.import_opt('connection', 'oslo.db.options', group='database') class StorageBadVersion(Exception): """Error raised when the storage backend version is not good enough.""" class StorageBadAggregate(Exception): """Error raised when an aggregate is unacceptable to storage backend.""" code = 400 def get_connection_from_config(conf, purpose=None): if conf.database_connection: conf.set_override('connection', conf.database_connection,
# limitations under the License. from oslo.config import cfg from oslo.db import options from oslo.db.sqlalchemy import session as db_session from blog.db.sqlalchemy import sqlite_lock from blog import exceptions as exc from blog.openstack.common import log as logging from blog import utils LOG = logging.getLogger(__name__) # Note(dzimine): sqlite only works for basic testing. options.set_defaults(cfg.CONF, connection="sqlite:///blog.sqlite") _DB_SESSION_THREAD_LOCAL_NAME = "db_sql_alchemy_session" _facade = None def _get_facade(): global _facade if not _facade: _facade = db_session.EngineFacade( cfg.CONF.database.connection, sqlite_fk=True, autocommit=False, **dict(cfg.CONF.database.iteritems())
# limitations under the License. from oslo.config import cfg from oslo.db import options from oslo.db.sqlalchemy import session as db_session from highlander.db.sqlalchemy import sqlite_lock from highlander import exceptions as exc from highlander.openstack.common import log as logging from highlander import utils LOG = logging.getLogger(__name__) # Note(dzimine): sqlite only works for basic testing. options.set_defaults(cfg.CONF, connection="sqlite:///highlander.sqlite") _DB_SESSION_THREAD_LOCAL_NAME = "db_sql_alchemy_session" _facade = None def _get_facade(): global _facade if not _facade: _facade = db_session.EngineFacade( cfg.CONF.database.connection, sqlite_fk=True, autocommit=False, **dict(cfg.CONF.database.iteritems())
] core_cli_opts = [] # Register the configuration options cfg.CONF.register_opts(core_opts) cfg.CONF.register_cli_opts(core_cli_opts) # Ensure that the control exchange is set correctly messaging.set_transport_defaults(control_exchange='octavia') _SQL_CONNECTION_DEFAULT = 'sqlite://' # Update the default QueuePool parameters. These can be tweaked by the # configuration variables - max_pool_size, max_overflow and pool_timeout db_options.set_defaults(cfg.CONF, connection=_SQL_CONNECTION_DEFAULT, sqlite_db='', max_pool_size=10, max_overflow=20, pool_timeout=10) def init(args, **kwargs): cfg.CONF(args=args, project='octavia', version='%%prog %s' % version.version_info.release_string(), **kwargs) def setup_logging(conf): """Sets up the logging options for a log with supplied name. :param conf: a cfg.ConfOpts object
def get_db(config): options.set_defaults(CONF, connection='sqlite://') config(verbose=False, debug=False) db_api = glance.db.sqlalchemy.api return db_api
def initialize(): """Initialize the module.""" db_options.set_defaults(CONF, connection="sqlite:///keystone.db")
def init(args, **kwargs): options.set_defaults(CONF, connection=_DEFAULT_SQL_CONNECTION, sqlite_db='daoliproxy.sqlite') cfg.CONF(args=args, project='daoliagent', version='1.0', **kwargs)
default='/var/lib/neutron', help=_("Where to store Neutron state files. " "This directory must be writable by the agent.")), ] # Register the configuration options cfg.CONF.register_opts(core_opts) cfg.CONF.register_cli_opts(core_cli_opts) # Ensure that the control exchange is set correctly messaging.set_transport_defaults(control_exchange='neutron') _SQL_CONNECTION_DEFAULT = 'sqlite://' # Update the default QueuePool parameters. These can be tweaked by the # configuration variables - max_pool_size, max_overflow and pool_timeout db_options.set_defaults(cfg.CONF, connection=_SQL_CONNECTION_DEFAULT, sqlite_db='', max_pool_size=10, max_overflow=20, pool_timeout=10) def init(args, **kwargs): cfg.CONF(args=args, project='neutron', version='%%prog %s' % version.version_info.release_string(), **kwargs) # FIXME(ihrachys): if import is put in global, circular import # failure occurs from neutron.common import rpc as n_rpc n_rpc.init(cfg.CONF) # Validate that the base_mac is of the correct format msg = attributes._validate_regex(cfg.CONF.base_mac,
# limitations under the License. from oslo.config import cfg from oslo.db import options from oslo.db.sqlalchemy import session as db_session from mistral.db.sqlalchemy import sqlite_lock from mistral import exceptions as exc from mistral.openstack.common import log as logging from mistral import utils LOG = logging.getLogger(__name__) # Note(dzimine): sqlite only works for basic testing. options.set_defaults(cfg.CONF, connection="sqlite:///mistral.sqlite") _DB_SESSION_THREAD_LOCAL_NAME = "db_sql_alchemy_session" _facade = None def _get_facade(): global _facade if not _facade: _facade = db_session.EngineFacade( cfg.CONF.database.connection, sqlite_fk=True, autocommit=False, **dict(cfg.CONF.database.iteritems())
state_opts = [ cfg.StrOpt('backend', default='cloudkitty.backend.file.FileBackend', help='Backend for the state manager.'), cfg.StrOpt('basepath', default='/var/lib/cloudkitty/states/', help='Storage directory for the file state backend.'), ] output_opts = [ cfg.StrOpt('backend', default='cloudkitty.backend.file.FileBackend', help='Backend for the output manager.'), cfg.StrOpt('basepath', default='/var/lib/cloudkitty/states/', help='Storage directory for the file output backend.'), cfg.ListOpt('pipeline', default=['osrf'], help='Output pipeline'), ] cfg.CONF.register_opts(auth_opts, 'auth') cfg.CONF.register_opts(collect_opts, 'collect') cfg.CONF.register_opts(state_opts, 'state') cfg.CONF.register_opts(output_opts, 'output') # oslo.db defaults db_options.set_defaults( cfg.CONF, connection='sqlite:////var/lib/cloudkitty/cloudkitty.sqlite')