From: Anton Arefiev Date: Wed, 17 Jun 2015 15:57:34 +0000 (+0300) Subject: Add drivers list generator X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a7f264f3afd6161d9fef3f4aed3e99a71dc27caf;p=openstack-build%2Fcinder-build.git Add drivers list generator It is useful to have a maintained (in source control) list of drivers that exist in Cinder. It could be used in docs and unit tests to check method impl on backend drivers. This change add tool for generate list of drivers based on existing BaseVD class in class hierarchy of volume drivers. Output example: Drivers: ['cinder.volume.drivers.lvm.LVMVolumeDriver', 'cinder.volume.drivers.rbd.RBDDriver', ...] Implements: blueprint drivers-list-generator Change-Id: I0e10906873e659e09a6e34531a0c932495d7c399 --- diff --git a/tools/generate_driver_list.py b/tools/generate_driver_list.py new file mode 100755 index 000000000..72d4d5af0 --- /dev/null +++ b/tools/generate_driver_list.py @@ -0,0 +1,52 @@ +#! /usr/bin/env python +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Generate list of cinder drivers""" + +import importlib +import inspect +import pkgutil +import pprint + +from cinder.volume import drivers +from cinder.volume import driver + +package = drivers + + +def get_driver_list(): + dr_list = [] + for _loader, modname, _ispkg in pkgutil.walk_packages( + path=package.__path__, + prefix=package.__name__ + '.', + onerror=lambda x: None): + try: + mod = importlib.import_module(modname) + list_classes = inspect.getmembers(mod, inspect.isclass) + dr_list += [ + modname + '.' + dr_name for dr_name, dr in list_classes + if driver.BaseVD in inspect.getmro(dr)] + except ImportError: + print("%s module ignored!!" % modname) + return dr_list + + +def main(): + dr_list = get_driver_list() + print("Drivers list:") + pprint.pprint(dr_list) + + +if __name__ == '__main__': + main() diff --git a/tox.ini b/tox.ini index 063a4a601..0e9d316ec 100644 --- a/tox.ini +++ b/tox.ini @@ -124,6 +124,11 @@ commands = {posargs} [testenv:docs] commands = python setup.py build_sphinx +[testenv:gendriverlist] +sitepackages = False +envdir = {toxworkdir}/venv +commands = python {toxinidir}/tools/generate_driver_list.py + [flake8] # Following checks are ignored on purpose. #