diff --git a/neutronclient/common/utils.py b/neutronclient/common/utils.py index b68a6089b..bdc4b5336 100644 --- a/neutronclient/common/utils.py +++ b/neutronclient/common/utils.py @@ -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): diff --git a/neutronclient/tests/unit/test_utils.py b/neutronclient/tests/unit/test_utils.py index f38783512..a0044d61a 100644 --- a/neutronclient/tests/unit/test_utils.py +++ b/neutronclient/tests/unit/test_utils.py @@ -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,