Ondřej Svoboda has uploaded a new change for review. Change subject: netinfo, tool: Make the bonding defaults a proper Python file ......................................................................
netinfo, tool: Make the bonding defaults a proper Python file Instead of loading a JSON dump (and playing tricks to load it in tests) it is easier to let Python load a module for us, employing its knowledge of PATH. TODO: See how to set the proper SELinux context in the generator. Change-Id: Ic1f62c0052e42ea23cc06e64fc9e158bf5dc4258 Signed-off-by: Ondřej Svoboda <[email protected]> --- M debian/vdsm-python.install M debian/vdsm.install M lib/vdsm/Makefile.am R lib/vdsm/bonding_defaults.py M lib/vdsm/netinfo.py M lib/vdsm/tool/dump_bonding_defaults.py M tests/netinfoTests.py M vdsm.spec.in M vdsm/Makefile.am 9 files changed, 14 insertions(+), 39 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/90/33890/1 diff --git a/debian/vdsm-python.install b/debian/vdsm-python.install index 1158db2..b1c2d40 100644 --- a/debian/vdsm-python.install +++ b/debian/vdsm-python.install @@ -1,6 +1,7 @@ ./etc/vdsm/vdsm.conf ./usr/bin/vdsm-tool ./usr/lib/python2.7/dist-packages/vdsm/__init__.py +./usr/lib/python2.7/dist-packages/vdsm/bonding_defaults.py ./usr/lib/python2.7/dist-packages/vdsm/compat.py ./usr/lib/python2.7/dist-packages/vdsm/config.py ./usr/lib/python2.7/dist-packages/vdsm/constants.py diff --git a/debian/vdsm.install b/debian/vdsm.install index 76380dd..650156e 100644 --- a/debian/vdsm.install +++ b/debian/vdsm.install @@ -23,7 +23,6 @@ ./lib/udev/rules.d/61-vdsm-lvm.rules ./usr/lib/python2.7/dist-packages/sos/plugins/vdsm.py ./usr/lib/python2.7/dist-packages/vdsmapi.py -./var/lib/vdsm/bonding-defaults.json ./usr/libexec/vdsm/curl-img-wrap ./usr/libexec/vdsm/ovirt_functions.sh ./usr/libexec/vdsm/persist-vdsm-hooks diff --git a/lib/vdsm/Makefile.am b/lib/vdsm/Makefile.am index 4bebf28..dcbef51 100644 --- a/lib/vdsm/Makefile.am +++ b/lib/vdsm/Makefile.am @@ -23,6 +23,7 @@ dist_vdsmpylib_PYTHON = \ __init__.py \ + bonding_defaults.py \ compat.py \ define.py \ exception.py \ diff --git a/vdsm/bonding-defaults.json b/lib/vdsm/bonding_defaults.py similarity index 98% rename from vdsm/bonding-defaults.json rename to lib/vdsm/bonding_defaults.py index 52f2d6c..6def630 100644 --- a/vdsm/bonding-defaults.json +++ b/lib/vdsm/bonding_defaults.py @@ -1,4 +1,4 @@ -{ +BONDING_DEFAULTS = { "0": { "ad_select": [ "stable", @@ -419,4 +419,4 @@ "0" ] } -} \ No newline at end of file +} diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py index 78d26fa..3d25f16 100644 --- a/lib/vdsm/netinfo.py +++ b/lib/vdsm/netinfo.py @@ -24,7 +24,6 @@ from datetime import datetime from functools import partial from itertools import chain -import json import logging import os import shlex @@ -32,6 +31,7 @@ import struct from xml.dom import minidom +from .bonding_defaults import BONDING_DEFAULTS from .config import config from . import constants from .ipwrapper import drv_name @@ -66,7 +66,6 @@ BONDING_MASTERS = '/sys/class/net/bonding_masters' BONDING_SLAVES = '/sys/class/net/%s/bonding/slaves' BONDING_OPT = '/sys/class/net/%s/bonding/%s' -BONDING_DEFAULTS = constants.P_VDSM_LIB + 'bonding-defaults.json' BRIDGING_OPT = '/sys/class/net/%s/bridge/%s' _BONDING_FAILOVER_MODES = frozenset(('1', '3')) _BONDING_LOADBALANCE_MODES = frozenset(('0', '2', '4', '5', '6')) @@ -403,27 +402,15 @@ @memoized -def _getAllDefaultBondingOptions(): - """ - Return default options per mode, in a dictionary of dictionaries. All keys - are numeric modes stored as strings for coherence with 'mode' option value. - """ - with open(BONDING_DEFAULTS) as defaults: - return json.loads(defaults.read()) - - -@memoized def _getDefaultBondingOptions(mode=None): """ Return default options for the given mode. If it is None, return options for the default mode (usually '0'). """ - defaults = _getAllDefaultBondingOptions() - if mode is None: - mode = defaults['0']['mode'][-1] + mode = BONDING_DEFAULTS['0']['mode'][-1] - return defaults[mode] + return BONDING_DEFAULTS[mode] def _getBondingOptions(bond): diff --git a/lib/vdsm/tool/dump_bonding_defaults.py b/lib/vdsm/tool/dump_bonding_defaults.py index 09bb82d..fb48f65 100644 --- a/lib/vdsm/tool/dump_bonding_defaults.py +++ b/lib/vdsm/tool/dump_bonding_defaults.py @@ -22,8 +22,7 @@ import random import string -from ..netinfo import (BONDING_MASTERS, BONDING_OPT, BONDING_DEFAULTS, - bondOpts, realBondOpts) +from ..netinfo import BONDING_MASTERS, BONDING_OPT, bondOpts, realBondOpts from . import expose, ExtraArgsError @@ -71,13 +70,16 @@ def main(*args): """dump-bonding-defaults - Read bonding option defaults (per mode) and dump them to BONDING_DEFAULTS - in JSON format. + Read bonding option defaults (per mode) and dump the dictionary to a Python + source file alongside lib/netinfo.py """ + BONDING_DEFAULTS = '../bonding_defaults.py' if len(args) > 1: raise ExtraArgsError() with open(BONDING_DEFAULTS, 'w') as defaults: + defaults.write('BONDING_DEFAULTS = ') json.dump(_get_default_bonding_options(), defaults, sort_keys=True, indent=4, separators=(',', ': ')) + defaults.write('\n') diff --git a/tests/netinfoTests.py b/tests/netinfoTests.py index e1a7fed..18a2b1d 100644 --- a/tests/netinfoTests.py +++ b/tests/netinfoTests.py @@ -301,9 +301,6 @@ self.assertNotIn('expired', dhcp4) self.assertNotIn('expired2', dhcp4) - @MonkeyPatch(netinfo, 'BONDING_DEFAULTS', netinfo.BONDING_DEFAULTS - if os.path.exists(netinfo.BONDING_DEFAULTS) - else '../vdsm/bonding-defaults.json') @ValidateRunningAsRoot @RequireBondingMod def testGetBondingOptions(self): diff --git a/vdsm.spec.in b/vdsm.spec.in index c38d5bb..44d01ae 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -1210,7 +1210,6 @@ %dir %{_sysconfdir}/pki/%{vdsm_name}/certs %dir %{_sysconfdir}/pki/%{vdsm_name}/libvirt-spice %config(noreplace) %{_sysconfdir}/pki/%{vdsm_name}/keys/libvirt_password -%{_localstatedir}/lib/%{vdsm_name}/bonding-defaults.json %dir %{_localstatedir}/lib/%{vdsm_name} %dir %{_localstatedir}/lib/%{vdsm_name}/netconfback %dir %{_localstatedir}/lib/%{vdsm_name}/persistence @@ -1230,6 +1229,7 @@ %dir %{python_sitelib}/%{vdsm_name}/netlink %dir %{python_sitelib}/%{vdsm_name}/tool %{python_sitelib}/%{vdsm_name}/__init__.py* +%{python_sitelib}/%{vdsm_name}/bonding_defaults.py %{python_sitelib}/%{vdsm_name}/compat.py* %{python_sitelib}/%{vdsm_name}/config.py* %{python_sitelib}/%{vdsm_name}/constants.py* diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am index d40c7d0..1c42fdf 100644 --- a/vdsm/Makefile.am +++ b/vdsm/Makefile.am @@ -91,7 +91,6 @@ $(nodist_man8_MANS) EXTRA_DIST = \ - bonding-defaults.json \ dsaversion.py.in \ dumpStorageTable.py.in \ libvirt_password \ @@ -131,7 +130,6 @@ chmod 775 $(DESTDIR)$(localstatedir)/lib/libvirt/qemu/channels install-data-local: \ - install-data-bonding-defaults \ install-data-dhclient-hooks \ install-data-libvirtpass \ install-data-logger \ @@ -158,7 +156,6 @@ $(MKDIR_P) $(DESTDIR)$(localstatedir)/lib/libvirt/qemu/channels uninstall-local: \ - uninstall-data-bonding-defaults \ uninstall-data-dhclient-hooks \ uninstall-data-libvirtpass \ uninstall-data-logger \ @@ -185,15 +182,6 @@ uninstall-data-libvirtpass: $(RM) $(DESTDIR)$(vdsmtsdir)/keys/libvirt_password - -# lib/vdsm does not exist yet -install-data-bonding-defaults: - $(MKDIR_P) $(DESTDIR)$(vdsmlibdir) - $(INSTALL_DATA) -m 600 $(srcdir)/bonding-defaults.json \ - $(DESTDIR)$(vdsmlibdir)/bonding-defaults.json - -uninstall-data-bonding-defaults: - $(RM) $(DESTDIR)$(vdsmlibdir)/bonding-defaults.json install-data-rwtab: $(MKDIR_P) $(DESTDIR)$(sysconfdir)/rwtab.d -- To view, visit http://gerrit.ovirt.org/33890 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic1f62c0052e42ea23cc06e64fc9e158bf5dc4258 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Ondřej Svoboda <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
