def test_capacity(self): """Check capacity of several VMDK files.""" vmdk1 = VMDK(path=self.blank_vmdk) self.assertEqual(vmdk1.capacity, "536870912") vmdk2 = VMDK(path=self.input_vmdk) self.assertEqual(vmdk2.capacity, "1073741824")
def test_capacity_drive_type(self): """Check capacity and predicted drive type of several VMDK files.""" vmdk1 = VMDK(path=self.blank_vmdk) self.assertEqual(vmdk1.capacity, "536870912") self.assertEqual(vmdk1.predicted_drive_type, 'harddisk') vmdk2 = VMDK(path=self.input_vmdk) self.assertEqual(vmdk2.capacity, "1073741824") self.assertEqual(vmdk2.predicted_drive_type, 'harddisk')
def test_create_monolithic_sparse(self): """Explicit subformat specification.""" disk_path = os.path.join(self.temp_dir, "foo.vmdk") VMDK.create_file(path=disk_path, capacity="16M", disk_subformat="monolithicSparse") vmdk = VMDK(disk_path) self.assertEqual(vmdk.path, os.path.join(self.temp_dir, "foo.vmdk")) self.assertEqual(vmdk.disk_format, "vmdk") self.assertEqual(vmdk.disk_subformat, "monolithicSparse") self.assertEqual(vmdk.disk_subformat, "monolithicSparse")
def test_create_default(self): """Default creation logic.""" disk_path = os.path.join(self.temp_dir, "foo.vmdk") VMDK.create_file(path=disk_path, capacity="16M") vmdk = VMDK(disk_path) self.assertEqual(vmdk.path, os.path.join(self.temp_dir, "foo.vmdk")) self.assertEqual(vmdk.disk_format, "vmdk") self.assertEqual(vmdk.disk_subformat, "streamOptimized") self.assertEqual(vmdk.disk_subformat, "streamOptimized") if helpers['qemu-img'].version < StrictVersion("2.5.1"): self.assertLogged(**QEMU_VERSION_WARNING)
def test_from_other_image_vmdk(self): """Test conversion of streamOptimized vmdk format to qcow2.""" qcow2 = QCOW2.from_other_image(VMDK(self.blank_vmdk), self.temp_dir) self.assertEqual(qcow2.disk_format, 'qcow2') self.assertEqual(qcow2.disk_subformat, None) self.assertEqual(qcow2.predicted_drive_type, 'harddisk')
def test_convert_from_vmdk_old_qemu(self, mock_vmdktool, mock_qemuimg, *_): """Test conversion from streamOptimized VMDK with old QEMU.""" RAW.from_other_image(VMDK(self.blank_vmdk), self.temp_dir) mock_vmdktool.assert_called_with( ['-s', os.path.join(self.temp_dir, "blank.img"), self.blank_vmdk]) mock_qemuimg.assert_not_called()
def test_convert_from_vmdk_new_qemu(self, mock_vmdktool, mock_qemuimg, *_): """Test conversion from streamOptimized VMDK with new QEMU.""" RAW.from_other_image(VMDK(self.blank_vmdk), self.temp_dir) mock_vmdktool.assert_not_called() mock_qemuimg.assert_called_with([ 'convert', '-O', 'raw', self.blank_vmdk, os.path.join(self.temp_dir, "blank.img") ])
def test_convert_from_vmdk_old_qemu(self, mock_qemuimg, mock_raw, *_): """Test conversion from streamOptimized VMDK with old QEMU.""" mock_raw.return_value = RAW(self.temp_disk) QCOW2.from_other_image(VMDK(self.blank_vmdk), self.temp_dir) mock_qemuimg.assert_called_with([ 'convert', '-O', 'qcow2', self.temp_disk, os.path.join(self.temp_dir, 'blank.qcow2') ])
def other_format_to_vmdk_test(self, disk_format, output_subformat="streamOptimized"): """Test conversion of various formats to vmdk.""" vmdk = VMDK.from_other_image(self.input_disks[disk_format], self.temp_dir, output_subformat) self.assertEqual(vmdk.disk_format, 'vmdk') self.assertEqual(vmdk.disk_subformat, output_subformat) # With older versions of QEMU, COT may convert the input image to a RAW # file as an intermediate step. Make sure it's cleaned up afterwards! temp_image = os.path.join(self.temp_dir, 'foo.img') self.assertFalse(os.path.exists(temp_image), "Temporary image {0} not deleted".format(temp_image))