Просмотр исходного кода

Merge pull request #64 from gabriel-samfira/call-sync

Call sync in _write_file_sudo() and PEP8
Nashwan Azhari 6 лет назад
Родитель
Сommit
793dcbf3af
3 измененных файлов с 11 добавлено и 11 удалено
  1. 2 0
      coriolis/osmorphing/base.py
  2. 5 4
      coriolis/osmorphing/debian.py
  3. 4 7
      coriolis/utils.py

+ 2 - 0
coriolis/osmorphing/base.py

@@ -144,6 +144,8 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
         self._write_file(tmp_file, content)
         self._exec_cmd_chroot("cp /%s /%s" % (tmp_file, chroot_path))
         self._exec_cmd_chroot("rm /%s" % tmp_file)
+        utils.exec_ssh_cmd(
+            self._ssh, "sudo sync", self._environment, get_pty=True)
 
     def _enable_systemd_service(self, service_name):
         self._exec_cmd_chroot("systemctl enable %s.service" % service_name)

+ 5 - 4
coriolis/osmorphing/debian.py

@@ -19,6 +19,7 @@ auto %(device_name)s
 iface %(device_name)s inet dhcp
 """
 
+
 class BaseDebianMorphingTools(base.BaseLinuxOSMorphingTools):
     def _check_os(self):
         lsb_release_path = "etc/lsb-release"
@@ -61,7 +62,7 @@ class BaseDebianMorphingTools(base.BaseLinuxOSMorphingTools):
         fp = StringIO()
         fp.write(LO_NIC_TPL)
         fp.write("\n\n")
-        for idx,_ in enumerate(nics_info):
+        for idx, _ in enumerate(nics_info):
             dev_name = "eth%d" % idx
             cfg = INTERFACES_NIC_TPL % {
                 "device_name": dev_name,
@@ -73,7 +74,7 @@ class BaseDebianMorphingTools(base.BaseLinuxOSMorphingTools):
 
     def _compose_netplan_cfg(self, nics_info):
         cfg = {
-            "network":{
+            "network": {
                 "version": 2,
                 "ethernets": {
                     "lo": {
@@ -85,7 +86,7 @@ class BaseDebianMorphingTools(base.BaseLinuxOSMorphingTools):
                 }
             }
         }
-        for idx,_ in enumerate(nics_info):
+        for idx, _ in enumerate(nics_info):
             cfg["network"]["ethernets"]["eth%d" % idx] = {
                 "dhcp4": True,
                 "dhcp6": True,
@@ -112,7 +113,7 @@ class BaseDebianMorphingTools(base.BaseLinuxOSMorphingTools):
                 if cnf.endswith(".yaml") or cnf.endswith(".yml"):
                     pth = "%s/%s" % (netplan_base, cnf)
                     self._exec_cmd_chroot(
-                        "cp %s %s.bak" % (pth, pth)
+                        "mv %s %s.bak" % (pth, pth)
                     )
             new_cfg = self._compose_netplan_cfg(nics_info)
             cfg_name = "%s/coriolis_netplan.yaml" % netplan_base

+ 4 - 7
coriolis/utils.py

@@ -609,8 +609,8 @@ def create_service(ssh, cmdline, svcname, run_as=None, start=True):
     else:
         raise exception.CoriolisException(
             "could not determine init system")
-        
-        
+
+
 class Grub2ConfigEditor(object):
     """This class edits GRUB2 configs, normally found in
     /etc/default/grub. This class tries to preserve commented
@@ -715,7 +715,6 @@ class Grub2ConfigEditor(object):
         else:
             raise ValueError("unknown option type: %s" % opt_type)
 
-
     def set_option(self, option, value):
         """Replaces the value of an option completely
         """
@@ -750,12 +749,12 @@ class Grub2ConfigEditor(object):
                 opt_found = True
                 found = False
                 for val in opt["option_value"]:
-                    if (val["opt_type"] == "key_val" and 
+                    if (val["opt_type"] == "key_val" and
                             value["opt_type"] == "key_val"):
                         if str(val["opt_key"]) == str(value["opt_key"]):
                             val["opt_val"] = value["opt_val"]
                             found = True
-                    elif (val["opt_type"] == "single" and 
+                    elif (val["opt_type"] == "single" and
                             value["opt_type"] == "single"):
                         if str(val["opt_val"]) == str(value["opt_val"]):
                             found = True
@@ -802,5 +801,3 @@ class Grub2ConfigEditor(object):
             tmp.write("%s\n" % fmt)
         tmp.seek(0)
         return tmp.read()
-
-