def create_test_volume_mapping(**kwargs): volume_mapping = get_test_volume_mapping(**kwargs) # Let DB generate ID if it isn't specified explicitly if CONF.db_type == 'sql' and 'id' not in kwargs: del volume_mapping['id'] dbapi = db_api._get_dbdriver_instance() return dbapi.create_volume_mapping(kwargs['context'], volume_mapping)
def create_test_resource_class(**kwargs): resource = get_test_resource_class(**kwargs) # Let DB generate ID if it isn't specified explicitly if CONF.db_type == 'sql' and 'id' not in kwargs: del resource['id'] dbapi = db_api._get_dbdriver_instance() return dbapi.create_resource_class(kwargs['context'], resource)
def create_test_allocation(**kwargs): allocation = get_test_allocation(**kwargs) # Let DB generate ID if it isn't specified explicitly if CONF.db_type == 'sql' and 'id' not in kwargs: del allocation['id'] dbapi = db_api._get_dbdriver_instance() return dbapi.create_allocation(kwargs['context'], allocation)
def create_test_resource_provider(**kw): provider = get_test_resource_provider(**kw) # Let DB generate ID if it isn't specified explicitly if CONF.db_type == 'sql' and 'id' not in kw: del provider['id'] dbapi = db_api._get_dbdriver_instance() return dbapi.create_resource_provider(kw['context'], provider)
def create_test_zun_service(**kwargs): zun_service = get_test_zun_service(**kwargs) # Let DB generate ID if it isn't specifiled explicitly if CONF.db_type == 'sql' and 'id' not in kwargs: del zun_service['id'] dbapi = db_api._get_dbdriver_instance() return dbapi.create_zun_service(zun_service)
def create_test_inventory(**kwargs): inventory = get_test_inventory(**kwargs) # Let DB generate ID if it isn't specified explicitly if CONF.db_type == 'sql' and 'id' not in kwargs: del inventory['id'] provider_id = inventory.pop('resource_provider_id') dbapi = db_api._get_dbdriver_instance() return dbapi.create_inventory(kwargs['context'], provider_id, inventory)
def setUp(self): super(DriverTestCase, self).setUp() self.dbapi = db_api._get_dbdriver_instance() global _DB_CACHE if not _DB_CACHE: _DB_CACHE = Database(sqla_api, migration, sql_connection=CONF.database.connection) self.useFixture(_DB_CACHE)
def setUp(self): super(DbTestCase, self).setUp() self.dbapi = (db_api._get_dbdriver_instance() if CONF.database.backend == "sqlalchemy" else etcd_api.get_backend()) global _DB_CACHE if not _DB_CACHE: _DB_CACHE = Database(sqla_api, migration, sql_connection=CONF.database.connection) self.useFixture(_DB_CACHE)
def create_test_container(**kwargs): """Create test container entry in DB and return Container DB object. Function to be used to create test Container objects in the database. :param kwargs: kwargs with overriding values for container's attributes. :returns: Test Container DB object. """ container = get_test_container(**kwargs) # Let DB generate ID if it isn't specified explicitly if CONF.db_type == 'sql' and 'id' not in kwargs: del container['id'] dbapi = db_api._get_dbdriver_instance() return dbapi.create_container(kwargs['context'], container)
def setUp(self): super(DriverTestCase, self).setUp() # NOTE(yuywz): In driver test cases, we use sqllite as # the DB backend, so we should set 'db_type' to 'sql' # to access sqllite DB with sqlalchemy api. cfg.CONF.set_override('db_type', 'sql') self.dbapi = db_api._get_dbdriver_instance() global _DB_CACHE if not _DB_CACHE: _DB_CACHE = Database(sqla_api, migration, sql_connection=CONF.database.connection) self.useFixture(_DB_CACHE)
def create_test_image(**kwargs): """Create test image entry in DB and return Image DB object. Function to be used to create test Image objects in the database. :param kwargs: kwargs with overriding values for image's attributes. :returns: Test Image DB object. """ image = get_test_image(**kwargs) # Let DB generate ID if it isn't specified explicitly if 'id' not in kwargs: del image['id'] if 'repo' not in kwargs: image['repo'] = _generate_repo_for_image() dbapi = db_api._get_dbdriver_instance() return dbapi.pull_image(kwargs['context'], image)
def _get_dbapi(): if CONF.database.backend == 'sqlalchemy': dbapi = db_api._get_dbdriver_instance() else: dbapi = etcd_api.get_backend() return dbapi
def _get_dbapi(): dbapi = db_api._get_dbdriver_instance() return dbapi
def new_websocket_client(self): """Called after a new WebSocket connection has been established.""" # Reopen the eventlet hub to make sure we don't share an epoll # fd with parent and/or siblings, which would be bad from eventlet import hubs hubs.use_hub() # The zun expected behavior is to have token # passed to the method GET of the request parse = urlparse.urlparse(self.path) if parse.scheme not in ('http', 'https'): # From a bug in urlparse in Python < 2.7.4 we cannot support # special schemes (cf: https://bugs.python.org/issue9374) if sys.version_info < (2, 7, 4): raise exception.ZunException( _("We do not support scheme '%s' under Python < 2.7.4, " "please use http or https") % parse.scheme) query = parse.query token = urlparse.parse_qs(query).get("token", [""]).pop() uuid = urlparse.parse_qs(query).get("uuid", [""]).pop() dbapi = db_api._get_dbdriver_instance() ctx = context.get_admin_context(all_tenants=True) if uuidutils.is_uuid_like(uuid): container = dbapi.get_container_by_uuid(ctx, uuid) else: container = dbapi.get_container_by_name(ctx, uuid) if token != container.websocket_token: raise exception.InvalidWebsocketToken(token) access_url = '%s?token=%s&uuid=%s' % (CONF.websocket_proxy.base_url, token, uuid) # Verify Origin expected_origin_hostname = self.headers.get('Host') if ':' in expected_origin_hostname: e = expected_origin_hostname if '[' in e and ']' in e: expected_origin_hostname = e.split(']')[0][1:] else: expected_origin_hostname = e.split(':')[0] expected_origin_hostnames = CONF.websocket_proxy.allowed_origins expected_origin_hostnames.append(expected_origin_hostname) origin_url = self.headers.get('Origin') # missing origin header indicates non-browser client which is OK if origin_url is not None: origin = urlparse.urlparse(origin_url) origin_hostname = origin.hostname origin_scheme = origin.scheme if origin_hostname == '' or origin_scheme == '': detail = _("Origin header not valid.") raise exception.ValidationError(detail) if origin_hostname not in expected_origin_hostnames: detail = _("Origin header does not match this host.") raise exception.ValidationError(detail) if not self.verify_origin_proto(access_url, origin_scheme): detail = _("Origin header protocol does not match this host.") raise exception.ValidationError(detail) if container.websocket_url: target_url = container.websocket_url escape = "~" close_wait = 0.5 wscls = WebSocketClient(host_url=target_url, escape=escape, close_wait=close_wait) wscls.connect() self.target = wscls else: raise exception.InvalidWebsocketUrl() # Start proxying try: self.do_proxy(self.target.ws) except Exception as e: if self.target.ws: self.target.ws.close() self.vmsg(_("%Websocket client or target closed")) raise
def create_test_compute_node(**kwargs): compute_host = get_test_compute_node(**kwargs) dbapi = db_api._get_dbdriver_instance() return dbapi.create_compute_node(kwargs['context'], compute_host)