Skip to content

Commit

Permalink
storage-operator/salt: use volume name for GTP label instead of UUID
Browse files Browse the repository at this point in the history
Will be less confusing.

Refs: #2421
Signed-off-by: Sylvain Laperche <[email protected]>
  • Loading branch information
slaperche-scality committed Jul 6, 2020
1 parent 57bc9fb commit ca23e09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/developer/architecture/volume.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ device. We use different strategies according to the **Volume** type:
* **sparseLoopDevice** without filesystem: we create a GUID Partition Table on
the sparse file and create a single partition encompassing the whole device,
setting the label of the partition to the **Volume** UUID. We can then use
``/dev/disk/by-partlabel/<volume-uuid>`` as device path.
``/dev/disk/by-partlabel/<volume-name>`` as device path.
* **rawBlockDevice** without filesystem:

* the **rawBlockDevice** is a disk (e.g. ``/dev/sdb``): we use the same
strategy as above.
* the **rawBlockDevice** is a partition (e.g. ``/dev/sdb1``): we re-label the
partition using the **Volume** UUID and use
``/dev/disk/by-partlabel/<volume-uuid>`` as device path.
``/dev/disk/by-partlabel/<volume-name>`` as device path.
* The **rawBlockDevice** is a LVM volume: we use the existing LVM UUID and
use ``/dev/disk/by-id/dm-uuid-LVM-<lvm-uuid>`` as device path.

Expand Down
26 changes: 14 additions & 12 deletions salt/_modules/metalk8s_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,18 @@ class SparseLoopDeviceBlock(SparseLoopDevice):

@property
def persistent_path(self):
return '/dev/disk/by-partlabel/{}'.format(self.get('metadata.uid'))
return '/dev/disk/by-partlabel/{}'.format(self.get('metadata.name'))

@property
def is_prepared(self):
"""Check if the volume is already prepared."""
# Partition 1 should be labelled with the volume UUID.
pattern = '1.+{}'.format(self.get('metadata.uid').lower())
pattern = '1.+{}'.format(re.escape(self.get('metadata.name').lower()))
result = _run_cmd(' '.join(['parted', self.path, 'print']))
return re.search(pattern, result['stdout']) is not None

def prepare(self, force=False):
prepare_block(self.path, self.get('metadata.uid'))
prepare_block(self.path, self.get('metadata.name'))


# }}}
Expand Down Expand Up @@ -468,7 +468,7 @@ def persistent_path(self):
realpath = os.path.realpath(symlink)
if os.path.basename(realpath) == name:
return symlink
return '/dev/disk/by-partlabel/{}'.format(self.get('metadata.uid'))
return '/dev/disk/by-partlabel/{}'.format(self.get('metadata.name'))

@property
def device_path(self):
Expand All @@ -483,23 +483,25 @@ def is_prepared(self):
if self._kind == DeviceType.LVM:
return True
partition = self._partition or '1'
pattern = '{}.+{}'.format(partition, self.get('metadata.uid').lower())
pattern = '{}.+{}'.format(
partition, re.escape(self.get('metadata.name').lower())
)
result = _run_cmd(' '.join(['parted', self.device_path, 'print']))
return re.search(pattern, result['stdout']) is not None

def prepare(self, force=False):
# Nothing to do in LVM case.
if self._kind == DeviceType.LVM:
return
uuid = self.get('metadata.uid')
# In case of partition, set the label to volume UUID.
name = self.get('metadata.name')
# In case of partition, set the label to volume name.
if self._kind == DeviceType.PARTITION:
_run_cmd(' '.join([
'parted', self.device_path, 'name', self._partition, uuid
'parted', self.device_path, 'name', self._partition, name
]))
# Otherwise, create a GPT table and a unique partition.
else:
prepare_block(self.path, uuid)
prepare_block(self.path, name)

class DeviceType:
DISK = 1
Expand Down Expand Up @@ -657,17 +659,17 @@ def _mkfs_xfs(path, uuid, force=False, options=None):
command.append(path)
return command

def prepare_block(path, uuid):
def prepare_block(path, name):
"""Prepare a "Block" volume.
We use a GPT table and a single partition to have a link between the volume
UUID and the paritition label.
name and the paritition label.
"""
# Create a GPT partition table.
_run_cmd(' '.join(['parted', path, 'mktable', 'gpt']))
# Create a single partition labelled with the volume UUID.
_run_cmd(' '.join([
'parted', '--align', 'optimal', path, 'mkpart', uuid, '0%', '100%',
'parted', '--align', 'optimal', path, 'mkpart', name, '0%', '100%',
]))

# }}}
2 changes: 1 addition & 1 deletion tests/post/steps/test_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def check_storage_is_created(context, host, name):
if volume['spec'].get('mode', 'Filesystem') == 'Filesystem':
host.run_test('test -b /dev/disk/by-uuid/{}'.format(uuid))
else:
host.run_test('test -b /dev/disk/by-partlabel/{}'.format(uuid))
host.run_test('test -b /dev/disk/by-partlabel/{}'.format(name))


@then(parsers.parse("the backing storage for Volume '{name}' is deleted"))
Expand Down

0 comments on commit ca23e09

Please sign in to comment.