summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Tantsur <dtantsur@protonmail.com>2020-05-29 14:16:53 +0200
committerDmitry Tantsur <dtantsur@protonmail.com>2020-06-02 15:05:59 +0200
commit6c1545b75b157584f04901cdbfa4897fd15042bb (patch)
tree9b4c5b194192a3ff5bbdeb8929bd49bb40dba0a6
parent3fbcc7c38e858fea2279d376c60367a844ac3a04 (diff)
downloadironic-python-agent-6c1545b75b157584f04901cdbfa4897fd15042bb.tar.gz
New extension call to return partition UUIDs
Currently we parse the success message from the write_image call. This is inconvenient and incompatible with the deploy steps split. Change-Id: I258dc1ff1ad1c9df5cbc26a7825d9e7ef2f3205b Story: #2006963
-rw-r--r--ironic_python_agent/extensions/standby.py11
-rw-r--r--ironic_python_agent/tests/unit/extensions/test_standby.py9
2 files changed, 20 insertions, 0 deletions
diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py
index bd0ade60..d6621634 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 b0cc081b..f3d5bccd 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)