1
# -*- encoding: utf-8 -*-
3
# Copyright © 2013 Intel Corp
5
# Authors: Lianhao Lu <lianhao.lu@intel.com>
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may
8
# not use this file except in compliance with the License. You may obtain
9
# a copy of the License at
11
# http://www.apache.org/licenses/LICENSE-2.0
13
# Unless required by applicable law or agreed to in writing, software
14
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
# License for the specific language governing permissions and limitations
22
from ceilometer.central import manager
23
from ceilometer.hardware.inspector import base as inspector_base
24
from ceilometer.tests import base as test_base
27
class FakeInspector(inspector_base.Inspector):
28
CPU = inspector_base.CPUStats(cpu_1_min=0.99,
31
DISK = (inspector_base.Disk(device='/dev/sda1', path='/'),
32
inspector_base.DiskStats(size=1000, used=90))
33
MEMORY = inspector_base.MemoryStats(total=1000, used=90)
34
NET = (inspector_base.Interface(name='test.teest',
37
inspector_base.InterfaceStats(bandwidth=1000,
42
def inspect_cpu(self, host):
45
def inspect_disk(self, host):
48
def inspect_memory(self, host):
51
def inspect_network(self, host):
55
class TestPollsterBase(test_base.BaseTestCase):
56
def faux_get_inspector(url, namespace=None):
57
return FakeInspector()
60
super(TestPollsterBase, self).setUp()
61
self.host = ["test://test"]
62
self.useFixture(fixtures.MonkeyPatch(
63
'ceilometer.hardware.inspector.get_inspector',
64
self.faux_get_inspector))
66
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
67
def _check_get_samples(self, factory, name,
68
expected_value, expected_type):
69
mgr = manager.AgentManager()
72
samples = list(pollster.get_samples(mgr, cache, self.host))
73
self.assertTrue(samples)
74
self.assertIn(pollster.CACHE_KEY, cache)
75
self.assertIn(self.host[0], cache[pollster.CACHE_KEY])
77
self.assertEqual(set([s.name for s in samples]),
79
match = [s for s in samples if s.name == name]
80
self.assertEqual(match[0].volume, expected_value)
81
self.assertEqual(match[0].type, expected_type)