Convert hypervisor test to requests_mock
Change-Id: Ie9acb8582ab52580c90b3511acf5e28eed2f9abf
This commit is contained in:
parent
0ad08858a5
commit
d69b81fe00
@ -268,6 +268,50 @@ def make_fake_server_group(id, name, policies):
|
||||
}))
|
||||
|
||||
|
||||
def make_fake_hypervisor(id, name):
|
||||
return json.loads(json.dumps({
|
||||
'id': id,
|
||||
'hypervisor_hostname': name,
|
||||
'state': 'up',
|
||||
'status': 'enabled',
|
||||
"cpu_info": {
|
||||
"arch": "x86_64",
|
||||
"model": "Nehalem",
|
||||
"vendor": "Intel",
|
||||
"features": [
|
||||
"pge",
|
||||
"clflush"
|
||||
],
|
||||
"topology": {
|
||||
"cores": 1,
|
||||
"threads": 1,
|
||||
"sockets": 4
|
||||
}
|
||||
},
|
||||
"current_workload": 0,
|
||||
"status": "enabled",
|
||||
"state": "up",
|
||||
"disk_available_least": 0,
|
||||
"host_ip": "1.1.1.1",
|
||||
"free_disk_gb": 1028,
|
||||
"free_ram_mb": 7680,
|
||||
"hypervisor_type": "fake",
|
||||
"hypervisor_version": 1000,
|
||||
"local_gb": 1028,
|
||||
"local_gb_used": 0,
|
||||
"memory_mb": 8192,
|
||||
"memory_mb_used": 512,
|
||||
"running_vms": 0,
|
||||
"service": {
|
||||
"host": "host1",
|
||||
"id": 7,
|
||||
"disabled_reason": None
|
||||
},
|
||||
"vcpus": 1,
|
||||
"vcpus_used": 0
|
||||
}))
|
||||
|
||||
|
||||
class FakeVolume(object):
|
||||
def __init__(
|
||||
self, id, status, name, attachments=[],
|
||||
|
@ -1192,17 +1192,23 @@ class TestShadeOperator(base.RequestsMockTestCase):
|
||||
get_session_mock.return_value = session_mock
|
||||
self.assertTrue(self.op_cloud.has_service("image"))
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'nova_client')
|
||||
def test_list_hypervisors(self, mock_nova):
|
||||
def test_list_hypervisors(self):
|
||||
'''This test verifies that calling list_hypervisors results in a call
|
||||
to nova client.'''
|
||||
mock_nova.hypervisors.list.return_value = [
|
||||
fakes.FakeHypervisor('1', 'testserver1'),
|
||||
fakes.FakeHypervisor('2', 'testserver2'),
|
||||
]
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
'compute', 'public', append=['os-hypervisors', 'detail']),
|
||||
json={'hypervisors': [
|
||||
fakes.make_fake_hypervisor('1', 'testserver1'),
|
||||
fakes.make_fake_hypervisor('2', 'testserver2'),
|
||||
]}),
|
||||
])
|
||||
|
||||
r = self.op_cloud.list_hypervisors()
|
||||
mock_nova.hypervisors.list.assert_called_once_with()
|
||||
|
||||
self.assertEqual(2, len(r))
|
||||
self.assertEqual('testserver1', r[0]['hypervisor_hostname'])
|
||||
self.assertEqual('testserver2', r[1]['hypervisor_hostname'])
|
||||
|
||||
self.assert_calls()
|
||||
|
Loading…
x
Reference in New Issue
Block a user