62008d4e5b
Some drivers/modules might raise NotImplementedError whereas we would expect things to work. Skipping test when such an error is raised would be a bad idea, we would know the test failed. So let's switch to a custom NotImplementedError and let's skip test only if this one is raised. Closes-Bug: #1369556 Change-Id: Ie88a281787218f9aba13b6e662eb4d49d3e685d0
56 lines
2.5 KiB
Python
56 lines
2.5 KiB
Python
# Copyright (c) 2014 VMware, Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
import ceilometer
|
|
from ceilometer.compute import plugin
|
|
from ceilometer.compute.pollsters import util
|
|
from ceilometer.compute.virt import inspector as virt_inspector
|
|
from ceilometer.openstack.common.gettextutils import _
|
|
from ceilometer.openstack.common import log
|
|
from ceilometer import sample
|
|
|
|
LOG = log.getLogger(__name__)
|
|
|
|
|
|
class MemoryUsagePollster(plugin.ComputePollster):
|
|
|
|
def get_samples(self, manager, cache, resources):
|
|
self._inspection_duration = self._record_poll_time()
|
|
for instance in resources:
|
|
LOG.debug(_('Checking memory usage for instance %s'), instance.id)
|
|
try:
|
|
memory_info = manager.inspector.inspect_memory_usage(
|
|
instance, self._inspection_duration)
|
|
LOG.debug(_("MEMORY USAGE: %(instance)s %(usage)f"),
|
|
({'instance': instance.__dict__,
|
|
'usage': memory_info.usage}))
|
|
yield util.make_sample_from_instance(
|
|
instance,
|
|
name='memory.usage',
|
|
type=sample.TYPE_GAUGE,
|
|
unit='MB',
|
|
volume=memory_info.usage,
|
|
)
|
|
except virt_inspector.InstanceNotFoundException as err:
|
|
# Instance was deleted while getting samples. Ignore it.
|
|
LOG.debug(_('Exception while getting samples %s'), err)
|
|
except ceilometer.NotImplementedError:
|
|
# Selected inspector does not implement this pollster.
|
|
LOG.debug(_('Obtaining Memory Usage is not implemented for %s'
|
|
), manager.inspector.__class__.__name__)
|
|
except Exception as err:
|
|
LOG.exception(_('Could not get Memory Usage for '
|
|
'%(id)s: %(e)s'), {'id': instance.id,
|
|
'e': err})
|