def test_add(self):
        """Test that we can add an image via the filesystem backend"""
        ChunkedFile.CHUNKSIZE = 1024
        expected_image_id = 42
        expected_file_size = 1024 * 5  # 5K
        expected_file_contents = "*" * expected_file_size
        expected_checksum = hashlib.md5(expected_file_contents).hexdigest()
        expected_location = "file://%s/%s" % (stubs.FAKE_FILESYSTEM_ROOTDIR,
                                              expected_image_id)
        image_file = StringIO.StringIO(expected_file_contents)

        location, size, checksum = FilesystemBackend.add(42, image_file,
                                                         FILESYSTEM_OPTIONS)

        self.assertEquals(expected_location, location)
        self.assertEquals(expected_file_size, size)
        self.assertEquals(expected_checksum, checksum)

        url_pieces = urlparse.urlparse("file:///tmp/glance-tests/42")
        new_image_file = FilesystemBackend.get(url_pieces)
        new_image_contents = ""
        new_image_file_size = 0

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

        self.assertEquals(expected_file_contents, new_image_contents)
        self.assertEquals(expected_file_size, new_image_file_size)
예제 #2
0
    def test_delete(self):
        """
        Test we can delete an existing image in the filesystem store
        """
        loc = get_location_from_uri("file:///tmp/glance-tests/2")
        FilesystemBackend.delete(loc)

        self.assertRaises(exception.NotFound,
                          FilesystemBackend.get,
                          loc)
    def test_delete(self):
        """
        Test we can delete an existing image in the filesystem store
        """
        url_pieces = urlparse.urlparse("file:///tmp/glance-tests/2")

        FilesystemBackend.delete(url_pieces)

        self.assertRaises(exception.NotFound,
                          FilesystemBackend.get,
                          url_pieces)
    def test_get(self):
        """Test a "normal" retrieval of an image in chunks"""
        url_pieces = urlparse.urlparse("file:///tmp/glance-tests/2")
        image_file = FilesystemBackend.get(url_pieces)

        expected_data = "chunk00000remainder"
        expected_num_chunks = 2
        data = ""
        num_chunks = 0

        for chunk in image_file:
            num_chunks += 1
            data += chunk
        self.assertEqual(expected_data, data)
        self.assertEqual(expected_num_chunks, num_chunks)
예제 #5
0
    def test_get(self):
        """Test a "normal" retrieval of an image in chunks"""
        loc = get_location_from_uri("file:///tmp/glance-tests/2")
        image_file = FilesystemBackend.get(loc)

        expected_data = "chunk00000remainder"
        expected_num_chunks = 2
        data = ""
        num_chunks = 0

        for chunk in image_file:
            num_chunks += 1
            data += chunk
        self.assertEqual(expected_data, data)
        self.assertEqual(expected_num_chunks, num_chunks)