def setUp(self):
        """Establish a clean test environment."""
        super(TestMultiStore, self).setUp()
        self.enabled_backends = {
            "file1": "file",
            "file2": "file",
        }
        self.conf = self._CONF
        self.conf(args=[])
        self.conf.register_opt(cfg.DictOpt('enabled_backends'))
        self.config(enabled_backends=self.enabled_backends)
        store.register_store_opts(self.conf)
        self.config(default_backend='file1', group='glance_store')

        # Ensure stores + locations cleared
        location.SCHEME_TO_CLS_BACKEND_MAP = {}
        store.create_multi_stores(self.conf)

        self.addCleanup(setattr, location, 'SCHEME_TO_CLS_BACKEND_MAP',
                        dict())
        self.test_dir = self.useFixture(fixtures.TempDir()).path
        self.addCleanup(self.conf.reset)

        self.store = filesystem.Store(self.conf, backend='file1')
        self.config(filesystem_store_datadir=self.test_dir,
                    filesystem_store_chunk_size=10,
                    group="file1")
        self.store.configure()
        self.register_store_backend_schemes(self.store, 'file', 'file1')
 def setUp(self):
     """Establish a clean test environment."""
     super(TestStore, self).setUp()
     self.store = filesystem.Store(self.conf)
     self.config(filesystem_store_datadir=self.test_dir,
                 filesystem_store_chunk_size=10,
                 stores=['glance.store.filesystem.Store'],
                 group="glance_store")
     self.store.configure()
     self.register_store_schemes(self.store, 'file')
     self.hash_algo = 'sha256'
Beispiel #3
0
 def setUp(self):
     """Establish a clean test environment."""
     super(TestStore, self).setUp()
     self.orig_chunksize = filesystem.Store.READ_CHUNKSIZE
     filesystem.Store.READ_CHUNKSIZE = 10
     self.store = filesystem.Store(self.conf)
     self.config(filesystem_store_datadir=self.test_dir,
                 stores=['glance.store.filesystem.Store'],
                 group="glance_store")
     self.store.configure()
     self.register_store_schemes(self.store, 'file')
    def test_add_to_different_backned(self):
        """Test that we can add an image via the filesystem backend."""
        self.store = filesystem.Store(self.conf, backend='file2')
        self.config(filesystem_store_datadir=self.test_dir,
                    group="file2")
        self.store.configure()
        self.register_store_backend_schemes(self.store, 'file', 'file2')

        filesystem.ChunkedFile.CHUNKSIZE = units.Ki
        expected_image_id = str(uuid.uuid4())
        expected_file_size = 5 * units.Ki  # 5K
        expected_file_contents = b"*" * expected_file_size
        expected_checksum = hashlib.md5(expected_file_contents).hexdigest()
        expected_location = "file://%s/%s" % (self.test_dir,
                                              expected_image_id)
        image_file = six.BytesIO(expected_file_contents)

        loc, size, checksum, metadata = self.store.add(expected_image_id,
                                                       image_file,
                                                       expected_file_size)

        self.assertEqual(expected_location, loc)
        self.assertEqual(expected_file_size, size)
        self.assertEqual(expected_checksum, checksum)
        self.assertEqual(u"file2", metadata['store'])

        uri = "file:///%s/%s" % (self.test_dir, expected_image_id)
        loc = location.get_location_from_uri_and_backend(
            uri, 'file2', conf=self.conf)
        (new_image_file, new_image_size) = self.store.get(loc)
        new_image_contents = b""
        new_image_file_size = 0

        for chunk in new_image_file:
            new_image_file_size += len(chunk)
            new_image_contents += chunk

        self.assertEqual(expected_file_contents, new_image_contents)
        self.assertEqual(expected_file_size, new_image_file_size)