def get_vnf_impl(cls, vnf_model_id): """ Find the implementing class from vnf_model["vnf"]["name"] field :param vnf_model_id: parsed vnfd model ID field :return: subclass of GenericVNF """ import_modules_from_package( "yardstick.network_services.vnf_generic.vnf") expected_name = vnf_model_id classes_found = [] def impl(): for name, class_ in ((c.__name__, c) for c in itersubclasses(GenericVNF)): if name == expected_name: yield class_ classes_found.append(name) try: return next(impl()) except StopIteration: pass raise IncorrectConfig("No implementation for %s found in %s" % (expected_name, classes_found))
def test_import_modules_from_package(self, mock_importutils, mock_walk): sep = os.sep mock_walk.return_value = ([('foo' + sep + '..' + sep + 'bar', [], ['baz.py'])]) utils.import_modules_from_package('foo.bar') mock_importutils.import_module.assert_called_with('bar.baz')
def test_import_modules_from_package_no_mod(self, mock_walk): yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__)) mock_walk.return_value = ([ (os.path.join(yardstick_root, 'foo'), ['bar'], ['__init__.py']), (os.path.join(yardstick_root, 'foo', 'bar'), [], ['baz.txt', 'qux.rst']) ]) utils.import_modules_from_package('foo.bar')
def test_import_modules_from_package(self, mock_importutils, mock_walk): yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__)) mock_walk.return_value = ([(os.path.join(yardstick_root, 'foo', os.pardir, 'bar'), [], ['baz.py'])]) utils.import_modules_from_package('foo.bar') mock_importutils.import_module.assert_called_with('bar.baz')
def test_import_modules_from_package_no_mod(self, mock_append, mock_walk): sep = os.sep mock_walk.return_value = ([ ('..' + sep + 'foo', ['bar'], ['__init__.py']), ('..' + sep + 'foo' + sep + 'bar', [], ['baz.txt', 'qux.rst']) ]) utils.import_modules_from_package('foo.bar') self.assertFalse(mock_append.called)
def test_import_package(self): module_name = 'yardstick.tests.functional.common.fake_module' library_name = 'fake_library' class_name = 'FakeClassToBeImported' self.assertNotIn(module_name, sys.modules) utils.import_modules_from_package(module_name) self.assertIn(module_name, sys.modules) module_obj = sys.modules[module_name] library_obj = getattr(module_obj, library_name) class_obj = getattr(library_obj, class_name) self.assertEqual(class_name, class_obj().__class__.__name__)
def get(tp_config): """Get the traffic profile instance for the given traffic type :param tp_config: loaded YAML file :return: """ profile_class = tp_config["traffic_profile"]["traffic_type"] import_modules_from_package( "yardstick.network_services.traffic_profile") try: return next(c for c in itersubclasses(TrafficProfile) if c.__name__ == profile_class)(tp_config) except StopIteration: raise RuntimeError("No implementation for %s", profile_class)
def get_vnf_impl(cls, vnf_model): """ Find the implementing class from vnf_model["vnf"]["name"] field :param vnf_model: dictionary containing a parsed vnfd :return: subclass of GenericVNF """ import_modules_from_package( "yardstick.network_services.vnf_generic.vnf") expected_name = vnf_model['id'] impl = (c for c in itersubclasses(GenericVNF) if c.__name__ == expected_name) try: return next(impl) except StopIteration: raise IncorrectConfig("No implementation for %s", expected_name)
def get_context_impl(self, nfvi_type): """ Find the implementing class from vnf_model["vnf"]["name"] field :param vnf_model: dictionary containing a parsed vnfd :return: subclass of GenericVNF """ import_modules_from_package("yardstick.benchmark.contexts") expected_name = nfvi_type impl = [ c for c in itersubclasses(StandaloneContext) if c.__name__ == expected_name ] try: return next(iter(impl)) except StopIteration: raise ValueError("No implementation for %s", expected_name)
############################################################################## # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## from oslo_config import cfg import yardstick.common.utils as utils utils.import_modules_from_package("yardstick.dispatcher") CONF = cfg.CONF OPTS = [ cfg.StrOpt('dispatcher', default='file', help='Dispatcher to store data.'), ] CONF.register_opts(OPTS)
############################################################################## # Copyright (c) 2015 Ericsson AB and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## from __future__ import absolute_import import yardstick.common.utils as utils utils.import_modules_from_package("yardstick.benchmark.contexts") utils.import_modules_from_package("yardstick.benchmark.runners") utils.import_modules_from_package("yardstick.benchmark.scenarios")
args.update({k: v for k, v in request.form.items()}) return action, args def _get_args(self): args = common_utils.translate_to_str(request.args) return args def _dispatch_post(self, **kwargs): action, args = self._post_args() args.update(kwargs) return self._dispatch(args, action) def _dispatch(self, args, action): try: return getattr(self, action)(args) except AttributeError: common_utils.result_handler(consts.API_ERROR, 'No such action') class Url(object): def __init__(self, url, target): super(Url, self).__init__() self.url = url self.target = target common_utils.import_modules_from_package("api.resources")
############################################################################## # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## from oslo_config import cfg import yardstick.common.utils as utils utils.import_modules_from_package("yardstick.dispatcher") CONF = cfg.CONF OPTS = [ cfg.StrOpt('dispatcher', default='file', help='Dispatcher to store data.'), ] CONF.register_opts(OPTS)
############################################################################## # Copyright (c) 2015 Ericsson AB and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import yardstick.common.utils as utils utils.import_modules_from_package("yardstick.benchmark.contexts") utils.import_modules_from_package("yardstick.benchmark.runners") utils.import_modules_from_package("yardstick.benchmark.scenarios")
args.update({k: v for k, v in request.form.items()}) return action, args def _get_args(self): args = common_utils.translate_to_str(request.args) return args def _dispatch_post(self, **kwargs): action, args = self._post_args() args.update(kwargs) return self._dispatch(args, action) def _dispatch(self, args, action): try: return getattr(self, action)(args) except AttributeError: common_utils.result_handler(consts.API_ERROR, 'No such action') class Url(object): def __init__(self, url, target): super(Url, self).__init__() self.url = url self.target = target common_utils.import_modules_from_package("api.resources")