diff options
| author | Zuul <zuul@review.openstack.org> | 2018-08-03 15:40:51 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2018-08-03 15:40:51 +0000 |
| commit | 667589bb007e144e37136e706c0b8196422b0344 (patch) | |
| tree | 72020d04ff1043ac912d89ea9de7e38e058eced9 | |
| parent | d0092633498c6611f5419d5b832042d57d344c8f (diff) | |
| parent | 7e0bcbbeee12ce93f317f52e7c27192d53f9c5d1 (diff) | |
| download | ironic-python-agent-3.3.0.tar.gz | |
Merge "fall back to PARTUUID if UUID not found."3.3.0
| -rw-r--r-- | ironic_python_agent/extensions/image.py | 7 | ||||
| -rw-r--r-- | ironic_python_agent/tests/unit/extensions/test_image.py | 25 |
2 files changed, 28 insertions, 4 deletions
diff --git a/ironic_python_agent/extensions/image.py b/ironic_python_agent/extensions/image.py index b6d1f0ea..e5b1b1aa 100644 --- a/ironic_python_agent/extensions/image.py +++ b/ironic_python_agent/extensions/image.py @@ -48,7 +48,8 @@ def _get_partition(device, uuid): LOG.warning("Couldn't re-read the partition table " "on device %s", device) - report = utils.execute('lsblk', '-PbioKNAME,UUID,TYPE', device)[0] + lsblk = utils.execute('lsblk', '-PbioKNAME,UUID,PARTUUID,TYPE', device) + report = lsblk[0] for line in report.split('\n'): part = {} # Split into KEY=VAL pairs @@ -63,6 +64,10 @@ def _get_partition(device, uuid): LOG.debug("Partition %(uuid)s found on device " "%(dev)s", {'uuid': uuid, 'dev': device}) return '/dev/' + part.get('KNAME') + if part.get('PARTUUID') == uuid: + LOG.debug("Partition %(uuid)s found on device " + "%(dev)s", {'uuid': uuid, 'dev': device}) + return '/dev/' + part.get('KNAME') else: error_msg = ("No partition with UUID %(uuid)s found on " "device %(dev)s" % {'uuid': uuid, 'dev': device}) diff --git a/ironic_python_agent/tests/unit/extensions/test_image.py b/ironic_python_agent/tests/unit/extensions/test_image.py index 347e2450..74942fa4 100644 --- a/ironic_python_agent/tests/unit/extensions/test_image.py +++ b/ironic_python_agent/tests/unit/extensions/test_image.py @@ -325,7 +325,8 @@ class TestImageExtension(base.IronicAgentTest): expected = [mock.call('partx', '-u', self.fake_dev, attempts=3, delay_on_retry=True), mock.call('udevadm', 'settle'), - mock.call('lsblk', '-PbioKNAME,UUID,TYPE', self.fake_dev)] + mock.call('lsblk', '-PbioKNAME,UUID,PARTUUID,TYPE', + self.fake_dev)] mock_execute.assert_has_calls(expected) self.assertFalse(mock_dispatch.called) @@ -342,7 +343,8 @@ class TestImageExtension(base.IronicAgentTest): expected = [mock.call('partx', '-u', self.fake_dev, attempts=3, delay_on_retry=True), mock.call('udevadm', 'settle'), - mock.call('lsblk', '-PbioKNAME,UUID,TYPE', self.fake_dev)] + mock.call('lsblk', '-PbioKNAME,UUID,PARTUUID,TYPE', + self.fake_dev)] mock_execute.assert_has_calls(expected) self.assertFalse(mock_dispatch.called) @@ -357,6 +359,23 @@ class TestImageExtension(base.IronicAgentTest): expected = [mock.call('partx', '-u', self.fake_dev, attempts=3, delay_on_retry=True), mock.call('udevadm', 'settle'), - mock.call('lsblk', '-PbioKNAME,UUID,TYPE', self.fake_dev)] + mock.call('lsblk', '-PbioKNAME,UUID,PARTUUID,TYPE', + self.fake_dev)] + mock_execute.assert_has_calls(expected) + self.assertFalse(mock_dispatch.called) + + def test__get_partition_partuuid(self, mock_execute, mock_dispatch): + lsblk_output = ('''KNAME="test" UUID="" TYPE="disk" + KNAME="test1" UUID="256a39e3-ca3c-4fb8-9cc2-b32eec441f47" TYPE="part" + KNAME="test2" PARTUUID="%s" TYPE="part"''' % self.fake_root_uuid) + mock_execute.side_effect = (None, None, [lsblk_output]) + + root_part = image._get_partition(self.fake_dev, self.fake_root_uuid) + self.assertEqual('/dev/test2', root_part) + expected = [mock.call('partx', '-u', self.fake_dev, attempts=3, + delay_on_retry=True), + mock.call('udevadm', 'settle'), + mock.call('lsblk', '-PbioKNAME,UUID,PARTUUID,TYPE', + self.fake_dev)] mock_execute.assert_has_calls(expected) self.assertFalse(mock_dispatch.called) |
