From 0ff37ff8599edb8208aa23df024dbe9b38a27111 Mon Sep 17 00:00:00 2001 From: Peter Razumovsky Date: Tue, 16 Aug 2016 14:40:11 +0300 Subject: [PATCH] Don't raise error in custom guidelines on IOError In some merge issues files or modules can be removed, but still registered in global env. In that cases custom guidelines raises an error with the message "No such file or directory". Add exception handling to avoid error raising. Instead of error, call warning and skip such class. Change-Id: I71af2fffc2bdec414cb68c40eaf3268fe81134de Closes-bug: #1613669 --- tools/custom_guidelines.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/custom_guidelines.py b/tools/custom_guidelines.py index 81e0569751..39d39981aa 100644 --- a/tools/custom_guidelines.py +++ b/tools/custom_guidelines.py @@ -13,15 +13,18 @@ import argparse import re - -import six import sys +from oslo_log import log +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 support +LOG = log.getLogger(__name__) class HeatCustomGuidelines(object): @@ -149,7 +152,12 @@ class HeatCustomGuidelines(object): def check_trailing_spaces(self): for cls in self.resources_classes: - cls_file = open(cls.__module__.replace('.', '/') + '.py') + try: + cls_file = open(cls.__module__.replace('.', '/') + '.py') + except IOError as ex: + LOG.warning(_LW('Cannot perform trailing spaces check on ' + 'resource module: %s') % six.text_type(ex)) + continue lines = [line.strip() for line in cls_file.readlines()] idx = 0 kwargs = {'path': cls.__module__}