Bladeren bron

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.
Daniel Vincze 1 jaar geleden
bovenliggende
commit
ecd24e092d

+ 8 - 0
coriolis/tasks/replica_tasks.py

@@ -92,7 +92,15 @@ def _preserve_old_export_info_nic_ips(old_export_info, new_export_info):
                 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)
 
 

+ 28 - 0
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"

+ 7 - 0
coriolis/tests/tasks/test_replica_tasks.py

@@ -61,6 +61,13 @@ class ReplicaTasksTestCase(test_base.CoriolisBaseTestCase):
             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):