diff --git a/ceph/utils.py b/ceph/utils.py index 74579d5..5ead3f8 100644 --- a/ceph/utils.py +++ b/ceph/utils.py @@ -1822,8 +1822,8 @@ def _luks_uuid(dev): def _initialize_disk(dev, dev_uuid, encrypt=False, key_manager=CEPH_KEY_MANAGER): """ - Initialize a raw block device with a single paritition - consuming 100% of the avaliable disk space. + Initialize a raw block device consuming 100% of the avaliable + disk space. Function assumes that block device has already been wiped. @@ -1834,45 +1834,30 @@ def _initialize_disk(dev, dev_uuid, encrypt=False, :raises: subprocess.CalledProcessError: if any parted calls fail :returns: str: Full path to new partition. """ - partition = _partition_name(dev) use_vaultlocker = encrypt and key_manager == VAULT_KEY_MANAGER if use_vaultlocker: # NOTE(jamespage): Check to see if already initialized as a LUKS # volume, which indicates this is a shared block # device for journal, db or wal volumes. - luks_uuid = _luks_uuid(partition) + luks_uuid = _luks_uuid(dev) if luks_uuid: return '/dev/mapper/crypt-{}'.format(luks_uuid) dm_crypt = '/dev/mapper/crypt-{}'.format(dev_uuid) - if not os.path.exists(partition): - subprocess.check_call([ - 'parted', '--script', - dev, - 'mklabel', - 'gpt', - ]) - subprocess.check_call([ - 'parted', '--script', - dev, - 'mkpart', - 'primary', '1', '100%', - ]) - if use_vaultlocker and not os.path.exists(dm_crypt): subprocess.check_call([ 'vaultlocker', 'encrypt', '--uuid', dev_uuid, - partition, + dev, ]) if use_vaultlocker: return dm_crypt else: - return partition + return dev def _allocate_logical_volume(dev, lv_type, osd_fsid, diff --git a/unit_tests/test_utils.py b/unit_tests/test_utils.py index 28352b0..70682dd 100644 --- a/unit_tests/test_utils.py +++ b/unit_tests/test_utils.py @@ -662,21 +662,8 @@ class CephInitializeDiskTestCase(unittest.TestCase): _luks_uuid.return_value = None self.assertEqual(utils._initialize_disk('/dev/sdb', 'test-UUID'), - '/dev/sdb1') - _check_call.assert_has_calls([ - call([ - 'parted', '--script', - '/dev/sdb', - 'mklabel', - 'gpt', - ]), - call([ - 'parted', '--script', - '/dev/sdb', - 'mkpart', - 'primary', '1', '100%', - ]), - ]) + '/dev/sdb') + _check_call.assert_not_called() @patch.object(utils, '_luks_uuid') @patch.object(utils.subprocess, 'check_call') @@ -690,23 +677,11 @@ class CephInitializeDiskTestCase(unittest.TestCase): True, 'vault'), '/dev/mapper/crypt-test-UUID') - _check_call.assert_has_calls([ - call([ - 'parted', '--script', - '/dev/sdb', - 'mklabel', - 'gpt', - ]), - call([ - 'parted', '--script', - '/dev/sdb', - 'mkpart', - 'primary', '1', '100%', - ]), - call(['vaultlocker', 'encrypt', - '--uuid', 'test-UUID', - '/dev/sdb1']), - ]) + _check_call.assert_called_once_with( + ['vaultlocker', 'encrypt', + '--uuid', 'test-UUID', + '/dev/sdb'] + ) @patch.object(utils, '_luks_uuid') @patch.object(utils.subprocess, 'check_call') @@ -724,18 +699,6 @@ class CephInitializeDiskTestCase(unittest.TestCase): '/dev/mapper/crypt-existing-UUID') _check_call.assert_not_called() - @patch.object(utils, '_luks_uuid') - @patch.object(utils.subprocess, 'check_call') - @patch.object(utils.os.path, 'exists') - def test_initialize_disk_exists(self, _exists, _check_call, - _luks_uuid): - _exists.return_value = True - _luks_uuid.return_value = None - self.assertEqual(utils._initialize_disk('/dev/sdb', - 'test-UUID'), - '/dev/sdb1') - _check_call.assert_not_called() - class CephActiveBlueStoreDeviceTestCase(unittest.TestCase):