summaryrefslogtreecommitdiff
path: root/tools/custom_guidelines.py
diff options
context:
space:
mode:
authorPeter Razumovsky <prazumovsky@mirantis.com>2017-03-22 14:24:18 +0400
committerPeter Razumovsky <prazumovsky@mirantis.com>2017-03-22 14:24:18 +0400
commit8d6d1ac935cd3a93bd0377a34cb2fe12bed7d955 (patch)
treea0c43a6966ad00d5f7c4b43073fb8dd5996ec07b /tools/custom_guidelines.py
parent253fae1df8fbf9739c8311024f927e91734e45c5 (diff)
downloadheat-8d6d1ac935cd3a93bd0377a34cb2fe12bed7d955.tar.gz
Check all resources with custom guidelines
If resource has available_resource_mapping method and it's not available, custom guidelines check will skip it, which is incorrect. This patch improves list of resources: now only hidden, contrib and manually excluded resources don't checked. Change-Id: Ic2cb37fb3fe4aefb8b3efb911aecf46155541469 Closes-bug: #1674949
Diffstat (limited to 'tools/custom_guidelines.py')
-rw-r--r--tools/custom_guidelines.py49
1 files changed, 34 insertions, 15 deletions
diff --git a/tools/custom_guidelines.py b/tools/custom_guidelines.py
index 39d39981a..f6a3f83d5 100644
--- a/tools/custom_guidelines.py
+++ b/tools/custom_guidelines.py
@@ -21,11 +21,12 @@ import six
from heat.common.i18n import _
from heat.common.i18n import _LW
from heat.engine import constraints
-from heat.engine import resources
+from heat.engine import plugin_manager
from heat.engine import support
LOG = log.getLogger(__name__)
+
class HeatCustomGuidelines(object):
_RULES = ['resource_descriptions', 'trailing_spaces']
@@ -33,20 +34,23 @@ class HeatCustomGuidelines(object):
def __init__(self, exclude):
self.error_count = 0
self.resources_classes = []
- global_env = resources.global_env()
- for resource_type in global_env.get_types():
- cls = global_env.get_class(resource_type)
- module = cls.__module__
- # Skip resources, which defined as template resource in environment
- if module == 'heat.engine.resources.template_resource':
- continue
- # Skip discovered plugin resources
- if module == 'heat.engine.plugins':
- continue
- path = module.replace('.', '/')
- if any(path.startswith(excl_path) for excl_path in exclude):
- continue
- self.resources_classes.append(cls)
+ all_resources = _load_all_resources()
+ for resource_type in all_resources:
+ for rsrc_cls in all_resources[resource_type]:
+ module = rsrc_cls.__module__
+ # Skip hidden resources check guidelines
+ if rsrc_cls.support_status.status == support.HIDDEN:
+ continue
+ # Skip resources, which defined as template resource in
+ # environment or cotrib resource
+ if module in ('heat.engine.resources.template_resource',
+ 'heat.engine.plugins'):
+ continue
+ # Skip manually excluded folders
+ path = module.replace('.', '/')
+ if any(path.startswith(excl_path) for excl_path in exclude):
+ continue
+ self.resources_classes.append(rsrc_cls)
def run_check(self):
print(_('Heat custom guidelines check started.'))
@@ -271,6 +275,21 @@ class HeatCustomGuidelines(object):
self.error_count += 1
+def _load_all_resources():
+ manager = plugin_manager.PluginManager('heat.engine.resources')
+ resource_mapping = plugin_manager.PluginMapping('resource')
+ res_plugin_mappings = resource_mapping.load_all(manager)
+
+ all_resources = {}
+ for mapping in res_plugin_mappings:
+ name, cls = mapping
+ if all_resources.get(name) is not None:
+ all_resources[name].append(cls)
+ else:
+ all_resources[name] = [cls]
+ return all_resources
+
+
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--exclude', '-e', metavar='<FOLDER>',