summaryrefslogtreecommitdiff
path: root/novaclient/tests
diff options
context:
space:
mode:
authorMatt Riedemann <mriedem.os@gmail.com>2019-05-17 18:07:38 -0400
committerMatt Riedemann <mriedem.os@gmail.com>2019-05-18 14:47:11 -0400
commit0dc6b96ec83703a0607c4df16e43856632aecb61 (patch)
tree6484b96440d2f99f9bb4a3fa8db66003b93e2f5b /novaclient/tests
parentdfb84228a2748bed82f9b83c1209d5e2e0557bfa (diff)
downloadpython-novaclient-0dc6b96ec83703a0607c4df16e43856632aecb61.tar.gz
Allow searching for hypervisors and getting back details
The 2.53 microversion allows listing hypervisors with details and filtering on a hypervisor_hostname substring pattern match. This makes the python API binding HypervisorManager.search method allow that as well by adding a new 'detailed' boolean kwarg which defaults to False for backward compatibility for the /search and /servers routes before 2.53, but allows searching and getting detailed results back as well. Change-Id: I81fa4520af3cc7f1298c262f4fdc4e15fbc6d7ba
Diffstat (limited to 'novaclient/tests')
-rw-r--r--novaclient/tests/functional/v2/test_hypervisors.py13
-rw-r--r--novaclient/tests/unit/v2/test_hypervisors.py23
2 files changed, 36 insertions, 0 deletions
diff --git a/novaclient/tests/functional/v2/test_hypervisors.py b/novaclient/tests/functional/v2/test_hypervisors.py
index ca66a44a..bb58648b 100644
--- a/novaclient/tests/functional/v2/test_hypervisors.py
+++ b/novaclient/tests/functional/v2/test_hypervisors.py
@@ -26,3 +26,16 @@ class TestHypervisorsV2_53(TestHypervisorsV28):
def test_list(self):
self._test_list(cpu_info_type=dict, uuid_as_id=True)
+
+ def test_search_with_details(self):
+ # First find a hypervisor from the list to search on.
+ hypervisors = self.client.hypervisors.list()
+ # Now search for that hypervisor with details.
+ hypervisor = hypervisors[0]
+ hypervisors = self.client.hypervisors.search(
+ hypervisor.hypervisor_hostname, detailed=True)
+ self.assertEqual(1, len(hypervisors))
+ hypervisor = hypervisors[0]
+ # We know we got details if service is in the response.
+ self.assertIsNotNone(hypervisor.service,
+ 'Expected service in hypervisor: %s' % hypervisor)
diff --git a/novaclient/tests/unit/v2/test_hypervisors.py b/novaclient/tests/unit/v2/test_hypervisors.py
index 0c24209b..3eaeb576 100644
--- a/novaclient/tests/unit/v2/test_hypervisors.py
+++ b/novaclient/tests/unit/v2/test_hypervisors.py
@@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import six
+
from novaclient import api_versions
from novaclient import exceptions
from novaclient.tests.unit.fixture_data import client
@@ -119,6 +121,14 @@ class HypervisorsTest(utils.FixturedTestCase):
self.cs.hypervisors.search,
hypervisor_match)
+ def test_hypervisor_search_detailed(self):
+ # detailed=True is not supported before 2.53
+ ex = self.assertRaises(exceptions.UnsupportedVersion,
+ self.cs.hypervisors.search, 'hyper',
+ detailed=True)
+ self.assertIn('Parameter "detailed" requires API version 2.53 or '
+ 'greater.', six.text_type(ex))
+
def test_hypervisor_servers(self):
expected = [
dict(id=self.data_fixture.hyper_id_1,
@@ -236,3 +246,16 @@ class HypervisorsV2_53Test(HypervisorsV233Test):
def setUp(self):
super(HypervisorsV2_53Test, self).setUp()
self.cs.api_version = api_versions.APIVersion("2.53")
+
+ def test_hypervisor_search_detailed(self):
+ expected = [
+ dict(id=self.data_fixture.hyper_id_1,
+ hypervisor_hostname='hyper1'),
+ dict(id=self.data_fixture.hyper_id_2,
+ hypervisor_hostname='hyper2')]
+ result = self.cs.hypervisors.search('hyper', detailed=True)
+ self.assert_request_id(result, fakes.FAKE_REQUEST_ID_LIST)
+ self.assert_called(
+ 'GET', '/os-hypervisors/detail?hypervisor_hostname_pattern=hyper')
+ for idx, hyper in enumerate(result):
+ self.compare_to_expected(expected[idx], hyper)