diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py index bd0ade60d..d66216341 100644 --- a/ironic_python_agent/extensions/standby.py +++ b/ironic_python_agent/extensions/standby.py @@ -619,6 +619,7 @@ class StandbyExtension(base.BaseAgentExtension): device) stream_to = self.partition_uuids['partitions']['root'] else: + self.partition_uuids = {} stream_to = device self._stream_raw_image_onto_device(image_info, stream_to) @@ -706,6 +707,16 @@ class StandbyExtension(base.BaseAgentExtension): LOG.error(error_msg) raise errors.CommandExecutionError(error_msg) + @base.sync_command('get_partition_uuids') + def get_partition_uuids(self): + """Return partition UUIDs.""" + # NOTE(dtantsur): None means prepare_image hasn't been called (an empty + # dict is used for whole disk images). + if self.partition_uuids is None: + LOG.warning('No partition UUIDs recorded yet, prepare_image ' + 'has to be called before get_partition_uuids') + return self.partition_uuids or {} + # TODO(TheJulia): Once we have deploy/clean steps, this should # become a step, which we ideally have enabled by default. def _sync_clock(self, ignore_errors=False): diff --git a/ironic_python_agent/tests/unit/extensions/test_standby.py b/ironic_python_agent/tests/unit/extensions/test_standby.py index b0cc081b1..f3d5bccdd 100644 --- a/ironic_python_agent/tests/unit/extensions/test_standby.py +++ b/ironic_python_agent/tests/unit/extensions/test_standby.py @@ -939,6 +939,9 @@ class TestStandbyExtension(base.IronicAgentTest): image_info['disk_format'] = 'raw' image_info['stream_raw_images'] = True self._test_prepare_image_raw(image_info, partition=True) + self.assertEqual({'root uuid': 'a318821b-2a60-40e5-a011-7ac07fce342b', + 'partitions': {'root': '/dev/foo-part1'}}, + self.agent_extension.partition_uuids) def test_prepare_partition_image_raw_and_stream_false(self): image_info = _build_fake_partition_image_info() @@ -1241,6 +1244,12 @@ class TestStandbyExtension(base.IronicAgentTest): self.agent_extension._sync_clock) execute_mock.assert_any_call('hwclock', '-v', '--systohc') + @mock.patch('ironic_python_agent.utils.execute', autospec=True) + def test_get_partition_uuids(self, execute_mock): + self.agent_extension.partition_uuids = {'1': '2'} + result = self.agent_extension.get_partition_uuids() + self.assertEqual({'1': '2'}, result.serialize()['command_result']) + @mock.patch('hashlib.md5', autospec=True) @mock.patch('requests.get', autospec=True)