Skip to content

Commit

Permalink
Merge pull request #1224 from vojtechtrefny/3.10-devel_stratis-add-me…
Browse files Browse the repository at this point in the history
…mber

Add support for adding new members to existing Stratis pool
  • Loading branch information
vojtechtrefny authored Apr 15, 2024
2 parents 6ab86cb + 8d50582 commit 954b7f1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
25 changes: 25 additions & 0 deletions blivet/devicelibs/stratis.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,28 @@ def create_filesystem(name, pool_uuid, fs_size=None):

# repopulate the stratis info cache so the new filesystem will be added
stratis_info.drop_cache()


def add_device(pool_uuid, device):
if not availability.STRATIS_DBUS.available:
raise StratisError("Stratis DBus service not available")

# repopulate the stratis info cache just to be sure all values are still valid
stratis_info.drop_cache()

pool_info = stratis_info.pools[pool_uuid]

try:
((succ, _paths), rc, err) = safe_dbus.call_sync(STRATIS_SERVICE,
pool_info.object_path,
STRATIS_POOL_INTF,
"AddDataDevs",
GLib.Variant("(as)", ([device],)))
except safe_dbus.DBusCallError as e:
raise StratisError("Failed to create stratis filesystem on '%s': %s" % (pool_info.name, str(e)))
else:
if not succ:
raise StratisError("Failed to create stratis filesystem on '%s': %s (%d)" % (pool_info.name, err, rc))

# repopulate the stratis info cache so the new filesystem will be added
stratis_info.drop_cache()
12 changes: 11 additions & 1 deletion blivet/devices/stratis.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from collections import defaultdict

from .container import ContainerDevice
from .storage import StorageDevice
from ..static_data import stratis_info
from ..storage_log import log_method_call
Expand All @@ -35,7 +36,7 @@
from .. import devicelibs


class StratisPoolDevice(StorageDevice):
class StratisPoolDevice(ContainerDevice):
""" A stratis pool device """

_type = "stratis pool"
Expand Down Expand Up @@ -184,6 +185,15 @@ def _add_parent(self, parent):

raise InconsistentParentSectorSize(msg)

parent.format.pool_name = self.name
parent.format.pool_uuid = self.uuid

def _add(self, member):
devicelibs.stratis.add_device(self.uuid, member.path)

def _remove(self, member):
raise DeviceError("Removing members from a Stratis pool is not supported")

def _destroy(self):
""" Destroy the device. """
log_method_call(self, self.name, status=self.status)
Expand Down
43 changes: 43 additions & 0 deletions tests/storage_tests/devices_test/stratis_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,46 @@ def test_stratis_overprovision(self):
self.assertIsNotNone(fs)
self.assertIsInstance(fs, blivet.devices.StratisFilesystemDevice)
self.assertAlmostEqual(fs.size, blivet.size.Size("2 GiB"), delta=blivet.size.Size("10 MiB"))

def test_stratis_add_device(self):
disk1 = self.storage.devicetree.get_device_by_path(self.vdevs[0])
self.assertIsNotNone(disk1)
self.storage.initialize_disk(disk1)

bd1 = self.storage.new_partition(size=blivet.size.Size("1 GiB"), fmt_type="stratis",
parents=[disk1])
self.storage.create_device(bd1)

blivet.partitioning.do_partitioning(self.storage)

pool = self.storage.new_stratis_pool(name="blivetTestPool", parents=[bd1])
self.storage.create_device(pool)

self.storage.do_it()
self.storage.reset()

disk2 = self.storage.devicetree.get_device_by_path(self.vdevs[1])
self.assertIsNotNone(disk2)
self.storage.initialize_disk(disk2)

bd2 = self.storage.new_partition(size=blivet.size.Size("1 GiB"), fmt_type="stratis",
parents=[disk2])
self.storage.create_device(bd2)

blivet.partitioning.do_partitioning(self.storage)

pool = self.storage.devicetree.get_device_by_name("blivetTestPool")

ac = blivet.deviceaction.ActionAddMember(pool, bd2)
self.storage.devicetree.actions.add(ac)
self.storage.do_it()
self.storage.reset()

pool = self.storage.devicetree.get_device_by_name("blivetTestPool")
self.assertIsNotNone(pool)
self.assertEqual(len(pool.parents), 2)
self.assertCountEqual([p.path for p in pool.parents], [self.vdevs[0] + "1", self.vdevs[1] + "1"])

bd2 = self.storage.devicetree.get_device_by_path(self.vdevs[1] + "1")
self.assertEqual(bd2.format.pool_name, pool.name)
self.assertEqual(bd2.format.pool_uuid, pool.uuid)

0 comments on commit 954b7f1

Please sign in to comment.