diff --git a/fuel_agent/drivers/nailgun.py b/fuel_agent/drivers/nailgun.py index a7173d7b..663adf3c 100644 --- a/fuel_agent/drivers/nailgun.py +++ b/fuel_agent/drivers/nailgun.py @@ -433,16 +433,27 @@ class Nailgun(base.BaseDataDriver): volume['partition_guid']) prt.set_guid(volume['partition_guid']) - if 'mount' in volume and volume['mount'] != 'none': + fs = volume.get('file_system') + if fs == 'none': + fs = None + mount = volume.get('mount') + if mount == 'none': + mount = None + + if fs is not None or mount is not None: + # NOTE(el): Set default file system to xfs for + # the purpose of backward compatibility with + # previous versions of fuel-agent. + if fs is None: + fs = 'xfs' LOG.debug('Adding file system on partition: ' - 'mount=%s type=%s' % - (volume['mount'], - volume.get('file_system', 'xfs'))) + 'mount=%s type=%s', mount, fs) partition_scheme.add_fs( - device=prt.name, mount=volume['mount'], - fs_type=volume.get('file_system', 'xfs'), + device=prt.name, + mount=mount, + fs_type=fs, fs_label=volume.get('disk_label')) - if volume['mount'] == '/boot' and not self._boot_done: + if mount == '/boot' and not self._boot_done: self._boot_done = True if volume['type'] == 'pv': diff --git a/fuel_agent/manager.py b/fuel_agent/manager.py index c8f64fec..f6a87713 100644 --- a/fuel_agent/manager.py +++ b/fuel_agent/manager.py @@ -547,9 +547,7 @@ class Manager(object): LOG.debug('Mounting target file systems into a flat set ' 'of temporary directories') mount_map = {} - for fs in self.driver.partition_scheme.fss: - if fs.mount == 'swap': - continue + for fs in self.driver.partition_scheme.fss_w_mountpoints: # It is an ugly hack to resolve python2/3 encoding issues and # should be removed after transistion to python3 try: @@ -636,8 +634,6 @@ class Manager(object): LOG.debug('Mounting target file systems: %s', chroot) # Here we are going to mount all file systems in partition scheme. for fs in self.driver.partition_scheme.fs_sorted_by_depth(): - if fs.mount == 'swap': - continue mount = chroot + fs.mount utils.makedirs_if_not_exists(mount) fu.mount_fs(fs.type, str(fs.device), mount) @@ -663,8 +659,6 @@ class Manager(object): fu.umount_fs(chroot + path) for fs in self.driver.partition_scheme.fs_sorted_by_depth( reverse=True): - if fs.mount == 'swap': - continue fu.umount_fs(chroot + fs.mount) def install_base_os(self, chroot): @@ -956,7 +950,9 @@ class Manager(object): # at fstab line. Currently we set it into 0 which means # a corresponding file system will never be checked. We assume # puppet or other configuration tool will care of it. - if fs.mount == '/': + if fs.mount is None: + LOG.debug('Skipping fstab entry creation for %s', fs) + elif fs.mount == '/': f.write(u'UUID=%s %s %s defaults,errors=panic 0 0\n' % (mount2uuid[fs.mount], fs.mount, fs.type)) else: diff --git a/fuel_agent/objects/partition/scheme.py b/fuel_agent/objects/partition/scheme.py index 350d43c8..a4de19c3 100644 --- a/fuel_agent/objects/partition/scheme.py +++ b/fuel_agent/objects/partition/scheme.py @@ -60,7 +60,7 @@ class PartitionScheme(object): def add_fs(self, **kwargs): fs = f_fs.FileSystem(**kwargs) - if not os.path.isabs(fs.mount) and fs.mount != 'swap': + if fs.mount and not os.path.isabs(fs.mount) and fs.mount != 'swap': raise errors.WrongFSMount( 'Incorrect mount point %s' % fs.mount) self.fss.append(fs) @@ -144,7 +144,15 @@ class PartitionScheme(object): """ def key(x): return x.mount.rstrip(os.path.sep).count(os.path.sep) - return sorted(self.fss, key=key, reverse=reverse) + return sorted(self.fss_w_mountpoints, key=key, reverse=reverse) + + @property + def fss_w_mountpoints(self): + """Returns a list of file systems which have mountpoints""" + # NOTE: `swap` mountpoint is not a real mountpoint, so has + # to be skipped. + return filter(lambda f: f.mount is not None and f.mount != "swap", + self.fss) def lv_by_device_name(self, device_name): return next((x for x in self.lvs if x.device_name == device_name), diff --git a/fuel_agent/tests/test_nailgun.py b/fuel_agent/tests/test_nailgun.py index dddaf48b..aa007774 100644 --- a/fuel_agent/tests/test_nailgun.py +++ b/fuel_agent/tests/test_nailgun.py @@ -26,6 +26,16 @@ from fuel_agent.objects import image from fuel_agent.utils import utils +SWIFT = { + 'disk_label': None, + 'file_system': 'xfs', + 'mount': 'none', + 'name': 'swift-storage', + 'partition_guid': 'deadbeef-9d34-4175-8ded-1ce68967a5ee', + 'size': 10, + 'type': 'partition' +} + CEPH_JOURNAL = { "partition_guid": "45b0969e-9b03-4f30-b4c6-b4b80ceff106", "name": "cephjournal", @@ -1666,6 +1676,22 @@ class TestNailgunMockedMeta(unittest2.TestCase): self.assertEqual(3, drv._get_partition_count('Boot')) self.assertEqual(1, drv._get_partition_count('TMP')) + def test_partition_scheme_no_mount_fs(self, mock_lbd, mock_image_meta): + p_data = copy.deepcopy(PROVISION_SAMPLE_DATA) + for i in range(0, 3): + p_data['ks_meta']['pm_data']['ks_spaces'][i]['volumes'].append( + SWIFT) + mock_lbd.return_value = LIST_BLOCK_DEVICES_SAMPLE + drv = nailgun.Nailgun(p_data) + p_scheme = drv.partition_scheme + self.assertEqual(4, len(list(p_scheme.fss_w_mountpoints))) + self.assertEqual(8, len(p_scheme.fss)) + self.assertEqual(4, len(p_scheme.pvs)) + self.assertEqual(3, len(p_scheme.lvs)) + self.assertEqual(2, len(p_scheme.vgs)) + self.assertEqual(3, len(p_scheme.parteds)) + self.assertEqual(3, drv._get_partition_count('swift-storage')) + def test_partition_scheme_ceph(self, mock_lbd, mock_image_meta): # TODO(agordeev): perform better testing of ceph logic p_data = copy.deepcopy(PROVISION_SAMPLE_DATA) @@ -1677,6 +1703,7 @@ class TestNailgunMockedMeta(unittest2.TestCase): mock_lbd.return_value = LIST_BLOCK_DEVICES_SAMPLE drv = nailgun.Nailgun(p_data) p_scheme = drv.partition_scheme + self.assertEqual(4, len(list(p_scheme.fss_w_mountpoints))) self.assertEqual(5, len(p_scheme.fss)) self.assertEqual(4, len(p_scheme.pvs)) self.assertEqual(3, len(p_scheme.lvs))