Prechádzať zdrojové kódy

OSmorphing: fix netpreserver read config permission denied

Cristian Matiut 9 mesiacov pred
rodič
commit
1cf7ee84c8

+ 9 - 0
coriolis/osmorphing/base.py

@@ -329,6 +329,15 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
         return utils.read_ssh_ini_config_file(
         return utils.read_ssh_ini_config_file(
             self._ssh, full_path, check_exists=check_exists)
             self._ssh, full_path, check_exists=check_exists)
 
 
+    def _read_config_file_sudo(self, chroot_path, check_exists=False):
+        if self._test_path_chroot(chroot_path) is False:
+            if check_exists:
+                raise IOError("could not find %s" % chroot_path)
+            return {}
+        content = self._read_file_sudo(chroot_path).decode()
+        config = utils.parse_ini_config(content)
+        return config
+
     def _copy_resolv_conf(self):
     def _copy_resolv_conf(self):
         resolv_conf = "etc/resolv.conf"
         resolv_conf = "etc/resolv.conf"
         resolv_conf_path = os.path.join(self._os_root_dir, resolv_conf)
         resolv_conf_path = os.path.join(self._os_root_dir, resolv_conf)

+ 1 - 1
coriolis/osmorphing/netpreserver/ifcfg.py

@@ -51,7 +51,7 @@ class IfcfgNetPreserver(base.BaseNetPreserver):
     def _get_ifcfgs_by_type(self, ifcfg_type, network_scripts_path):
     def _get_ifcfgs_by_type(self, ifcfg_type, network_scripts_path):
         ifcfgs = []
         ifcfgs = []
         for ifcfg_file in self._get_net_config_files(network_scripts_path):
         for ifcfg_file in self._get_net_config_files(network_scripts_path):
-            ifcfg = self.osmorphing_tool._read_config_file(ifcfg_file)
+            ifcfg = self.osmorphing_tool._read_config_file_sudo(ifcfg_file)
             if ifcfg.get("TYPE") == ifcfg_type:
             if ifcfg.get("TYPE") == ifcfg_type:
                 ifcfgs.append((ifcfg_file, ifcfg))
                 ifcfgs.append((ifcfg_file, ifcfg))
         return ifcfgs
         return ifcfgs

+ 1 - 1
coriolis/osmorphing/netpreserver/nmconnection.py

@@ -65,7 +65,7 @@ class NmconnectionNetPreserver(base.BaseNetPreserver):
     def _get_keyfiles_by_type(self, nmconnection_type, network_scripts_path):
     def _get_keyfiles_by_type(self, nmconnection_type, network_scripts_path):
         keyfiles = []
         keyfiles = []
         for file in self._get_nmconnection_files(network_scripts_path):
         for file in self._get_nmconnection_files(network_scripts_path):
-            keyfile = self.osmorphing_tool._read_config_file(file)
+            keyfile = self.osmorphing_tool._read_config_file_sudo(file)
             if keyfile.get("type") == nmconnection_type:
             if keyfile.get("type") == nmconnection_type:
                 keyfiles.append((file, keyfile))
                 keyfiles.append((file, keyfile))
         return keyfiles
         return keyfiles