Improve test coverage: hypervisor list

The existing test for list_hypervisors() did not go deep enough
into the call stack to test the actual underlying nova client call.

Change-Id: I1d4cd9bc9424dfed6554794fa7a80db74cdac8a3
This commit is contained in:
David Shrewsbury 2015-12-08 10:35:41 -05:00
parent bdefef8c9a
commit f0440f80b7
2 changed files with 14 additions and 9 deletions

View File

@ -193,3 +193,9 @@ class FakeGroup(object):
self.name = name
self.description = description
self.domain = domain
class FakeHypervisor(object):
def __init__(self, id, hostname):
self.id = id
self.hypervisor_hostname = hostname

View File

@ -19,7 +19,6 @@ import testtools
from os_client_config import cloud_config
import shade
import munch
from shade import exc
from shade import meta
from shade.tests import fakes
@ -1054,17 +1053,17 @@ class TestShadeOperator(base.TestCase):
get_session_mock.return_value = session_mock
self.assertTrue(self.cloud.has_service("image"))
@mock.patch.object(shade._tasks.HypervisorList, 'main')
def test_list_hypervisors(self, mock_hypervisorlist):
@mock.patch.object(shade.OpenStackCloud, 'nova_client')
def test_list_hypervisors(self, mock_nova):
'''This test verifies that calling list_hypervisors results in a call
to the HypervisorList task.'''
mock_hypervisorlist.return_value = [
munch.Munch({'hypervisor_hostname': 'testserver1',
'id': '1'}),
munch.Munch({'hypervisor_hostname': 'testserver2',
'id': '2'})
to nova client.'''
mock_nova.hypervisors.list.return_value = [
fakes.FakeHypervisor('1', 'testserver1'),
fakes.FakeHypervisor('2', 'testserver2'),
]
r = self.cloud.list_hypervisors()
mock_nova.hypervisors.list.assert_called_once_with()
self.assertEquals(2, len(r))
self.assertEquals('testserver1', r[0]['hypervisor_hostname'])
self.assertEquals('testserver2', r[1]['hypervisor_hostname'])