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:
Aaron Rosen 2014-09-03 22:01:56 -07:00
parent b5f629f38a
commit 72afc0f424
2 changed files with 2 additions and 24 deletions

View File

@ -19,12 +19,12 @@
import logging import logging
import os import os
import sys
import six import six
from neutronclient.common import _ from neutronclient.common import _
from neutronclient.common import exceptions from neutronclient.common import exceptions
from neutronclient.openstack.common import importutils
from neutronclient.openstack.common import strutils from neutronclient.openstack.common import strutils
@ -40,17 +40,6 @@ def env(*vars, **kwargs):
return kwargs.get('default', '') 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): def get_client_class(api_name, version, version_map):
"""Returns the client class for the requested API version. """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())} 'map_keys': ', '.join(version_map.keys())}
raise exceptions.UnsupportedVersion(msg) 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): def get_item_properties(item, fields, mixed_case_fields=(), formatters=None):

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import sys
import testtools import testtools
from neutronclient.common import exceptions from neutronclient.common import exceptions
@ -106,15 +104,6 @@ class TestUtils(testtools.TestCase):
class ImportClassTestCase(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): def test_get_client_class_invalid_version(self):
self.assertRaises( self.assertRaises(
exceptions.UnsupportedVersion, exceptions.UnsupportedVersion,