Fix wrong unit test about config option enabled_apis

Accorrding to declaration of config option 'enabled_apis'[1],
it only allows values from ['osapi_compute', 'metadata'], otherwise
a ValueError will be raised when use its value.

oslo.config will land patch "Fix conversion to item_type on __call__ in
List type" again[2], which was reverted due to Nova test failure.

This commit will adjust Nova unit test to make the config option be
used as expected: only accept valid values in unit test.

[1] abb33a4577/nova/conf/service.py (L84)
[2] https://review.openstack.org/#/c/398335

Change-Id: I61983d34269a44940bbb99783143767cf4c97cb1
This commit is contained in:
ChangBo Guo(gcb) 2017-03-17 16:14:26 +08:00
parent 2a41eb8786
commit 36af34a153
1 changed files with 7 additions and 26 deletions

View File

@ -26,26 +26,8 @@ from nova import test
@mock.patch('nova.objects.Service.enable_min_version_cache')
class TestNovaAPI(test.NoDBTestCase):
@mock.patch('nova.service.process_launcher')
def test_with_ec2(self, launcher, version_cache):
"""Ensure that we don't explode if enabled_apis is wrong.
If the end user hasn't updated their config, an ec2 entry
might accidentally kill them in starting up their server. This
tests that our new safety filter will prevent that.
The metadata api is excluded because it loads a bunch of the
network stack, which requires other mocking.
"""
self.flags(enabled_apis=['ec2', 'osapi_compute'])
# required because of where the portbind happens, so that we
# collide on ports.
self.flags(osapi_compute_listen_port=0)
api.main()
version_cache.assert_called_once_with()
def test_continues_on_failure(self, version_cache):
count = [1, 2]
count = [1]
fake_server = mock.MagicMock()
fake_server.workers = 123
@ -56,19 +38,18 @@ class TestNovaAPI(test.NoDBTestCase):
raise exception.PasteAppNotFound(name=api, path='/')
return fake_server
self.flags(enabled_apis=['foo', 'bar', 'baz'])
self.flags(enabled_apis=['osapi_compute', 'metadata'])
with mock.patch.object(api, 'service') as mock_service:
mock_service.WSGIService.side_effect = fake_service
api.main()
mock_service.WSGIService.assert_has_calls([
mock.call('foo', use_ssl=False),
mock.call('bar', use_ssl=False),
mock.call('baz', use_ssl=False),
mock.call('osapi_compute', use_ssl=False),
mock.call('metadata', use_ssl=False),
])
launcher = mock_service.process_launcher.return_value
launcher.launch_service.assert_called_once_with(
fake_server, workers=123)
self.assertFalse(version_cache.called)
self.assertTrue(version_cache.called)
@mock.patch('sys.exit')
def test_fails_if_none_started(self, mock_exit, version_cache):
@ -84,7 +65,7 @@ class TestNovaAPI(test.NoDBTestCase):
@mock.patch('sys.exit')
def test_fails_if_all_failed(self, mock_exit, version_cache):
mock_exit.side_effect = test.TestingException
self.flags(enabled_apis=['foo', 'bar'])
self.flags(enabled_apis=['osapi_compute', 'metadata'])
with mock.patch.object(api, 'service') as mock_service:
mock_service.WSGIService.side_effect = exception.PasteAppNotFound(
name='foo', path='/')
@ -92,4 +73,4 @@ class TestNovaAPI(test.NoDBTestCase):
mock_exit.assert_called_once_with(1)
launcher = mock_service.process_launcher.return_value
self.assertFalse(launcher.wait.called)
self.assertFalse(version_cache.called)
self.assertTrue(version_cache.called)