Change in vdsm[master]: vdsm-tool: suppoort dependencies between ModuleConfigure
mtayer at redhat.com
mtayer at redhat.com
Tue Aug 12 18:39:56 UTC 2014
mooli tayer has uploaded a new change for review.
Change subject: vdsm-tool: suppoort dependencies between ModuleConfigure
......................................................................
vdsm-tool: suppoort dependencies between ModuleConfigure
Change-Id: Ibf63ce9aa3ca8edb82091d09b976e8e23896524e
Signed-off-by: Mooli Tayer <mtayer at redhat.com>
---
M lib/vdsm/tool/configurator.py
M lib/vdsm/tool/configurators/__init__.py
M tests/toolTests.py
3 files changed, 126 insertions(+), 9 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/23/31423/1
diff --git a/lib/vdsm/tool/configurator.py b/lib/vdsm/tool/configurator.py
index 50bdc53..608dbbf 100644
--- a/lib/vdsm/tool/configurator.py
+++ b/lib/vdsm/tool/configurator.py
@@ -31,7 +31,7 @@
sanlock
-__configurers = (
+_configurers = (
libvirt.Libvirt(),
sanlock.Sanlock(),
)
@@ -48,7 +48,7 @@
configurer_to_trigger = []
sys.stdout.write("\nChecking configuration status...\n\n")
- for c in __configurers:
+ for c in _configurers:
if c.getName() in args.modules:
isconfigured = c.isconfigured()
override = args.force and isconfigured != CONFIGURED
@@ -74,7 +74,7 @@
for s in services:
service.service_stop(s)
- sys.stdout.write("\nRunning configure...\n")
+ sys.stdout.write("\nRunning configure on:%s...\n")
for c in configurer_to_trigger:
c.configure()
sys.stdout.write("Reconfiguration of %s is done.\n" % (c.getName(),))
@@ -95,7 +95,7 @@
args = _parse_args(*args)
m = [
- c.getName() for c in __configurers
+ c.getName() for c in _configurers
if c.getName() in args.modules and c.isconfigured() == NOT_CONFIGURED
]
@@ -132,7 +132,7 @@
args = _parse_args(*args)
m = [
- c.getName() for c in __configurers
+ c.getName() for c in _configurers
if c.getName() in args.modules and not c.validate()
]
@@ -153,8 +153,8 @@
"""
args = _parse_args(*args)
failed = False
- for c in __configurers:
- if c.getName() in args.modules:
+ for c in _configurers:
+ if c.getName() in reversed(args.modules):
try:
c.removeConf()
sys.stderr.write(
@@ -173,9 +173,36 @@
raise InvalidRun("Remove configuration failed")
+def _add_dependencies(modules):
+ with_dep = set(modules)
+ for c in _configurers:
+ if c.getName() in modules:
+ with_dep.update(c.requires())
+ return list(with_dep)
+
+
+def _sort_modules(modules):
+ sortedModules = []
+ while modules:
+ foundNext = False
+
+ for c in _configurers:
+ if c.getName() in modules:
+ if not c.requires() or c.requires().issubset(sortedModules):
+ foundNext = True
+ modules.remove(c.getName())
+ sortedModules.append(c.getName())
+ break
+
+ if not foundNext:
+ raise RuntimeError("Dependency circle found!")
+
+ return sortedModules
+
+
def _parse_args(action, *args):
parser = argparse.ArgumentParser('vdsm-tool %s' % (action))
- allModules = [n.getName() for n in __configurers]
+ allModules = [n.getName() for n in _configurers]
parser.add_argument(
'--module',
dest='modules',
@@ -199,6 +226,13 @@
help='Force configuration, trigger services restart',
)
args = parser.parse_args(args)
+
if not args.modules:
args.modules = allModules
+ else:
+ # add dependencies
+ args.modules = _add_dependencies(args.modules)
+
+ args.modules = _sort_modules(args.modules)
+
return args
diff --git a/lib/vdsm/tool/configurators/__init__.py b/lib/vdsm/tool/configurators/__init__.py
index 41bc1d0..ef379ab 100644
--- a/lib/vdsm/tool/configurators/__init__.py
+++ b/lib/vdsm/tool/configurators/__init__.py
@@ -64,3 +64,6 @@
def removeConf(self):
pass
+
+ def requires(self):
+ return set()
diff --git a/tests/toolTests.py b/tests/toolTests.py
index ad08ba8..c80cc7c 100644
--- a/tests/toolTests.py
+++ b/tests/toolTests.py
@@ -17,7 +17,11 @@
#
# Refer to the README and COPYING files for full details of the license
#
-from vdsm.tool.configurators import NOT_CONFIGURED, NOT_SURE
+from vdsm.tool import configurator
+from vdsm.tool.configurators import \
+ ModuleConfigure, \
+ NOT_CONFIGURED,\
+ NOT_SURE
from vdsm.tool.configurators.configfile import ConfigFile, ParserWrapper
from vdsm.tool.configurators.libvirt import Libvirt
from vdsm.tool import upgrade
@@ -31,6 +35,82 @@
dirName = os.path.dirname(os.path.realpath(__file__))
+class MockModuleConfigurator(ModuleConfigure):
+
+ def __init__(self, name, dependencies):
+ self._name = name
+ self._dependencies = dependencies
+
+ def getName(self):
+ return self._name
+
+ def requires(self):
+ return self._dependencies
+
+
+class ConfiguratorTests(TestCase):
+
+ @monkeypatch.MonkeyPatch(
+ configurator,
+ '_configurers',
+ (
+ MockModuleConfigurator('a', set('b')),
+ MockModuleConfigurator('b', set('a'))
+ )
+ )
+ def testDependencyCircle(self):
+ self.assertRaises(
+ RuntimeError,
+ configurator._parse_args,
+ 'validate-config'
+ )
+
+ @monkeypatch.MonkeyPatch(
+ configurator,
+ '_configurers',
+ (
+ MockModuleConfigurator('a', {'b', 'c'}),
+ MockModuleConfigurator('b', {'c'}),
+ MockModuleConfigurator('c', set())
+ )
+ )
+ def testNormalDependencies(self):
+ self.assertEqual(
+ configurator._parse_args('validate-config').modules,
+ ['c', 'b', 'a']
+ )
+
+ @monkeypatch.MonkeyPatch(
+ configurator,
+ '_configurers',
+ (
+ MockModuleConfigurator('a', set()),
+ MockModuleConfigurator('b', set()),
+ MockModuleConfigurator('c', set())
+ )
+ )
+ def testNoDependencies(self):
+ configurator._parse_args('validate-config').modules
+
+ @monkeypatch.MonkeyPatch(
+ configurator,
+ '_configurers',
+ (
+ MockModuleConfigurator('a', {'b', 'c'}),
+ MockModuleConfigurator('b', set()),
+ MockModuleConfigurator('c', set())
+ )
+ )
+ def testDependenciesAddition(self):
+ modules = configurator._parse_args(
+ 'validate-config',
+ '--module=a'
+ ).modules
+ self.assertTrue('a' in modules)
+ self.assertTrue('b' in modules)
+ self.assertTrue('c' in modules)
+
+
class LibvirtModuleConfigureTests(TestCase):
test_env = {}
--
To view, visit http://gerrit.ovirt.org/31423
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibf63ce9aa3ca8edb82091d09b976e8e23896524e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: mooli tayer <mtayer at redhat.com>
More information about the vdsm-patches
mailing list