# this module must only import other modules that do
# not require loggers to be created, so this cannot
-# include yardstick.common.utils
from yardstick.common import constants
+from yardstick.common import exceptions
+
try:
# do not use yardstick.common.utils.makedirs
from yardstick.cmd.commands import plugin
from yardstick.cmd.commands import env
from yardstick.cmd.commands import report
+from yardstick.common import import_tools
+
CONF = cfg.CONF
cli_opts = [
return None
-class YardstickCLI(): # pragma: no cover
+@import_tools.decorator_banned_modules
+class YardstickCLI(object): # pragma: no cover
"""Command-line interface to yardstick"""
# Command categories
# register subcommands to parse additional command line arguments
def parser(subparsers):
- self._add_command_parsers(YardstickCLI.categories, subparsers)
+ self._add_command_parsers(self.categories, subparsers)
category_opt = cfg.SubCommandOpt("category",
title="Command categories",
'"%(class_name)" class.')
+class YardstickBannedModuleImported(YardstickException):
+ # pragma: no cover
+ message = 'Module "%(module)s" cannnot be imported. Reason: "%(reason)s"'
+
+
class HeatTemplateError(YardstickException):
"""Error in Heat during the stack deployment"""
message = ('Error in Heat during the creation of the OpenStack stack '
--- /dev/null
+# Copyright (c) 2018 Intel Corporation
+#
+# 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.
+
+import sys
+
+from yardstick.common import exceptions
+
+
+BANNED_MODULES = {'ansible': 'Module with GPLv3 license'}
+
+
+def decorator_banned_modules(cls):
+ def _class(*args, **kwargs):
+ for module in sys.modules:
+ for banned_module, reason in BANNED_MODULES.items():
+ if module.startswith(banned_module):
+ raise exceptions.YardstickBannedModuleImported(
+ module=banned_module, reason=reason)
+ return cls(*args, **kwargs)
+ return _class
--- /dev/null
+# Copyright (c) 2018 Intel Corporation
+#
+# 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.
+
+
+class BannedClass(object):
+ pass
--- /dev/null
+# Copyright (c) 2018 Intel Corporation
+#
+# 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.
+
+from yardstick.common import import_tools
+from yardstick.tests.unit.common.banned_modules import banned_module
+
+
+@import_tools.decorator_banned_modules
+class ImportingClass(banned_module.BannedClass):
+ pass
--- /dev/null
+# Copyright (c) 2018 Intel Corporation
+#
+# 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.
+
+import unittest
+
+from yardstick.common import exceptions as y_exc
+from yardstick.common import import_tools
+
+
+@import_tools.decorator_banned_modules
+class DummyClass(object):
+ pass
+
+
+class DecoratorBannedModule(unittest.TestCase):
+
+ MODULE = 'yardstick.tests.unit.common.banned_modules.banned_module'
+
+ def test_passt(self):
+ self.assertIsNotNone(DummyClass())
+
+ def test_banned_module(self):
+ import_tools.BANNED_MODULES[self.MODULE] = 'Banned module!!'
+ from yardstick.tests.unit.common.banned_modules import importing_module
+ self.addCleanup(self._remove_module)
+
+ with self.assertRaises(y_exc.YardstickBannedModuleImported) as exc:
+ importing_module.ImportingClass()
+
+ msg = ('Module "%s" cannnot be imported. Reason: "Banned module!!"'
+ % self.MODULE)
+ self.assertEqual(msg, str(exc.exception))
+
+ def _remove_module(self):
+ del import_tools.BANNED_MODULES[self.MODULE]