コード例 #1
0
    def test_create_runtime(self):
        runtime = self.create_runtime()
        runtime_id = runtime.id
        # Set status to verify it is changed during creation.
        db_api.update_runtime(runtime_id, {'status': status.CREATING})

        self.default_engine.create_runtime(mock.Mock(), runtime_id)

        self.orchestrator.create_pool.assert_called_once_with(
            runtime_id, runtime.image)
        runtime = db_api.get_runtime(runtime_id)
        self.assertEqual(status.AVAILABLE, runtime.status)
コード例 #2
0
    def test_create_runtime_failed(self):
        runtime = self.create_runtime()
        runtime_id = runtime.id
        # Set status to verify it is changed during creation.
        db_api.update_runtime(runtime_id, {'status': status.CREATING})
        self.orchestrator.create_pool.side_effect = RuntimeError

        self.default_engine.create_runtime(mock.Mock(), runtime_id)

        self.orchestrator.create_pool.assert_called_once_with(
            runtime_id, runtime.image, trusted=True)
        runtime = db_api.get_runtime(runtime_id)
        self.assertEqual(status.ERROR, runtime.status)
コード例 #3
0
ファイル: default_engine.py プロジェクト: baikai/qinling
    def update_runtime(self, ctx, runtime_id, image=None, pre_image=None):
        LOG.info('Start to update runtime %s, image: %s, pre_image: %s',
                 runtime_id, image, pre_image)

        ret = self.orchestrator.update_pool(runtime_id, image=image)

        if ret:
            values = {'status': status.AVAILABLE}
            db_api.update_runtime(runtime_id, values)

            LOG.info('Updated runtime %s.', runtime_id)
        else:
            values = {'status': status.AVAILABLE, 'image': pre_image}
            db_api.update_runtime(runtime_id, values)

            LOG.info('Rollbacked runtime %s.', runtime_id)
コード例 #4
0
    def test_update_runtime(self):
        runtime = self.create_runtime()
        runtime_id = runtime.id
        # Set status to verify it is changed during update.
        db_api.update_runtime(runtime_id, {'status': status.UPGRADING})
        image = self.rand_name('new_image', prefix=self.prefix)
        pre_image = self.rand_name('pre_image', prefix=self.prefix)
        self.orchestrator.update_pool.return_value = True

        self.default_engine.update_runtime(mock.Mock(), runtime_id, image,
                                           pre_image)

        self.orchestrator.update_pool.assert_called_once_with(runtime_id,
                                                              image=image)
        runtime = db_api.get_runtime(runtime_id)
        self.assertEqual(runtime.status, status.AVAILABLE)
コード例 #5
0
    def update_runtime(self, ctx, runtime_id, image=None, pre_image=None):
        resource = {'type': 'runtime', 'id': runtime_id}
        LOG.info('Start to update, image=%s', image, resource=resource)

        labels = {'runtime_id': runtime_id}
        ret = self.orchestrator.update_pool(runtime_id,
                                            labels=labels,
                                            image=image)

        if ret:
            values = {'status': status.AVAILABLE}
            db_api.update_runtime(runtime_id, values)

            LOG.info('Updated.', resource=resource)
        else:
            values = {'status': status.AVAILABLE, 'image': pre_image}
            db_api.update_runtime(runtime_id, values)

            LOG.info('Rollbacked.', resource=resource)
コード例 #6
0
    def put(self, id, runtime):
        """Update runtime.

        Currently, we support update name, description, image. When
        updating image, send message to engine for asynchronous
        handling.
        """
        acl.enforce('runtime:update', context.get_ctx())

        values = {}
        for key in UPDATE_ALLOWED:
            if runtime.to_dict().get(key) is not None:
                values.update({key: runtime.to_dict()[key]})

        LOG.info('Update resource, params: %s',
                 values,
                 resource={
                     'type': self.type,
                     'id': id
                 })

        image = values.get('image')

        with db_api.transaction():
            if image is not None:
                pre_runtime = db_api.get_runtime(id)
                if pre_runtime.status != status.AVAILABLE:
                    raise exc.RuntimeNotAvailableException(
                        'Runtime %s is not available.' % id)

                pre_image = pre_runtime.image
                if pre_image != image:
                    # Ensure there is no function running in the runtime.
                    db_funcs = db_api.get_functions(insecure=True,
                                                    fields=['id'],
                                                    runtime_id=id)
                    func_ids = [func.id for func in db_funcs]

                    for id in func_ids:
                        if etcd_util.get_service_url(id):
                            raise exc.NotAllowedException(
                                'Runtime %s is still in use by functions.' %
                                id)

                    values['status'] = status.UPGRADING
                    self.engine_client.update_runtime(
                        id,
                        image=image,
                        pre_image=pre_image,
                    )

            runtime_db = db_api.update_runtime(id, values)

        return resources.Runtime.from_db_obj(runtime_db)
コード例 #7
0
ファイル: runtime.py プロジェクト: huzhengchuan/qinling
    def put(self, id, runtime):
        """Update runtime.

        Currently, we only support update name, description, image. When
        updating image, send message to engine for asynchronous handling.
        """
        values = {}
        for key in UPDATE_ALLOWED:
            if runtime.to_dict().get(key) is not None:
                values.update({key: runtime.to_dict()[key]})

        LOG.info('Update resource, params: %s',
                 values,
                 resource={
                     'type': self.type,
                     'id': id
                 })

        with db_api.transaction():
            if 'image' in values:
                pre_runtime = db_api.get_runtime(id)
                if pre_runtime.status != status.AVAILABLE:
                    raise exc.RuntimeNotAvailableException(
                        'Runtime %s is not available.' % id)

                pre_image = pre_runtime.image
                if pre_image != values['image']:
                    # Ensure there is no function running in the runtime.
                    db_funcs = db_api.get_functions(insecure=True,
                                                    fields=['id'],
                                                    runtime_id=id)
                    func_ids = [func.id for func in db_funcs]

                    mappings = db_api.get_function_service_mappings(
                        insecure=True, function_id={'in': func_ids})
                    if mappings:
                        raise exc.NotAllowedException(
                            'Runtime %s is still in use by functions.' % id)

                    values['status'] = status.UPGRADING

                    self.engine_client.update_runtime(id,
                                                      image=values['image'],
                                                      pre_image=pre_image)
                else:
                    values.pop('image')

            runtime_db = db_api.update_runtime(id, values)

        return resources.Runtime.from_dict(runtime_db.to_dict())