Merge "Check all resources with custom guidelines"

This commit is contained in:
Jenkins 2017-04-03 10:01:07 +00:00 committed by Gerrit Code Review
commit dbd92e29b3
1 changed files with 34 additions and 15 deletions

View File

@ -20,11 +20,12 @@ import six
from heat.common.i18n import _ from heat.common.i18n import _
from heat.engine import constraints from heat.engine import constraints
from heat.engine import resources from heat.engine import plugin_manager
from heat.engine import support from heat.engine import support
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
class HeatCustomGuidelines(object): class HeatCustomGuidelines(object):
_RULES = ['resource_descriptions', 'trailing_spaces'] _RULES = ['resource_descriptions', 'trailing_spaces']
@ -32,20 +33,23 @@ class HeatCustomGuidelines(object):
def __init__(self, exclude): def __init__(self, exclude):
self.error_count = 0 self.error_count = 0
self.resources_classes = [] self.resources_classes = []
global_env = resources.global_env() all_resources = _load_all_resources()
for resource_type in global_env.get_types(): for resource_type in all_resources:
cls = global_env.get_class(resource_type) for rsrc_cls in all_resources[resource_type]:
module = cls.__module__ module = rsrc_cls.__module__
# Skip resources, which defined as template resource in environment # Skip hidden resources check guidelines
if module == 'heat.engine.resources.template_resource': if rsrc_cls.support_status.status == support.HIDDEN:
continue continue
# Skip discovered plugin resources # Skip resources, which defined as template resource in
if module == 'heat.engine.plugins': # environment or cotrib resource
continue if module in ('heat.engine.resources.template_resource',
path = module.replace('.', '/') 'heat.engine.plugins'):
if any(path.startswith(excl_path) for excl_path in exclude): continue
continue # Skip manually excluded folders
self.resources_classes.append(cls) 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): def run_check(self):
print(_('Heat custom guidelines check started.')) print(_('Heat custom guidelines check started.'))
@ -270,6 +274,21 @@ class HeatCustomGuidelines(object):
self.error_count += 1 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(): def parse_args():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--exclude', '-e', metavar='<FOLDER>', parser.add_argument('--exclude', '-e', metavar='<FOLDER>',