Change in vdsm[master]: utils: move rget to utils
phoracek at redhat.com
phoracek at redhat.com
Fri Apr 8 10:59:44 UTC 2016
Petr Horáček has uploaded a new change for review.
Change subject: utils: move rget to utils
......................................................................
utils: move rget to utils
Move rget from ovs utils to vdsm utils so we can use it with both
hook and native ovs.
Change-Id: I93ae32e5ffbfa20a79081aea330e3df3663c3966
Bug-Url: https://bugzilla.redhat.com/1234867
Signed-off-by: Petr Horáček <phoracek at redhat.com>
---
M lib/vdsm/utils.py
M tests/utilsTests.py
M vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
3 files changed, 23 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/60/55860/1
diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index 2370fcd..720262f 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -916,3 +916,16 @@
return func(inst, *args, **kwargs)
return wrapper
+
+
+def rget(dict, keys, default=None):
+ """Recursive dictionary.get()
+
+ >>> rget({'a': {'b': 'hello'}}, ('a', 'b'))
+ 'hello'
+ """
+ if dict is None:
+ return default
+ elif len(keys) == 0:
+ return dict
+ return rget(dict.get(keys[0]), keys[1:], default)
diff --git a/tests/utilsTests.py b/tests/utilsTests.py
index c8b4d17..133327d 100644
--- a/tests/utilsTests.py
+++ b/tests/utilsTests.py
@@ -341,6 +341,14 @@
def test_unique(self, iterable, unique_items):
self.assertEquals(utils.unique(iterable,), unique_items)
+ def test_rget(self):
+ self.assertEqual(
+ utils.rget({'a': {'b': 'hello'}}, ('a', 'b')),
+ 'hello')
+ self.assertEqual(
+ utils.rget({'a': {'b': 'hello'}}, ('a', 'c'), default='bye'),
+ 'bye')
+
class AsyncProcessOperationTests(TestCaseBase):
def _echo(self, text):
diff --git a/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py b/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
index 57098f1..4e023ba 100644
--- a/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
+++ b/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
@@ -25,10 +25,11 @@
from vdsm.netinfo.cache import CachingNetInfo
from vdsm.netinfo.bonding import parse_bond_options
from vdsm.network.configurators import libvirt
+from vdsm.utils import rget
import hooking
-from ovs_utils import (is_ovs_bond, iter_ovs_nets, iter_ovs_bonds, rget,
+from ovs_utils import (is_ovs_bond, iter_ovs_nets, iter_ovs_bonds,
destroy_ovs_bridge, BRIDGE_NAME, EXT_OVS_VSCTL)
import ovs_utils
--
To view, visit https://gerrit.ovirt.org/55860
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I93ae32e5ffbfa20a79081aea330e3df3663c3966
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Petr Horáček <phoracek at redhat.com>
More information about the vdsm-patches
mailing list