Fixes naming for the partitions in baremetal.

This fix differentiates between the partition names for
the baremetal and the iSCSI device names used by conductor.
This is required for supporting partition images for
ironic-python-agent and ironic agent drivers. The
ironic-python-agent should be able to
name the device partitions as /dev/sda1, /dev/sda2, etc.

Change-Id: I22bc29a39bf5c35f3eecb6d4e51cebd6aee0ce19
Partial-bug: 1526289
This commit is contained in:
Nisha Agarwal 2016-02-16 20:35:28 -08:00
parent c8dbc2e0ed
commit f8bb790f00
2 changed files with 45 additions and 4 deletions

@ -121,6 +121,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"):
@ -148,7 +155,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 = {}
# For uefi localboot, switch partition table to gpt and create the efi

@ -254,15 +254,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(