[unittests] Increase agent module unittests coverage

Add tests to increase unittest coverage of ceilometer.agent and
ceilometer.hardware modules.

Change-Id: I8ca246f9ace4427c3cf0dd4d314995c4815b59e4
This commit is contained in:
Igor Degtiarov 2015-04-28 18:56:09 +03:00
parent 1b593e9b00
commit 80045c13e2
2 changed files with 66 additions and 1 deletions

View File

@ -20,6 +20,8 @@ from oslo_config import fixture as fixture_config
from oslotest import base
from ceilometer.agent.discovery import endpoint
from ceilometer.agent.discovery import localnode
from ceilometer.hardware import discovery as hardware
class TestEndpointDiscovery(base.BaseTestCase):
@ -51,3 +53,56 @@ class TestEndpointDiscovery(base.BaseTestCase):
self.assertEqual(expected,
self.manager.keystone.service_catalog.get_urls
.call_args_list)
def test_keystone_called_no_endpoints(self):
self.manager.keystone.service_catalog.get_urls.return_value = []
self.assertEqual([], self.discovery.discover(self.manager))
class TestLocalnodeDiscovery(base.BaseTestCase):
def setUp(self):
super(TestLocalnodeDiscovery, self).setUp()
self.discovery = localnode.LocalNodeDiscovery()
self.manager = mock.MagicMock()
def test_lockalnode_discovery(self):
self.assertEqual(['local_host'], self.discovery.discover(self.manager))
class TestHardwareDiscovery(base.BaseTestCase):
class MockInstance(object):
addresses = {'ctlplane': [
{'addr': '0.0.0.0',
'OS-EXT-IPS-MAC:mac_addr': '01-23-45-67-89-ab'}
]}
id = 'resource_id'
image = {'id': 'image_id'}
flavor = {'id': 'flavor_id'}
expected = {
'resource_id': 'resource_id',
'resource_url': 'snmp://ro_snmp_user:password@0.0.0.0',
'mac_addr': '01-23-45-67-89-ab',
'image_id': 'image_id',
'flavor_id': 'flavor_id',
}
def setUp(self):
super(TestHardwareDiscovery, self).setUp()
self.discovery = hardware.NodesDiscoveryTripleO()
self.discovery.nova_cli = mock.MagicMock()
self.manager = mock.MagicMock()
def test_hardware_discovery(self):
self.discovery.nova_cli.instance_get_all.return_value = [
self.MockInstance()]
resources = self.discovery.discover(self.manager)
self.assertEqual(1, len(resources))
self.assertEqual(self.expected, resources[0])
def test_hardware_discovery_without_flavor(self):
instance = self.MockInstance()
instance.flavor = {}
self.discovery.nova_cli.instance_get_all.return_value = [instance]
resources = self.discovery.discover(self.manager)
self.assertEqual(0, len(resources))

View File

@ -20,6 +20,7 @@ from oslotest import base
from oslotest import mockpatch
from stevedore import extension
from ceilometer.agent import base as agent_base
from ceilometer.agent import manager
from ceilometer.agent import plugin_base
from ceilometer import pipeline
@ -69,7 +70,9 @@ class TestManager(base.BaseTestCase):
mock.Mock(return_value=None))
@mock.patch('ceilometer.agent.base.LOG')
def test_load_failed_plugins(self, LOG):
mgr = manager.AgentManager(namespaces=['ipmi'],
# Here we additionally check that namespaces will be converted to the
# list if param was not set as a list.
mgr = manager.AgentManager(namespaces='ipmi',
pollster_list=['hardware.ipmi.node.*'])
# 0 pollsters
self.assertEqual(0, len(mgr.extensions))
@ -104,6 +107,13 @@ class TestManager(base.BaseTestCase):
['ipmi'],
['hardware.ipmi.node.*'])
def test_load_plugins_pollster_list_forbidden(self):
manager.cfg.CONF.set_override('backend_url', 'http://',
group='coordination')
self.assertRaises(agent_base.PollsterListForbidden,
manager.AgentManager,
pollster_list=['disk.*'])
class TestPollsterKeystone(agentbase.TestPollster):
@plugin_base.check_keystone