@mock.patch('cloudbaseinit.metadata.services.osconfigdrive.windows.'
                'WindowsConfigDriveManager._extract_files_from_iso')
    @mock.patch('cloudbaseinit.metadata.services.osconfigdrive.windows.'
                'WindowsConfigDriveManager._write_iso_file')
    @mock.patch('cloudbaseinit.metadata.services.osconfigdrive.windows.'
                'WindowsConfigDriveManager._get_iso_file_size')
    def _test_extract_iso_from_devices(self, mock_get_iso_file_size,
                                       mock_write_iso_file,
                                       mock_extract_files_from_iso,
                                       found=True):
        # For every device (mock) in the list of available devices:
        #   first - skip (no size)
        #   second - error (throws Exception)
        #   third - extract (is ok)
        #   fourth - unreachable (already found ok device)
        size = 100 * 512
        devices = [mock.MagicMock() for _ in range(4)]
        devices[1].__enter__.side_effect = [Exception]
        rest = [size] if found else [None]
        mock_get_iso_file_size.side_effect = [None] + rest * 2
        file_path = os.path.join("tempdir", "uuid.iso")

        with self.snatcher:
            response = self._config_manager._extract_iso_from_devices(devices)
        self.mock_gettempdir.assert_called_once_with()
        mock_get_iso_file_size.assert_has_calls([
            mock.call(devices[0]), mock.call(devices[2])])
        expected_log = [
            "ISO extraction failed on %(device)s with %(error)r" %
            {"device": devices[1], "error": Exception()}]
        if found:
            mock_write_iso_file.assert_called_once_with(devices[2],
                                                        file_path, size)
            mock_extract_files_from_iso.assert_called_once_with(file_path)
            expected_log.append("ISO9660 disk found on %s" % devices[2])
        self.assertEqual(expected_log, self.snatcher.output)
        self.assertEqual(found, response)
dataset/ETHPy150Open openstack/cloudbase-init/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py/TestWindowsConfigDriveManager._test_extract_iso_from_devices/original