summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hudson-Doyle <[email protected]>2019-05-28 23:41:59 +0000
committerServer Team CI Bot <[email protected]>2019-05-28 23:41:59 +0000
commitb6e8a1c1be0b165181f984f1fc81d6d4d0a3ca1a (patch)
treef659a6191aab26caad51ee63defbaeb0c974258e
parent8c347f4d8782b63cb18678d17b4250cfefbdaa73 (diff)
mdadm: fix install to existing raid
Just change the export=False to export=True in the call to mdadm_examine in md_check_array_membership. LP: #1830157
-rw-r--r--curtin/block/mdadm.py2
-rw-r--r--examples/tests/preserve-raid.yaml108
-rw-r--r--examples/tests/preserve.yaml72
-rw-r--r--tests/unittests/test_block_mdadm.py2
-rw-r--r--tests/vmtests/test_preserve.py39
-rw-r--r--tests/vmtests/test_preserve_raid.py39
6 files changed, 260 insertions, 2 deletions
diff --git a/curtin/block/mdadm.py b/curtin/block/mdadm.py
index d8373e3e..b7c4d068 100644
--- a/curtin/block/mdadm.py
+++ b/curtin/block/mdadm.py
@@ -819,7 +819,7 @@ def md_check_array_membership(md_devname, devices):
# validate that all devices are members of the correct array
md_uuid = md_get_uuid(md_devname)
for device in devices:
- dev_examine = mdadm_examine(device, export=False)
+ dev_examine = mdadm_examine(device, export=True)
if 'MD_UUID' not in dev_examine:
raise ValueError('Device is not part of an array: ' + device)
dev_uuid = dev_examine['MD_UUID']
diff --git a/examples/tests/preserve-raid.yaml b/examples/tests/preserve-raid.yaml
new file mode 100644
index 00000000..3a6cc188
--- /dev/null
+++ b/examples/tests/preserve-raid.yaml
@@ -0,0 +1,108 @@
+showtrace: true
+
+bucket:
+ - &setup |
+ parted /dev/disk/by-id/virtio-disk-b --script -- \
+ mklabel gpt \
+ mkpart primary 1GiB 9GiB
+ parted /dev/disk/by-id/virtio-disk-c --script -- \
+ mklabel gpt \
+ mkpart primary 1GiB 9GiB
+ udevadm settle
+ mdadm --create --metadata 1.2 --level 1 -n 2 /dev/md1 --assume-clean \
+ /dev/disk/by-id/virtio-disk-b-part1 /dev/disk/by-id/virtio-disk-c-part1
+ udevadm settle
+ mkfs.ext4 /dev/md1
+ mount /dev/md1 /mnt
+ touch /mnt/existing
+ umount /mnt
+ mdadm --stop /dev/md1
+ udevadm settle
+
+# Create a RAID now to test curtin's reuse of existing RAIDs.
+early_commands:
+ 00-setup-raid: [sh, -exuc, *setup]
+
+storage:
+ config:
+ - type: disk
+ id: id_disk0
+ serial: disk-a
+ ptable: gpt
+ wipe: superblock
+ - type: disk
+ id: id_disk1
+ serial: disk-b
+ ptable: gpt
+ preserve: true
+ - type: disk
+ id: id_disk2
+ serial: disk-c
+ ptable: gpt
+ preserve: true
+ - type: partition
+ id: id_disk0_part1
+ device: id_disk0
+ flag: boot
+ number: 1
+ size: 512M
+ - type: partition
+ id: id_disk0_part2
+ device: id_disk0
+ number: 2
+ size: 3G
+ - type: partition
+ id: id_disk0_part3
+ device: id_disk0
+ number: 3
+ size: 3G
+ - type: partition
+ id: id_disk1_part1
+ device: id_disk1
+ flag: boot
+ number: 1
+ size: 8G
+ preserve: true
+ - type: partition
+ id: id_disk2_part1
+ device: id_disk2
+ flag: boot
+ number: 1
+ size: 8G
+ preserve: true
+ - type: raid
+ id: raid-md1
+ name: md1
+ raidlevel: raid1
+ devices:
+ - id_disk1_part1
+ - id_disk2_part1
+ spare_devices: []
+ metadata: 1.2
+ preserve: true
+ - type: format
+ id: id_efi_format
+ volume: id_disk0_part1
+ fstype: fat32
+ - type: format
+ id: id_root_format
+ volume: id_disk0_part2
+ fstype: ext4
+ - type: format
+ id: id_raid-md1_format
+ volume: raid-md1
+ fstype: ext4
+ preserve: true
+ - type: mount
+ device: id_root_format
+ id: id_root_mount
+ path: /
+ - type: mount
+ id: id_efi_mount
+ device: id_efi_format
+ path: /boot/efi
+ - type: mount
+ id: id_raid-md1_mount
+ device: id_raid-md1_format
+ path: /srv
+ version: 1
diff --git a/examples/tests/preserve.yaml b/examples/tests/preserve.yaml
new file mode 100644
index 00000000..de8a9759
--- /dev/null
+++ b/examples/tests/preserve.yaml
@@ -0,0 +1,72 @@
+showtrace: true
+
+bucket:
+ - &setup |
+ parted /dev/disk/by-id/virtio-disk-a --script -- \
+ mklabel gpt \
+ mkpart primary ext4 2MiB 514MiB \
+ set 1 esp on \
+ mkpart primary ext4 1GiB 4GiB \
+ mkpart primary ext4 4GiB 7GiB
+ udevadm settle
+ mkfs.ext4 /dev/disk/by-id/virtio-disk-a-part3
+ mount /dev/disk/by-id/virtio-disk-a-part3 /mnt
+ touch /mnt/existing
+ umount /mnt
+
+# Partition the disk now to test curtin's reuse of partitions.
+early_commands:
+ 00-setup-disk: [sh, -exuc, *setup]
+
+storage:
+ config:
+ - type: disk
+ id: id_disk0
+ serial: disk-a
+ ptable: gpt
+ preserve: true
+ - type: partition
+ id: id_disk0_part1
+ device: id_disk0
+ flag: boot
+ number: 1
+ size: 512M
+ preserve: true
+ - type: partition
+ id: id_disk0_part2
+ device: id_disk0
+ number: 2
+ size: 3G
+ preserve: true
+ - type: partition
+ id: id_disk0_part3
+ device: id_disk0
+ number: 3
+ size: 3G
+ preserve: true
+ - type: format
+ id: id_efi_format
+ volume: id_disk0_part1
+ fstype: fat32
+ - type: format
+ id: id_root_format
+ volume: id_disk0_part2
+ fstype: ext4
+ - type: format
+ id: id_srv_format
+ volume: id_disk0_part3
+ fstype: ext4
+ preserve: true
+ - type: mount
+ device: id_root_format
+ id: id_root_mount
+ path: /
+ - type: mount
+ id: id_efi_mount
+ device: id_efi_format
+ path: /boot/efi
+ - type: mount
+ id: id_srv_mount
+ device: id_srv_format
+ path: /srv
+ version: 1
diff --git a/tests/unittests/test_block_mdadm.py b/tests/unittests/test_block_mdadm.py
index f9164b45..e778871c 100644
--- a/tests/unittests/test_block_mdadm.py
+++ b/tests/unittests/test_block_mdadm.py
@@ -994,7 +994,7 @@ class TestBlockMdadmMdHelpers(CiTestCase):
mock_examine.side_effect = [md_dict] * len(devices)
expected_calls = []
for dev in devices:
- expected_calls.append(call(dev, export=False))
+ expected_calls.append(call(dev, export=True))
rv = mdadm.md_check_array_membership(mdname, devices)
diff --git a/tests/vmtests/test_preserve.py b/tests/vmtests/test_preserve.py
new file mode 100644
index 00000000..2387aa42
--- /dev/null
+++ b/tests/vmtests/test_preserve.py
@@ -0,0 +1,39 @@
+# This file is part of curtin. See LICENSE file for copyright and license info.
+
+from . import VMBaseClass
+from .releases import base_vm_classes as relbase
+
+import textwrap
+
+
+class TestPreserve(VMBaseClass):
+ """ Test that curtin can reuse a partition. """
+ conf_file = "examples/tests/preserve.yaml"
+ extra_disks = ['10G']
+ uefi = True
+ extra_collect_scripts = [textwrap.dedent("""
+ cd OUTPUT_COLLECT_D
+ ls /srv > ls-srv
+ exit 0
+ """)]
+
+ def test_existing_exists(self):
+ self.assertIn('existing', self.load_collect_file('ls-srv'))
+
+
+class BionicTestPreserve(relbase.bionic, TestPreserve):
+ __test__ = True
+
+
+class CosmicTestPreserve(relbase.cosmic, TestPreserve):
+ __test__ = True
+
+
+class DiscoTestPreserve(relbase.disco, TestPreserve):
+ __test__ = True
+
+
+class EoanTestPreserve(relbase.eoan, TestPreserve):
+ __test__ = True
+
+# vi: ts=4 expandtab syntax=python
diff --git a/tests/vmtests/test_preserve_raid.py b/tests/vmtests/test_preserve_raid.py
new file mode 100644
index 00000000..cf2b8089
--- /dev/null
+++ b/tests/vmtests/test_preserve_raid.py
@@ -0,0 +1,39 @@
+# This file is part of curtin. See LICENSE file for copyright and license info.
+
+from . import VMBaseClass
+from .releases import base_vm_classes as relbase
+
+import textwrap
+
+
+class TestPreserveRAID(VMBaseClass):
+ """ Test that curtin can reuse a RAID. """
+ conf_file = "examples/tests/preserve-raid.yaml"
+ extra_disks = ['10G', '10G', '10G']
+ uefi = True
+ extra_collect_scripts = [textwrap.dedent("""
+ cd OUTPUT_COLLECT_D
+ ls /srv > ls-srv
+ exit 0
+ """)]
+
+ def test_existing_exists(self):
+ self.assertIn('existing', self.load_collect_file('ls-srv'))
+
+
+class BionicTestPreserveRAID(relbase.bionic, TestPreserveRAID):
+ __test__ = True
+
+
+class CosmicTestPreserveRAID(relbase.cosmic, TestPreserveRAID):
+ __test__ = True
+
+
+class DiscoTestPreserveRAID(relbase.disco, TestPreserveRAID):
+ __test__ = True
+
+
+class EoanTestPreserveRAID(relbase.eoan, TestPreserveRAID):
+ __test__ = True
+
+# vi: ts=4 expandtab syntax=python