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:
parent
bdefef8c9a
commit
f0440f80b7
@ -193,3 +193,9 @@ class FakeGroup(object):
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.description = description
|
self.description = description
|
||||||
self.domain = domain
|
self.domain = domain
|
||||||
|
|
||||||
|
|
||||||
|
class FakeHypervisor(object):
|
||||||
|
def __init__(self, id, hostname):
|
||||||
|
self.id = id
|
||||||
|
self.hypervisor_hostname = hostname
|
||||||
|
@ -19,7 +19,6 @@ import testtools
|
|||||||
|
|
||||||
from os_client_config import cloud_config
|
from os_client_config import cloud_config
|
||||||
import shade
|
import shade
|
||||||
import munch
|
|
||||||
from shade import exc
|
from shade import exc
|
||||||
from shade import meta
|
from shade import meta
|
||||||
from shade.tests import fakes
|
from shade.tests import fakes
|
||||||
@ -1054,17 +1053,17 @@ class TestShadeOperator(base.TestCase):
|
|||||||
get_session_mock.return_value = session_mock
|
get_session_mock.return_value = session_mock
|
||||||
self.assertTrue(self.cloud.has_service("image"))
|
self.assertTrue(self.cloud.has_service("image"))
|
||||||
|
|
||||||
@mock.patch.object(shade._tasks.HypervisorList, 'main')
|
@mock.patch.object(shade.OpenStackCloud, 'nova_client')
|
||||||
def test_list_hypervisors(self, mock_hypervisorlist):
|
def test_list_hypervisors(self, mock_nova):
|
||||||
'''This test verifies that calling list_hypervisors results in a call
|
'''This test verifies that calling list_hypervisors results in a call
|
||||||
to the HypervisorList task.'''
|
to nova client.'''
|
||||||
mock_hypervisorlist.return_value = [
|
mock_nova.hypervisors.list.return_value = [
|
||||||
munch.Munch({'hypervisor_hostname': 'testserver1',
|
fakes.FakeHypervisor('1', 'testserver1'),
|
||||||
'id': '1'}),
|
fakes.FakeHypervisor('2', 'testserver2'),
|
||||||
munch.Munch({'hypervisor_hostname': 'testserver2',
|
|
||||||
'id': '2'})
|
|
||||||
]
|
]
|
||||||
|
|
||||||
r = self.cloud.list_hypervisors()
|
r = self.cloud.list_hypervisors()
|
||||||
|
mock_nova.hypervisors.list.assert_called_once_with()
|
||||||
self.assertEquals(2, len(r))
|
self.assertEquals(2, len(r))
|
||||||
self.assertEquals('testserver1', r[0]['hypervisor_hostname'])
|
self.assertEquals('testserver1', r[0]['hypervisor_hostname'])
|
||||||
|
self.assertEquals('testserver2', r[1]['hypervisor_hostname'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user