Merge "Add swap support"
This commit is contained in:
commit
950ad3324d
@ -33,7 +33,8 @@ file_system_max_label_length = {
|
||||
"ext3": 16,
|
||||
"ext4": 16,
|
||||
"xfs": 12,
|
||||
"vfat": 11
|
||||
"vfat": 11,
|
||||
"swap": 16
|
||||
}
|
||||
|
||||
|
||||
@ -102,8 +103,10 @@ class FilesystemNode(NodeBase):
|
||||
return (edge_from, edge_to)
|
||||
|
||||
def create(self):
|
||||
if self.type in ('swap'):
|
||||
cmd = ["mkswap"]
|
||||
else:
|
||||
cmd = ["mkfs"]
|
||||
|
||||
cmd.extend(['-t', self.type])
|
||||
if self.opts:
|
||||
cmd.extend(self.opts)
|
||||
@ -113,7 +116,7 @@ class FilesystemNode(NodeBase):
|
||||
else:
|
||||
cmd.extend(["-L", self.label])
|
||||
|
||||
if self.type in ('ext2', 'ext3', 'ext4'):
|
||||
if self.type in ('ext2', 'ext3', 'ext4', 'swap'):
|
||||
cmd.extend(['-U', self.uuid])
|
||||
elif self.type == 'xfs':
|
||||
cmd.extend(['-m', "uuid=%s" % self.uuid])
|
||||
|
@ -73,6 +73,10 @@ class MountPointNode(NodeBase):
|
||||
return (edge_from, edge_to)
|
||||
|
||||
def create(self):
|
||||
if (self.state['filesys'][self.base]['fstype'] == 'swap'):
|
||||
# No need to mount/activate swap during image build.
|
||||
mount_point = self.mount_point = 'none'
|
||||
else:
|
||||
logger.debug("mount called [%s]", self.mount_point)
|
||||
rel_mp = self.mount_point if self.mount_point[0] != '/' \
|
||||
else self.mount_point[1:]
|
||||
@ -95,6 +99,9 @@ class MountPointNode(NodeBase):
|
||||
self.state['mount_order'].append(self.mount_point)
|
||||
|
||||
def umount(self):
|
||||
if (self.state['filesys'][self.base]['fstype'] == 'swap'):
|
||||
# Swap not mounted/activated during image build.
|
||||
return
|
||||
logger.info("Called for [%s]", self.name)
|
||||
# Before calling umount, call 'fstrim' on suitable mounted
|
||||
# file systems. This discards unused blocks from the mounted
|
||||
|
@ -40,12 +40,15 @@ class FstabNode(NodeBase):
|
||||
if 'fstab' not in self.state:
|
||||
self.state['fstab'] = {}
|
||||
|
||||
swap = 'none' in self.state['mount'] and \
|
||||
self.state['mount']['none']['name'] == self.base
|
||||
|
||||
self.state['fstab'][self.base] = {
|
||||
'name': self.name,
|
||||
'base': self.base,
|
||||
'options': self.options,
|
||||
'dump-freq': self.dump_freq,
|
||||
'fsck-passno': self.fsck_passno
|
||||
'options': 'sw' if swap else self.options,
|
||||
'dump-freq': 0 if swap else self.dump_freq,
|
||||
'fsck-passno': 0 if swap else self.fsck_passno
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,12 +27,16 @@
|
||||
lvs:
|
||||
- name: lv_root
|
||||
base: vg
|
||||
size: 2000M
|
||||
size: 1900M
|
||||
|
||||
- name: lv_var
|
||||
base: vg
|
||||
size: 500M
|
||||
|
||||
- name: lv_swap
|
||||
base: vg
|
||||
size: 100M
|
||||
|
||||
- mkfs:
|
||||
base: boot
|
||||
type: ext3
|
||||
@ -62,3 +66,13 @@
|
||||
fstab:
|
||||
options: "noacl"
|
||||
fsck-passno: 2
|
||||
|
||||
- mkfs:
|
||||
name: mkfs_swap
|
||||
base: lv_swap
|
||||
type: "swap"
|
||||
mount:
|
||||
mount_point: none
|
||||
fstab:
|
||||
options: "sw"
|
||||
fsck-passno: 0
|
||||
|
@ -9,13 +9,16 @@
|
||||
- name: root
|
||||
base: image0
|
||||
flags: [boot, primary]
|
||||
size: 55%
|
||||
size: 54%
|
||||
- name: var
|
||||
base: image0
|
||||
size: 40%
|
||||
- name: var_log
|
||||
base: image0
|
||||
size: 5%
|
||||
- name: swap
|
||||
base: image0
|
||||
size: 1%
|
||||
|
||||
- mkfs:
|
||||
base: root
|
||||
@ -67,3 +70,20 @@
|
||||
name: fstab_mount_mkfs_var_log
|
||||
fsck-passno: 1
|
||||
options: defaults
|
||||
|
||||
- mkfs:
|
||||
base: swap
|
||||
name: mkfs_swap
|
||||
type: swap
|
||||
uuid: swap-uuid-1234
|
||||
|
||||
- mount:
|
||||
base: mkfs_swap
|
||||
name: mount_mkfs_swap
|
||||
mount_point: none
|
||||
|
||||
- fstab:
|
||||
base: mount_mkfs_swap
|
||||
name: fstab_mount_mkfs_swap
|
||||
fsck-passno: 0
|
||||
options: sw
|
||||
|
@ -8,7 +8,7 @@
|
||||
partitions:
|
||||
- name: root
|
||||
flags: [boot, primary]
|
||||
size: 55%
|
||||
size: 54%
|
||||
mkfs:
|
||||
type: xfs
|
||||
uuid: root-uuid-1234
|
||||
@ -37,4 +37,13 @@
|
||||
fstab:
|
||||
options: "defaults"
|
||||
fsck-passno: 1
|
||||
|
||||
- name: swap
|
||||
size: 1%
|
||||
mkfs:
|
||||
type: swap
|
||||
uuid: swap-uuid-1234
|
||||
mount:
|
||||
mount_point: none
|
||||
fstab:
|
||||
fsck-passno: 0
|
||||
options: "sw"
|
||||
|
@ -80,6 +80,7 @@ class TestMountOrder(tc.TestGraphGeneration):
|
||||
state['blockdev']['root'] = {'device': '/dev/loopXp1/root'}
|
||||
state['blockdev']['var'] = {'device': '/dev/loopXp2/var'}
|
||||
state['blockdev']['var_log'] = {'device': '/dev/loopXp3/var_log'}
|
||||
state['blockdev']['swap'] = {'device': '/dev/loopXp4/swap'}
|
||||
|
||||
for node in call_order:
|
||||
if isinstance(node, (FilesystemNode, MountPointNode)):
|
||||
@ -89,7 +90,8 @@ class TestMountOrder(tc.TestGraphGeneration):
|
||||
node.umount()
|
||||
|
||||
# ensure that partitions were mounted in order root->var->var/log
|
||||
self.assertListEqual(state['mount_order'], ['/', '/var', '/var/log'])
|
||||
self.assertListEqual(state['mount_order'],
|
||||
['/', '/var', '/var/log', 'none'])
|
||||
|
||||
# fs creation sequence (note we don't care about order of this
|
||||
# as they're all independent)
|
||||
@ -101,7 +103,9 @@ class TestMountOrder(tc.TestGraphGeneration):
|
||||
'-m', 'uuid=var-uuid-1234',
|
||||
'-q', '/dev/loopXp2/var']),
|
||||
mock.call(['mkfs', '-t', 'vfat', '-n', 'VARLOG',
|
||||
'/dev/loopXp3/var_log'])
|
||||
'/dev/loopXp3/var_log']),
|
||||
mock.call(['mkswap', '-L', 'mkfs_swap', '-U', 'swap-uuid-1234',
|
||||
'/dev/loopXp4/swap'])
|
||||
]
|
||||
self.assertEqual(mock_exec_sudo_mkfs.call_count, len(cmd_sequence))
|
||||
mock_exec_sudo_mkfs.assert_has_calls(cmd_sequence, any_order=True)
|
||||
@ -154,6 +158,10 @@ class TestMountOrder(tc.TestGraphGeneration):
|
||||
'device': '/dev/loopXp3',
|
||||
'fstype': 'vfat',
|
||||
},
|
||||
'mkfs_swap': {
|
||||
'device': '/dev/loopXp4',
|
||||
'fstype': 'swap',
|
||||
},
|
||||
}
|
||||
|
||||
for node in call_order:
|
||||
@ -164,7 +172,9 @@ class TestMountOrder(tc.TestGraphGeneration):
|
||||
node.umount()
|
||||
|
||||
# ensure that partitions are mounted in order / -> /boot -> /var
|
||||
self.assertListEqual(state['mount_order'], ['/', '/boot', '/var'])
|
||||
# swap not mounted in runtime, but should be in 'mount_order' list
|
||||
self.assertListEqual(state['mount_order'],
|
||||
['/', '/boot', '/var', 'none'])
|
||||
|
||||
cmd_sequence = [
|
||||
# mount sequence
|
||||
|
4
releasenotes/notes/swap_support-9ac267f56a0c0424.yaml
Normal file
4
releasenotes/notes/swap_support-9ac267f56a0c0424.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds swap as a valid "filesystem" for block devices
|
Loading…
Reference in New Issue
Block a user