From 97e4d8d3496cbe3319e9a70e0c1d3a7deee3d16f Mon Sep 17 00:00:00 2001 From: Daniel Vincze Date: Mon, 14 Apr 2025 13:10:17 +0300 Subject: [PATCH 1/2] Add `hostname` to export_info Adds `hostname` property to the instance export information, used in order to attempt hostname preservation --- coriolis/schemas/vm_export_info_schema.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/coriolis/schemas/vm_export_info_schema.json b/coriolis/schemas/vm_export_info_schema.json index 47a5691a1..05f3017e1 100644 --- a/coriolis/schemas/vm_export_info_schema.json +++ b/coriolis/schemas/vm_export_info_schema.json @@ -22,6 +22,10 @@ "type": "string", "description": "Human-readable identifier of the VM. It can be optionally used as an alternative to 'id' for identifying instances on platforms which also feature a non-ID naming scheme (e.g. VMWare VM paths)" }, + "hostname": { + "type": "string", + "description": "Guest hostname of the VM." + }, "dynamic_memory_enabled": { "type": "boolean", "description": "Indicates whether not the VM's physical memory was allocated dynamically." From 446fc16f6fb7c6e2f9506e2ba999aace70ad5810 Mon Sep 17 00:00:00 2001 From: Daniel Vincze Date: Tue, 15 Apr 2025 15:40:26 +0300 Subject: [PATCH 2/2] Preserve exported VM hostname information This patch will make sure that the `hostname` property value of the export_info is preserved while the instance loses that source information (e.g. due to a shutdown). This will help in keeping the hostname information when retrying deployment executions. --- coriolis/tasks/replica_tasks.py | 8 ++++++ .../tests/tasks/data/test_hostname_update.yml | 28 +++++++++++++++++++ coriolis/tests/tasks/test_replica_tasks.py | 7 +++++ 3 files changed, 43 insertions(+) create mode 100644 coriolis/tests/tasks/data/test_hostname_update.yml diff --git a/coriolis/tasks/replica_tasks.py b/coriolis/tasks/replica_tasks.py index bdeb88bfa..0407e8bca 100644 --- a/coriolis/tasks/replica_tasks.py +++ b/coriolis/tasks/replica_tasks.py @@ -92,7 +92,15 @@ def _get_nic(nics_info, nic_id): new_info['ip_addresses'] = old_ips +def _preserve_hostname_info(old_export_info, new_export_info): + old_hostname = old_export_info.get("hostname", "") + new_hostname = new_export_info.get("hostname", "") + if not new_hostname: + new_export_info['hostname'] = old_hostname + + def _update_export_info(old_export_info, result_export_info): + _preserve_hostname_info(old_export_info, result_export_info) _preserve_old_export_info_nic_ips(old_export_info, result_export_info) diff --git a/coriolis/tests/tasks/data/test_hostname_update.yml b/coriolis/tests/tasks/data/test_hostname_update.yml new file mode 100644 index 000000000..f6647751a --- /dev/null +++ b/coriolis/tests/tasks/data/test_hostname_update.yml @@ -0,0 +1,28 @@ +# No hostnames +- old_export_info: {} + new_export_info: {} + expected_export_info: + hostname: "" + +# Hostname in old info +- old_export_info: + hostname: old.host.name + new_export_info: {} + expected_export_info: + hostname: old.host.name + +# Hostname in new info only +- old_export_info: + hostname: "" + new_export_info: + hostname: "new.host.name" + expected_export_info: + hostname: "new.host.name" + +# Hostname update from old to new +- old_export_info: + hostname: "old.host.name" + new_export_info: + hostname: "new.host.name" + expected_export_info: + hostname: "new.host.name" diff --git a/coriolis/tests/tasks/test_replica_tasks.py b/coriolis/tests/tasks/test_replica_tasks.py index 8a5d6d548..1e3207d3e 100644 --- a/coriolis/tests/tasks/test_replica_tasks.py +++ b/coriolis/tests/tasks/test_replica_tasks.py @@ -61,6 +61,13 @@ def test__preserve_old_export_info_nic_ips( old_export_info, new_export_info) self.assertEqual(new_export_info, expected_export_info) + @ddt.file_data("data/test_hostname_update.yml") + @ddt.unpack + def test__preserve_hostname_info( + self, old_export_info, new_export_info, expected_export_info): + replica_tasks._preserve_hostname_info(old_export_info, new_export_info) + self.assertEqual(new_export_info, expected_export_info) + class GetInstanceInfoTaskTestCase(test_base.CoriolisBaseTestCase):