Pass full path to pkgutil.iter_modules()
On my production system, when using client version 3, an exception is raised with an incomplete message as the installed novaclient is failing to find the bundled client versions. This commit creates a new _get_available_client_versions() method and moves the client version searching from get_client_class() into it. We also update __get_available_client_versions() to pass pkgutil.iter_modules the full path to novaclient rather than 'novaclient', which is what actually resolves the issue here. Lastly, we add a single test to ensure that __get_available_client_versions() does not return an empty list. Change-Id: I07ce414863e833c72e50ad8cf1824054cfb41457 Closes-Bug: #1463809
This commit is contained in:
parent
73957fc5ff
commit
84aec86319
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user