Beispiel #1
0
 def test_get_container_by_uuid(self):
     container = utils.create_test_container(context=self.context)
     res = dbapi.get_container_by_uuid(self.context,
                                       container.container_type,
                                       container.uuid)
     self.assertEqual(container.id, res.id)
     self.assertEqual(container.uuid, res.uuid)
Beispiel #2
0
 def test_get_container_by_uuid(self):
     container = utils.create_test_container(context=self.context)
     res = dbapi.get_container_by_uuid(self.context,
                                       container.container_type,
                                       container.uuid)
     self.assertEqual(container.id, res.id)
     self.assertEqual(container.uuid, res.uuid)
Beispiel #3
0
 def test_get_container_by_uuid(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     container = utils.create_test_container(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(container.as_dict(
     ))
     res = dbapi.get_container_by_uuid(self.context, container.uuid)
     self.assertEqual(container.id, res.id)
     self.assertEqual(container.uuid, res.uuid)
Beispiel #4
0
    def get_by_uuid(cls, context, uuid):
        """Find a container based on uuid and return a :class:`Container` object.

        :param uuid: the uuid of a container.
        :param context: Security context
        :returns: a :class:`Container` object.
        """
        db_container = dbapi.get_container_by_uuid(context, uuid)
        container = Container._from_db_object(cls(context), db_container)
        return container
Beispiel #5
0
    def get_by_uuid(cls, context, uuid):
        """Find a container based on uuid and return a :class:`Container` object.

        :param uuid: the uuid of a container.
        :param context: Security context
        :returns: a :class:`Container` object.
        """
        db_container = dbapi.get_container_by_uuid(context, cls.container_type,
                                                   uuid)
        container = cls._from_db_object(cls(context), db_container)
        return container
Beispiel #6
0
    def get_container_any_type(context, uuid):
        """Find a container of any type based on uuid.

        :param uuid: the uuid of a container.
        :param context: Security context
        :returns: a :class:`ContainerBase` object.
        """
        db_container = dbapi.get_container_by_uuid(context, consts.TYPE_ANY,
                                                   uuid)
        type = db_container['container_type']
        if type == consts.TYPE_CONTAINER:
            container_cls = Container
        elif type == consts.TYPE_CAPSULE:
            container_cls = Capsule
        elif type == consts.TYPE_CAPSULE_CONTAINER:
            container_cls = CapsuleContainer
        elif type == consts.TYPE_CAPSULE_INIT_CONTAINER:
            container_cls = CapsuleInitContainer
        else:
            raise exception.ZunException(_('Unknown container type: %s'), type)

        obj = container_cls(context)
        container = container_cls._from_db_object(obj, db_container)
        return container
Beispiel #7
0
    def get_container_any_type(context, uuid):
        """Find a container of any type based on uuid.

        :param uuid: the uuid of a container.
        :param context: Security context
        :returns: a :class:`ContainerBase` object.
        """
        db_container = dbapi.get_container_by_uuid(context, consts.TYPE_ANY,
                                                   uuid)
        type = db_container['container_type']
        if type == consts.TYPE_CONTAINER:
            container_cls = Container
        elif type == consts.TYPE_CAPSULE:
            container_cls = Capsule
        elif type == consts.TYPE_CAPSULE_CONTAINER:
            container_cls = CapsuleContainer
        elif type == consts.TYPE_CAPSULE_INIT_CONTAINER:
            container_cls = CapsuleInitContainer
        else:
            raise exception.ZunException(_('Unknown container type: %s'), type)

        obj = container_cls(context)
        container = container_cls._from_db_object(obj, db_container)
        return container