Change in vdsm[ovirt-3.5]: split network restoration from vdsmd.service

ibarkan at redhat.com ibarkan at redhat.com
Wed Mar 25 08:37:52 UTC 2015


Ido Barkan has uploaded a new change for review.

Change subject: split network restoration from vdsmd.service
......................................................................

split network restoration from vdsmd.service

Right now the task of doing network restoration is delegated to the vdsmd
service initialization. Since systemd does not expect that a long lived deamon
such as dhclient will stay alive after ExecStartPre stage, it might kill
dhclient, if that was spawned on dhcp persistent interfaces.

This patch splits systemd vdsm service into 2 dependant units:
1. vdsm-network.service which
   upgrades unified persistence and 3.0.0 networks if needed and then restore
   networks as its main mission

2. vdsmd.service which reconfigures the persistent network configuration of
   vdsm using the configured net_configurator

Note that from now on, disabling vdsmd cannot render the machine inaccessible
as the vdsm networks will be started upon boot. Note also that since it is
inconvenient to implement logic on service files, vdsm-restore-net-config
learned how to no-op when nets_restored mark exists and this functionality was
removed from the bash part.

Change-Id: I70cdf1e8a1e7063ec850081ac6199728d4cde381
Bug-Url: https://bugzilla.redhat.com/1204782
Signed-off-by: Ido Barkan <ibarkan at redhat.com>
---
M .gitignore
M init/systemd/Makefile.am
A init/systemd/vdsm-network.service.in
M init/systemd/vdsmd.service.in
M init/sysvinit/vdsmd.init.in
M init/vdsmd_init_common.sh.in
M lib/vdsm/tool/restore_nets.py
M vdsm.spec.in
M vdsm/vdsm-restore-net-config
9 files changed, 85 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/27/39127/1

diff --git a/.gitignore b/.gitignore
index c434554..55da53b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@
 init/systemd/systemd-vdsmd
 init/systemd/vdsm-tmpfiles.d.conf
 init/systemd/vdsmd.service
+init/systemd/vdsmd-network.service
 init/sysvinit/supervdsmd.init
 init/sysvinit/vdsmd.init
 init/upstart/supervdsmd.upstart
diff --git a/init/systemd/Makefile.am b/init/systemd/Makefile.am
index 4a871df..3f721c5 100644
--- a/init/systemd/Makefile.am
+++ b/init/systemd/Makefile.am
@@ -23,8 +23,9 @@
 nodist_noinst_DATA = \
 	supervdsmd.service \
 	systemd-vdsmd \
-	vdsm-tmpfiles.d.conf \
 	vdsmd.service \
+	vdsm-network.service \
+	vdsm-tmpfiles.d.conf \
 	$(NULL)
 
 CLEANFILES = \
@@ -37,6 +38,7 @@
 	systemd-vdsmd.in \
 	vdsm-tmpfiles.d.conf.in \
 	vdsmd.service.in \
+	vdsm-network.service.in \
 	$(NULL)
 
 all-local: \
diff --git a/init/systemd/vdsm-network.service.in b/init/systemd/vdsm-network.service.in
new file mode 100644
index 0000000..d863f1b
--- /dev/null
+++ b/init/systemd/vdsm-network.service.in
@@ -0,0 +1,16 @@
+[Unit]
+Description=Virtual Desktop Server Manager network restoration
+Wants=network.target
+Requires=libvirtd.service
+After=libvirtd.service
+
+[Service]
+Type=oneshot
+EnvironmentFile=-/etc/sysconfig/vdsm
+ExecStartPre=@BINDIR@/vdsm-tool --vvverbose --append --logfile=@VDSMLOGDIR@/upgrade.log upgrade-unified-persistence
+ExecStartPre=@BINDIR@/vdsm-tool --vvverbose --append --logfile=@VDSMLOGDIR@/upgrade.log upgrade-3.0.0-networks
+ExecStart=@VDSMDIR@/vdsm-restore-net-config
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target
\ No newline at end of file
diff --git a/init/systemd/vdsmd.service.in b/init/systemd/vdsmd.service.in
index 67f0dad..0f48cdf 100644
--- a/init/systemd/vdsmd.service.in
+++ b/init/systemd/vdsmd.service.in
@@ -1,7 +1,9 @@
 [Unit]
 Description=Virtual Desktop Server Manager
 Requires=multipathd.service libvirtd.service time-sync.target \
-         iscsid.service rpcbind.service supervdsmd.service sanlock.service
+         iscsid.service rpcbind.service supervdsmd.service sanlock.service \
+         vdsm-network.service
+After=vdsm-network.service
 Conflicts=libvirt-guests.service ksmtuned.service
 
 [Service]
diff --git a/init/sysvinit/vdsmd.init.in b/init/sysvinit/vdsmd.init.in
index 2ba8011..efddeb4 100755
--- a/init/sysvinit/vdsmd.init.in
+++ b/init/sysvinit/vdsmd.init.in
@@ -141,6 +141,21 @@
     fi
 }
 
+restore_nets(){
+    "@PYTHON@" "@VDSMDIR@/vdsm-restore-net-config" || return 1
+    return 0
+}
+
+unified_network_persistence_upgrade(){
+    echo 'Upgrading to unified persistence if needed'
+    "$VDSM_TOOL" ${UPGRADE_LOGGING_PARAMS} upgrade-unified-persistence
+}
+
+upgrade_300_nets(){
+    echo 'Upgrading to v3.x networking if needed'
+    "$VDSM_TOOL" ${UPGRADE_LOGGING_PARAMS} upgrade-3.0.0-networks
+}
+
 start() {
     test_already_running && return 0
 
@@ -155,6 +170,10 @@
 
     "${VDSMD_INIT_COMMON}" --pre-start || return 1
 
+    unified_network_persistence_upgrade || return 1
+    restore_nets || return 1
+    upgrade_300_nets || return 1
+
     echo $"Starting up vdsm daemon: "
     DAEMON_COREFILE_LIMIT=unlimited NICELEVEL="${NICE_LOWEST}" daemon \
         --user=vdsm "@VDSMDIR@/daemonAdapter" -0 /dev/null -1 /dev/null \
diff --git a/init/vdsmd_init_common.sh.in b/init/vdsmd_init_common.sh.in
index c94639b..784dd5a 100644
--- a/init/vdsmd_init_common.sh.in
+++ b/init/vdsmd_init_common.sh.in
@@ -246,23 +246,6 @@
 }
 
 
-task_restore_nets(){
-    local restoration_file="@VDSMRUNDIR@/nets_restored"
-    if [ ! -f "${restoration_file}" ]; then
-        "@PYTHON@" "@VDSMDIR@/vdsm-restore-net-config" || return 1
-        touch "${restoration_file}"
-    fi
-    return 0
-}
-
-task_unified_network_persistence_upgrade(){
-    "$VDSM_TOOL" ${UPGRADE_LOGGING_PARAMS} upgrade-unified-persistence
-}
-
-task_upgrade_300_nets(){
-    "$VDSM_TOOL" ${UPGRADE_LOGGING_PARAMS} upgrade-3.0.0-networks
-}
-
 task_upgraded_version_check(){
     local upgraded_ver_file="@VDSMLIBDIR@/upgraded_version"
     if [ -f "${upgraded_ver_file}" ]; then
@@ -328,9 +311,6 @@
             tune_system \
             test_space \
             test_lo \
-            unified_network_persistence_upgrade \
-            restore_nets \
-            upgrade_300_nets \
             "
         ;;
     --post-stop)
diff --git a/lib/vdsm/tool/restore_nets.py b/lib/vdsm/tool/restore_nets.py
index 41c11ee..fdc3fa2 100644
--- a/lib/vdsm/tool/restore_nets.py
+++ b/lib/vdsm/tool/restore_nets.py
@@ -37,8 +37,8 @@
 
 
 def restore():
-    rc, out, err = utils.execCmd([os.path.join(
-        P_VDSM, 'vdsm-restore-net-config')], raw=True)
+    rc, out, err = utils.execCmd(
+        [os.path.join(P_VDSM, 'vdsm-restore-net-config'), '--force'], raw=True)
     sys.stdout.write(out)
     sys.stderr.write(err)
     if rc != 0:
diff --git a/vdsm.spec.in b/vdsm.spec.in
index d2bd5ee..d39f71f 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -699,6 +699,7 @@
 %if 0%{?with_systemd}
 install -Dm 0755 init/systemd/systemd-vdsmd %{buildroot}/usr/lib/systemd/systemd-vdsmd
 install -Dm 0644 init/systemd/vdsmd.service %{buildroot}%{_unitdir}/vdsmd.service
+install -Dm 0644 init/systemd/vdsm-network.service %{buildroot}%{_unitdir}/vdsm-network.service
 install -Dm 0644 init/systemd/supervdsmd.service %{buildroot}%{_unitdir}/supervdsmd.service
 
 install -Dm 0755 vdsm_reg/vdsm-reg.init \
@@ -812,6 +813,7 @@
 /bin/systemctl restart systemd-modules-load.service >/dev/null 2>&1 || :
 if [ "$1" -eq 1 ] ; then
     /bin/systemctl enable vdsmd.service >/dev/null 2>&1 || :
+    /bin/systemctl enable vdsm-network.service >/dev/null 2>&1 || :
     /bin/systemctl enable supervdsmd.service >/dev/null 2>&1 || :
 fi
 /bin/systemctl daemon-reload >/dev/null 2>&1 || :
@@ -847,12 +849,14 @@
 %else
 %if 0%{?with_systemd_macros}
 %systemd_preun vdsmd.service
+%systemd_preun vdsmd-network.service
 %systemd_preun supervdsmd.service
 %else
 if [ "$1" -eq 0 ]; then
     /bin/systemctl --no-reload disable vdsmd.service > /dev/null 2>&1 || :
     /bin/systemctl --no-reload disable supervdsmd.service > /dev/null 2>&1 || :
     /bin/systemctl stop vdsmd.service > /dev/null 2>&1 || :
+    /bin/systemctl stop vdsm-network.service > /dev/null 2>&1 || :
     /bin/systemctl stop supervdsmd.service > /dev/null 2>&1 || :
 fi
 exit 0
@@ -956,6 +960,7 @@
 %if 0%{?with_systemd}
 /usr/lib/systemd/systemd-vdsmd
 %{_unitdir}/vdsmd.service
+%{_unitdir}/vdsm-network.service
 %{_unitdir}/supervdsmd.service
 %else
 %{_initrddir}/vdsmd
diff --git a/vdsm/vdsm-restore-net-config b/vdsm/vdsm-restore-net-config
index 974ffc8..d7cb8c7 100755
--- a/vdsm/vdsm-restore-net-config
+++ b/vdsm/vdsm-restore-net-config
@@ -18,11 +18,14 @@
 #
 # Refer to the README and COPYING files for full details of the license
 #
+import argparse
 import logging
 import logging.config
+import os
 
 from vdsm.config import config
 from vdsm import netinfo
+from vdsm.constants import P_VDSM_RUN
 
 # Ifcfg persistence restoration
 from network.configurators import ifcfg
@@ -32,6 +35,8 @@
 from network import configurators
 from vdsm.netconfpersistence import RunningConfig, PersistentConfig
 import pkgutil
+
+_NETS_RESTORED_MARK = os.path.join(P_VDSM_RUN, 'nets_restored')
 
 
 def ifcfg_restoration():
@@ -126,11 +131,26 @@
         yield cls
 
 
-def restore():
+def _nets_already_restored(nets_restored_mark):
+    return os.path.exists(nets_restored_mark)
+
+
+def touch_file(file_path):
+    with open(file_path, 'a'):
+        os.utime(file_path, None)
+
+
+def restore(args):
+    if not args.force and _nets_already_restored(_NETS_RESTORED_MARK):
+        logging.info('networks already restored. doing nothing.')
+        return
+
     if config.get('vars', 'net_persistence') == 'unified':
         unified_restoration()
     else:
         ifcfg_restoration()
+
+    touch_file(_NETS_RESTORED_MARK)
 
 
 if __name__ == '__main__':
@@ -142,4 +162,18 @@
                             level=logging.DEBUG)
         logging.error('Could not init proper logging', exc_info=True)
 
-    restore()
+    restore_help = ("Restores the network configuration from vdsm configured "
+                    "network system persistence.\n"
+                    "Restoration will delete any trace of network system "
+                    "persistence except the vdsm internal persistent network "
+                    "configuration. In order to avoid this use --no-flush.")
+    parser = argparse.ArgumentParser(description=restore_help)
+
+    force_option_help = ("Restore networks even if the " + _NETS_RESTORED_MARK
+                         + " mark exists. The mark is created upon a previous "
+                           "successful restore")
+    parser.add_argument('--force', action='store_true', default=False,
+                        help=force_option_help)
+
+    args = parser.parse_args()
+    restore(args)


-- 
To view, visit https://gerrit.ovirt.org/39127
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I70cdf1e8a1e7063ec850081ac6199728d4cde381
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Ido Barkan <ibarkan at redhat.com>


More information about the vdsm-patches mailing list