Change in vdsm[ovirt-3.6]: configurator doesn't load pyc files under configurators folder

ybronhei at redhat.com ybronhei at redhat.com
Thu Sep 10 13:26:17 UTC 2015


Yaniv Bronhaim has uploaded a new change for review.

Change subject: configurator doesn't load pyc files under configurators folder
......................................................................

configurator doesn't load pyc files under configurators folder

configurator loads dynamically modules from configurators folder. It
searches for py files only. In ovirt-node installation we install only pyc
files and this caused us to miss all configurators modules in ovirt-node
installation. The listmodules function now returns a set to avoid
duplicate module names.

Change-Id: Ia529de0069e2f4ec168a4b9df82ba62c56d66730
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1259247
Signed-off-by: Yaniv Bronhaim <ybronhei at redhat.com>
---
M lib/vdsm/tool/configurator.py
M tests/toolTests.py
2 files changed, 27 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/11/46011/1

diff --git a/lib/vdsm/tool/configurator.py b/lib/vdsm/tool/configurator.py
index 5ed905d..20924ba 100644
--- a/lib/vdsm/tool/configurator.py
+++ b/lib/vdsm/tool/configurator.py
@@ -29,9 +29,9 @@
 
 
 from collections import deque
-from glob import iglob
 import argparse
 import os
+import re
 import sys
 import traceback
 
@@ -50,21 +50,18 @@
     return __import__(pkg, globals(), locals(), [mname], level=0)
 
 
-def _listmodules(pkg):
+def _listmodules(path):
     """Return base file names for all modules under pkg."""
-    path = os.path.join(os.path.abspath(pkg.__path__[0]), '')
-    getmname = lambda x: os.path.basename(os.path.splitext(x)[0])
-    filter_ = lambda x: not x.startswith('_')
-
-    return [
-        getmname(module)
-        for module in iglob("%s*.py" % path)
-        if filter_(getmname(module))
-    ]
+    is_module = re.compile(r"^[^_].*\.pyc?$").search
+    return set(
+        os.path.splitext(name)[0]
+        for name in os.listdir(path)
+        if is_module(name)
+    )
 
 
 _CONFIGURATORS = {}
-for module in _listmodules(configurators):
+for module in _listmodules(configurators.__path__[0]):
     _CONFIGURATORS[module] = _import_module(configurators, module)
     if not hasattr(_CONFIGURATORS[module], 'name'):
         setattr(_CONFIGURATORS[module], 'name', module)
diff --git a/tests/toolTests.py b/tests/toolTests.py
index c8c7d1e..0c9666d 100644
--- a/tests/toolTests.py
+++ b/tests/toolTests.py
@@ -30,7 +30,8 @@
 from vdsm.tool import upgrade
 from vdsm import utils
 import monkeypatch
-from testlib import VdsmTestCase
+from testlib import (VdsmTestCase, namedTemporaryDir, permutations,
+                     expandPermutations)
 from testValidation import ValidateRunningAsRoot
 from unittest import TestCase
 import tempfile
@@ -83,8 +84,24 @@
         dict((m.name, m) for m in mockConfigurers))
 
 
+ at expandPermutations
 class PatchConfiguratorsTests(VdsmTestCase):
 
+    @permutations([(('a.py', 'b.py'), ('a', 'b')),
+                   (('a.py', 'b.py', 'a.pyc', 'a.pyioas'), ('a', 'b')),
+                   (('a.py', 'b.py', 'a.pyc', 'a.py'), ('a', 'b')),
+                   (('a.py', 'b.py', 'a.pyc', '_my.py'), ('a', 'b'))])
+    def testListConfiguratorsModulesFolder(self, files, expected_modules):
+        expected = set(expected_modules)
+        with namedTemporaryDir() as path:
+            for f in files:
+                utils.touchFile(os.path.join(path, f))
+            result = configurator._listmodules(path)
+        self.assertEquals(
+            result,
+            expected,
+        )
+
     def testPatch(self):
         self.configurator = MockModuleConfigurator('a')
         self.function_was_run = False


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia529de0069e2f4ec168a4b9df82ba62c56d66730
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Yaniv Bronhaim <ybronhei at redhat.com>


More information about the vdsm-patches mailing list