Merge "Tests: Make fake_notifier per-instance"
This commit is contained in:
commit
d8d672a5b2
@ -125,10 +125,26 @@ _patch_mock_to_raise_for_invalid_assert_calls()
|
||||
class TestCase(testtools.TestCase):
|
||||
"""Test case base class for all unit tests."""
|
||||
|
||||
def _get_joined_notifier(self, *args, **kwargs):
|
||||
# We create a new fake notifier but we join the notifications with
|
||||
# the default notifier
|
||||
notifier = fake_notifier.get_fake_notifier(*args, **kwargs)
|
||||
notifier.notifications = self.notifier.notifications
|
||||
return notifier
|
||||
|
||||
def setUp(self):
|
||||
"""Run before each test method to initialize test environment."""
|
||||
super(TestCase, self).setUp()
|
||||
|
||||
# Create default notifier
|
||||
self.notifier = fake_notifier.get_fake_notifier()
|
||||
|
||||
# Mock rpc get notifier with fake notifier method that joins all
|
||||
# notifications with the default notifier
|
||||
p = mock.patch('cinder.rpc.get_notifier',
|
||||
side_effect=self._get_joined_notifier)
|
||||
p.start()
|
||||
|
||||
# Import cinder objects for test cases
|
||||
objects.register_all()
|
||||
|
||||
|
@ -23,7 +23,6 @@ from cinder.api.contrib import types_extra_specs
|
||||
from cinder import exception
|
||||
from cinder import test
|
||||
from cinder.tests.unit.api import fakes
|
||||
from cinder.tests.unit import fake_notifier
|
||||
import cinder.wsgi
|
||||
|
||||
|
||||
@ -71,8 +70,6 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
||||
self.controller = types_extra_specs.VolumeTypeExtraSpecsController()
|
||||
|
||||
"""to reset notifier drivers left over from other api/contrib tests"""
|
||||
fake_notifier.reset()
|
||||
self.addCleanup(fake_notifier.reset)
|
||||
|
||||
def test_index(self):
|
||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_get',
|
||||
@ -113,10 +110,10 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_delete',
|
||||
delete_volume_type_extra_specs)
|
||||
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
req = fakes.HTTPRequest.blank(self.api_path + '/key5')
|
||||
self.controller.delete(req, 1, 'key5')
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
||||
self.assertEqual(len(self.notifier.notifications), 1)
|
||||
|
||||
def test_delete_not_found(self):
|
||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_delete',
|
||||
@ -132,10 +129,10 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
||||
return_create_volume_type_extra_specs)
|
||||
body = {"extra_specs": {"key1": "value1"}}
|
||||
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
req = fakes.HTTPRequest.blank(self.api_path)
|
||||
res_dict = self.controller.create(req, 1, body)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
||||
self.assertEqual(len(self.notifier.notifications), 1)
|
||||
|
||||
self.assertEqual('value1', res_dict['extra_specs']['key1'])
|
||||
|
||||
@ -152,11 +149,11 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
||||
|
||||
body = {"extra_specs": {"other_alphanum.-_:": "value1"}}
|
||||
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.api_path)
|
||||
res_dict = self.controller.create(req, 1, body)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
||||
self.assertEqual(len(self.notifier.notifications), 1)
|
||||
self.assertEqual('value1',
|
||||
res_dict['extra_specs']['other_alphanum.-_:'])
|
||||
|
||||
@ -175,11 +172,11 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
||||
"other2_alphanum.-_:": "value2",
|
||||
"other3_alphanum.-_:": "value3"}}
|
||||
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.api_path)
|
||||
res_dict = self.controller.create(req, 1, body)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
||||
self.assertEqual(len(self.notifier.notifications), 1)
|
||||
self.assertEqual('value1',
|
||||
res_dict['extra_specs']['other_alphanum.-_:'])
|
||||
self.assertEqual('value2',
|
||||
@ -193,10 +190,10 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
||||
return_create_volume_type_extra_specs)
|
||||
body = {"key1": "value1"}
|
||||
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
req = fakes.HTTPRequest.blank(self.api_path + '/key1')
|
||||
res_dict = self.controller.update(req, 1, 'key1', body)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
||||
self.assertEqual(len(self.notifier.notifications), 1)
|
||||
|
||||
self.assertEqual('value1', res_dict['key1'])
|
||||
|
||||
|
@ -21,7 +21,6 @@ from cinder.api.contrib import types_manage
|
||||
from cinder import exception
|
||||
from cinder import test
|
||||
from cinder.tests.unit.api import fakes
|
||||
from cinder.tests.unit import fake_notifier
|
||||
from cinder.volume import volume_types
|
||||
|
||||
|
||||
@ -143,8 +142,6 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
self.flags(host='fake')
|
||||
self.controller = types_manage.VolumeTypesManageController()
|
||||
"""to reset notifier drivers left over from other api/contrib tests"""
|
||||
fake_notifier.reset()
|
||||
self.addCleanup(fake_notifier.reset)
|
||||
|
||||
def tearDown(self):
|
||||
super(VolumeTypesManageApiTest, self).tearDown()
|
||||
@ -156,9 +153,9 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
return_volume_types_destroy)
|
||||
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/1')
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
self.controller._delete(req, 1)
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
def test_volume_types_delete_not_found(self):
|
||||
self.stubs.Set(volume_types, 'get_volume_type',
|
||||
@ -166,11 +163,11 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
self.stubs.Set(volume_types, 'destroy',
|
||||
return_volume_types_destroy)
|
||||
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/777')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller._delete,
|
||||
req, '777')
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
def test_volume_types_with_volumes_destroy(self):
|
||||
self.stubs.Set(volume_types, 'get_volume_type',
|
||||
@ -178,9 +175,9 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
self.stubs.Set(volume_types, 'destroy',
|
||||
return_volume_types_with_volumes_destroy)
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/1')
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
self.controller._delete(req, 1)
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
def test_create(self):
|
||||
self.stubs.Set(volume_types, 'create',
|
||||
@ -192,10 +189,10 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
"extra_specs": {"key1": "value1"}}}
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types')
|
||||
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
res_dict = self.controller._create(req, body)
|
||||
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
self._check_test_results(res_dict, {
|
||||
'expected_name': 'vol_type_1', 'expected_desc': 'vol_type_desc_1'})
|
||||
|
||||
@ -277,9 +274,9 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/1')
|
||||
req.method = 'PUT'
|
||||
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
res_dict = self.controller._update(req, '1', body)
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
self._check_test_results(res_dict,
|
||||
{'expected_desc': 'vol_type_desc_1_1',
|
||||
'expected_name': 'vol_type_1_1'})
|
||||
@ -329,10 +326,10 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/777')
|
||||
req.method = 'PUT'
|
||||
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller._update, req, '777', body)
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
def test_update_db_fail(self):
|
||||
self.stubs.Set(volume_types, 'update',
|
||||
@ -345,10 +342,10 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/1')
|
||||
req.method = 'PUT'
|
||||
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
self.assertRaises(webob.exc.HTTPInternalServerError,
|
||||
self.controller._update, req, '1', body)
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
def test_update_no_name_no_description(self):
|
||||
body = {"volume_type": {}}
|
||||
@ -377,9 +374,9 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/999')
|
||||
req.method = 'PUT'
|
||||
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
res_dict = self.controller._update(req, '999', body)
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
self._check_test_results(res_dict,
|
||||
{'expected_name': 'vol_type_999_999',
|
||||
'expected_desc': 'vol_type_desc_999'})
|
||||
@ -394,9 +391,9 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/888')
|
||||
req.method = 'PUT'
|
||||
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
res_dict = self.controller._update(req, '888', body)
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
self._check_test_results(res_dict,
|
||||
{'expected_name': 'vol_type_888',
|
||||
'expected_desc': 'vol_type_desc_888_888'})
|
||||
@ -411,20 +408,20 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/666')
|
||||
req.method = 'PUT'
|
||||
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.controller._update, req, '666', body)
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
# delete
|
||||
fake_notifier.reset()
|
||||
self.notifier.reset()
|
||||
self.stubs.Set(volume_types, 'destroy',
|
||||
return_volume_types_destroy)
|
||||
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/1')
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
self.controller._delete(req, '1')
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
# update again
|
||||
self.stubs.Set(volume_types, 'update',
|
||||
@ -435,13 +432,13 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/types/666')
|
||||
req.method = 'PUT'
|
||||
|
||||
fake_notifier.reset()
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
|
||||
self.notifier.reset()
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
res_dict = self.controller._update(req, '666', body)
|
||||
self._check_test_results(res_dict,
|
||||
{'expected_name': 'vol_type_666',
|
||||
'expected_desc': 'vol_type_desc_666'})
|
||||
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
def _check_test_results(self, results, expected_results):
|
||||
self.assertEqual(1, len(results))
|
||||
|
@ -21,7 +21,6 @@ from cinder import context
|
||||
from cinder import db
|
||||
from cinder import test
|
||||
from cinder.tests.unit.api import fakes
|
||||
from cinder.tests.unit import fake_notifier
|
||||
|
||||
|
||||
def return_volume_type_encryption(context, volume_type_id):
|
||||
@ -55,8 +54,6 @@ class VolumeTypeEncryptionTest(test.TestCase):
|
||||
self.flags(host='fake')
|
||||
self.api_path = '/v2/fake/os-volume-types/1/encryption'
|
||||
"""to reset notifier drivers left over from other api/contrib tests"""
|
||||
fake_notifier.reset()
|
||||
self.addCleanup(fake_notifier.reset)
|
||||
|
||||
def _get_response(self, volume_type, admin=True,
|
||||
url='/v2/fake/types/%s/encryption',
|
||||
@ -165,7 +162,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
|
||||
'provider': provider,
|
||||
'volume_type_id': volume_type['id']}}
|
||||
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
res = self._get_response(volume_type)
|
||||
res_dict = json.loads(res.body)
|
||||
self.assertEqual(200, res.status_code)
|
||||
@ -180,7 +177,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
|
||||
req_headers='application/json')
|
||||
res_dict = json.loads(res.body)
|
||||
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
|
||||
self.assertEqual(len(self.notifier.notifications), 1)
|
||||
|
||||
# check response
|
||||
self.assertIn('encryption', res_dict)
|
||||
@ -235,7 +232,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
|
||||
req_headers='application/json')
|
||||
res_dict = json.loads(res.body)
|
||||
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
self.assertEqual(404, res.status_code)
|
||||
|
||||
expected = {
|
||||
|
@ -57,7 +57,6 @@ def stub_snapshot_get(self, context, snapshot_id):
|
||||
class VolumeApiTest(test.TestCase):
|
||||
def setUp(self):
|
||||
super(VolumeApiTest, self).setUp()
|
||||
self.addCleanup(fake_notifier.reset)
|
||||
self.ext_mgr = extensions.ExtensionManager()
|
||||
self.ext_mgr.extensions = {}
|
||||
fake_image.stub_out_image_service(self.stubs)
|
||||
@ -245,7 +244,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
body = {"volume": updates}
|
||||
req = fakes.HTTPRequest.blank('/v1/volumes/1')
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
res_dict = self.controller.update(req, '1', body)
|
||||
expected = {'volume': {
|
||||
'status': 'fakestatus',
|
||||
@ -265,7 +264,7 @@ class VolumeApiTest(test.TestCase):
|
||||
'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1),
|
||||
'size': 1}}
|
||||
self.assertEqual(res_dict, expected)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
||||
self.assertEqual(len(self.notifier.notifications), 2)
|
||||
|
||||
def test_volume_update_metadata(self):
|
||||
self.stubs.Set(db, 'volume_get', stubs.stub_volume_get_db)
|
||||
@ -276,7 +275,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
body = {"volume": updates}
|
||||
req = fakes.HTTPRequest.blank('/v1/volumes/1')
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
res_dict = self.controller.update(req, '1', body)
|
||||
expected = {'volume': {
|
||||
'status': 'fakestatus',
|
||||
@ -298,7 +297,7 @@ class VolumeApiTest(test.TestCase):
|
||||
'size': 1
|
||||
}}
|
||||
self.assertEqual(res_dict, expected)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
||||
self.assertEqual(len(self.notifier.notifications), 2)
|
||||
|
||||
def test_volume_update_with_admin_metadata(self):
|
||||
self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
|
||||
@ -323,7 +322,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
body = {"volume": updates}
|
||||
req = fakes.HTTPRequest.blank('/v1/volumes/1')
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
admin_ctx = context.RequestContext('admin', 'fakeproject', True)
|
||||
req.environ['cinder.context'] = admin_ctx
|
||||
res_dict = self.controller.update(req, '1', body)
|
||||
@ -352,7 +351,7 @@ class VolumeApiTest(test.TestCase):
|
||||
'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1),
|
||||
'size': 1}}
|
||||
self.assertEqual(res_dict, expected)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
||||
self.assertEqual(len(self.notifier.notifications), 2)
|
||||
|
||||
def test_update_empty_body(self):
|
||||
body = {}
|
||||
|
@ -62,7 +62,6 @@ def stub_snapshot_get(self, context, snapshot_id):
|
||||
class VolumeApiTest(test.TestCase):
|
||||
def setUp(self):
|
||||
super(VolumeApiTest, self).setUp()
|
||||
self.addCleanup(fake_notifier.reset)
|
||||
self.ext_mgr = extensions.ExtensionManager()
|
||||
self.ext_mgr.extensions = {}
|
||||
fake_image.stub_out_image_service(self.stubs)
|
||||
@ -477,7 +476,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
body = {"volume": updates}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes/1')
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
res_dict = self.controller.update(req, '1', body)
|
||||
expected = {
|
||||
'volume': {
|
||||
@ -512,7 +511,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
}
|
||||
self.assertEqual(res_dict, expected)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
||||
self.assertEqual(len(self.notifier.notifications), 2)
|
||||
|
||||
def test_volume_update_deprecation(self):
|
||||
self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
|
||||
@ -524,7 +523,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
body = {"volume": updates}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes/1')
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
res_dict = self.controller.update(req, '1', body)
|
||||
expected = {
|
||||
'volume': {
|
||||
@ -559,7 +558,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
}
|
||||
self.assertEqual(res_dict, expected)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
||||
self.assertEqual(len(self.notifier.notifications), 2)
|
||||
|
||||
def test_volume_update_deprecation_key_priority(self):
|
||||
"""Test current update keys have priority over deprecated keys."""
|
||||
@ -574,7 +573,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
body = {"volume": updates}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes/1')
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
res_dict = self.controller.update(req, '1', body)
|
||||
expected = {
|
||||
'volume': {
|
||||
@ -609,7 +608,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
}
|
||||
self.assertEqual(res_dict, expected)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
||||
self.assertEqual(len(self.notifier.notifications), 2)
|
||||
|
||||
def test_volume_update_metadata(self):
|
||||
self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
|
||||
@ -620,7 +619,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
body = {"volume": updates}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes/1')
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
res_dict = self.controller.update(req, '1', body)
|
||||
expected = {'volume': {
|
||||
'status': 'fakestatus',
|
||||
@ -655,7 +654,7 @@ class VolumeApiTest(test.TestCase):
|
||||
],
|
||||
}}
|
||||
self.assertEqual(res_dict, expected)
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
|
||||
self.assertEqual(len(self.notifier.notifications), 2)
|
||||
|
||||
def test_volume_update_with_admin_metadata(self):
|
||||
self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
|
||||
@ -680,7 +679,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
body = {"volume": updates}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes/1')
|
||||
self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
|
||||
self.assertEqual(len(self.notifier.notifications), 0)
|
||||
admin_ctx = context.RequestContext('admin', 'fake', True)
|
||||
req.environ['cinder.context'] = admin_ctx
|
||||
res_dict = self.controller.update(req, '1', body)
|
||||
@ -723,7 +722,7 @@ class VolumeApiTest(test.TestCase):
|
||||
],
|
||||
}}
|
||||
self.assertEqual(expected, res_dict)
|
||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
||||
self.assertEqual(2, len(self.notifier.notifications))
|
||||
|
||||
def test_update_empty_body(self):
|
||||
body = {}
|
||||
|
@ -20,12 +20,6 @@ import oslo_messaging as messaging
|
||||
|
||||
from cinder import rpc
|
||||
|
||||
NOTIFICATIONS = []
|
||||
|
||||
|
||||
def reset():
|
||||
del NOTIFICATIONS[:]
|
||||
|
||||
|
||||
FakeMessage = collections.namedtuple('Message',
|
||||
['publisher_id', 'priority',
|
||||
@ -64,9 +58,11 @@ class FakeNotifier(object):
|
||||
priority=priority,
|
||||
event_type=event_type,
|
||||
payload=payload)
|
||||
NOTIFICATIONS.append(msg)
|
||||
self.notifications.append(msg)
|
||||
|
||||
def reset(self):
|
||||
del self.notifications[:]
|
||||
|
||||
|
||||
def stub_notifier(stubs):
|
||||
stubs.Set(messaging, 'Notifier', FakeNotifier)
|
||||
|
@ -57,7 +57,6 @@ from cinder.tests.unit.api import fakes
|
||||
from cinder.tests.unit.brick import fake_lvm
|
||||
from cinder.tests.unit import conf_fixture
|
||||
from cinder.tests.unit import fake_driver
|
||||
from cinder.tests.unit import fake_notifier
|
||||
from cinder.tests.unit.image import fake as fake_image
|
||||
from cinder.tests.unit.keymgr import fake as fake_keymgr
|
||||
from cinder.tests.unit import utils as tests_utils
|
||||
@ -138,7 +137,6 @@ class BaseVolumeTestCase(test.TestCase):
|
||||
self.called = []
|
||||
|
||||
def _cleanup(self):
|
||||
fake_notifier.reset()
|
||||
try:
|
||||
shutil.rmtree(CONF.volumes_dir)
|
||||
except OSError:
|
||||
@ -428,8 +426,8 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
|
||||
volume_id = volume['id']
|
||||
self.assertIsNone(volume['encryption_key_id'])
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
self.assertEqual(0, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
self.assertRaises(exception.DriverNotInitialized,
|
||||
self.volume.create_volume,
|
||||
self.context, volume_id)
|
||||
@ -506,8 +504,8 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
|
||||
volume_id = volume['id']
|
||||
self.assertIsNone(volume['encryption_key_id'])
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
self.assertEqual(0, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
self.assertRaises(exception.DriverNotInitialized,
|
||||
self.volume.delete_volume,
|
||||
self.context, volume_id)
|
||||
@ -538,12 +536,12 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
**self.volume_params)
|
||||
volume_id = volume['id']
|
||||
self.assertIsNone(volume['encryption_key_id'])
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
self.assertEqual(0, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
self.volume.create_volume(self.context, volume_id)
|
||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
msg = fake_notifier.NOTIFICATIONS[0]
|
||||
self.assertEqual(2, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
msg = self.notifier.notifications[0]
|
||||
self.assertEqual('volume.create.start', msg['event_type'])
|
||||
expected = {
|
||||
'status': 'creating',
|
||||
@ -564,7 +562,7 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
'metadata': [],
|
||||
}
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[1]
|
||||
msg = self.notifier.notifications[1]
|
||||
self.assertEqual('volume.create.end', msg['event_type'])
|
||||
expected['status'] = 'available'
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
@ -575,12 +573,12 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
vol = db.volume_get(context.get_admin_context(read_deleted='yes'),
|
||||
volume_id)
|
||||
self.assertEqual('deleted', vol['status'])
|
||||
self.assertEqual(4, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
msg = fake_notifier.NOTIFICATIONS[2]
|
||||
self.assertEqual(4, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
msg = self.notifier.notifications[2]
|
||||
self.assertEqual('volume.delete.start', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[3]
|
||||
msg = self.notifier.notifications[3]
|
||||
self.assertEqual('volume.delete.end', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
self.assertRaises(exception.NotFound,
|
||||
@ -2824,22 +2822,22 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
self.context,
|
||||
availability_zone=CONF.storage_availability_zone,
|
||||
**self.volume_params)
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
self.assertEqual(0, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
self.volume.create_volume(self.context, volume['id'])
|
||||
msg = fake_notifier.NOTIFICATIONS[0]
|
||||
msg = self.notifier.notifications[0]
|
||||
self.assertEqual('volume.create.start', msg['event_type'])
|
||||
self.assertEqual('creating', msg['payload']['status'])
|
||||
self.assertEqual('INFO', msg['priority'])
|
||||
msg = fake_notifier.NOTIFICATIONS[1]
|
||||
msg = self.notifier.notifications[1]
|
||||
self.assertEqual('volume.create.end', msg['event_type'])
|
||||
self.assertEqual('available', msg['payload']['status'])
|
||||
self.assertEqual('INFO', msg['priority'])
|
||||
if len(fake_notifier.NOTIFICATIONS) > 2:
|
||||
if len(self.notifier.notifications) > 2:
|
||||
# Cause an assert to print the unexpected item
|
||||
self.assertFalse(fake_notifier.NOTIFICATIONS[2])
|
||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
self.assertFalse(self.notifier.notifications[2])
|
||||
self.assertEqual(2, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
|
||||
snapshot_id = self._create_snapshot(volume['id'],
|
||||
size=volume['size'])['id']
|
||||
@ -2848,7 +2846,7 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
self.assertEqual(snapshot_id,
|
||||
db.snapshot_get(context.get_admin_context(),
|
||||
snapshot_id).id)
|
||||
msg = fake_notifier.NOTIFICATIONS[2]
|
||||
msg = self.notifier.notifications[2]
|
||||
self.assertEqual('snapshot.create.start', msg['event_type'])
|
||||
expected = {
|
||||
'created_at': 'DONTCARE',
|
||||
@ -2864,33 +2862,33 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
'metadata': '',
|
||||
}
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[3]
|
||||
msg = self.notifier.notifications[3]
|
||||
self.assertEqual('snapshot.create.end', msg['event_type'])
|
||||
expected['status'] = 'available'
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
|
||||
if len(fake_notifier.NOTIFICATIONS) > 4:
|
||||
if len(self.notifier.notifications) > 4:
|
||||
# Cause an assert to print the unexpected item
|
||||
self.assertFalse(fake_notifier.NOTIFICATIONS[4])
|
||||
self.assertFalse(self.notifier.notifications[4])
|
||||
|
||||
self.assertEqual(4, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
self.assertEqual(4, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
|
||||
self.volume.delete_snapshot(self.context, snapshot_obj)
|
||||
msg = fake_notifier.NOTIFICATIONS[4]
|
||||
msg = self.notifier.notifications[4]
|
||||
self.assertEqual('snapshot.delete.start', msg['event_type'])
|
||||
expected['status'] = 'available'
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[5]
|
||||
msg = self.notifier.notifications[5]
|
||||
self.assertEqual('snapshot.delete.end', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
|
||||
if len(fake_notifier.NOTIFICATIONS) > 6:
|
||||
if len(self.notifier.notifications) > 6:
|
||||
# Cause an assert to print the unexpected item
|
||||
self.assertFalse(fake_notifier.NOTIFICATIONS[6])
|
||||
self.assertFalse(self.notifier.notifications[6])
|
||||
|
||||
self.assertEqual(6, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
self.assertEqual(6, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
|
||||
snap = db.snapshot_get(context.get_admin_context(read_deleted='yes'),
|
||||
snapshot_id)
|
||||
@ -4540,12 +4538,12 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
availability_zone=CONF.storage_availability_zone,
|
||||
volume_type='type1,type2')
|
||||
group_id = group['id']
|
||||
self.assertEqual(0, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
self.assertEqual(0, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
self.volume.create_consistencygroup(self.context, group_id)
|
||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
msg = fake_notifier.NOTIFICATIONS[0]
|
||||
self.assertEqual(2, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
msg = self.notifier.notifications[0]
|
||||
self.assertEqual('consistencygroup.create.start', msg['event_type'])
|
||||
expected = {
|
||||
'status': 'available',
|
||||
@ -4557,7 +4555,7 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
'consistencygroup_id': group_id
|
||||
}
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[1]
|
||||
msg = self.notifier.notifications[1]
|
||||
self.assertEqual(msg['event_type'], 'consistencygroup.create.end')
|
||||
expected['status'] = 'available'
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
@ -4571,12 +4569,12 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
context.get_admin_context(read_deleted='yes'),
|
||||
group_id)
|
||||
self.assertEqual('deleted', cg['status'])
|
||||
self.assertEqual(4, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
msg = fake_notifier.NOTIFICATIONS[2]
|
||||
self.assertEqual(4, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
msg = self.notifier.notifications[2]
|
||||
self.assertEqual('consistencygroup.delete.start', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[3]
|
||||
msg = self.notifier.notifications[3]
|
||||
self.assertEqual('consistencygroup.delete.end', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
self.assertRaises(exception.NotFound,
|
||||
@ -4639,12 +4637,12 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
'consistencygroup_id': group_id
|
||||
}
|
||||
self.assertEqual('available', cg['status'])
|
||||
self.assertEqual(10, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
msg = fake_notifier.NOTIFICATIONS[6]
|
||||
self.assertEqual(10, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
msg = self.notifier.notifications[6]
|
||||
self.assertEqual('consistencygroup.update.start', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[8]
|
||||
msg = self.notifier.notifications[8]
|
||||
self.assertEqual('consistencygroup.update.end', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
cgvolumes = db.volume_get_all_by_group(self.context, group_id)
|
||||
@ -4739,30 +4737,30 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
}
|
||||
self.assertEqual('available', cg2['status'])
|
||||
|
||||
msg = fake_notifier.NOTIFICATIONS[2]
|
||||
msg = self.notifier.notifications[2]
|
||||
self.assertEqual('consistencygroup.create.start', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[4]
|
||||
msg = self.notifier.notifications[4]
|
||||
self.assertEqual('consistencygroup.create.end', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
|
||||
if len(fake_notifier.NOTIFICATIONS) > 6:
|
||||
self.assertFalse(fake_notifier.NOTIFICATIONS[6])
|
||||
self.assertEqual(6, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
if len(self.notifier.notifications) > 6:
|
||||
self.assertFalse(self.notifier.notifications[6])
|
||||
self.assertEqual(6, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
|
||||
self.volume.delete_consistencygroup(self.context, group2_id)
|
||||
|
||||
if len(fake_notifier.NOTIFICATIONS) > 10:
|
||||
self.assertFalse(fake_notifier.NOTIFICATIONS[10])
|
||||
self.assertEqual(10, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
if len(self.notifier.notifications) > 10:
|
||||
self.assertFalse(self.notifier.notifications[10])
|
||||
self.assertEqual(10, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
|
||||
msg = fake_notifier.NOTIFICATIONS[6]
|
||||
msg = self.notifier.notifications[6]
|
||||
self.assertEqual('consistencygroup.delete.start', msg['event_type'])
|
||||
expected['status'] = 'available'
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[8]
|
||||
msg = self.notifier.notifications[8]
|
||||
self.assertEqual('consistencygroup.delete.end', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
|
||||
@ -4880,10 +4878,10 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
consistencygroup_id=group_id)
|
||||
cgsnapshot_id = cgsnapshot['id']
|
||||
|
||||
if len(fake_notifier.NOTIFICATIONS) > 2:
|
||||
self.assertFalse(fake_notifier.NOTIFICATIONS[2])
|
||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
if len(self.notifier.notifications) > 2:
|
||||
self.assertFalse(self.notifier.notifications[2])
|
||||
self.assertEqual(2, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
|
||||
cgsnapshot_returns = self._create_cgsnapshot(group_id, volume_id)
|
||||
cgsnapshot_id = cgsnapshot_returns[0]['id']
|
||||
@ -4892,10 +4890,10 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
db.cgsnapshot_get(context.get_admin_context(),
|
||||
cgsnapshot_id).id)
|
||||
|
||||
if len(fake_notifier.NOTIFICATIONS) > 6:
|
||||
self.assertFalse(fake_notifier.NOTIFICATIONS[6])
|
||||
if len(self.notifier.notifications) > 6:
|
||||
self.assertFalse(self.notifier.notifications[6])
|
||||
|
||||
msg = fake_notifier.NOTIFICATIONS[2]
|
||||
msg = self.notifier.notifications[2]
|
||||
self.assertEqual('cgsnapshot.create.start', msg['event_type'])
|
||||
expected = {
|
||||
'created_at': 'DONTCARE',
|
||||
@ -4907,32 +4905,32 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
'consistencygroup_id': group_id
|
||||
}
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[3]
|
||||
msg = self.notifier.notifications[3]
|
||||
self.assertEqual('snapshot.create.start', msg['event_type'])
|
||||
msg = fake_notifier.NOTIFICATIONS[4]
|
||||
msg = self.notifier.notifications[4]
|
||||
self.assertEqual('cgsnapshot.create.end', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[5]
|
||||
msg = self.notifier.notifications[5]
|
||||
self.assertEqual('snapshot.create.end', msg['event_type'])
|
||||
|
||||
self.assertEqual(6, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
self.assertEqual(6, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
|
||||
self.volume.delete_cgsnapshot(self.context, cgsnapshot_id)
|
||||
|
||||
if len(fake_notifier.NOTIFICATIONS) > 10:
|
||||
self.assertFalse(fake_notifier.NOTIFICATIONS[10])
|
||||
if len(self.notifier.notifications) > 10:
|
||||
self.assertFalse(self.notifier.notifications[10])
|
||||
|
||||
msg = fake_notifier.NOTIFICATIONS[6]
|
||||
msg = self.notifier.notifications[6]
|
||||
self.assertEqual('cgsnapshot.delete.start', msg['event_type'])
|
||||
expected['status'] = 'available'
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = fake_notifier.NOTIFICATIONS[8]
|
||||
msg = self.notifier.notifications[8]
|
||||
self.assertEqual('cgsnapshot.delete.end', msg['event_type'])
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
|
||||
self.assertEqual(10, len(fake_notifier.NOTIFICATIONS),
|
||||
fake_notifier.NOTIFICATIONS)
|
||||
self.assertEqual(10, len(self.notifier.notifications),
|
||||
self.notifier.notifications)
|
||||
|
||||
cgsnap = db.cgsnapshot_get(
|
||||
context.get_admin_context(read_deleted='yes'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user