Merge "Leverage neutronclient.openstack.common.importutils import_class"

This commit is contained in:
Jenkins
2014-10-14 06:33:08 +00:00
committed by Gerrit Code Review
2 changed files with 2 additions and 24 deletions

View File

@@ -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):

View File

@@ -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,