File: fstab_test.py

package info (click to toggle)
kiwi 10.2.36-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 7,664 kB
  • sloc: python: 69,179; sh: 4,228; xml: 3,383; ansic: 391; makefile: 353
file content (122 lines) | stat: -rw-r--r-- 4,246 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import io
import logging
from pytest import fixture
from unittest.mock import (
    MagicMock, patch, call
)
from kiwi.utils.fstab import Fstab
from kiwi.utils.fstab import fstab_entry_type


class TestFstab(object):
    @fixture(autouse=True)
    def inject_fixtures(self, caplog):
        self._caplog = caplog

    def setup(self):
        self.fstab = Fstab()
        self.fstab.read('../data/fstab')

    def setup_method(self, cls):
        self.setup()

    def test_read(self):
        with self._caplog.at_level(logging.WARNING):
            self.fstab.read('../data/fstab')
            assert format(
                'Mountpoint for "LABEL=bar /home xfs defaults 0 0" '
                'in use by "LABEL=foo /home ext4 defaults 0 0", skipped'
            ) in self._caplog.text

    def test_get_devices(self):
        assert self.fstab.get_devices() == [
            fstab_entry_type(
                fstype='ext4',
                mountpoint='/',
                device_path='/dev/disk/'
                'by-uuid/bd604632-663b-4d4c-b5b0-8d8686267ea2',
                device_spec='UUID=bd604632-663b-4d4c-b5b0-8d8686267ea2',
                options='acl,user_xattr',
                dump='0',
                fs_passno='1'
            ),
            fstab_entry_type(
                fstype='swap',
                mountpoint='swap',
                device_path='/dev/disk/'
                'by-uuid/daa5a8c3-5c72-4343-a1d4-bb74ec4e586e',
                device_spec='UUID=daa5a8c3-5c72-4343-a1d4-bb74ec4e586e',
                options='defaults',
                dump='0',
                fs_passno='0'
            ),
            fstab_entry_type(
                fstype='vfat',
                mountpoint='/boot/efi',
                device_path='/dev/disk/by-uuid/FCF7-B051',
                device_spec='UUID=FCF7-B051',
                options='defaults',
                dump='0',
                fs_passno='0'
            ),
            fstab_entry_type(
                fstype='xfs',
                mountpoint='/boot',
                device_path='/dev/disk/by-label/BOOT',
                device_spec='LABEL=BOOT',
                options='defaults',
                dump='0',
                fs_passno='0'
            ),
            fstab_entry_type(
                fstype='ext4',
                mountpoint='/home',
                device_path='/dev/disk/by-label/foo',
                device_spec='LABEL=foo',
                options='defaults',
                dump='0',
                fs_passno='0'
            ),
            fstab_entry_type(
                fstype='ext4',
                mountpoint='/bar',
                device_path='/dev/disk/by-partuuid/3c8bd108-01',
                device_spec='PARTUUID=3c8bd108-01',
                options='defaults',
                dump='0',
                fs_passno='0'
            ),
            fstab_entry_type(
                fstype='ext4',
                mountpoint='/foo',
                device_path='/dev/mynode',
                device_spec='/dev/mynode',
                options='defaults',
                dump='0',
                fs_passno='0'
            )
        ]

    def test_export_and_canonical_order(self):
        with patch('builtins.open', create=True) as mock_open:
            mock_open.return_value = MagicMock(spec=io.IOBase)
            self.fstab.export('filename')
            file_handle = mock_open.return_value.__enter__.return_value
            mock_open.assert_called_once_with(
                'filename', 'w'
            )
            assert file_handle.write.call_args_list == [
                call(
                    'UUID=daa5a8c3-5c72-4343-a1d4-bb74ec4e586e swap '
                    'swap defaults 0 0\n'
                ),
                call(
                    'UUID=bd604632-663b-4d4c-b5b0-8d8686267ea2 / '
                    'ext4 acl,user_xattr 0 1\n'
                ),
                call('PARTUUID=3c8bd108-01 /bar ext4 defaults 0 0\n'),
                call('LABEL=BOOT /boot xfs defaults 0 0\n'),
                call('/dev/mynode /foo ext4 defaults 0 0\n'),
                call('LABEL=foo /home ext4 defaults 0 0\n'),
                call('UUID=FCF7-B051 /boot/efi vfat defaults 0 0\n')
            ]