Beispiel #1
0
    def setUp(self):
        cfg.CONF.set_override("enable_authentication", False)
        super(DbTestCase, self).setUp()

        self.dbapi = dbapi.get_instance()

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api,
                                 sql_connection=CONF.database.connection)
        self.useFixture(_DB_CACHE)
Beispiel #2
0
    def setUp(self):
        cfg.CONF.set_override("enable_authentication", False)
        super(DbTestCase, self).setUp()

        self.dbapi = dbapi.get_instance()

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api,
                                 sql_connection=CONF.database.connection,
                                 sqlite_db=CONF.database.sqlite_db,
                                 sqlite_clean_db='clean.sqlite')
        self.useFixture(_DB_CACHE)
Beispiel #3
0
    def setUp(self):
        super(FunctionalTest, self).setUp()
        cfg.CONF.set_override("auth_version", "v2.0",
                              group='keystone_authtoken')
        cfg.CONF.set_override("admin_user", "admin",
                              group='keystone_authtoken')
        self.app = self._make_app()
        self.dbapi = dbapi.get_instance()

        def reset_pecan():
            pecan.set_config({}, overwrite=True)

        self.addCleanup(reset_pecan)

        p = mock.patch('cloudpulse.api.controllers.v1' +
                       '.Controller._check_version')
        self._check_version = p.start()
        self.addCleanup(p.stop)
Beispiel #4
0
    def setUp(self):
        super(FunctionalTest, self).setUp()
        cfg.CONF.set_override("auth_version",
                              "v2.0",
                              group='keystone_authtoken')
        cfg.CONF.set_override("admin_user",
                              "admin",
                              group='keystone_authtoken')
        self.app = self._make_app()
        self.dbapi = dbapi.get_instance()

        def reset_pecan():
            pecan.set_config({}, overwrite=True)

        self.addCleanup(reset_pecan)

        p = mock.patch('cloudpulse.api.controllers.v1' +
                       '.Controller._check_version')
        self._check_version = p.start()
        self.addCleanup(p.stop)
Beispiel #5
0
class CpulseLock(base.CloudpulsePersistentObject, base.CloudpulseObject,
                 base.CloudpulseObjectDictCompat):
    # Version 1.0: Initial version
    VERSION = '1.0'

    dbapi = dbapi.get_instance()

    fields = {
        'test_name': fields.StringField(nullable=True),
        'conductor_id': fields.StringField(nullable=True),
    }

    @base.remotable_classmethod
    def create(cls, test_name, conductor_id):
        return cls.dbapi.create_test_lock(test_name, conductor_id)

    @base.remotable_classmethod
    def steal(cls, test_name, old_conductor_id, new_conductor_id):
        return cls.dbapi.steal_test_lock(test_name, old_conductor_id,
                                         new_conductor_id)

    @base.remotable_classmethod
    def release(cls, test_name, conductor_id):
        return cls.dbapi.release_test_lock(test_name, conductor_id)
Beispiel #6
0
def create_cpulse_test(**kw):
    test = get_cpulse_test(**kw)
    dbapi = db_api.get_instance()
    return dbapi.create_test(test)
Beispiel #7
0
class Cpulse(base.CloudpulsePersistentObject, base.CloudpulseObject,
             base.CloudpulseObjectDictCompat):
    # Version 1.0: Initial version
    VERSION = '1.0'

    dbapi = dbapi.get_instance()

    fields = {
        'id': fields.IntegerField(),
        'uuid': fields.UUIDField(nullable=True),
        'name': fields.StringField(nullable=True),
        'state': fields.StringField(nullable=True),
        'result': fields.StringField(nullable=True),
        'testtype': fields.StringField(nullable=True)
    }

    @staticmethod
    def _from_db_object(test, db):
        """Converts a database entity to a formal object."""
        for field in test.fields:
            test[field] = db[field]

        test.obj_reset_changes()
        return test

    @staticmethod
    def _from_db_object_list(db_objects, cls, ctx):
        """Converts a list of db entities to a list of formal objects."""
        return [Cpulse._from_db_object(cls(ctx), obj) for obj in db_objects]

    @base.remotable_classmethod
    def get(cls, context, test_id):
        """Find a test based on its id or uuid and return a Cpulse object.

        :param test_id: the id *or* uuid of a test.
        :returns: a :class:`Cpulse` object.
        """
        if utils.is_int_like(test_id):
            return cls.get_by_id(context, test_id)
        elif utils.is_uuid_like(test_id):
            return cls.get_by_uuid(context, test_id)
        else:
            raise exception.InvalidIdentity(identity=test_id)

    @base.remotable_classmethod
    def get_by_id(cls, context, test_id):
        """Find a test based on its integer id and return a Cpulse object.

        :param test_id: the id of a test.
        :returns: a :class:`Cpulse` object.
        """
        db = cls.dbapi.get_test_by_id(context, test_id)
        test = Cpulse._from_db_object(cls(context), db)
        return test

    @base.remotable_classmethod
    def get_by_uuid(cls, context, uuid):
        """Find a test based on uuid and return a :class:`Cpulse` object.

        :param uuid: the uuid of a test.
        :param context: Security context
        :returns: a :class:`Cpulse` object.
        """
        db = cls.dbapi.get_test_by_uuid(context, uuid)
        test = Cpulse._from_db_object(cls(context), db)
        return test

    @base.remotable_classmethod
    def get_by_name(cls, context, name):
        """Find a test based on name and return a Cpulse object.

        :param name: the logical name of a test.
        :param context: Security context
        :returns: a :class:`Cpulse` object.
        """
        db = cls.dbapi.get_test_by_name(context, name)
        test = Cpulse._from_db_object(cls(context), db)
        return test

    @base.remotable_classmethod
    def list(cls,
             context,
             limit=None,
             marker=None,
             sort_key=None,
             sort_dir=None):
        """Return a list of Cpulse objects.

        :param context: Security context.
        :param limit: maximum number of resources to return in a single result.
        :param marker: pagination marker for large data sets.
        :param sort_key: column to sort results by.
        :param sort_dir: direction to sort. "asc" or "desc".
        :returns: a list of :class:`Cpulse` object.

        """
        db = cls.dbapi.get_test_list(context,
                                     limit=limit,
                                     marker=marker,
                                     sort_key=sort_key,
                                     sort_dir=sort_dir)
        return Cpulse._from_db_object_list(db, cls, context)

    @base.remotable
    def create(self, context=None):
        """Create a Cpulse record in the DB.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Cpulse(context)

        """
        values = self.obj_get_changes()
        LOG.info(_LI('Dumping CREATE test datastructure  %s') % str(values))
        db = self.dbapi.create_test(values)
        self._from_db_object(self, db)

    @base.remotable
    def destroy(self, context=None):
        """Delete the Cpulse from the DB.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Cpulse(context)
        """
        self.dbapi.destroy_test(self.uuid)
        self.obj_reset_changes()

    @base.remotable
    def save(self, context=None):
        """Save updates to this Cpulse.

        Updates will be made column by column based on the result
        of self.what_changed().

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Cpulse(context)
        """
        updates = self.obj_get_changes()
        self.dbapi.update_test(self.uuid, updates)

        self.obj_reset_changes()

    @base.remotable
    def refresh(self, context=None):
        """Loads updates for this Cpulse.

        Loads a test with the same uuid from the database and
        checks for updated attributes. Updates are applied from
        the loaded test column by column, if there are any updates.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Cpulse(context)
        """
        current = self.__class__.get_by_uuid(self._context, uuid=self.uuid)
        for field in self.fields:
            if self.obj_attr_is_set(field) and self[field] != current[field]:
                self[field] = current[field]