@@ -514,6 +514,13 @@ def _test(self, compute_node_get_all):
514
514
515
515
_test (self )
516
516
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
+
517
524
def test_show_compute_host_not_mapped (self ):
518
525
"""Tests that if a service is deleted but the compute node is not we
519
526
don't fail when listing hypervisors.
@@ -543,13 +550,6 @@ def test_show_non_integer_id(self):
543
550
req = self ._get_request (True )
544
551
self .assertRaises (exc .HTTPNotFound , self .controller .show , req , 'abc' )
545
552
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
-
553
553
def test_uptime (self ):
554
554
with mock .patch .object (
555
555
self .controller .host_api , 'get_host_uptime' ,
@@ -737,7 +737,7 @@ def test_servers_with_non_integer_hypervisor_id(self):
737
737
self .controller .servers , req , 'abc' )
738
738
self .assertEqual (1 , mock_node_search .call_count )
739
739
740
- def test_servers_with_no_server (self ):
740
+ def test_servers_with_no_servers (self ):
741
741
with mock .patch .object (self .controller .host_api ,
742
742
'instance_get_all_by_host' ,
743
743
return_value = []) as mock_inst_get_all :
@@ -1036,7 +1036,27 @@ def test_servers(self):
1036
1036
self .controller .servers ,
1037
1037
self ._get_request (True ), 'hyper' )
1038
1038
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 ):
1040
1060
"""Tests GET /os-hypervisors?with_servers=1 when there are no
1041
1061
instances on the given host.
1042
1062
"""
@@ -1053,7 +1073,7 @@ def test_servers_with_no_server(self):
1053
1073
mock .call (req .environ ['nova.context' ], TEST_HYPERS_OBJ [0 ].host ),
1054
1074
mock .call (req .environ ['nova.context' ], TEST_HYPERS_OBJ [1 ].host )))
1055
1075
1056
- def test_servers_not_mapped (self ):
1076
+ def test_index_with_servers_not_mapped (self ):
1057
1077
"""Tests that instance_get_all_by_host fails with HostMappingNotFound.
1058
1078
"""
1059
1079
req = self ._get_request (use_admin_context = True ,
@@ -1064,7 +1084,7 @@ def test_servers_not_mapped(self):
1064
1084
result = self .controller .index (req )
1065
1085
self .assertEqual (dict (hypervisors = []), result )
1066
1086
1067
- def test_servers_compute_host_not_found (self ):
1087
+ def test_index_with_servers_compute_host_not_found (self ):
1068
1088
req = self ._get_request (
1069
1089
use_admin_context = True ,
1070
1090
url = '/os-hypervisors?with_servers=1' )
@@ -1084,7 +1104,7 @@ def test_servers_compute_host_not_found(self):
1084
1104
result = self .controller .index (req )
1085
1105
self .assertEqual ({'hypervisors' : []}, result )
1086
1106
1087
- def test_list_with_servers (self ):
1107
+ def test_index_with_servers (self ):
1088
1108
"""Tests GET /os-hypervisors?with_servers=True"""
1089
1109
instances = [
1090
1110
objects .InstanceList (objects = [objects .Instance (
@@ -1109,14 +1129,14 @@ def test_list_with_servers(self):
1109
1129
mock .call (req .environ ['nova.context' ], TEST_HYPERS_OBJ [0 ].host ),
1110
1130
mock .call (req .environ ['nova.context' ], TEST_HYPERS_OBJ [1 ].host )))
1111
1131
1112
- def test_list_with_servers_invalid_parameter (self ):
1132
+ def test_index_with_servers_invalid_parameter (self ):
1113
1133
"""Tests using an invalid with_servers query parameter."""
1114
1134
req = self ._get_request (use_admin_context = True ,
1115
1135
url = '/os-hypervisors?with_servers=invalid' )
1116
1136
self .assertRaises (
1117
1137
exception .ValidationError , self .controller .index , req )
1118
1138
1119
- def test_list_with_hostname_pattern_and_paging_parameters (self ):
1139
+ def test_index_with_hostname_pattern_and_paging_parameters (self ):
1120
1140
"""This is a negative test to validate that trying to list hypervisors
1121
1141
with a hostname pattern and paging parameters results in a 400 error.
1122
1142
"""
@@ -1129,7 +1149,7 @@ def test_list_with_hostname_pattern_and_paging_parameters(self):
1129
1149
'hypervisor_hostname_pattern query parameter is not '
1130
1150
'supported.' , str (ex ))
1131
1151
1132
- def test_servers_with_non_integer_hypervisor_id (self ):
1152
+ def test_index_with_hostname_pattern_no_match (self ):
1133
1153
"""This is a poorly named test, it's really checking the 404 case where
1134
1154
there is no match for the hostname pattern.
1135
1155
"""
@@ -1143,19 +1163,7 @@ def test_servers_with_non_integer_hypervisor_id(self):
1143
1163
self .assertRaises (exc .HTTPNotFound , self .controller .index , req )
1144
1164
s .assert_called_once_with (req .environ ['nova.context' ], 'shenzhen' )
1145
1165
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 ):
1159
1167
"""Test listing hypervisors with details and using the
1160
1168
hypervisor_hostname_pattern query string.
1161
1169
"""
@@ -1177,7 +1185,7 @@ def test_search(self):
1177
1185
self .assertNotIn ('hypervisors_links' , result )
1178
1186
self .assertDictEqual (expected , result )
1179
1187
1180
- def test_search_invalid_hostname_pattern_parameter (self ):
1188
+ def test_detail_invalid_hostname_pattern_parameter (self ):
1181
1189
"""Tests passing an invalid hypervisor_hostname_pattern query
1182
1190
parameter.
1183
1191
"""
@@ -1187,6 +1195,12 @@ def test_search_invalid_hostname_pattern_parameter(self):
1187
1195
self .assertRaises (
1188
1196
exception .ValidationError , self .controller .detail , req )
1189
1197
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
+
1190
1204
def test_search_non_exist (self ):
1191
1205
"""This is a duplicate of test_servers_with_non_integer_hypervisor_id.
1192
1206
"""
@@ -1256,6 +1270,17 @@ def test_show_with_servers(self):
1256
1270
mock_inst_get_all .assert_called_once_with (
1257
1271
req .environ ['nova.context' ], TEST_HYPERS_OBJ [0 ].host )
1258
1272
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
+
1259
1284
def test_uptime_non_integer_id (self ):
1260
1285
"""There is no reason to test this for 2.53 since 2.53 requires a
1261
1286
non-integer id (requires a uuid).
@@ -1370,22 +1395,11 @@ def test_index_duplicate_query_parameters_validation(self):
1370
1395
self .assertRaises (exception .ValidationError ,
1371
1396
self .controller .index , req )
1372
1397
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
-
1384
1398
1385
1399
class HypervisorsTestV275 (HypervisorsTestV253 ):
1386
1400
api_version = '2.75'
1387
1401
1388
- def _test_servers_with_no_server (self , func , version = None , ** kwargs ):
1402
+ def _test_servers_with_no_servers (self , func , version = None , ** kwargs ):
1389
1403
"""Tests GET APIs return 'servers' field in response even
1390
1404
no servers on hypervisors.
1391
1405
"""
@@ -1401,39 +1415,38 @@ def _test_servers_with_no_server(self, func, version=None, **kwargs):
1401
1415
result = func (req , ** kwargs )
1402
1416
return result
1403
1417
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 )
1407
1420
for hyper in result ['hypervisors' ]:
1408
- self .assertNotIn ( 'servers' , hyper )
1421
+ self .assertEqual ( 0 , len ( hyper [ 'servers' ]) )
1409
1422
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' )
1413
1426
for hyper in result ['hypervisors' ]:
1414
1427
self .assertNotIn ('servers' , hyper )
1415
1428
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 )
1424
1431
for hyper in result ['hypervisors' ]:
1425
1432
self .assertEqual (0 , len (hyper ['servers' ]))
1426
1433
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' )
1429
1437
for hyper in result ['hypervisors' ]:
1430
- self .assertEqual ( 0 , len ( hyper [ 'servers' ]) )
1438
+ self .assertNotIn ( 'servers' , hyper )
1431
1439
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 )
1435
1443
self .assertEqual (0 , len (result ['hypervisor' ]['servers' ]))
1436
1444
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
+
1437
1450
1438
1451
class HypervisorsTestV288 (HypervisorsTestV275 ):
1439
1452
api_version = '2.88'
0 commit comments