Merge "remove duplicate log exception message"

This commit is contained in:
Jenkins 2015-09-09 10:22:00 +00:00 committed by Gerrit Code Review
commit 2e96b159cf
3 changed files with 67 additions and 3 deletions
ceilometer
compute
hardware
tests/unit/agent

@ -37,8 +37,15 @@ class InstanceDiscovery(plugin_base.DiscoveryBase):
def discover(self, manager, param=None):
"""Discover resources to monitor."""
instances = self.nova_cli.instance_get_all_by_host(
cfg.CONF.host, self.last_run)
try:
instances = self.nova_cli.instance_get_all_by_host(
cfg.CONF.host, self.last_run)
except Exception:
# NOTE(zqfan): instance_get_all_by_host is wrapped and will log
# exception when there is any error. It is no need to raise it
# again and print one more time.
return []
for instance in instances:
if getattr(instance, 'OS-EXT-STS:vm_state', None) in ['deleted',
'error']:

@ -55,8 +55,14 @@ class NodesDiscoveryTripleO(plugin_base.DiscoveryBase):
instance_get_all will return all instances if last_run is None,
and will return only the instances changed since the last_run time.
"""
try:
instances = self.nova_cli.instance_get_all(self.last_run)
except Exception:
# NOTE(zqfan): instance_get_all is wrapped and will log exception
# when there is any error. It is no need to raise it again and
# print one more time.
return []
instances = self.nova_cli.instance_get_all(self.last_run)
for instance in instances:
if getattr(instance, 'OS-EXT-STS:vm_state', None) in ['deleted',
'error']:

@ -19,11 +19,13 @@ import shutil
import eventlet
import mock
from novaclient import client as novaclient
from oslo_service import service as os_service
from oslo_utils import fileutils
from oslo_utils import timeutils
from oslotest import base
from oslotest import mockpatch
import requests
import six
from stevedore import extension
import yaml
@ -31,6 +33,7 @@ import yaml
from ceilometer.agent import base as agent_base
from ceilometer.agent import manager
from ceilometer.agent import plugin_base
from ceilometer.hardware import discovery
from ceilometer import pipeline
from ceilometer.tests.unit.agent import agentbase
@ -300,6 +303,54 @@ class TestRunTasks(agentbase.BaseAgentManagerTestCase):
self.assertFalse(self.PollsterKeystone.samples)
self.assertFalse(self.notified_samples)
@mock.patch('ceilometer.agent.base.LOG')
@mock.patch('ceilometer.nova_client.LOG')
def test_hardware_discover_fail_minimize_logs(self, novalog, baselog):
self.useFixture(mockpatch.PatchObject(
novaclient.HTTPClient,
'authenticate',
side_effect=requests.ConnectionError))
class PollsterHardware(agentbase.TestPollster):
discovery = 'tripleo_overcloud_nodes'
class PollsterHardwareAnother(agentbase.TestPollster):
discovery = 'tripleo_overcloud_nodes'
self.mgr.extensions.extend([
extension.Extension('testhardware',
None,
None,
PollsterHardware(), ),
extension.Extension('testhardware2',
None,
None,
PollsterHardwareAnother(), )
])
ext = extension.Extension('tripleo_overcloud_nodes',
None,
None,
discovery.NodesDiscoveryTripleO())
self.mgr.discovery_manager = (extension.ExtensionManager
.make_test_instance([ext]))
self.pipeline_cfg = {
'sources': [{
'name': "test_hardware",
'interval': 10,
'meters': ['testhardware', 'testhardware2'],
'sinks': ['test_sink']}],
'sinks': [{
'name': 'test_sink',
'transformers': [],
'publishers': ["test"]}]
}
self.mgr.polling_manager = pipeline.PollingManager(self.pipeline_cfg)
polling_tasks = self.mgr.setup_polling_tasks()
self.mgr.interval_task(list(polling_tasks.values())[0])
self.assertEqual(1, novalog.exception.call_count)
self.assertFalse(baselog.exception.called)
@mock.patch('ceilometer.agent.base.LOG')
def test_polling_exception(self, LOG):
source_name = 'test_pollingexception'