예제 #1
0
def run_task(task_id, task_type, context,
             task_repo=None, image_repo=None, image_factory=None):
    #TODO(nikhil): if task_repo is None get new task repo
    #TODO(nikhil): if image_repo is None get new image repo
    #TODO(nikhil): if image_factory is None get new image factory
    LOG.info(_LI("Loading known task scripts for task_id %(task_id)s "
                 "of type %(task_type)s"), {'task_id': task_id,
                                            'task_type': task_type})
    if task_type == 'import':
        image_import.run(task_id, context, task_repo,
                         image_repo, image_factory)

    else:
        msg = _LE("This task type %(task_type)s is not supported by the "
                  "current deployment of Glance. Please refer the "
                  "documentation provided by OpenStack or your operator "
                  "for more information.") % {'task_type': task_type}
        LOG.error(msg)
        task = task_repo.get(task_id)
        task.fail(msg)
        if task_repo:
            task_repo.save(task)
        else:
            LOG.error(_LE("Failed to save task %(task_id)s in DB as task_repo "
                          "is %(task_repo)s"), {"task_id": task_id,
                                                "task_repo": task_repo})
예제 #2
0
    def test_run(self):
        with mock.patch.object(image_import_script, "_execute") as mock_execute:
            task_id = mock.ANY
            context = mock.ANY
            task_repo = mock.ANY
            image_repo = mock.ANY
            image_factory = mock.ANY
            image_import_script.run(task_id, context, task_repo, image_repo, image_factory)

        mock_execute.assert_called_once_with(task_id, task_repo, image_repo, image_factory)
예제 #3
0
    def test_run(self):
        with mock.patch.object(image_import_script,
                               '_execute') as mock_execute:
            task_id = mock.ANY
            context = mock.ANY
            task_repo = mock.ANY
            image_repo = mock.ANY
            image_factory = mock.ANY
            image_import_script.run(task_id, context, task_repo, image_repo,
                                    image_factory)

        mock_execute.assert_called_once_with(task_id, task_repo, image_repo,
                                             image_factory)
예제 #4
0
파일: __init__.py 프로젝트: yebinama/glance
def run_task(task_id,
             task_type,
             context,
             task_repo=None,
             image_repo=None,
             image_factory=None):
    # TODO(nikhil): if task_repo is None get new task repo
    # TODO(nikhil): if image_repo is None get new image repo
    # TODO(nikhil): if image_factory is None get new image factory
    LOG.info(
        _LI("Loading known task scripts for task_id %(task_id)s "
            "of type %(task_type)s"), {
                'task_id': task_id,
                'task_type': task_type
            })
    if task_type == 'import':
        image_import.run(task_id, context, task_repo, image_repo,
                         image_factory)

    elif task_type == 'api_image_import':
        api_image_import.run(task_id, context, task_repo, image_repo,
                             image_factory)

    else:
        msg = _LE("This task type %(task_type)s is not supported by the "
                  "current deployment of Glance. Please refer the "
                  "documentation provided by OpenStack or your operator "
                  "for more information.") % {
                      'task_type': task_type
                  }
        LOG.error(msg)
        task = task_repo.get(task_id)
        task.fail(msg)
        if task_repo:
            task_repo.save(task)
        else:
            LOG.error(
                _LE("Failed to save task %(task_id)s in DB as task_repo "
                    "is %(task_repo)s"), {
                        "task_id": task_id,
                        "task_repo": task_repo
                    })