Jelajahi Sumber

Fixes osmorphing DNS issues

Alessandro Pilotti 10 tahun lalu
induk
melakukan
1a542b3868

+ 23 - 0
coriolis/osmorphing/base.py

@@ -76,6 +76,12 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
 
         return add, remove
 
+    def pre_packages_install(self):
+        self._copy_resolv_conf()
+
+    def post_packages_install(self):
+        self._restore_resolv_conf()
+
     def _test_path(self, chroot_path):
         path = os.path.join(self._os_root_dir, chroot_path)
         return utils.test_ssh_path(self._ssh, path)
@@ -133,3 +139,20 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
                 name, value = m.groups()
                 config[name] = value
         return config
+
+    def _copy_resolv_conf(self):
+        resolv_conf_path = os.path.join(self._os_root_dir, "etc/resolv.conf")
+        resolv_conf_path_old = "%s.old" % resolv_conf_path
+
+        if self._test_path(resolv_conf_path):
+            self._exec_cmd(
+                "sudo mv -f %s %s" % (resolv_conf_path, resolv_conf_path_old))
+        self._exec_cmd("sudo cp /etc/resolv.conf %s" % resolv_conf_path)
+
+    def _restore_resolv_conf(self):
+        resolv_conf_path = os.path.join(self._os_root_dir, "etc/resolv.conf")
+        resolv_conf_path_old = "%s.old" % resolv_conf_path
+
+        if self._test_path(resolv_conf_path_old):
+            self._exec_cmd(
+                "sudo mv -f %s %s" % (resolv_conf_path_old, resolv_conf_path))

+ 1 - 0
coriolis/osmorphing/debian.py

@@ -34,6 +34,7 @@ class DebianMorphingTools(base.BaseLinuxOSMorphingTools):
                            interfaces_path)
 
     def pre_packages_install(self):
+        super(DebianMorphingTools, self).pre_packages_install()
         apt_get_cmd = 'apt-get update -y'
         self._exec_cmd_chroot(apt_get_cmd)
 

+ 3 - 0
coriolis/osmorphing/redhat.py

@@ -195,6 +195,8 @@ class RedHatMorphingTools(base.BaseLinuxOSMorphingTools):
         self._exec_cmd_chroot("touch /.autorelabel")
 
     def pre_packages_install(self):
+        super(RedHatMorphingTools, self).pre_packages_install()
+
         distro, version = self.check_os()
         if distro == RELEASE_RHEL and "cloud-init" in self.get_packages()[0]:
             major_version = version.split(".")[0]
@@ -210,3 +212,4 @@ class RedHatMorphingTools(base.BaseLinuxOSMorphingTools):
         self._run_dracut()
         self._configure_cloud_init()
         self._set_selinux_autorelabel()
+        super(RedHatMorphingTools, self).post_packages_install()

+ 2 - 5
coriolis/osmorphing/suse.py

@@ -37,12 +37,8 @@ class SUSEMorphingTools(base.BaseLinuxOSMorphingTools):
         # TODO: add networking support
         pass
 
-    def _copy_resolv_conf(self):
-        resolv_conf_path = os.path.join(self._os_root_dir, "etc/resolv.conf")
-        self._exec_cmd("sudo cp -f /etc/resolv.conf %s" % resolv_conf_path)
-
     def pre_packages_install(self):
-        self._copy_resolv_conf()
+        super(SUSEMorphingTools, self).pre_packages_install()
 
         if self._platform == constants.PLATFORM_OPENSTACK:
             # TODO: use OS version to choose the right repo
@@ -103,3 +99,4 @@ class SUSEMorphingTools(base.BaseLinuxOSMorphingTools):
     def post_packages_install(self):
         self._run_dracut()
         self._configure_cloud_init()
+        super(SUSEMorphingTools, self).post_packages_install()