def _do_mount(self): """Run CD-ROM installation source setup.""" log.debug("Trying to detect CD-ROM automatically") device_tree = STORAGE.get_proxy(DEVICE_TREE) device_name = "" for dev_name in device_tree.FindOpticalMedia(): try: device_data = DeviceData.from_structure( device_tree.GetDeviceData(dev_name)) mount(device_data.path, self._target_mount, "iso9660", "ro") except PayloadSetupError: continue if is_valid_install_disk(self._target_mount): device_name = dev_name log.info("using CD-ROM device %s mounted at %s", dev_name, self._target_mount) break else: unmount(self._target_mount) if not device_name: raise SourceSetupError("Found no CD-ROM")
def find_optical_install_media(): """Find a device with a valid optical install media. Return the first device containing a valid optical install media for this product. FIXME: This is duplicated in SetUpCdromSourceTask.run :return: a device name or None """ device_tree = STORAGE.get_proxy(DEVICE_TREE) for dev in device_tree.FindOpticalMedia(): mountpoint = tempfile.mkdtemp() try: try: payload_utils.mount_device(dev, mountpoint) except MountFilesystemError: continue try: if not is_valid_install_disk(mountpoint): continue finally: payload_utils.unmount_device(dev, mountpoint) finally: os.rmdir(mountpoint) return dev return None
def _choose_installation_device(self, device_tree, devices_candidates): device_name = "" for dev_name in devices_candidates: try: device_data = DeviceData.from_structure( device_tree.GetDeviceData(dev_name)) mount(device_data.path, self._target_mount, "iso9660", "ro") except OSError as e: log.debug("Failed to mount %s: %s", dev_name, str(e)) continue if is_valid_install_disk(self._target_mount): device_name = dev_name log.info("using CD-ROM device %s mounted at %s", dev_name, self._target_mount) break else: unmount(self._target_mount) return device_name
def test_fail_no_file(self, open_mock, get_arch_mock): """Test installation disk validation - no file.""" # the exception is caught inside - check that get_arch() is not called instead assert not is_valid_install_disk("/some/dir") get_arch_mock.assert_not_called()
def test_fail_arch(self, open_mock, get_arch_mock): """Test installation disk validation - arch mismatch.""" assert not is_valid_install_disk("/some/dir")
def test_success(self, open_mock, get_arch_mock): """Test installation disk validation - arch match.""" assert is_valid_install_disk("/some/dir")
def fail_arch_test(self, open_mock, get_arch_mock): """Test installation disk validation - arch mismatch.""" self.assertFalse(is_valid_install_disk("/some/dir"))
def success_test(self, open_mock, get_arch_mock): """Test installation disk validation - arch match.""" self.assertTrue(is_valid_install_disk("/some/dir"))