Move label formatting to make_fs from driver
The code that truncated and formatted labels was in driver - too high up in code hierarchy. The label is now simply passed to make_fs and it handles it properly. Change-Id: I87c151e4f01784101977bdd46c3e64401090fc05 Closes-Bug: #1505621
This commit is contained in:
parent
6faa1e0ba8
commit
b895d7dc49
@ -168,13 +168,6 @@ class Nailgun(BaseDataDriver):
|
||||
'Disk not found: %s' % ks_disk['name'])
|
||||
return found[0]
|
||||
|
||||
def _getlabel(self, label):
|
||||
if not label:
|
||||
return ''
|
||||
# XFS will refuse to format a partition if the
|
||||
# disk label is > 12 characters.
|
||||
return ' -L {0} '.format(label[:12])
|
||||
|
||||
def _get_partition_count(self, name):
|
||||
count = 0
|
||||
for disk in self.ks_disks:
|
||||
@ -365,7 +358,7 @@ class Nailgun(BaseDataDriver):
|
||||
partition_scheme.add_fs(
|
||||
device=prt.name, mount=volume['mount'],
|
||||
fs_type=volume.get('file_system', 'xfs'),
|
||||
fs_label=self._getlabel(volume.get('disk_label')))
|
||||
fs_label=volume.get('disk_label'))
|
||||
if volume['mount'] == '/boot' and not self._boot_done:
|
||||
self._boot_done = True
|
||||
|
||||
@ -411,7 +404,7 @@ class Nailgun(BaseDataDriver):
|
||||
partition_scheme.md_attach_by_mount(
|
||||
device=prt.name, mount=volume['mount'],
|
||||
fs_type=volume.get('file_system', 'xfs'),
|
||||
fs_label=self._getlabel(volume.get('disk_label')),
|
||||
fs_label=volume.get('disk_label'),
|
||||
metadata=metadata)
|
||||
|
||||
if 'mount' in volume and volume['mount'] == '/boot' and \
|
||||
@ -423,7 +416,7 @@ class Nailgun(BaseDataDriver):
|
||||
partition_scheme.add_fs(
|
||||
device=prt.name, mount=volume['mount'],
|
||||
fs_type=volume.get('file_system', 'ext2'),
|
||||
fs_label=self._getlabel(volume.get('disk_label')))
|
||||
fs_label=volume.get('disk_label'))
|
||||
self._boot_done = True
|
||||
|
||||
# this partition will be used to put there configdrive image
|
||||
@ -464,7 +457,7 @@ class Nailgun(BaseDataDriver):
|
||||
partition_scheme.add_fs(
|
||||
device=lv.device_name, mount=volume['mount'],
|
||||
fs_type=volume.get('file_system', 'xfs'),
|
||||
fs_label=self._getlabel(volume.get('disk_label')))
|
||||
fs_label=volume.get('disk_label'))
|
||||
|
||||
partition_scheme.elevate_keep_data()
|
||||
return partition_scheme
|
||||
|
@ -33,12 +33,12 @@ class TestFSUtils(unittest2.TestCase):
|
||||
mock_exec.assert_called_once_with('mkfs.xfs', '-f', '/dev/fake')
|
||||
|
||||
def test_make_fs(self, mock_exec):
|
||||
fu.make_fs('ext4', '-F', '-L fake_label', '/dev/fake')
|
||||
fu.make_fs('ext4', '-F', 'fake_label', '/dev/fake')
|
||||
mock_exec.assert_called_once_with('mkfs.ext4', '-F', '-L',
|
||||
'fake_label', '/dev/fake')
|
||||
|
||||
def test_make_fs_swap(self, mock_exec):
|
||||
fu.make_fs('swap', '-f', '-L fake_label', '/dev/fake')
|
||||
fu.make_fs('swap', '-f', 'fake_label', '/dev/fake')
|
||||
mock_exec.assert_called_once_with('mkswap', '-f', '-L', 'fake_label',
|
||||
'/dev/fake')
|
||||
|
||||
@ -128,3 +128,17 @@ class TestFSUtils(unittest2.TestCase):
|
||||
self.assertRaises(errors.ProcessExecutionError,
|
||||
fu.umount_fs, '/fake', try_lazy_umount=False)
|
||||
self.assertEqual(expected_calls, mock_exec.call_args_list)
|
||||
|
||||
def test_format_fs_label(self, _):
|
||||
short_label = 'label'
|
||||
long_label = '0123456789ABCD'
|
||||
long_label_trimmed = long_label[:12]
|
||||
template = ' -L {0} '
|
||||
|
||||
self.assertEqual(fu.format_fs_label(None), '')
|
||||
|
||||
self.assertEqual(fu.format_fs_label(short_label),
|
||||
template.format(short_label))
|
||||
|
||||
self.assertEqual(fu.format_fs_label(long_label),
|
||||
template.format(long_label_trimmed))
|
||||
|
@ -1024,14 +1024,6 @@ class TestNailgunMockedMeta(unittest2.TestCase):
|
||||
img.size, fake_image_meta['images'][0]['raw_size'])
|
||||
self.assertEqual(img.md5, fake_image_meta['images'][0]['raw_md5'])
|
||||
|
||||
def test_getlabel(self, mock_lbd, mock_image_meta):
|
||||
mock_lbd.return_value = LIST_BLOCK_DEVICES_SAMPLE
|
||||
drv = nailgun.Nailgun(PROVISION_SAMPLE_DATA)
|
||||
self.assertEqual('', drv._getlabel(None))
|
||||
long_label = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
self.assertEqual(' -L %s ' % long_label[:12],
|
||||
drv._getlabel(long_label))
|
||||
|
||||
def test_disk_dev_not_found(self, mock_lbd, mock_image_meta):
|
||||
mock_lbd.return_value = LIST_BLOCK_DEVICES_SAMPLE
|
||||
drv = nailgun.Nailgun(PROVISION_SAMPLE_DATA)
|
||||
|
@ -19,6 +19,18 @@ from fuel_agent.utils import utils
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def format_fs_label(label):
|
||||
"""Format filesystem label to match mkfs format
|
||||
|
||||
Labels longer than 12 will be truncated to 12 first characters because of
|
||||
xfs limitations
|
||||
"""
|
||||
if not label:
|
||||
return ''
|
||||
else:
|
||||
return ' -L {0} '.format(label[:12])
|
||||
|
||||
|
||||
def make_fs(fs_type, fs_options, fs_label, dev):
|
||||
# NOTE(agordeev): notice the different flag to force the fs creating
|
||||
# ext* uses -F flag, xfs/mkswap uses -f flag.
|
||||
@ -31,7 +43,7 @@ def make_fs(fs_type, fs_options, fs_label, dev):
|
||||
# Othwerwise, it will fail to proceed if filesystem exists.
|
||||
fs_options += ' -f '
|
||||
cmd_line.append(cmd_name)
|
||||
for opt in (fs_options, fs_label):
|
||||
for opt in (fs_options, format_fs_label(fs_label)):
|
||||
cmd_line.extend([s for s in opt.split(' ') if s])
|
||||
cmd_line.append(dev)
|
||||
utils.execute(*cmd_line)
|
||||
|
Loading…
x
Reference in New Issue
Block a user