Skip to content

Commit 7527fdf

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "tests: Clean up 'test_hypervisors'"
2 parents e6f5e81 + 7aa7fb9 commit 7527fdf

File tree

1 file changed

+75
-62
lines changed

1 file changed

+75
-62
lines changed

nova/tests/unit/api/openstack/compute/test_hypervisors.py

Lines changed: 75 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,13 @@ def _test(self, compute_node_get_all):
514514

515515
_test(self)
516516

517+
def test_show(self):
518+
req = self._get_request(True)
519+
hyper_id = self._get_hyper_id()
520+
result = self.controller.show(req, hyper_id)
521+
522+
self.assertEqual({'hypervisor': self.DETAIL_HYPERS_DICTS[0]}, result)
523+
517524
def test_show_compute_host_not_mapped(self):
518525
"""Tests that if a service is deleted but the compute node is not we
519526
don't fail when listing hypervisors.
@@ -543,13 +550,6 @@ def test_show_non_integer_id(self):
543550
req = self._get_request(True)
544551
self.assertRaises(exc.HTTPNotFound, self.controller.show, req, 'abc')
545552

546-
def test_show_with_id(self):
547-
req = self._get_request(True)
548-
hyper_id = self._get_hyper_id()
549-
result = self.controller.show(req, hyper_id)
550-
551-
self.assertEqual(dict(hypervisor=self.DETAIL_HYPERS_DICTS[0]), result)
552-
553553
def test_uptime(self):
554554
with mock.patch.object(
555555
self.controller.host_api, 'get_host_uptime',
@@ -737,7 +737,7 @@ def test_servers_with_non_integer_hypervisor_id(self):
737737
self.controller.servers, req, 'abc')
738738
self.assertEqual(1, mock_node_search.call_count)
739739

740-
def test_servers_with_no_server(self):
740+
def test_servers_with_no_servers(self):
741741
with mock.patch.object(self.controller.host_api,
742742
'instance_get_all_by_host',
743743
return_value=[]) as mock_inst_get_all:
@@ -1036,7 +1036,27 @@ def test_servers(self):
10361036
self.controller.servers,
10371037
self._get_request(True), 'hyper')
10381038

1039-
def test_servers_with_no_server(self):
1039+
def test_servers_not_mapped(self):
1040+
# the separate 'servers' API has been removed, so skip this test
1041+
pass
1042+
1043+
def test_servers_compute_host_not_found(self):
1044+
# the separate 'servers' API has been removed, so skip this test
1045+
pass
1046+
1047+
def test_servers_non_id(self):
1048+
# the separate 'servers' API has been removed, so skip this test
1049+
pass
1050+
1051+
def test_servers_with_non_integer_hypervisor_id(self):
1052+
# the separate 'servers' API has been removed, so skip this test
1053+
pass
1054+
1055+
def test_servers_with_no_servers(self):
1056+
# the separate 'servers' API has been removed, so skip this test
1057+
pass
1058+
1059+
def test_index_with_no_servers(self):
10401060
"""Tests GET /os-hypervisors?with_servers=1 when there are no
10411061
instances on the given host.
10421062
"""
@@ -1053,7 +1073,7 @@ def test_servers_with_no_server(self):
10531073
mock.call(req.environ['nova.context'], TEST_HYPERS_OBJ[0].host),
10541074
mock.call(req.environ['nova.context'], TEST_HYPERS_OBJ[1].host)))
10551075

1056-
def test_servers_not_mapped(self):
1076+
def test_index_with_servers_not_mapped(self):
10571077
"""Tests that instance_get_all_by_host fails with HostMappingNotFound.
10581078
"""
10591079
req = self._get_request(use_admin_context=True,
@@ -1064,7 +1084,7 @@ def test_servers_not_mapped(self):
10641084
result = self.controller.index(req)
10651085
self.assertEqual(dict(hypervisors=[]), result)
10661086

1067-
def test_servers_compute_host_not_found(self):
1087+
def test_index_with_servers_compute_host_not_found(self):
10681088
req = self._get_request(
10691089
use_admin_context=True,
10701090
url='/os-hypervisors?with_servers=1')
@@ -1084,7 +1104,7 @@ def test_servers_compute_host_not_found(self):
10841104
result = self.controller.index(req)
10851105
self.assertEqual({'hypervisors': []}, result)
10861106

1087-
def test_list_with_servers(self):
1107+
def test_index_with_servers(self):
10881108
"""Tests GET /os-hypervisors?with_servers=True"""
10891109
instances = [
10901110
objects.InstanceList(objects=[objects.Instance(
@@ -1109,14 +1129,14 @@ def test_list_with_servers(self):
11091129
mock.call(req.environ['nova.context'], TEST_HYPERS_OBJ[0].host),
11101130
mock.call(req.environ['nova.context'], TEST_HYPERS_OBJ[1].host)))
11111131

1112-
def test_list_with_servers_invalid_parameter(self):
1132+
def test_index_with_servers_invalid_parameter(self):
11131133
"""Tests using an invalid with_servers query parameter."""
11141134
req = self._get_request(use_admin_context=True,
11151135
url='/os-hypervisors?with_servers=invalid')
11161136
self.assertRaises(
11171137
exception.ValidationError, self.controller.index, req)
11181138

1119-
def test_list_with_hostname_pattern_and_paging_parameters(self):
1139+
def test_index_with_hostname_pattern_and_paging_parameters(self):
11201140
"""This is a negative test to validate that trying to list hypervisors
11211141
with a hostname pattern and paging parameters results in a 400 error.
11221142
"""
@@ -1129,7 +1149,7 @@ def test_list_with_hostname_pattern_and_paging_parameters(self):
11291149
'hypervisor_hostname_pattern query parameter is not '
11301150
'supported.', str(ex))
11311151

1132-
def test_servers_with_non_integer_hypervisor_id(self):
1152+
def test_index_with_hostname_pattern_no_match(self):
11331153
"""This is a poorly named test, it's really checking the 404 case where
11341154
there is no match for the hostname pattern.
11351155
"""
@@ -1143,19 +1163,7 @@ def test_servers_with_non_integer_hypervisor_id(self):
11431163
self.assertRaises(exc.HTTPNotFound, self.controller.index, req)
11441164
s.assert_called_once_with(req.environ['nova.context'], 'shenzhen')
11451165

1146-
def test_servers_non_id(self):
1147-
"""There is no reason to test this for 2.53 since the
1148-
/os-hypervisors/servers route is deprecated.
1149-
"""
1150-
pass
1151-
1152-
def test_search_old_route(self):
1153-
"""Asserts that calling the search route after 2.52 fails."""
1154-
self.assertRaises(exception.VersionNotFoundForAPIMethod,
1155-
self.controller.search,
1156-
self._get_request(True), 'hyper')
1157-
1158-
def test_search(self):
1166+
def test_detail_with_hostname_pattern(self):
11591167
"""Test listing hypervisors with details and using the
11601168
hypervisor_hostname_pattern query string.
11611169
"""
@@ -1177,7 +1185,7 @@ def test_search(self):
11771185
self.assertNotIn('hypervisors_links', result)
11781186
self.assertDictEqual(expected, result)
11791187

1180-
def test_search_invalid_hostname_pattern_parameter(self):
1188+
def test_detail_invalid_hostname_pattern_parameter(self):
11811189
"""Tests passing an invalid hypervisor_hostname_pattern query
11821190
parameter.
11831191
"""
@@ -1187,6 +1195,12 @@ def test_search_invalid_hostname_pattern_parameter(self):
11871195
self.assertRaises(
11881196
exception.ValidationError, self.controller.detail, req)
11891197

1198+
def test_search(self):
1199+
"""Asserts that calling the search route after 2.52 fails."""
1200+
self.assertRaises(exception.VersionNotFoundForAPIMethod,
1201+
self.controller.search,
1202+
self._get_request(True), 'hyper')
1203+
11901204
def test_search_non_exist(self):
11911205
"""This is a duplicate of test_servers_with_non_integer_hypervisor_id.
11921206
"""
@@ -1256,6 +1270,17 @@ def test_show_with_servers(self):
12561270
mock_inst_get_all.assert_called_once_with(
12571271
req.environ['nova.context'], TEST_HYPERS_OBJ[0].host)
12581272

1273+
def test_show_duplicate_query_parameters_validation(self):
1274+
"""Tests that the show query parameter schema enforces only a single
1275+
entry for any query parameter.
1276+
"""
1277+
req = self._get_request(
1278+
use_admin_context=True,
1279+
url='/os-hypervisors/%s?with_servers=1&with_servers=1' %
1280+
uuids.hyper1)
1281+
self.assertRaises(exception.ValidationError,
1282+
self.controller.show, req, uuids.hyper1)
1283+
12591284
def test_uptime_non_integer_id(self):
12601285
"""There is no reason to test this for 2.53 since 2.53 requires a
12611286
non-integer id (requires a uuid).
@@ -1370,22 +1395,11 @@ def test_index_duplicate_query_parameters_validation(self):
13701395
self.assertRaises(exception.ValidationError,
13711396
self.controller.index, req)
13721397

1373-
def test_show_duplicate_query_parameters_validation(self):
1374-
"""Tests that the show query parameter schema enforces only a single
1375-
entry for any query parameter.
1376-
"""
1377-
req = self._get_request(
1378-
use_admin_context=True,
1379-
url='/os-hypervisors/%s?with_servers=1&with_servers=1' %
1380-
uuids.hyper1)
1381-
self.assertRaises(exception.ValidationError,
1382-
self.controller.show, req, uuids.hyper1)
1383-
13841398

13851399
class HypervisorsTestV275(HypervisorsTestV253):
13861400
api_version = '2.75'
13871401

1388-
def _test_servers_with_no_server(self, func, version=None, **kwargs):
1402+
def _test_servers_with_no_servers(self, func, version=None, **kwargs):
13891403
"""Tests GET APIs return 'servers' field in response even
13901404
no servers on hypervisors.
13911405
"""
@@ -1401,39 +1415,38 @@ def _test_servers_with_no_server(self, func, version=None, **kwargs):
14011415
result = func(req, **kwargs)
14021416
return result
14031417

1404-
def test_list_servers_with_no_server_old_version(self):
1405-
result = self._test_servers_with_no_server(self.controller.index,
1406-
version='2.74')
1418+
def test_index_with_no_servers(self):
1419+
result = self._test_servers_with_no_servers(self.controller.index)
14071420
for hyper in result['hypervisors']:
1408-
self.assertNotIn('servers', hyper)
1421+
self.assertEqual(0, len(hyper['servers']))
14091422

1410-
def test_list_detail_servers_with_no_server_old_version(self):
1411-
result = self._test_servers_with_no_server(self.controller.detail,
1412-
version='2.74')
1423+
def test_index_with_no_servers_old_version(self):
1424+
result = self._test_servers_with_no_servers(
1425+
self.controller.index, version='2.74')
14131426
for hyper in result['hypervisors']:
14141427
self.assertNotIn('servers', hyper)
14151428

1416-
def test_show_servers_with_no_server_old_version(self):
1417-
result = self._test_servers_with_no_server(self.controller.show,
1418-
version='2.74',
1419-
id=uuids.hyper1)
1420-
self.assertNotIn('servers', result['hypervisor'])
1421-
1422-
def test_servers_with_no_server(self):
1423-
result = self._test_servers_with_no_server(self.controller.index)
1429+
def test_detail_with_no_servers(self):
1430+
result = self._test_servers_with_no_servers(self.controller.detail)
14241431
for hyper in result['hypervisors']:
14251432
self.assertEqual(0, len(hyper['servers']))
14261433

1427-
def test_list_detail_servers_with_empty_server_list(self):
1428-
result = self._test_servers_with_no_server(self.controller.detail)
1434+
def test_detail_with_no_servers_old_version(self):
1435+
result = self._test_servers_with_no_servers(
1436+
self.controller.detail, version='2.74')
14291437
for hyper in result['hypervisors']:
1430-
self.assertEqual(0, len(hyper['servers']))
1438+
self.assertNotIn('servers', hyper)
14311439

1432-
def test_show_servers_with_empty_server_list(self):
1433-
result = self._test_servers_with_no_server(self.controller.show,
1434-
id=uuids.hyper1)
1440+
def test_show_with_no_servers(self):
1441+
result = self._test_servers_with_no_servers(
1442+
self.controller.show, id=uuids.hyper1)
14351443
self.assertEqual(0, len(result['hypervisor']['servers']))
14361444

1445+
def test_show_with_no_servers_old_version(self):
1446+
result = self._test_servers_with_no_servers(
1447+
self.controller.show, version='2.74', id=uuids.hyper1)
1448+
self.assertNotIn('servers', result['hypervisor'])
1449+
14371450

14381451
class HypervisorsTestV288(HypervisorsTestV275):
14391452
api_version = '2.88'

0 commit comments

Comments
 (0)