Merge "Fixes naming for the partitions in baremetal."

This commit is contained in:
Jenkins 2016-03-03 16:13:48 +00:00 committed by Gerrit Code Review
commit 3bdfe793f4
2 changed files with 45 additions and 4 deletions

View File

@ -120,6 +120,13 @@ def get_disk_identifier(dev):
return disk_identifier[0]
def is_iscsi_device(dev, node_uuid):
"""check whether the device path belongs to an iscsi device. """
iscsi_id = "iqn.2008-10.org.openstack:%s" % node_uuid
return iscsi_id in dev
def make_partitions(dev, root_mb, swap_mb, ephemeral_mb,
configdrive_mb, node_uuid, commit=True,
boot_option="netboot", boot_mode="bios",
@ -151,7 +158,16 @@ def make_partitions(dev, root_mb, swap_mb, ephemeral_mb,
LOG.debug("Starting to partition the disk device: %(dev)s "
"for node %(node)s",
{'dev': dev, 'node': node_uuid})
part_template = dev + '-part%d'
# the actual device names in the baremetal are like /dev/sda, /dev/sdb etc.
# While for the iSCSI device, the naming convention has a format which has
# iqn also embedded in it.
# When this function is called by ironic-conductor, the iSCSI device name
# should be appended by "part%d". While on the baremetal, it should name
# the device partitions as /dev/sda1 and not /dev/sda-part1.
if is_iscsi_device(dev, node_uuid):
part_template = dev + '-part%d'
else:
part_template = dev + '%d'
part_dict = {}
if disk_label is None:

View File

@ -294,15 +294,40 @@ class MakePartitionsTestCase(test_base.BaseTestCase):
run_as_root=True, check_exit_code=[0])
mock_exc.assert_has_calls([parted_call])
def test_make_partitions_with_iscsi_device(self, mock_exc):
self.ephemeral_mb = 2048
expected_mkpart = ['mkpart', 'primary', '', '1', '2049',
'mkpart', 'primary', 'linux-swap', '2049', '2561',
'mkpart', 'primary', '', '2561', '3585']
self.dev = '/dev/iqn.2008-10.org.openstack:%s.fake-9' % self.node_uuid
ep = '/dev/iqn.2008-10.org.openstack:%s.fake-9-part1' % self.node_uuid
swap = ('/dev/iqn.2008-10.org.openstack:%s.fake-9-part2'
% self.node_uuid)
root = ('/dev/iqn.2008-10.org.openstack:%s.fake-9-part3'
% self.node_uuid)
expected_result = {'ephemeral': ep,
'swap': swap,
'root': root}
cmd = self._get_parted_cmd(self.dev) + expected_mkpart
mock_exc.return_value = (None, None)
result = disk_utils.make_partitions(
self.dev, self.root_mb, self.swap_mb, self.ephemeral_mb,
self.configdrive_mb, self.node_uuid)
parted_call = mock.call(*cmd, use_standard_locale=True,
run_as_root=True, check_exit_code=[0])
mock_exc.assert_has_calls([parted_call])
self.assertEqual(expected_result, result)
def test_make_partitions_with_local_device(self, mock_exc):
self.ephemeral_mb = 2048
expected_mkpart = ['mkpart', 'primary', '', '1', '2049',
'mkpart', 'primary', 'linux-swap', '2049', '2561',
'mkpart', 'primary', '', '2561', '3585']
self.dev = 'fake-dev'
expected_result = {'ephemeral': 'fake-dev-part1',
'swap': 'fake-dev-part2',
'root': 'fake-dev-part3'}
expected_result = {'ephemeral': 'fake-dev1',
'swap': 'fake-dev2',
'root': 'fake-dev3'}
cmd = self._get_parted_cmd(self.dev) + expected_mkpart
mock_exc.return_value = (None, None)
result = disk_utils.make_partitions(