示例#1
0
 def test_unpack_task_input(self):
     task_input = {"import_from": "foo",
                   "import_from_format": "bar",
                   "image_properties": "baz"}
     task = mock.Mock(task_input=task_input)
     self.assertEqual(task_input,
                      script_utils.unpack_task_input(task))
示例#2
0
def _execute(t_id, task_repo, image_repo, image_factory):
    task = script_utils.get_task(task_repo, t_id)

    if task is None:
        # NOTE: This happens if task is not found in the database. In
        # such cases, there is no way to update the task status so,
        # it's ignored here.
        return

    try:
        task_input = script_utils.unpack_task_input(task)

        image_id = task_input.get('image_id')

        task.succeed({'image_id': image_id})
    except Exception as e:
        # Note: The message string contains Error in it to indicate
        # in the task.message that it's a error message for the user.

        # TODO(nikhil): need to bring back save_and_reraise_exception when
        # necessary
        err_msg = ("Error: " + six.text_type(type(e)) + ': ' +
                   encodeutils.exception_to_unicode(e))
        log_msg = err_msg + ("Task ID %s" % task.task_id)
        LOG.exception(log_msg)

        task.fail(_(err_msg))  # noqa
    finally:
        task_repo.save(task)
示例#3
0
def _execute(t_id, task_repo, image_repo, image_factory):
    task = script_utils.get_task(task_repo, t_id)

    if task is None:
        # NOTE: This happens if task is not found in the database. In
        # such cases, there is no way to update the task status so,
        # it's ignored here.
        return

    try:
        task_input = script_utils.unpack_task_input(task)

        uri = script_utils.validate_location_uri(task_input.get('import_from'))
        image_id = import_image(image_repo, image_factory, task_input, t_id,
                                uri)

        task.succeed({'image_id': image_id})
    except Exception as e:
        # Note: The message string contains Error in it to indicate
        # in the task.message that it's a error message for the user.

        # TODO(nikhil): need to bring back save_and_reraise_exception when
        # necessary
        err_msg = ("Error: " + six.text_type(type(e)) + ': ' +
                   common_utils.exception_to_str(e))
        log_msg = _LE(err_msg + ("Task ID %s" % task.task_id))  # noqa
        LOG.exception(log_msg)

        task.fail(_LE(err_msg))  # noqa
    finally:
        task_repo.save(task)
示例#4
0
 def test_unpack_task_input(self):
     task_input = {"import_from": "foo",
                   "import_from_format": "bar",
                   "image_properties": "baz"}
     task = mock.Mock(task_input=task_input)
     self.assertEqual(task_input,
                      script_utils.unpack_task_input(task))
示例#5
0
    def _get_flow(self, task):
        try:
            task_input = script_utils.unpack_task_input(task)
            uri = script_utils.validate_location_uri(
                task_input.get('import_from'))

            kwds = {
                'uri': uri,
                'task_id': task.task_id,
                'task_type': task.type,
                'context': self.context,
                'task_repo': self.task_repo,
                'image_repo': self.image_repo,
                'image_factory': self.image_factory
            }

            return driver.DriverManager('glance.flows',
                                        task.type,
                                        invoke_on_load=True,
                                        invoke_kwds=kwds).driver
        except urllib.error.URLError as exc:
            raise exception.ImportTaskError(message=exc.reason)
        except exception.BadStoreUri as exc:
            raise exception.ImportTaskError(message=exc.msg)
        except RuntimeError:
            raise NotImplementedError()
示例#6
0
    def _get_flow(self, task):
        try:
            task_input = script_utils.unpack_task_input(task)

            kwds = {
                'task_id': task.task_id,
                'task_type': task.type,
                'context': self.context,
                'task_repo': self.task_repo,
                'image_repo': self.image_repo,
                'image_factory': self.image_factory,
                'backend': task_input.get('backend')
            }

            if self.admin_repo:
                kwds['admin_repo'] = self.admin_repo

            if task.type == "import":
                uri = script_utils.validate_location_uri(
                    task_input.get('import_from'))
                kwds['uri'] = uri
            if task.type == 'api_image_import':
                kwds['image_id'] = task_input['image_id']
                kwds['import_req'] = task_input['import_req']
            return driver.DriverManager('glance.flows',
                                        task.type,
                                        invoke_on_load=True,
                                        invoke_kwds=kwds).driver
        except urllib.error.URLError as exc:
            raise exception.ImportTaskError(message=exc.reason)
        except (exception.BadStoreUri, exception.Invalid) as exc:
            raise exception.ImportTaskError(message=exc.msg)
        except RuntimeError:
            raise NotImplementedError()
示例#7
0
    def _get_flow(self, task):
        try:
            task_input = script_utils.unpack_task_input(task)

            kwds = {
                'task_id': task.task_id,
                'task_type': task.type,
                'context': self.context,
                'task_repo': self.task_repo,
                'image_repo': self.image_repo,
                'image_factory': self.image_factory
            }

            if task.type == "import":
                uri = script_utils.validate_location_uri(
                    task_input.get('import_from'))
                kwds['uri'] = uri
            if task.type == 'api_image_import':
                kwds['image_id'] = task_input['image_id']
                kwds['import_req'] = task_input['import_req']
                kwds['backend'] = task_input['backend']
            return driver.DriverManager('glance.flows', task.type,
                                        invoke_on_load=True,
                                        invoke_kwds=kwds).driver
        except urllib.error.URLError as exc:
            raise exception.ImportTaskError(message=exc.reason)
        except (exception.BadStoreUri, exception.Invalid) as exc:
            raise exception.ImportTaskError(message=exc.msg)
        except RuntimeError:
            raise NotImplementedError()
示例#8
0
    def execute(self):
        task = script_utils.get_task(self.task_repo, self.task_id)
        if task is None:
            return
        task_input = script_utils.unpack_task_input(task)
        image = image_import.create_image(
            self.image_repo, self.image_factory,
            task_input.get('image_properties'), self.task_id)

        LOG.debug("Task %(task_id)s created image %(image_id)s",
                  {'task_id': task.task_id, 'image_id': image.image_id})
        return image.image_id
示例#9
0
    def execute(self):
        task = script_utils.get_task(self.task_repo, self.task_id)
        if task is None:
            return
        task_input = script_utils.unpack_task_input(task)
        image = image_import.create_image(
            self.image_repo, self.image_factory,
            task_input.get('image_properties'), self.task_id)

        LOG.debug("Task %(task_id)s created image %(image_id)s",
                  {'task_id': task.task_id, 'image_id': image.image_id})
        return image.image_id
示例#10
0
    def _get_flow(self, task):
        try:
            task_input = script_utils.unpack_task_input(task)
            uri = script_utils.validate_location_uri(task_input.get("import_from"))

            kwds = {
                "uri": uri,
                "task_id": task.task_id,
                "task_type": task.type,
                "context": self.context,
                "task_repo": self.task_repo,
                "image_repo": self.image_repo,
                "image_factory": self.image_factory,
            }

            return driver.DriverManager("glance.flows", task.type, invoke_on_load=True, invoke_kwds=kwds).driver
        except RuntimeError:
            raise NotImplementedError()
示例#11
0
    def _get_flow(self, task):
        try:
            task_input = script_utils.unpack_task_input(task)
            uri = script_utils.validate_location_uri(
                task_input.get('import_from'))

            kwds = {
                'uri': uri,
                'task_id': task.task_id,
                'task_type': task.type,
                'context': self.context,
                'task_repo': self.task_repo,
                'image_repo': self.image_repo,
                'image_factory': self.image_factory
            }

            return driver.DriverManager('glance.flows', task.type,
                                        invoke_on_load=True,
                                        invoke_kwds=kwds).driver
        except RuntimeError:
            raise NotImplementedError()