From 4085a9872854bfa815e676f7e22b496308e60fe4 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Fri, 26 Apr 2024 13:01:43 +0200 Subject: [PATCH] feat: Add support for adding new devices to existing Stratis pools Related: RHEL-31854 --- library/blivet.py | 27 ++++++++++++++++++++++++ tests/tests_stratis.yml | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/library/blivet.py b/library/blivet.py index ec70bb01..e44ac759 100644 --- a/library/blivet.py +++ b/library/blivet.py @@ -1923,6 +1923,33 @@ def _member_management_is_destructive(self): return False + def _manage_members(self): + """ Schedule actions as needed to configure this pool's members. """ + if not self._device: + return + + add_disks = [d for d in self._disks if d not in self._device.ancestors] + remove_disks = [bd for bd in self._device.blockdevs if not any(d in bd.ancestors for d in self._disks)] + + if remove_disks: + raise BlivetAnsibleError("cannot remove members '%s' from pool '%s': Stratis doesn't " + "support removing members from existing pools" % + (", ".join(d.name for d in remove_disks), + self._device.name)) + + if not add_disks: + return + + for disk in add_disks: + member = self._create_one_member(disk) + try: + ac = ActionAddMember(self._device, member) + self._blivet.devicetree.actions.add(ac) + except Exception as e: + raise BlivetAnsibleError("failed to add disk '%s' to pool '%s': %s" % (disk.name, + self._pool['name'], + str(e))) + def _get_format(self): fmt = get_format("stratis") if not fmt.supported or not fmt.formattable: diff --git a/tests/tests_stratis.yml b/tests/tests_stratis.yml index 923272fd..0ccb2860 100644 --- a/tests/tests_stratis.yml +++ b/tests/tests_stratis.yml @@ -160,3 +160,49 @@ - name: Verify role results include_tasks: verify-role-results.yml + + # XXX blivet supporting this is not yet released + - name: Run test only if blivet supports this functionality + when: false + block: + - name: Create one Stratis pool on one disk + include_role: + name: linux-system-roles.storage + vars: + storage_pools: + - name: foo + disks: "{{ unused_disks[0] }}" + type: stratis + + - name: Verify role results + include_tasks: verify-role-results.yml + + - name: Add the second disk to the pool + include_role: + name: linux-system-roles.storage + vars: + storage_pools: + - name: foo + disks: "{{ [unused_disks[0], unused_disks[1]] }}" + type: stratis + + - name: Verify role results + include_tasks: verify-role-results.yml + + - name: Clean up + include_role: + name: linux-system-roles.storage + vars: + storage_pools: + - name: foo + disks: "{{ unused_disks }}" + type: stratis + state: absent + volumes: + - name: test1 + size: "{{ volume_size }}" + mount_point: "{{ mount_location }}" + state: absent + + - name: Verify role results + include_tasks: verify-role-results.yml