From e1eaaa3290cceb0c261ab57372657193aef9cb52 Mon Sep 17 00:00:00 2001 From: Gabriel Hurley Date: Wed, 6 Jun 2012 18:52:27 -0700 Subject: [PATCH] Prevent erroneous log message when accessing security rules. Fixes bug 1009797. Change-Id: Ic8f627610b235c5d71a210800b3318619715106e --- horizon/api/base.py | 11 ++++++----- horizon/api/nova.py | 10 +++++----- .../nova/instances_and_volumes/instances/detail.html | 5 ++++- horizon/exceptions.py | 8 ++++---- horizon/static/horizon/js/horizon.js | 5 +++-- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/horizon/api/base.py b/horizon/api/base.py index 54ae3db13..15f9f9eeb 100644 --- a/horizon/api/base.py +++ b/horizon/api/base.py @@ -48,10 +48,11 @@ class APIResourceWrapper(object): # __getattr__ won't find properties return self._apiresource.__getattribute__(attr) else: - LOG.debug('Attempted to access unknown attribute "%s" on' - ' APIResource object of type "%s" wrapping resource of' - ' type "%s"' % (attr, self.__class__, - self._apiresource.__class__)) + msg = ('Attempted to access unknown attribute "%s" on ' + 'APIResource object of type "%s" wrapping resource of ' + 'type "%s".') % (attr, self.__class__, + self._apiresource.__class__) + LOG.debug(exceptions.error_color(msg)) raise AttributeError(attr) @@ -74,7 +75,7 @@ class APIDictWrapper(object): except KeyError: msg = 'Unknown attribute "%(attr)s" on APIResource object ' \ 'of type "%(cls)s"' % {'attr': attr, 'cls': self.__class__} - LOG.debug(msg) + LOG.debug(exceptions.error_color(msg)) raise AttributeError(msg) def __getitem__(self, item): diff --git a/horizon/api/nova.py b/horizon/api/nova.py index 5c575908d..4f124487a 100644 --- a/horizon/api/nova.py +++ b/horizon/api/nova.py @@ -162,11 +162,11 @@ class SecurityGroup(APIResourceWrapper): @property def rules(self): """Wraps transmitted rule info in the novaclient rule class.""" - if not hasattr(self, "_rules"): + if "_rules" not in self.__dict__: manager = nova_rules.SecurityGroupRuleManager self._rules = [nova_rules.SecurityGroupRule(manager, rule) for \ rule in self._apiresource.rules] - return self._rules + return self.__dict__['_rules'] @rules.setter def rules(self, value): @@ -330,11 +330,11 @@ def server_security_groups(request, instance_id): % instance_id) if body: # Wrap data in SG objects as novaclient would. - sg_objects = [NovaSecurityGroup(nclient.security_groups, sg) for - sg in body.get('security_groups', [])] + sg_objs = [NovaSecurityGroup(nclient.security_groups, sg, loaded=True) + for sg in body.get('security_groups', [])] # Then wrap novaclient's object with our own. Yes, sadly wrapping # with two layers of objects is necessary. - security_groups = [SecurityGroup(sg) for sg in sg_objects] + security_groups = [SecurityGroup(sg) for sg in sg_objs] # Package up the rules, as well. for sg in security_groups: rule_objects = [SecurityGroupRule(rule) for rule in sg.rules] diff --git a/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/detail.html b/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/detail.html index 410be0a63..57c1093ad 100644 --- a/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/detail.html +++ b/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/detail.html @@ -25,7 +25,10 @@ }); setInterval(function() { - horizon.instances.getConsoleLog($("#tail_length"), false); + // Don't poll for something that's not there... + if ($("#tail_length").length) { + horizon.instances.getConsoleLog($("#tail_length"), false); + } }, 10000); {% endblock %} diff --git a/horizon/exceptions.py b/horizon/exceptions.py index 78364bf59..01188277f 100644 --- a/horizon/exceptions.py +++ b/horizon/exceptions.py @@ -219,7 +219,7 @@ RECOVERABLE = (keystoneclient.ClientException, RECOVERABLE += tuple(EXCEPTION_CONFIG.get('recoverable', [])) -def _error_color(msg): +def error_color(msg): return termcolors.colorize(msg, **PALETTE['ERROR']) @@ -280,7 +280,7 @@ def handle(request, message=None, redirect=None, ignore=False, return NotAuthorized request.user_logout() if not force_silence and not handled: - log_method(_error_color("Unauthorized: %s" % exc_value)) + log_method(error_color("Unauthorized: %s" % exc_value)) if not handled: # We get some pretty useless error messages back from # some clients, so let's define our own fallback. @@ -291,7 +291,7 @@ def handle(request, message=None, redirect=None, ignore=False, if issubclass(exc_type, NOT_FOUND): wrap = True if not force_silence and not handled and (not ignore or force_log): - log_method(_error_color("Not Found: %s" % exc_value)) + log_method(error_color("Not Found: %s" % exc_value)) if not ignore and not handled: messages.error(request, message or exc_value) if redirect: @@ -302,7 +302,7 @@ def handle(request, message=None, redirect=None, ignore=False, if issubclass(exc_type, RECOVERABLE): wrap = True if not force_silence and not handled and (not ignore or force_log): - log_method(_error_color("Recoverable error: %s" % exc_value)) + log_method(error_color("Recoverable error: %s" % exc_value)) if not ignore and not handled: messages.error(request, message or exc_value) if redirect: diff --git a/horizon/static/horizon/js/horizon.js b/horizon/static/horizon/js/horizon.js index 7485ac2df..2a54b9d55 100644 --- a/horizon/static/horizon/js/horizon.js +++ b/horizon/static/horizon/js/horizon.js @@ -293,10 +293,11 @@ var Horizon = function() { user_decided_length: false, getConsoleLog: function(form_element, via_user_submit) { + var data; if(this.user_decided_length) { - var data = $(form_element).serialize(); + data = $(form_element).serialize(); } else { - var data = "length=35"; + data = "length=35"; } $.ajax({