|
37 | 37 | from nova import exception |
38 | 38 | from nova.objects import base as obj_base |
39 | 39 | from nova.objects import instance as instance_obj |
| 40 | +from nova.objects import service as service_obj |
40 | 41 | from nova import test |
41 | 42 | from nova.tests import fixtures as nova_fixtures |
42 | 43 | from nova.tests.unit.objects import test_objects |
@@ -1207,3 +1208,89 @@ def test_get_sdk_adapter_conf_group_fail(self): |
1207 | 1208 | self.mock_get_confgrp.assert_called_once_with(self.service_type) |
1208 | 1209 | self.mock_connection.assert_not_called() |
1209 | 1210 | self.mock_get_auth_sess.assert_not_called() |
| 1211 | + |
| 1212 | + |
| 1213 | +class TestOldComputeCheck(test.NoDBTestCase): |
| 1214 | + |
| 1215 | + @mock.patch('nova.objects.service.get_minimum_version_all_cells') |
| 1216 | + def test_no_compute(self, mock_get_min_service): |
| 1217 | + mock_get_min_service.return_value = 0 |
| 1218 | + |
| 1219 | + utils.raise_if_old_compute() |
| 1220 | + |
| 1221 | + mock_get_min_service.assert_called_once_with( |
| 1222 | + mock.ANY, ['nova-compute']) |
| 1223 | + |
| 1224 | + @mock.patch('nova.objects.service.get_minimum_version_all_cells') |
| 1225 | + def test_old_but_supported_compute(self, mock_get_min_service): |
| 1226 | + oldest = service_obj.SERVICE_VERSION_ALIASES[ |
| 1227 | + service_obj.OLDEST_SUPPORTED_SERVICE_VERSION] |
| 1228 | + mock_get_min_service.return_value = oldest |
| 1229 | + |
| 1230 | + utils.raise_if_old_compute() |
| 1231 | + |
| 1232 | + mock_get_min_service.assert_called_once_with( |
| 1233 | + mock.ANY, ['nova-compute']) |
| 1234 | + |
| 1235 | + @mock.patch('nova.objects.service.get_minimum_version_all_cells') |
| 1236 | + def test_new_compute(self, mock_get_min_service): |
| 1237 | + mock_get_min_service.return_value = service_obj.SERVICE_VERSION |
| 1238 | + |
| 1239 | + utils.raise_if_old_compute() |
| 1240 | + |
| 1241 | + mock_get_min_service.assert_called_once_with( |
| 1242 | + mock.ANY, ['nova-compute']) |
| 1243 | + |
| 1244 | + @mock.patch('nova.objects.service.Service.get_minimum_version') |
| 1245 | + def test_too_old_compute_cell(self, mock_get_min_service): |
| 1246 | + self.flags(group='api_database', connection=None) |
| 1247 | + oldest = service_obj.SERVICE_VERSION_ALIASES[ |
| 1248 | + service_obj.OLDEST_SUPPORTED_SERVICE_VERSION] |
| 1249 | + mock_get_min_service.return_value = oldest - 1 |
| 1250 | + |
| 1251 | + ex = self.assertRaises( |
| 1252 | + exception.TooOldComputeService, utils.raise_if_old_compute) |
| 1253 | + |
| 1254 | + self.assertIn('cell', str(ex)) |
| 1255 | + mock_get_min_service.assert_called_once_with(mock.ANY, 'nova-compute') |
| 1256 | + |
| 1257 | + @mock.patch('nova.objects.service.get_minimum_version_all_cells') |
| 1258 | + def test_too_old_compute_top_level(self, mock_get_min_service): |
| 1259 | + self.flags(group='api_database', connection='fake db connection') |
| 1260 | + oldest = service_obj.SERVICE_VERSION_ALIASES[ |
| 1261 | + service_obj.OLDEST_SUPPORTED_SERVICE_VERSION] |
| 1262 | + mock_get_min_service.return_value = oldest - 1 |
| 1263 | + |
| 1264 | + ex = self.assertRaises( |
| 1265 | + exception.TooOldComputeService, utils.raise_if_old_compute) |
| 1266 | + |
| 1267 | + self.assertIn('system', str(ex)) |
| 1268 | + mock_get_min_service.assert_called_once_with( |
| 1269 | + mock.ANY, ['nova-compute']) |
| 1270 | + |
| 1271 | + @mock.patch.object(utils.LOG, 'warning') |
| 1272 | + @mock.patch('nova.objects.service.Service.get_minimum_version') |
| 1273 | + @mock.patch('nova.objects.service.get_minimum_version_all_cells') |
| 1274 | + def test_api_db_is_configured_but_the_service_cannot_access_db( |
| 1275 | + self, mock_get_all, mock_get, mock_warn): |
| 1276 | + # This is the case when the nova-compute service is wrongly configured |
| 1277 | + # with db credentials but nova-compute is never allowed to access the |
| 1278 | + # db directly. |
| 1279 | + mock_get_all.side_effect = exception.DBNotAllowed( |
| 1280 | + binary='nova-compute') |
| 1281 | + |
| 1282 | + oldest = service_obj.SERVICE_VERSION_ALIASES[ |
| 1283 | + service_obj.OLDEST_SUPPORTED_SERVICE_VERSION] |
| 1284 | + mock_get.return_value = oldest - 1 |
| 1285 | + |
| 1286 | + ex = self.assertRaises( |
| 1287 | + exception.TooOldComputeService, utils.raise_if_old_compute) |
| 1288 | + |
| 1289 | + self.assertIn('cell', str(ex)) |
| 1290 | + mock_get_all.assert_called_once_with(mock.ANY, ['nova-compute']) |
| 1291 | + mock_get.assert_called_once_with(mock.ANY, 'nova-compute') |
| 1292 | + mock_warn.assert_called_once_with( |
| 1293 | + 'This service is configured for access to the API database but is ' |
| 1294 | + 'not allowed to directly access the database. You should run this ' |
| 1295 | + 'service without the [api_database]/connection config option. The ' |
| 1296 | + 'service version check will only query the local cell.') |
0 commit comments