2
0
Эх сурвалжийг харах

Fix new cloud-init version service enablement.

New cloud-init version (>26) changed its systemd unit service name,
therefore the enablement method needs to reflect that.
Daniel Vincze 6 өдөр өмнө
parent
commit
8d01e26a91

+ 12 - 1
coriolis/osmorphing/base.py

@@ -25,6 +25,8 @@ REQUIRED_DETECTED_OS_FIELDS = [
     "os_type", "distribution_name", "release_version",
     "friendly_release_name"]
 DEFAULT_CLOUD_USER = "cloud-user"
+CLOUD_INIT_SERVICE_UNIT_NAME = "cloud-init"
+CLOUD_INIT_SERVICE_UNIT_NAME_FALLBACK = "cloud-init-main"
 
 
 class BaseOSMorphingTools(object, with_metaclass(abc.ABCMeta)):
@@ -472,7 +474,16 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
         self._write_cloud_init_mods_config(cloud_cfg_mods)
 
         if self._has_systemd_chroot():
-            self._enable_systemd_service("cloud-init")
+            try:
+                self._enable_systemd_service(CLOUD_INIT_SERVICE_UNIT_NAME)
+            except exception.CoriolisException:
+                LOG.warning(
+                    "Failed to enable service unit with name "
+                    f"{CLOUD_INIT_SERVICE_UNIT_NAME}. Trying new name.")
+                # NOTE(dvincze): New versions of cloud-init (>26) got its
+                # unit service name renamed.
+                self._enable_systemd_service(
+                    CLOUD_INIT_SERVICE_UNIT_NAME_FALLBACK)
 
     def _test_path_chroot(self, path):
         # This method uses _exec_cmd_chroot() instead of SFTP stat()