Example #1
0
 def test_get_fstab(self):
     self.volume_manager.volume_group = 'vgroup'
     self.volume_manager._add_to_volume_map('device')
     volume_mount = Mock()
     volume_mount.mountpoint = '/var/tmp/kiwi_volumes.XXX/var/tmp'
     volume_mount.device = self.volume_manager.volume_map['device']
     self.volume_manager.mount_list = [volume_mount]
     assert self.volume_manager.get_fstab(None, 'ext3') == [
         '/dev/vgroup/device /var/tmp ext3 a,b,c 0 0'
     ]
     self.volumes.append(
         volume_type(
             name='device',
             size='freespace:100',
             realpath='/var/tmp',
             mountpoint=volume_mount.mountpoint,
             fullsize=False,
             label=None,
             attributes=['enable-for-filesystem-check'],
             is_root_volume=False
         )
     )
     assert self.volume_manager.get_fstab(None, 'ext3') == [
         '/dev/vgroup/device /var/tmp ext3 a,b,c 0 2'
     ]
Example #2
0
 def test_get_fstab(self, mock_command):
     blkid_result = Mock()
     blkid_result.output = 'id'
     mock_command.return_value = blkid_result
     volume_mount = Mock()
     volume_mount.mountpoint = \
         '/var/tmp/kiwi_volumes.XXX/@/.snapshots/1/snapshot/var/tmp'
     volume_mount.device = 'device'
     self.volume_manager.toplevel_volume = '@/.snapshots/1/snapshot'
     self.volume_manager.subvol_mount_list = [volume_mount]
     assert self.volume_manager.get_fstab() == [
         'LABEL=id /var/tmp btrfs defaults,subvol=@/var/tmp 0 0'
     ]
     self.volumes.append(
         volume_type(name='device',
                     size='freespace:100',
                     realpath='/var/tmp',
                     mountpoint=volume_mount.mountpoint,
                     fullsize=False,
                     label=None,
                     attributes=['enable-for-filesystem-check'],
                     is_root_volume=False))
     assert self.volume_manager.get_fstab() == [
         'LABEL=id /var/tmp btrfs defaults,subvol=@/var/tmp 0 2'
     ]
Example #3
0
 def setup(self, mock_path):
     self.volumes = [
         volume_type(
             name='LVRoot', size='freespace:100', realpath='/',
             mountpoint=None, fullsize=False, label=None, attributes=[],
             is_root_volume=True
         ),
         volume_type(
             name='LVSwap', size='size:100', realpath='swap',
             mountpoint=None, fullsize=False, label='SWAP', attributes=[],
             is_root_volume=False
         ),
         volume_type(
             name='LVetc', size='freespace:200', realpath='/etc',
             mountpoint='/etc', fullsize=False, label='etc', attributes=[],
             is_root_volume=False
         ),
         volume_type(
             name='myvol', size='size:500', realpath='/data',
             mountpoint='LVdata', fullsize=False, label=None, attributes=[],
             is_root_volume=False
         ),
         volume_type(
             name='LVhome', size=None, realpath='/home',
             mountpoint='/home', fullsize=True, label=None, attributes=[],
             is_root_volume=False
         ),
     ]
     mock_path.return_value = True
     self.device_map = {
         'root': Mock()
     }
     self.device_map['root'].is_loop = Mock(
         return_value=True
     )
     self.device_map['root'].get_device = Mock(
         return_value='/dev/storage'
     )
     self.volume_manager = VolumeManagerLVM(
         self.device_map, 'root_dir', self.volumes,
         {'some-arg': 'some-val', 'fs_mount_options': ['a,b,c']}
     )
     assert self.volume_manager.mount_options == 'a,b,c'
Example #4
0
 def setup(self, mock_path):
     self.volumes = [
         volume_type(name='LVRoot',
                     size='freespace:100',
                     realpath='/',
                     mountpoint=None,
                     fullsize=False,
                     label=None,
                     attributes=[],
                     is_root_volume=True),
         volume_type(name='LVetc',
                     size='freespace:200',
                     realpath='/etc',
                     mountpoint='/etc',
                     fullsize=False,
                     label=None,
                     attributes=[],
                     is_root_volume=False),
         volume_type(name='myvol',
                     size='size:500',
                     realpath='/data',
                     mountpoint='LVdata',
                     fullsize=False,
                     label=None,
                     attributes=[],
                     is_root_volume=False),
         volume_type(name='LVhome',
                     size=None,
                     realpath='/home',
                     mountpoint='/home',
                     fullsize=True,
                     label=None,
                     attributes=[],
                     is_root_volume=False)
     ]
     mock_path.return_value = True
     self.device_map = {'root': Mock()}
     self.device_map['root'].is_loop = Mock(return_value=True)
     self.device_map['root'].get_device = Mock(return_value='/dev/storage')
     self.volume_manager = VolumeManagerBtrfs(self.device_map, 'root_dir',
                                              self.volumes)
Example #5
0
    def test_create_volumes(
        self, mock_attrs, mock_mount, mock_mapped_device, mock_fs,
        mock_command, mock_size, mock_create, mock_os_exists
    ):
        mock_os_exists_return_list = [True, True, False, False, False]

        def mock_os_exists_return(path):
            return mock_os_exists_return_list.pop()

        mock_os_exists.side_effect = mock_os_exists_return
        filesystem = Mock()
        mock_fs.return_value = filesystem
        self.volume_manager.mountpoint = 'tmpdir'
        mock_mapped_device.return_value = 'mapped_device'
        size = Mock()
        size.customize = Mock(
            return_value=42
        )
        mock_size.return_value = size
        self.volume_manager.volume_group = 'volume_group'
        self.volume_manager.create_volumes('ext3')
        myvol_size = 500
        etc_size = 200 + 42 + Defaults.get_min_volume_mbytes()
        root_size = 100 + 42 + Defaults.get_min_volume_mbytes()

        assert mock_attrs.call_args_list == [
            call(
                'root_dir', volume_type(
                    name='LVSwap', size='size:100', realpath='swap',
                    mountpoint=None, fullsize=False, label='SWAP',
                    attributes=[], is_root_volume=False
                )
            ),
            call(
                'root_dir', volume_type(
                    name='LVRoot', size='freespace:100', realpath='/',
                    mountpoint=None, fullsize=False, label=None,
                    attributes=[], is_root_volume=True
                )
            ),
            call(
                'root_dir', volume_type(
                    name='myvol', size='size:500', realpath='/data',
                    mountpoint='LVdata', fullsize=False, label=None,
                    attributes=[], is_root_volume=False
                )
            ),
            call(
                'root_dir', volume_type(
                    name='LVetc', size='freespace:200', realpath='/etc',
                    mountpoint='/etc', fullsize=False, label='etc',
                    attributes=[], is_root_volume=False
                )
            )
        ]
        assert mock_mount.call_args_list == [
            call(device='/dev/volume_group/LVRoot', mountpoint='tmpdir'),
            call(device='/dev/volume_group/myvol', mountpoint='tmpdir//data'),
            call(device='/dev/volume_group/LVetc', mountpoint='tmpdir//etc'),
            call(device='/dev/volume_group/LVhome', mountpoint='tmpdir//home')
        ]
        assert mock_command.call_args_list == [
            call(
                ['lvcreate'] + self.volume_manager.lvm_tool_options + [
                    '-Zn', '-L', '100', '-n', 'LVSwap', 'volume_group'
                ]
            ),
            call(
                ['vgscan'] + self.volume_manager.lvm_tool_options + [
                    '--mknodes'
                ]
            ),
            call(
                ['lvcreate'] + self.volume_manager.lvm_tool_options + [
                    '-Zn', '-L', format(root_size), '-n', 'LVRoot',
                    'volume_group'
                ]
            ),
            call(
                ['vgscan'] + self.volume_manager.lvm_tool_options + [
                    '--mknodes'
                ]
            ),
            call(
                ['lvcreate'] + self.volume_manager.lvm_tool_options + [
                    '-Zn', '-L', format(myvol_size), '-n', 'myvol',
                    'volume_group'
                ]
            ),
            call(
                ['vgscan'] + self.volume_manager.lvm_tool_options + [
                    '--mknodes'
                ]
            ),
            call(
                ['lvcreate'] + self.volume_manager.lvm_tool_options + [
                    '-Zn', '-L', format(etc_size), '-n', 'LVetc',
                    'volume_group'
                ]
            ),
            call(
                ['vgscan'] + self.volume_manager.lvm_tool_options + [
                    '--mknodes'
                ]
            ),
            call(
                ['lvcreate'] + self.volume_manager.lvm_tool_options + [
                    '-Zn', '-l', '+100%FREE', '-n', 'LVhome', 'volume_group'
                ]
            ),
            call(
                ['vgscan'] + self.volume_manager.lvm_tool_options + [
                    '--mknodes'
                ]
            )
        ]
        assert mock_fs.call_args_list == [
            call(
                custom_args={'create_options': [], 'mount_options': ['a,b,c']},
                device_provider='mapped_device',
                name='ext3'
            ),
            call(
                custom_args={'create_options': [], 'mount_options': ['a,b,c']},
                device_provider='mapped_device',
                name='ext3'
            ),
            call(
                custom_args={'create_options': [], 'mount_options': ['a,b,c']},
                device_provider='mapped_device',
                name='ext3'
            ),
            call(
                custom_args={'create_options': [], 'mount_options': ['a,b,c']},
                device_provider='mapped_device',
                name='ext3'
            )
        ]
        assert filesystem.create_on_device.call_args_list == [
            call(label='ROOT'),
            call(label=None),
            call(label='etc'),
            call(label=None)
        ]

        assert mock_create.call_args_list == [
            call('root_dir/etc'), call('root_dir/data'), call('root_dir/home')
        ]
        self.volume_manager.volume_group = None
Example #6
0
    def test_create_volumes(self, mock_attrs, mock_path, mock_mount,
                            mock_command, mock_os_exists):
        volume_mount = Mock()
        mock_mount.return_value = volume_mount
        self.volume_manager.mountpoint = 'tmpdir'
        self.volume_manager.custom_args['root_is_snapshot'] = True
        mock_os_exists.return_value = False

        self.volume_manager.create_volumes('btrfs')

        assert mock_attrs.call_args_list == [
            call(
                'tmpdir/@/',
                volume_type(name='myvol',
                            size='size:500',
                            realpath='/data',
                            mountpoint='LVdata',
                            fullsize=False,
                            label=None,
                            attributes=[],
                            is_root_volume=False)),
            call(
                'tmpdir/@/',
                volume_type(name='LVetc',
                            size='freespace:200',
                            realpath='/etc',
                            mountpoint='/etc',
                            fullsize=False,
                            label=None,
                            attributes=[],
                            is_root_volume=False)),
            call(
                'tmpdir/@/',
                volume_type(name='LVhome',
                            size=None,
                            realpath='/home',
                            mountpoint='/home',
                            fullsize=True,
                            label=None,
                            attributes=[],
                            is_root_volume=False))
        ]
        assert mock_path.call_args_list == [
            call('root_dir/etc'),
            call('root_dir/data'),
            call('root_dir/home'),
            call('tmpdir/@'),
            call('tmpdir/@'),
            call('tmpdir/@')
        ]
        assert mock_command.call_args_list == [
            call(['btrfs', 'subvolume', 'create', 'tmpdir/@/data']),
            call(['btrfs', 'subvolume', 'create', 'tmpdir/@/etc']),
            call(['btrfs', 'subvolume', 'create', 'tmpdir/@/home'])
        ]
        assert mock_mount.call_args_list == [
            call(device='/dev/storage',
                 mountpoint='tmpdir/@/.snapshots/1/snapshot/data'),
            call(device='/dev/storage',
                 mountpoint='tmpdir/@/.snapshots/1/snapshot/etc'),
            call(device='/dev/storage',
                 mountpoint='tmpdir/@/.snapshots/1/snapshot/home')
        ]