Merge "Pass full path to pkgutil.iter_modules()"

This commit is contained in:
Jenkins 2015-06-14 05:50:03 +00:00 committed by Gerrit Code Review
commit 7d12815605
2 changed files with 17 additions and 7 deletions
novaclient

@ -773,6 +773,18 @@ def _discover_via_entry_points():
yield name, module
def _get_available_client_versions():
# NOTE(andreykurilin): available clients version should not be
# hardcoded, so let's discover them.
matcher = re.compile(r"v[0-9_]*$")
submodules = pkgutil.iter_modules([os.path.dirname(__file__)])
available_versions = [
name[1:].replace("_", ".") for loader, name, ispkg in submodules
if matcher.search(name)]
return available_versions
def get_client_class(version):
version = str(version)
if version in DEPRECATED_VERSIONS:
@ -786,13 +798,7 @@ def get_client_class(version):
return importutils.import_class(
"novaclient.v%s.client.Client" % version)
except ImportError:
# NOTE(andreykurilin): available clients version should not be
# hardcoded, so let's discover them.
matcher = re.compile(r"v[0-9_]*$")
submodules = pkgutil.iter_modules(['novaclient'])
available_versions = [
name[1:].replace("_", ".") for loader, name, ispkg in submodules
if matcher.search(name)]
available_versions = _get_available_client_versions()
msg = _("Invalid client version '%(version)s'. must be one of: "
"%(keys)s") % {'version': version,
'keys': ', '.join(available_versions)}

@ -161,6 +161,10 @@ class ClientTest(utils.TestCase):
self._check_version_url('http://foo.com/nova/v2/%s',
'http://foo.com/nova/')
def test_get_available_client_versions(self):
output = novaclient.client._get_available_client_versions()
self.assertNotEqual([], output)
def test_get_client_class_v2(self):
output = novaclient.client.get_client_class('2')
self.assertEqual(output, novaclient.v2.client.Client)