예제 #1
0
    def write_conf(self, **kwargs):
        """
        Writes the configuration file for the server to its intended
        destination.  Returns the name of the configuration file.
        """

        if self.conf_file_name:
            return self.conf_file_name
        if not self.conf_base:
            raise RuntimeError("Subclass did not populate config_base!")

        conf_override = self.__dict__.copy()
        if kwargs:
            conf_override.update(**kwargs)

        # A config file to use just for this test...we don't want
        # to trample on currently-running Tank servers, now do we?

        conf_dir = os.path.join(self.test_dir, 'etc')
        conf_filepath = os.path.join(conf_dir, "%s.conf" % self.server_name)
        utils.safe_mkdirs(conf_dir)
        with open(conf_filepath, 'wb') as conf_file:
            conf_file.write(self.conf_base % conf_override)
            conf_file.flush()
            self.conf_file_name = conf_file.name

        return self.conf_file_name
예제 #2
0
    def write_conf(self, **kwargs):
        """
        Writes the configuration file for the server to its intended
        destination.  Returns the name of the configuration file.
        """

        if self.conf_file_name:
            return self.conf_file_name
        if not self.conf_base:
            raise RuntimeError("Subclass did not populate config_base!")

        conf_override = self.__dict__.copy()
        if kwargs:
            conf_override.update(**kwargs)

        # A config file to use just for this test...we don't want
        # to trample on currently-running Tank servers, now do we?

        conf_dir = os.path.join(self.test_dir, 'etc')
        conf_filepath = os.path.join(conf_dir, "%s.conf" % self.server_name)
        utils.safe_mkdirs(conf_dir)
        with open(conf_filepath, 'wb') as conf_file:
            conf_file.write(self.conf_base % conf_override)
            conf_file.flush()
            self.conf_file_name = conf_file.name

        return self.conf_file_name
예제 #3
0
def schedule_delete_from_backend(uri, conf, context, image_id, **kwargs):
    """
    Given a uri and a time, schedule the deletion of an image.
    """
    conf.register_opts(delete_opts)
    if not conf.delayed_delete:
        registry.update_image_metadata(context, image_id,
                                       {'status': 'deleted'})
        try:
            return delete_from_backend(uri, **kwargs)
        except (UnsupportedBackend, exception.NotFound):
            msg = _("Failed to delete image from store (%(uri)s).") % locals()
            logger.error(msg)

    datadir = get_scrubber_datadir(conf)
    delete_time = time.time() + conf.scrub_time
    file_path = os.path.join(datadir, str(image_id))
    utils.safe_mkdirs(datadir)

    if os.path.exists(file_path):
        msg = _("Image id %(image_id)s already queued for delete") % {
                'image_id': image_id}
        raise exception.Duplicate(msg)

    with open(file_path, 'w') as f:
        f.write('\n'.join([uri, str(int(delete_time))]))
    os.chmod(file_path, 0600)
    os.utime(file_path, (delete_time, delete_time))

    registry.update_image_metadata(context, image_id,
                                   {'status': 'pending_delete'})
예제 #4
0
def schedule_delete_from_backend(uri, conf, context, image_id, **kwargs):
    """
    Given a uri and a time, schedule the deletion of an image.
    """
    conf.register_opts(delete_opts)
    if not conf.delayed_delete:
        registry.update_image_metadata(context, image_id,
                                       {'status': 'deleted'})
        try:
            return delete_from_backend(uri, **kwargs)
        except (UnsupportedBackend, exception.NotFound):
            msg = _("Failed to delete image from store (%(uri)s).") % locals()
            logger.error(msg)

    datadir = get_scrubber_datadir(conf)
    delete_time = time.time() + conf.scrub_time
    file_path = os.path.join(datadir, str(image_id))
    utils.safe_mkdirs(datadir)

    if os.path.exists(file_path):
        msg = _("Image id %(image_id)s already queued for delete") % {
            'image_id': image_id
        }
        raise exception.Duplicate(msg)

    with open(file_path, 'w') as f:
        f.write('\n'.join([uri, str(int(delete_time))]))
    os.chmod(file_path, 0600)
    os.utime(file_path, (delete_time, delete_time))

    registry.update_image_metadata(context, image_id,
                                   {'status': 'pending_delete'})
예제 #5
0
    def __init__(self, conf, **local_conf):
        self.conf = conf
        self.conf.register_opts(self.opts)

        self.datadir = store.get_scrubber_datadir(conf)
        self.cleanup = self.conf.cleanup_scrubber
        self.cleanup_time = self.conf.cleanup_scrubber_time

        host, port = registry.get_registry_addr(conf)

        logger.info(_("Initializing scrubber with conf: %s") %
                    {'datadir': self.datadir, 'cleanup': self.cleanup,
                     'cleanup_time': self.cleanup_time,
                     'registry_host': host, 'registry_port': port})

        self.registry = client.RegistryClient(host, port)

        utils.safe_mkdirs(self.datadir)

        store.create_stores(conf)
예제 #6
0
파일: base.py 프로젝트: wendy-king/x7_venv
    def set_paths(self):
        """
        Creates all necessary directories under the base cache directory
        """

        self.base_dir = self.conf.image_cache_dir
        if self.base_dir is None:
            msg = _('Failed to read %s from config') % 'image_cache_dir'
            logger.error(msg)
            driver = self.__class__.__module__
            raise exception.BadDriverConfiguration(driver_name=driver,
                                                   reason=msg)

        self.incomplete_dir = os.path.join(self.base_dir, 'incomplete')
        self.invalid_dir = os.path.join(self.base_dir, 'invalid')
        self.queue_dir = os.path.join(self.base_dir, 'queue')

        dirs = [self.incomplete_dir, self.invalid_dir, self.queue_dir]

        for path in dirs:
            utils.safe_mkdirs(path)
예제 #7
0
    def set_paths(self):
        """
        Creates all necessary directories under the base cache directory
        """

        self.base_dir = self.conf.image_cache_dir
        if self.base_dir is None:
            msg = _('Failed to read %s from config') % 'image_cache_dir'
            logger.error(msg)
            driver = self.__class__.__module__
            raise exception.BadDriverConfiguration(driver_name=driver,
                                                   reason=msg)

        self.incomplete_dir = os.path.join(self.base_dir, 'incomplete')
        self.invalid_dir = os.path.join(self.base_dir, 'invalid')
        self.queue_dir = os.path.join(self.base_dir, 'queue')

        dirs = [self.incomplete_dir, self.invalid_dir, self.queue_dir]

        for path in dirs:
            utils.safe_mkdirs(path)
예제 #8
0
    def setUp(self):
        """
        Test to see if the pre-requisites for the image cache
        are working (python-xattr installed and xattr support on the
        filesystem)
        """
        if getattr(self, 'disable', False):
            return

        self.cache_dir = os.path.join(
            "/", "tmp", "test.cache.%d" % random.randint(0, 1000000))
        utils.safe_mkdirs(self.cache_dir)

        if not getattr(self, 'inited', False):
            try:
                import xattr
            except ImportError:
                self.inited = True
                self.disabled = True
                self.disabled_message = ("python-xattr not installed.")
                return

        self.inited = True
        self.disabled = False
        self.conf = test_utils.TestConfigOpts({
            'image_cache_dir': self.cache_dir,
            'image_cache_driver': 'xattr',
            'image_cache_max_size': 1024 * 5,
            'registry_host': '0.0.0.0',
            'registry_port': 9191
        })
        self.cache = image_cache.ImageCache(self.conf)

        if not xattr_writes_supported(self.cache_dir):
            self.inited = True
            self.disabled = True
            self.disabled_message = ("filesystem does not support xattr")
            return
예제 #9
0
    def setUp(self):

        self.test_id = random.randint(0, 100000)
        self.test_dir = os.path.join("/", "tmp", "test.%d" % self.test_id)
        utils.safe_mkdirs(self.test_dir)

        self.api_protocol = 'http'
        self.api_port = get_unused_port()
        self.registry_port = get_unused_port()

        self.api_server = ApiServer(self.test_dir,
                                    self.api_port,
                                    self.registry_port)
        self.registry_server = RegistryServer(self.test_dir,
                                              self.registry_port)

        self.scrubber_daemon = ScrubberDaemon(self.test_dir,
                                              self.registry_port)

        self.pid_files = [self.api_server.pid_file,
                          self.registry_server.pid_file,
                          self.scrubber_daemon.pid_file]
        self.files_to_destroy = []
예제 #10
0
    def setUp(self):

        self.test_id = random.randint(0, 100000)
        self.test_dir = os.path.join("/", "tmp", "test.%d" % self.test_id)
        utils.safe_mkdirs(self.test_dir)

        self.api_protocol = 'http'
        self.api_port = get_unused_port()
        self.registry_port = get_unused_port()

        self.api_server = ApiServer(self.test_dir, self.api_port,
                                    self.registry_port)
        self.registry_server = RegistryServer(self.test_dir,
                                              self.registry_port)

        self.scrubber_daemon = ScrubberDaemon(self.test_dir,
                                              self.registry_port)

        self.pid_files = [
            self.api_server.pid_file, self.registry_server.pid_file,
            self.scrubber_daemon.pid_file
        ]
        self.files_to_destroy = []
예제 #11
0
    def setUp(self):
        """
        Test to see if the pre-requisites for the image cache
        are working (python-xattr installed and xattr support on the
        filesystem)
        """
        if getattr(self, 'disable', False):
            return

        self.cache_dir = os.path.join("/", "tmp", "test.cache.%d" %
                                      random.randint(0, 1000000))
        utils.safe_mkdirs(self.cache_dir)

        if not getattr(self, 'inited', False):
            try:
                import xattr
            except ImportError:
                self.inited = True
                self.disabled = True
                self.disabled_message = ("python-xattr not installed.")
                return

        self.inited = True
        self.disabled = False
        self.conf = test_utils.TestConfigOpts({
                'image_cache_dir': self.cache_dir,
                'image_cache_driver': 'xattr',
                'image_cache_max_size': 1024 * 5,
                'registry_host': '0.0.0.0',
                'registry_port': 9191})
        self.cache = image_cache.ImageCache(self.conf)

        if not xattr_writes_supported(self.cache_dir):
            self.inited = True
            self.disabled = True
            self.disabled_message = ("filesystem does not support xattr")
            return
예제 #12
0
    def __init__(self, conf, **local_conf):
        self.conf = conf
        self.conf.register_opts(self.opts)

        self.datadir = store.get_scrubber_datadir(conf)
        self.cleanup = self.conf.cleanup_scrubber
        self.cleanup_time = self.conf.cleanup_scrubber_time

        host, port = registry.get_registry_addr(conf)

        logger.info(
            _("Initializing scrubber with conf: %s") % {
                'datadir': self.datadir,
                'cleanup': self.cleanup,
                'cleanup_time': self.cleanup_time,
                'registry_host': host,
                'registry_port': port
            })

        self.registry = client.RegistryClient(host, port)

        utils.safe_mkdirs(self.datadir)

        store.create_stores(conf)