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
This commit is contained in:
Peter Razumovsky 2017-03-22 14:24:18 +04:00
parent 253fae1df8
commit 8d6d1ac935
1 changed files with 34 additions and 15 deletions

View File

@ -21,11 +21,12 @@ import six
from heat.common.i18n import _ from heat.common.i18n import _
from heat.common.i18n import _LW from heat.common.i18n import _LW
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']
@ -33,20 +34,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.'))
@ -271,6 +275,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>',