Leverage neutronclient.openstack.common.importutils import_class
This patch allows us to drop our version of import_class in favor of openstack.common.importutils version's. Change-Id: Ia96f06e2dc7dfb9824377e3a7381da2732dd2c15 Closes-bug: 1365273
This commit is contained in:
parent
b5f629f38a
commit
72afc0f424
@ -19,12 +19,12 @@
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
from neutronclient.common import _
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.openstack.common import importutils
|
||||
from neutronclient.openstack.common import strutils
|
||||
|
||||
|
||||
@ -40,17 +40,6 @@ def env(*vars, **kwargs):
|
||||
return kwargs.get('default', '')
|
||||
|
||||
|
||||
def import_class(import_str):
|
||||
"""Returns a class from a string including module and class.
|
||||
|
||||
:param import_str: a string representation of the class name
|
||||
:rtype: the requested class
|
||||
"""
|
||||
mod_str, _sep, class_str = import_str.rpartition('.')
|
||||
__import__(mod_str)
|
||||
return getattr(sys.modules[mod_str], class_str)
|
||||
|
||||
|
||||
def get_client_class(api_name, version, version_map):
|
||||
"""Returns the client class for the requested API version.
|
||||
|
||||
@ -68,7 +57,7 @@ def get_client_class(api_name, version, version_map):
|
||||
'map_keys': ', '.join(version_map.keys())}
|
||||
raise exceptions.UnsupportedVersion(msg)
|
||||
|
||||
return import_class(client_path)
|
||||
return importutils.import_class(client_path)
|
||||
|
||||
|
||||
def get_item_properties(item, fields, mixed_case_fields=(), formatters=None):
|
||||
|
@ -13,8 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sys
|
||||
|
||||
import testtools
|
||||
|
||||
from neutronclient.common import exceptions
|
||||
@ -106,15 +104,6 @@ class TestUtils(testtools.TestCase):
|
||||
|
||||
|
||||
class ImportClassTestCase(testtools.TestCase):
|
||||
def test_import_class(self):
|
||||
dt = utils.import_class('datetime.datetime')
|
||||
self.assertTrue(sys.modules['datetime'].datetime is dt)
|
||||
|
||||
def test_import_bad_class(self):
|
||||
self.assertRaises(
|
||||
ImportError, utils.import_class,
|
||||
'lol.u_mad.brah')
|
||||
|
||||
def test_get_client_class_invalid_version(self):
|
||||
self.assertRaises(
|
||||
exceptions.UnsupportedVersion,
|
||||
|
Loading…
Reference in New Issue
Block a user