Change in vdsm[ovirt-3.6]: hooks: after_network_setup_fail

phoracek at redhat.com phoracek at redhat.com
Thu Dec 3 23:31:02 UTC 2015


Hello Ido Barkan, Dan Kenigsberg,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/49688

to review the following change.

Change subject: hooks: after_network_setup_fail
......................................................................

hooks: after_network_setup_fail

When an exception occurs during network setup, rollback is executed
and after_network_setup is never triggered.

This hook point triggers hooks right after setupNetworks fails and
finishes its rollback.

We need this for Open vSwitch hook. However, this hook point might
be useful for other cases as well.

Change-Id: I8a5d086b15b72c13d2b390c1310c2279446ac14f
Signed-off-by: Petr Horáček <phoracek at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/45085
Continuous-Integration: Jenkins CI
Reviewed-by: Ido Barkan <ibarkan at redhat.com>
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
Bug-Url: https://bugzilla.redhat.com/1234867
---
M debian/vdsm.dirs
M vdsm.spec.in
M vdsm/API.py
M vdsm/hooks.py
M vdsm/vdsmd.8.in
M vdsm_hooks/Makefile.am
6 files changed, 33 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/88/49688/1

diff --git a/debian/vdsm.dirs b/debian/vdsm.dirs
index 7e75399..b621e07 100644
--- a/debian/vdsm.dirs
+++ b/debian/vdsm.dirs
@@ -21,6 +21,7 @@
 usr/libexec/vdsm/hooks/after_get_vm_stats
 usr/libexec/vdsm/hooks/after_hostdev_list_by_caps
 usr/libexec/vdsm/hooks/after_network_setup
+usr/libexec/vdsm/hooks/after_network_setup_fail
 usr/libexec/vdsm/hooks/after_nic_hotplug
 usr/libexec/vdsm/hooks/after_nic_hotplug_fail
 usr/libexec/vdsm/hooks/after_nic_hotunplug
diff --git a/vdsm.spec.in b/vdsm.spec.in
index b7cb5b8..696920d 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -988,6 +988,7 @@
 %dir %{_libexecdir}/%{vdsm_name}/hooks/after_vdsm_stop
 %dir %{_libexecdir}/%{vdsm_name}/hooks/before_network_setup
 %dir %{_libexecdir}/%{vdsm_name}/hooks/after_network_setup
+%dir %{_libexecdir}/%{vdsm_name}/hooks/after_network_setup_fail
 %dir %{_libexecdir}/%{vdsm_name}/hooks/before_set_num_of_cpus
 %dir %{_libexecdir}/%{vdsm_name}/hooks/after_set_num_of_cpus
 %dir %{_libexecdir}/%{vdsm_name}/hooks/before_memory_hotplug
diff --git a/vdsm/API.py b/vdsm/API.py
index 117b0ee..e68c04d 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -69,6 +69,15 @@
 USER_SHUTDOWN_MESSAGE = 'System going down'
 
 
+def _after_network_setup_fail(networks, bondings, options):
+    # TODO: it might be useful to pass failure description in 'response' field
+    network_config_dict = {
+        'request': {'networks': dict(networks),
+                    'bondings': dict(bondings),
+                    'options': dict(options)}}
+    hooks.after_network_setup_fail(network_config_dict)
+
+
 def updateTimestamp():
     # The setup+editNetwork API uses this log file to
     # determine if this host is still accessible.  We use a
@@ -1482,10 +1491,16 @@
 
             with self._rollback() as rollbackCtx:
                 supervdsm.getProxy().setupNetworks(networks, bondings, options)
+
+            if rollbackCtx['status'] != doneCode:
+                _after_network_setup_fail(networks, bondings, options)
             return rollbackCtx
         except hooks.HookError as e:
+            _after_network_setup_fail(networks, bondings, options)
             return response.error('hookError', 'Hook error: ' + str(e))
-
+        except:
+            _after_network_setup_fail(networks, bondings, options)
+            raise
         finally:
             self._cif._networkSemaphore.release()
 
diff --git a/vdsm/hooks.py b/vdsm/hooks.py
index 2aa5882..45068a2 100644
--- a/vdsm/hooks.py
+++ b/vdsm/hooks.py
@@ -351,6 +351,11 @@
                         raiseError=False, hookType=_JSON_HOOK)
 
 
+def after_network_setup_fail(network_config_dict):
+    return _runHooksDir(network_config_dict, 'after_network_setup_fail',
+                        raiseError=False, hookType=_JSON_HOOK)
+
+
 def before_get_vm_stats():
     return _runHooksDir({}, 'before_get_vm_stats', raiseError=True,
                         hookType=_JSON_HOOK)
diff --git a/vdsm/vdsmd.8.in b/vdsm/vdsmd.8.in
index 903c08c..096ce08 100644
--- a/vdsm/vdsmd.8.in
+++ b/vdsm/vdsmd.8.in
@@ -57,7 +57,7 @@
     before_disk_hotplug, after_disk_hotplug,
     before_disk_hotunplug, after_disk_hotunplug,
     before_vdsm_start, after_vdsm_stop,
-    before_network_setup, after_network_setup,
+    before_network_setup, after_network_setup, after_network_setup_fail,
     before_set_num_of_cpus, after_set_num_of_cpus,
     before_get_vm_stats, after_get_vm_stats,
     before_get_all_vm_stats, after_get_all_vm_stats,
@@ -73,8 +73,9 @@
 
 .SS Hook environment
 Each hook script (except before_vdsm_start, after_vdsm_stop,
-before_network_setup and after_network_setup, before_get_vm_stats,
-after_get_vm_stats, before_get_all_vm_stats, after_get_all_vm_stats,
+before_network_setup, after_network_setup and after_network_setup_fail,
+before_get_vm_stats, after_get_vm_stats,
+before_get_all_vm_stats, after_get_all_vm_stats,
 before_get_caps, after_get_caps,
 before_get_stats, after_get_stats, after_hostdev_list_by_caps,
 before_ifcfg_write and after_ifcfg_write) inherit
@@ -87,8 +88,9 @@
 available as the environment variable
 .B vmId.
 
-The before_network_setup, after_network_setup, before_ifcfg_write and
-after_ifcfg_write hooks do also include an extra environment variable
+The before_network_setup, after_network_setup, after_network_setup_fail,
+before_ifcfg_write and after_ifcfg_write hooks do also include an extra
+environment variable
 .B _hook_json
 which holds a pointer to a file with the network parameters that vdsm is
 setting up (
@@ -97,8 +99,8 @@
 , the request may be modified by the before_network_setup hook as thus affect
 the operation ultimately taken place by Vdsm.
 
-The JSON format of this file for before_network_setup and
-after_network_setup has one section: request, this section
+The JSON format of this file for before_network_setup, after_network_setup and
+after_network_setup_fail has one section: request, this section
 contains networks, bondings and options, those parameters are specified
 in the setupNetworks VDSM API call.
 
diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am
index 2f7638c..f922fa3 100644
--- a/vdsm_hooks/Makefile.am
+++ b/vdsm_hooks/Makefile.am
@@ -117,6 +117,7 @@
 	after_vdsm_stop \
 	before_network_setup \
 	after_network_setup \
+	after_network_setup_fail \
 	before_set_num_of_cpus \
 	after_set_num_of_cpus \
 	before_get_vm_stats \


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8a5d086b15b72c13d2b390c1310c2279446ac14f
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Petr Horáček <phoracek at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Ido Barkan <ibarkan at redhat.com>


More information about the vdsm-patches mailing list