teach shade how to list_hypervisors

adds a list_hypervisors method to shade, along with a corresponding unit
test.

Change-Id: Ia7d8f7249356f28fdbad6c513adee4176615142f
This commit is contained in:
Lars Kellogg-Stedman 2015-10-30 19:33:32 -04:00
parent 5dca987851
commit 234a2bf068
3 changed files with 35 additions and 0 deletions

View File

@ -126,6 +126,11 @@ class ServerRebuild(task_manager.Task):
return client.nova_client.servers.rebuild(**self.args)
class HypervisorList(task_manager.Task):
def main(self, client):
return client.nova_client.hypervisors.list(**self.args)
class KeypairList(task_manager.Task):
def main(self, client):
return client.nova_client.keypairs.list()

View File

@ -1486,3 +1486,17 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
)
return True
def list_hypervisors(self):
"""List all hypervisors
:returns: A list of hypervisor dicts.
"""
try:
return self.manager.submitTask(_tasks.HypervisorList())
except OpenStackCloudException:
raise
except Exception as e:
raise OpenStackCloudException(
"Error fetching hypervisor list: %s" % str(e))

View File

@ -19,6 +19,7 @@ import testtools
import os_client_config.cloud_config
import shade
import munch
from shade import exc
from shade import meta
from shade.tests import fakes
@ -1038,3 +1039,18 @@ class TestShadeOperator(base.TestCase):
def test_has_service_yes(self, session_mock):
session_mock.get_endpoint.return_value = 'http://fake.url'
self.assertTrue(self.cloud.has_service("image"))
@mock.patch.object(shade._tasks.HypervisorList, 'main')
def test_list_hypervisors(self, mock_hypervisorlist):
'''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'})
]
r = self.cloud.list_hypervisors()
self.assertEquals(2, len(r))
self.assertEquals('testserver1', r[0]['hypervisor_hostname'])