Exemple #1
0
    def test_table_queries(self):
        self.engine.execute(tables.Queues.insert(),
                            id=1,
                            project='test',
                            name='zaqar',
                            metadata=utils.json_encode('aaaa'))
        self.engine.execute(tables.Messages.insert(),
                            id=1,
                            qid=1,
                            ttl=10,
                            body=utils.json_encode('bbbb'),
                            client='a',
                            created=datetime.datetime.now())
        self.engine.execute(tables.Claims.insert(),
                            id=1,
                            qid=1,
                            ttl=10,
                            created=datetime.datetime.now())

        rs = self.engine.execute(tables.Claims.select())
        row = rs.fetchone()

        self.assertEqual(row.id, 1)
        self.assertEqual(row.qid, 1)
        self.assertEqual(row.ttl, 10)

        self.engine.execute(tables.Claims.delete(tables.Claims.c.id == 1))
        rs = self.engine.execute(tables.Claims.select())
        row = rs.fetchone()

        self.assertIsNone(row)
Exemple #2
0
    def _create(self,
                name,
                weight,
                uri,
                group=None,
                flavor=None,
                options=None):
        opts = None if options is None else utils.json_encode(options)

        if group is not None:
            self._ensure_group_exists(group)

        try:
            stmt = sa.sql.expression.insert(tables.Pools).values(name=name,
                                                                 weight=weight,
                                                                 uri=uri,
                                                                 group=group,
                                                                 flavor=flavor,
                                                                 options=opts)
            self.driver.run(stmt)

        except oslo_db.exception.DBDuplicateEntry:
            # TODO(cpp-cabrera): merge update/create into a single
            # method with introduction of upsert
            self._update(name,
                         weight=weight,
                         uri=uri,
                         group=group,
                         flavor=flavor,
                         options=options)
Exemple #3
0
    def create(self, name, pool_group=None, project=None, capabilities=None):
        cap = None if capabilities is None else utils.json_encode(capabilities)

        try:
            if pool_group is not None:
                stmt = sa.sql.expression.insert(tables.Flavors).values(
                    name=name,
                    pool_group=pool_group,
                    project=project,
                    capabilities=cap)
            else:
                stmt = sa.sql.expression.insert(tables.Flavors).values(
                    name=name, project=project, capabilities=cap)
            self.driver.run(stmt)
        except oslo_db.exception.DBDuplicateEntry:
            # NOTE(gengchc2): If you do not use the removal group scheme to
            # configure flavor, pool_group can be None..
            if pool_group is not None:
                flavor_obj = {}
                flavor_obj["pool_group"] = pool_group
                if not list(self._pools_ctrl.get_pools_by_flavor(flavor_obj)):
                    raise errors.PoolGroupDoesNotExist(pool_group)

            # TODO(flaper87): merge update/create into a single
            # method with introduction of upsert
            self.update(name,
                        pool_group=pool_group,
                        project=project,
                        capabilities=capabilities)
Exemple #4
0
    def create(self, name, project=None, capabilities=None):
        cap = None if capabilities is None else utils.json_encode(capabilities)

        try:
            stmt = sa.sql.expression.insert(tables.Flavors).values(
                name=name, project=project, capabilities=cap)
            self.driver.run(stmt)
        except oslo_db.exception.DBDuplicateEntry:
            # TODO(flaper87): merge update/create into a single
            # method with introduction of upsert
            self.update(name, project=project, capabilities=capabilities)
Exemple #5
0
    def test_table_queries(self):
        self.engine.execute(tables.Queues.insert(), id=1, project='test',
                            name='zaqar', metadata=utils.json_encode('aaaa'))
        self.engine.execute(tables.Messages.insert(), id=1, qid=1, ttl=10,
                            body=utils.json_encode('bbbb'), client='a',
                            created=datetime.datetime.now())
        self.engine.execute(tables.Claims.insert(), id=1, qid=1, ttl=10,
                            created=datetime.datetime.now())

        rs = self.engine.execute(tables.Claims.select())
        row = rs.fetchone()

        self.assertEqual(row.id, 1)
        self.assertEqual(row.qid, 1)
        self.assertEqual(row.ttl, 10)

        self.engine.execute(tables.Claims.delete(tables.Claims.c.id == 1))
        rs = self.engine.execute(tables.Claims.select())
        row = rs.fetchone()

        self.assertIsNone(row)
Exemple #6
0
    def _create(self, name, metadata=None, project=None):
        if project is None:
            project = ''

        try:
            smeta = utils.json_encode(metadata or {})
            ins = tables.Queues.insert().values(project=project,
                                                name=name,
                                                metadata=smeta)
            res = self.driver.run(ins)
        except sa.exc.IntegrityError:
            return False

        return res.rowcount == 1
Exemple #7
0
    def create(self, name, pool, project=None, capabilities=None):
        cap = None if capabilities is None else utils.json_encode(capabilities)

        try:
            stmt = sa.sql.expression.insert(tables.Flavors).values(
                name=name, pool=pool, project=project, capabilities=cap)
            self.driver.connection.execute(stmt)
        except sa.exc.IntegrityError:
            if not self._pools_ctrl.get_group(pool):
                raise errors.PoolDoesNotExist(pool)

            # TODO(flaper87): merge update/create into a single
            # method with introduction of upsert
            self.update(name, pool=pool, project=project, capabilities=cap)
Exemple #8
0
    def _create(self, name, metadata=None, project=None):
        if project is None:
            project = ''

        try:
            smeta = utils.json_encode(metadata or {})
            ins = tables.Queues.insert().values(project=project,
                                                name=name,
                                                metadata=smeta)
            res = self.driver.run(ins)
        except oslo_db.exception.DBDuplicateEntry:
            return False

        return res.rowcount == 1
Exemple #9
0
    def _create(self, name, metadata=None, project=None):
        if project is None:
            project = ''

        try:
            smeta = utils.json_encode(metadata or {})
            ins = tables.Queues.insert().values(project=project,
                                                name=name,
                                                metadata=smeta)
            res = self.driver.run(ins)
        except sa.exc.IntegrityError:
            return False

        return res.rowcount == 1
Exemple #10
0
    def _create(self, name, weight, uri, group=None, options=None):
        opts = None if options is None else utils.json_encode(options)

        try:
            stmt = sa.sql.expression.insert(tables.Pools).values(
                name=name, weight=weight, uri=uri, group=group, options=opts
            )
            self._conn.execute(stmt)

        except sa.exc.IntegrityError:
            # TODO(cpp-cabrera): merge update/create into a single
            # method with introduction of upsert
            self.update(name, weight=weight, uri=uri,
                        group=group, options=options)
Exemple #11
0
    def create(self, name, pool, project=None, capabilities=None):
        cap = None if capabilities is None else utils.json_encode(capabilities)

        try:
            stmt = sa.sql.expression.insert(tables.Flavors).values(
                name=name, pool=pool, project=project, capabilities=cap
            )
            self.driver.connection.execute(stmt)
        except sa.exc.IntegrityError:
            if not self._pools_ctrl.get_group(pool):
                raise errors.PoolDoesNotExist(pool)

            # TODO(flaper87): merge update/create into a single
            # method with introduction of upsert
            self.update(name, pool=pool, project=project, capabilities=cap)
Exemple #12
0
    def _create(self, name, weight, uri, flavor=None,
                options=None):
        opts = None if options is None else utils.json_encode(options)

        try:
            stmt = sa.sql.expression.insert(tables.Pools).values(
                name=name, weight=weight, uri=uri,
                flavor=flavor, options=opts
            )
            self.driver.run(stmt)

        except oslo_db.exception.DBDuplicateEntry:
            # TODO(cpp-cabrera): merge update/create into a single
            # method with introduction of upsert
            self._update(name, weight=weight, uri=uri,
                         flavor=flavor, options=options)
Exemple #13
0
    def set_metadata(self, name, metadata, project):
        if project is None:
            project = ''

        update = (tables.Queues.update().where(
            sa.and_(tables.Queues.c.project == project,
                    tables.Queues.c.name == name)).values(
                        metadata=utils.json_encode(metadata)))

        res = self.driver.run(update)

        try:
            if res.rowcount != 1:
                raise errors.QueueDoesNotExist(name, project)
        finally:
            res.close()
Exemple #14
0
    def set_metadata(self, name, metadata, project):
        if project is None:
            project = ''

        update = (tables.Queues.update().
                  where(sa.and_(
                      tables.Queues.c.project == project,
                      tables.Queues.c.name == name)).
                  values(metadata=utils.json_encode(metadata)))

        res = self.driver.run(update)

        try:
            if res.rowcount != 1:
                raise errors.QueueDoesNotExist(name, project)
        finally:
            res.close()
Exemple #15
0
    def update(self, name, project=None, capabilities=None):
        fields = {}

        if capabilities is not None:
            fields['capabilities'] = capabilities

        assert fields, '`capabilities` not found in kwargs'
        if 'capabilities' in fields:
            fields['capabilities'] = utils.json_encode(fields['capabilities'])

        stmt = sa.sql.update(tables.Flavors).where(
            sa.and_(tables.Flavors.c.name == name,
                    tables.Flavors.c.project == project)).values(**fields)

        res = self.driver.run(stmt)
        if res.rowcount == 0:
            raise errors.FlavorDoesNotExist(name)
Exemple #16
0
    def create(self, name, pool_group, project=None, capabilities=None):
        cap = None if capabilities is None else utils.json_encode(capabilities)

        try:
            stmt = sa.sql.expression.insert(tables.Flavors).values(
                name=name, pool_group=pool_group, project=project,
                capabilities=cap
            )
            self.driver.run(stmt)
        except oslo_db.exception.DBDuplicateEntry:
            if not self._pools_ctrl.get_pools_by_group(pool_group):
                raise errors.PoolGroupDoesNotExist(pool_group)

            # TODO(flaper87): merge update/create into a single
            # method with introduction of upsert
            self.update(name, pool_group=pool_group,
                        project=project,
                        capabilities=cap)
Exemple #17
0
    def create(self, name, weight, uri, group=None, options=None):
        opts = None if options is None else utils.json_encode(options)

        try:
            stmt = sa.sql.expression.insert(tables.Pools).values(name=name,
                                                                 weight=weight,
                                                                 uri=uri,
                                                                 group=group,
                                                                 options=opts)
            self._conn.execute(stmt)

        except sa.exc.IntegrityError:
            # TODO(cpp-cabrera): merge update/create into a single
            # method with introduction of upsert
            self.update(name,
                        weight=weight,
                        uri=uri,
                        group=group,
                        options=options)
Exemple #18
0
    def _update(self, name, **kwargs):
        # NOTE(cpp-cabrera): by pruning None-valued kwargs, we avoid
        # overwriting the existing options field with None, since that
        # one can be null.
        names = ('uri', 'weight', 'group', 'options')
        fields = common_utils.fields(kwargs, names,
                                     pred=lambda x: x is not None)

        assert fields, ('`weight`, `uri`, `group`, '
                        'or `options` not found in kwargs')

        if 'options' in fields:
            fields['options'] = utils.json_encode(fields['options'])

        stmt = sa.sql.update(tables.Pools).where(
            tables.Pools.c.name == name).values(**fields)

        res = self._conn.execute(stmt)
        if res.rowcount == 0:
            raise errors.PoolDoesNotExist(name)
Exemple #19
0
    def _update(self, name, **kwargs):
        # NOTE(cpp-cabrera): by pruning None-valued kwargs, we avoid
        # overwriting the existing options field with None, since that
        # one can be null.
        names = ('uri', 'weight', 'flavor', 'options')
        fields = common_utils.fields(kwargs, names,
                                     pred=lambda x: x is not None)

        assert fields, ('`weight`, `uri`, `flavor`, '
                        'or `options` not found in kwargs')

        if 'options' in fields:
            fields['options'] = utils.json_encode(fields['options'])

        stmt = sa.sql.update(tables.Pools).where(
            tables.Pools.c.name == name).values(**fields)

        res = self.driver.run(stmt)
        if res.rowcount == 0:
            raise errors.PoolDoesNotExist(name)
Exemple #20
0
    def update(self, name, project=None, pool_group=None, capabilities=None):
        fields = {}

        if capabilities is not None:
            fields['capabilities'] = capabilities

        if pool_group is not None:
            fields['pool_group'] = pool_group

        assert fields, '`pool_group` or `capabilities` not found in kwargs'
        if 'capabilities' in fields:
            fields['capabilities'] = utils.json_encode(fields['capabilities'])

        stmt = sa.sql.update(tables.Flavors).where(
            sa.and_(tables.Flavors.c.name == name,
                    tables.Flavors.c.project == project)).values(**fields)

        res = self.driver.connection.execute(stmt)
        if res.rowcount == 0:
            raise errors.FlavorDoesNotExist(name)
Exemple #21
0
    def update(self, name, project=None, pool=None, capabilities=None):
        fields = {}

        if capabilities is not None:
            fields["capabilities"] = capabilities

        if pool is not None:
            fields["pool"] = pool

        assert fields, "`pool` or `capabilities` not found in kwargs"
        if "capabilities" in fields:
            fields["capabilities"] = utils.json_encode(fields["capabilities"])

        stmt = (
            sa.sql.update(tables.Flavors)
            .where(sa.and_(tables.Flavors.c.name == name, tables.Flavors.c.project == project))
            .values(**fields)
        )

        res = self.driver.connection.execute(stmt)
        if res.rowcount == 0:
            raise errors.FlavorDoesNotExist(name)
Exemple #22
0
 def it():
     for m in messages:
         yield dict(qid=qid,
                    ttl=m['ttl'],
                    body=utils.json_encode(m['body']),
                    client=str(client_uuid))
Exemple #23
0
 def it():
     for m in messages:
         yield dict(qid=qid,
                    ttl=m['ttl'],
                    body=utils.json_encode(m['body']),
                    client=str(client_uuid))