Hello Dan Kenigsberg,
I'd like you to do a code review. Please visit
https://gerrit.ovirt.org/49696
to review the following change.
Change subject: hooks: ovs: add script name to log
......................................................................
hooks: ovs: add script name to log
Change-Id: I8e40406fb2dfce6099a2c288b5d3c37ceec839d1
Signed-off-by: Petr Horáček <[email protected]>
Reviewed-on: https://gerrit.ovirt.org/46916
Continuous-Integration: Jenkins CI
Reviewed-by: Dan Kenigsberg <[email protected]>
Tested-by: Dan Kenigsberg <[email protected]>
Bug-Url: https://bugzilla.redhat.com/1234867
---
M vdsm_hooks/ovs/ovs_after_get_stats.py
M vdsm_hooks/ovs/ovs_after_network_setup.py
M vdsm_hooks/ovs/ovs_after_network_setup_fail.py
M vdsm_hooks/ovs/ovs_before_network_setup.py
M vdsm_hooks/ovs/ovs_before_network_setup_ip.py
M vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
M vdsm_hooks/ovs/ovs_utils.py
7 files changed, 56 insertions(+), 30 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/96/49696/1
diff --git a/vdsm_hooks/ovs/ovs_after_get_stats.py
b/vdsm_hooks/ovs/ovs_after_get_stats.py
index 6209f0a..b902f57 100755
--- a/vdsm_hooks/ovs/ovs_after_get_stats.py
+++ b/vdsm_hooks/ovs/ovs_after_get_stats.py
@@ -17,6 +17,7 @@
#
# Refer to the README and COPYING files for full details of the license
#
+from functools import partial
import traceback
from vdsm.netconfpersistence import RunningConfig
@@ -24,6 +25,9 @@
import hooking
from ovs_utils import is_ovs_network
+import ovs_utils
+
+log = partial(ovs_utils.log, tag='ovs_after_get_stats: ')
def ovs_networks_stats(stats):
@@ -50,8 +54,7 @@
ovs_networks_stats[vlan_name] = stats[network]
ovs_networks_stats[vlan_name]['name'] = vlan_name
- hooking.log('Updating network stats with OVS networks: %s' %
- ovs_networks_stats)
+ log('Updating network stats with OVS networks: %s' % ovs_networks_stats)
return ovs_networks_stats
diff --git a/vdsm_hooks/ovs/ovs_after_network_setup.py
b/vdsm_hooks/ovs/ovs_after_network_setup.py
index 0d3bb94..560ede3 100755
--- a/vdsm_hooks/ovs/ovs_after_network_setup.py
+++ b/vdsm_hooks/ovs/ovs_after_network_setup.py
@@ -17,6 +17,7 @@
#
# Refer to the README and COPYING files for full details of the license
#
+from functools import partial
import errno
import os
import traceback
@@ -24,6 +25,9 @@
import hooking
from ovs_utils import INIT_CONFIG_FILE
+import ovs_utils
+
+log = partial(ovs_utils.log, tag='ovs_after_network_setup: ')
def _remove_init_config():
@@ -42,10 +46,9 @@
'_inOVSRollback')
if in_ovs_rollback:
- hooking.log('Rollback is done. Removing OVS init_config backup.')
+ log('Rollback is done. Removing OVS init_config backup.')
else:
- hooking.log('Network setup was successful. Removing OVS init_config '
- 'backup.')
+ log('Network setup was successful. Removing OVS init_config backup.')
_remove_init_config()
diff --git a/vdsm_hooks/ovs/ovs_after_network_setup_fail.py
b/vdsm_hooks/ovs/ovs_after_network_setup_fail.py
index c9b224b..4400e80 100755
--- a/vdsm_hooks/ovs/ovs_after_network_setup_fail.py
+++ b/vdsm_hooks/ovs/ovs_after_network_setup_fail.py
@@ -17,11 +17,16 @@
#
# Refer to the README and COPYING files for full details of the license
#
+from functools import partial
import traceback
from vdsm import supervdsm
import hooking
+
+import ovs_utils
+
+log = partial(ovs_utils.log, tag='ovs_after_network_setup_fail: ')
def main():
@@ -30,10 +35,10 @@
in_rollback = setup_nets_config['request']['options'].get('_inRollback')
if in_rollback:
- hooking.log('Configuration failed with _inRollback=True.')
+ log('Configuration failed with _inRollback=True.')
else:
- hooking.log('Configuration failed. At this point, non-OVS rollback '
- 'should be done. Executing OVS rollback.')
+ log('Configuration failed. At this point, non-OVS rollback should be '
+ 'done. Executing OVS rollback.')
supervdsm.getProxy().setupNetworks(
{}, {}, {'connectivityCheck': False, '_inRollback': True,
'_inOVSRollback': True})
diff --git a/vdsm_hooks/ovs/ovs_before_network_setup.py
b/vdsm_hooks/ovs/ovs_before_network_setup.py
index bea3c33..6e48037 100755
--- a/vdsm_hooks/ovs/ovs_before_network_setup.py
+++ b/vdsm_hooks/ovs/ovs_before_network_setup.py
@@ -24,6 +24,7 @@
import pickle
from copy import deepcopy
+from functools import partial
import errno
import sys
import traceback
@@ -43,10 +44,13 @@
from ovs_setup_mtu import configure_mtu
from ovs_setup_libvirt import (create_libvirt_nets, remove_libvirt_nets,
prepare_libvirt)
+import ovs_utils
# TODO: move required modules into vdsm/lib
sys.path.append('/usr/share/vdsm')
from network.configurators import libvirt
+
+log = partial(ovs_utils.log, tag='ovs_before_network_setup: ')
def _set_nets_bonds(config, nets, bonds):
@@ -80,8 +84,8 @@
def _destroy_ovs_libvirt_nets(initial_config, running_config):
- hooking.log('Removing OVS and libvirt networks: %s %s' %
- (initial_config, running_config))
+ log('Removing OVS and libvirt networks: %s %s' % (initial_config,
+ running_config))
for libvirt_ovs_nets in (iter_ovs_nets(running_config.networks),
iter_ovs_nets(initial_config.networks)):
for net, attrs in libvirt_ovs_nets:
@@ -121,12 +125,12 @@
def _rollback(running_config):
initial_config = _load_init_config()
if initial_config is None:
- hooking.log('No needed OVS changes to be done.')
+ log('No needed OVS changes to be done.')
else:
- hooking.log('Removing OVS networks.')
+ log('Removing OVS networks.')
_destroy_ovs_libvirt_nets(initial_config, running_config)
_drop_ovs_nets_config(running_config)
- hooking.log('Reconfiguring OVS networks according to initial_config.')
+ log('Reconfiguring OVS networks according to initial_config.')
_configure(initial_config.networks, initial_config.bonds,
running_config, save_init_config=False)
@@ -138,8 +142,8 @@
libvirt_create, libvirt_remove = prepare_libvirt(nets, running_config)
if save_init_config:
- hooking.log('Saving initial configuration for optional rollback: %s' %
- initial_config)
+ log('Saving initial configuration for optional rollback: %s' %
+ initial_config)
_save_init_config(initial_config)
remove_libvirt_nets(libvirt_remove)
@@ -147,8 +151,8 @@
configure_mtu(running_config)
configure_ip(nets, initial_config.networks)
- hooking.log('Saving running configuration: %s %s' %
- (running_config.networks, running_config.bonds))
+ log('Saving running configuration: %s %s' % (running_config.networks,
+ running_config.bonds))
running_config.save()
# we have to create libvirt nets last. when an exception occurs, rollback
@@ -159,7 +163,7 @@
def main():
setup_nets_config = hooking.read_json()
- hooking.log('Hook started, handling: %s' % setup_nets_config)
+ log('Hook started, handling: %s' % setup_nets_config)
running_config = RunningConfig()
networks = setup_nets_config['request']['networks']
@@ -169,19 +173,19 @@
'_inOVSRollback')
if in_ovs_rollback:
- hooking.log('OVS rollback is to be done.')
+ log('OVS rollback is to be done.')
_rollback(running_config)
_set_nets_bonds(setup_nets_config['request'], {}, {})
- hooking.log('OVS rollback finished, returning empty networks and '
- 'bondings configuration back to VDSM.')
+ log('OVS rollback finished, returning empty networks and bondings '
+ 'configuration back to VDSM.')
else:
ovs_nets, non_ovs_nets, ovs_bonds, non_ovs_bonds = \
_separate_ovs_nets_bonds(networks, bondings, running_config)
_configure(ovs_nets, ovs_bonds, running_config)
_set_nets_bonds(setup_nets_config['request'], non_ovs_nets,
non_ovs_bonds)
- hooking.log('Hook finished, returning non-OVS networks and bondings '
- 'back to VDSM: %s' % setup_nets_config)
+ log('Hook finished, returning non-OVS networks and bondings back to '
+ 'VDSM: %s' % setup_nets_config)
hooking.write_json(setup_nets_config)
diff --git a/vdsm_hooks/ovs/ovs_before_network_setup_ip.py
b/vdsm_hooks/ovs/ovs_before_network_setup_ip.py
index c29d517..88feec8 100644
--- a/vdsm_hooks/ovs/ovs_before_network_setup_ip.py
+++ b/vdsm_hooks/ovs/ovs_before_network_setup_ip.py
@@ -18,14 +18,14 @@
# Refer to the README and COPYING files for full details of the license
#
from collections import namedtuple
+from functools import partial
import os
import sys
from vdsm import ipwrapper, sysctl
-import hooking
-
from ovs_utils import suppress, BRIDGE_NAME
+import ovs_utils
# TODO: move required modules into vdsm/lib
sys.path.append('/usr/share/vdsm')
@@ -33,6 +33,8 @@
from network.configurators.iproute2 import Iproute2
from network.models import NetDevice, IPv4, IPv6
from network.sourceroute import DynamicSourceRoute
+
+log = partial(ovs_utils.log, tag='ovs_before_network_setup_ip: ')
iproute2 = Iproute2()
@@ -63,7 +65,7 @@
dhclient = DhcpClient(iface, family, default_route)
rc = dhclient.start(blockingdhcp)
if blockingdhcp and rc:
- hooking.log('failed to start dhclient%s on iface %s' % (family, iface))
+ log('failed to start dhclient%s on iface %s' % (family, iface))
def _set_ip_config(ip_config):
@@ -168,8 +170,8 @@
if ip_config.ipv4 or ip_config.ipv6:
ip_config_to_set[ip_config.top_dev] = ip_config
- hooking.log('Remove IP configuration of: %s' % ip_config_to_remove)
- hooking.log('Set IP configuration: %s' % ip_config_to_set)
+ log('Remove IP configuration of: %s' % ip_config_to_remove)
+ log('Set IP configuration: %s' % ip_config_to_set)
for iface, ip_config in ip_config_to_remove.iteritems():
_remove_ip_config(ip_config)
for iface, ip_config in ip_config_to_set.items():
diff --git a/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
b/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
index 528f8ef..6f8f080 100644
--- a/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
+++ b/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
@@ -17,6 +17,7 @@
#
# Refer to the README and COPYING files for full details of the license
#
+from functools import partial
import sys
from vdsm.netinfo import NetInfo
@@ -26,10 +27,13 @@
from ovs_utils import (get_bond_options, is_ovs_bond, iter_ovs_nets,
iter_ovs_bonds, rget, suppress, destroy_ovs_bridge,
BRIDGE_NAME, EXT_OVS_VSCTL)
+import ovs_utils
# TODO: move required modules into vdsm/lib
sys.path.append('/usr/share/vdsm')
from network.configurators import libvirt
+
+log = partial(ovs_utils.log, tag='ovs_before_network_setup_ovs: ')
VALID_MODES = frozenset(['active-backup', 'balance-tcp', 'balance-slb'])
VALID_LACP = frozenset(['active', 'passive', 'off'])
@@ -41,7 +45,7 @@
return
for bond, attr in iter_ovs_bonds(running_config.bonds):
return
- hooking.log('Removing redundant OVS bridge')
+ log('Removing redundant OVS bridge')
destroy_ovs_bridge()
@@ -62,7 +66,7 @@
if commands:
commands = [EXT_OVS_VSCTL, '--', '--may-exist', 'add-br',
BRIDGE_NAME] + commands
- hooking.log('Executing commands: %s' % ' '.join(commands))
+ log('Executing commands: %s' % ' '.join(commands))
rc, _, err = hooking.execCmd(commands)
if rc != 0:
raise Exception('Executing commands failed: %s' % '\n'.join(err))
diff --git a/vdsm_hooks/ovs/ovs_utils.py b/vdsm_hooks/ovs/ovs_utils.py
index 23ab618..16be474 100644
--- a/vdsm_hooks/ovs/ovs_utils.py
+++ b/vdsm_hooks/ovs/ovs_utils.py
@@ -20,6 +20,7 @@
from contextlib import contextmanager
from hooking import execCmd
+import hooking
from vdsm.utils import CommandPath
@@ -114,3 +115,7 @@
rc, _, err = execCmd(commands)
if rc != 0:
raise Exception('\n'.join(err))
+
+
+def log(message, tag='OVS: '):
+ hooking.log('%s%s' % (tag, message))
--
To view, visit https://gerrit.ovirt.org/49696
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e40406fb2dfce6099a2c288b5d3c37ceec839d1
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Petr Horáček <[email protected]>
Gerrit-Reviewer: Dan Kenigsberg <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches