예제 #1
0
파일: test_utils.py 프로젝트: ppatel826/zun
 def test_get_image_pull_policy(self):
     self.assertEqual('always',
                      utils.get_image_pull_policy('always',
                                                  'latest'))
     self.assertEqual('always',
                      utils.get_image_pull_policy(None,
                                                  'latest'))
     self.assertEqual('ifnotpresent',
                      utils.get_image_pull_policy(None,
                                                  '2.0'))
예제 #2
0
 def test_get_image_pull_policy(self):
     self.assertEqual('always',
                      utils.get_image_pull_policy('always',
                                                  'latest'))
     self.assertEqual('always',
                      utils.get_image_pull_policy(None,
                                                  'latest'))
     self.assertEqual('always',
                      utils.get_image_pull_policy(None,
                                                  '2.0'))
예제 #3
0
파일: manager.py 프로젝트: prameswar/zun
    def _do_container_create(self, context, container, reraise=False):
        LOG.debug('Creating container: %s', container.uuid)

        container.task_state = fields.TaskState.SANDBOX_CREATING
        container.save(context)
        sandbox_id = None
        sandbox_image = 'kubernetes/pause'
        repo, tag = utils.parse_image_name(sandbox_image)
        try:
            image = image_driver.pull_image(context, repo, tag, 'ifnotpresent')
            sandbox_id = self.driver.create_sandbox(context,
                                                    container,
                                                    image=sandbox_image)
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception(_LE("Unexpected exception: %s"),
                              six.text_type(e))
                self._fail_container(context, container, six.text_type(e))
            return

        self.driver.set_sandbox_id(container, sandbox_id)
        container.task_state = fields.TaskState.IMAGE_PULLING
        container.save(context)
        repo, tag = utils.parse_image_name(container.image)
        image_pull_policy = utils.get_image_pull_policy(
            container.image_pull_policy, tag)
        try:
            image = image_driver.pull_image(context, repo, tag,
                                            image_pull_policy)
        except exception.ImageNotFound as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error(six.text_type(e))
                self._do_sandbox_cleanup(context, sandbox_id)
                self._fail_container(context, container, six.text_type(e))
            return
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error(
                    _LE("Error occurred while calling Docker image API: %s"),
                    six.text_type(e))
                self._do_sandbox_cleanup(context, sandbox_id)
                self._fail_container(context, container, six.text_type(e))
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception(_LE("Unexpected exception: %s"),
                              six.text_type(e))
                self._do_sandbox_cleanup(context, sandbox_id)
                self._fail_container(context, container, six.text_type(e))
            return

        container.task_state = fields.TaskState.CONTAINER_CREATING
        container.save(context)
        try:
            container = self.driver.create(context, container, sandbox_id,
                                           image)
            container.addresses = self._get_container_addresses(
                context, container)
            container.task_state = None
            container.save(context)
            return container
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error(
                    _LE("Error occurred while calling Docker create API: %s"),
                    six.text_type(e))
                self._do_sandbox_cleanup(context, sandbox_id)
                self._fail_container(context, container, six.text_type(e))
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception(_LE("Unexpected exception: %s"),
                              six.text_type(e))
                self._do_sandbox_cleanup(context, sandbox_id)
                self._fail_container(context, container, six.text_type(e))
            return
예제 #4
0
    def _do_container_create_base(self,
                                  context,
                                  container,
                                  requested_networks,
                                  requested_volumes,
                                  sandbox=None,
                                  limits=None,
                                  reraise=False):
        self._update_task_state(context, container, consts.IMAGE_PULLING)
        repo, tag = utils.parse_image_name(container.image)
        image_pull_policy = utils.get_image_pull_policy(
            container.image_pull_policy, tag)
        image_driver_name = container.image_driver
        try:
            image, image_loaded = image_driver.pull_image(
                context, repo, tag, image_pull_policy, image_driver_name)
            image['repo'], image['tag'] = repo, tag
            if not image_loaded:
                self.driver.load_image(image['path'])
        except exception.ImageNotFound as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error(six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error("Error occurred while calling Docker image API: %s",
                          six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception("Unexpected exception: %s", six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return

        container.task_state = consts.CONTAINER_CREATING
        container.image_driver = image.get('driver')
        container.save(context)
        try:
            if image['driver'] == 'glance':
                self.driver.read_tar_image(image)
            container = self.driver.create(context, container, image,
                                           requested_networks,
                                           requested_volumes)
            self._update_task_state(context, container, None)
            return container
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error("Error occurred while calling Docker create API: %s",
                          six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context,
                                     container,
                                     six.text_type(e),
                                     unset_host=True)
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception("Unexpected exception: %s", six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context,
                                     container,
                                     six.text_type(e),
                                     unset_host=True)
            return
예제 #5
0
파일: manager.py 프로젝트: zwphit/zun
    def _do_container_create(self, context, container, requested_networks,
                             limits=None, reraise=False):
        LOG.debug('Creating container: %s', container.uuid)

        # check if container driver is NovaDockerDriver and
        # security_groups is non empty, then return by setting
        # the error message in database
        if ('NovaDockerDriver' in CONF.container_driver and
                container.security_groups):
            msg = "security_groups can not be provided with NovaDockerDriver"
            self._fail_container(self, context, container, msg)
            return

        sandbox_id = None
        if self.use_sandbox:
            sandbox_id = self._create_sandbox(context, container,
                                              requested_networks, reraise)
            if sandbox_id is None:
                return

        self._update_task_state(context, container, consts.IMAGE_PULLING)
        repo, tag = utils.parse_image_name(container.image)
        image_pull_policy = utils.get_image_pull_policy(
            container.image_pull_policy, tag)
        image_driver_name = container.image_driver
        try:
            image, image_loaded = image_driver.pull_image(
                context, repo, tag, image_pull_policy, image_driver_name)
            if not image_loaded:
                self.driver.load_image(image['path'])
        except exception.ImageNotFound as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error(six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error("Error occurred while calling Docker image API: %s",
                          six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception("Unexpected exception: %s",
                              six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return

        container.task_state = consts.CONTAINER_CREATING
        container.image_driver = image.get('driver')
        container.save(context)
        try:
            limits = limits
            rt = self._get_resource_tracker()
            with rt.container_claim(context, container, container.host,
                                    limits):
                container = self.driver.create(context, container, image)
                self._update_task_state(context, container, None)
                return container
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error("Error occurred while calling Docker create API: %s",
                          six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e),
                                     unset_host=True)
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception("Unexpected exception: %s",
                              six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e),
                                     unset_host=True)
            return