diff options
author | Matt Riedemann <mriedem.os@gmail.com> | 2018-06-26 16:06:20 -0400 |
---|---|---|
committer | Matt Riedemann <mriedem.os@gmail.com> | 2018-06-27 10:09:55 -0400 |
commit | 1160921c2d053ce33279ca4ec1f00572271e7c95 (patch) | |
tree | 1449af2ee44028488bbbbb38183c987e532a59ea /nova/tests/unit/objects/test_instance_group.py | |
parent | 53f14a7edb2aabdeb4a8f41213f30bfcb0c0bd9e (diff) | |
download | nova-1160921c2d053ce33279ca4ec1f00572271e7c95.tar.gz |
Remove compatibility code for instance groups
The /345_require_online_migration_completion cell database
migration added in Ocata prevents anyone from upgrading
the cell database schema until they have performed the online
instance group data migrations via the
"nova-manage db online_data_migrations" command.
This means we can remove the compatibility code in the InstanceGroup
object which performs a lookup routine in the API database and
if not found it falls back to the cell database, which at this
point should be empty, therefore making that dead code now.
The test_get_by_name and test_get_by_hint tests are moved
from _TestInstanceGroupListObject to _TestInstanceGroupObject
since they don't have anything to do with InstanceGroupList.
A follow up change will remove the now unused main DB API
methods for instance groups.
Change-Id: Ifbd53b13fa0fef62e0329283b73d587f367e46c2
Diffstat (limited to 'nova/tests/unit/objects/test_instance_group.py')
-rw-r--r-- | nova/tests/unit/objects/test_instance_group.py | 130 |
1 files changed, 55 insertions, 75 deletions
diff --git a/nova/tests/unit/objects/test_instance_group.py b/nova/tests/unit/objects/test_instance_group.py index 48aa992a4e..da42ee02d1 100644 --- a/nova/tests/unit/objects/test_instance_group.py +++ b/nova/tests/unit/objects/test_instance_group.py @@ -37,22 +37,19 @@ _INST_GROUP_DB = { 'name': 'fake_name', 'policies': ['policy1', 'policy2'], 'members': ['instance_id1', 'instance_id2'], - 'deleted': False, 'created_at': _TS_NOW, - 'updated_at': _TS_NOW, - 'deleted_at': None, + 'updated_at': _TS_NOW } class _TestInstanceGroupObject(object): - @mock.patch('nova.db.instance_group_get', return_value=_INST_GROUP_DB) @mock.patch('nova.objects.InstanceGroup._get_from_db_by_uuid', - side_effect=exception.InstanceGroupNotFound(group_uuid=_DB_UUID)) - def test_get_by_uuid_main(self, mock_api_get, mock_db_get): + return_value=_INST_GROUP_DB) + def test_get_by_uuid(self, mock_api_get): obj = objects.InstanceGroup.get_by_uuid(self.context, _DB_UUID) - mock_db_get.assert_called_once_with(self.context, _DB_UUID) + mock_api_get.assert_called_once_with(self.context, _DB_UUID) self.assertEqual(_INST_GROUP_DB['members'], obj.members) self.assertEqual(_INST_GROUP_DB['policies'], obj.policies) self.assertEqual(_DB_UUID, obj.uuid) @@ -60,18 +57,15 @@ class _TestInstanceGroupObject(object): self.assertEqual(_INST_GROUP_DB['user_id'], obj.user_id) self.assertEqual(_INST_GROUP_DB['name'], obj.name) - @mock.patch('nova.db.instance_group_get_by_instance', + @mock.patch('nova.objects.InstanceGroup._get_from_db_by_instance', return_value=_INST_GROUP_DB) - @mock.patch('nova.objects.InstanceGroup._get_from_db_by_instance') - def test_get_by_instance_uuid_main(self, mock_api_get, mock_db_get): - error = exception.InstanceGroupNotFound(group_uuid='') - mock_api_get.side_effect = error + def test_get_by_instance_uuid(self, mock_api_get): objects.InstanceGroup.get_by_instance_uuid( self.context, mock.sentinel.instance_uuid) - mock_db_get.assert_called_once_with( + mock_api_get.assert_called_once_with( self.context, mock.sentinel.instance_uuid) - @mock.patch('nova.db.instance_group_get') + @mock.patch('nova.objects.InstanceGroup._get_from_db_by_uuid') def test_refresh(self, mock_db_get): changed_group = copy.deepcopy(_INST_GROUP_DB) changed_group['name'] = 'new_name' @@ -84,23 +78,27 @@ class _TestInstanceGroupObject(object): self.assertEqual(set([]), obj.obj_what_changed()) @mock.patch('nova.compute.utils.notify_about_server_group_update') - @mock.patch('nova.db.instance_group_update') - @mock.patch('nova.db.instance_group_get') - def test_save_main(self, mock_db_get, mock_db_update, mock_notify): + @mock.patch('nova.objects.InstanceGroup._get_from_db_by_uuid') + @mock.patch('nova.objects.instance_group._instance_group_policies_add') + @mock.patch('nova.objects.instance_group._instance_group_members_add') + def test_save(self, mock_members_add, mock_policies_add, mock_db_get, + mock_notify): changed_group = copy.deepcopy(_INST_GROUP_DB) changed_group['name'] = 'new_name' - mock_db_get.side_effect = [_INST_GROUP_DB, changed_group] - obj = objects.InstanceGroup.get_by_uuid(self.context, - _DB_UUID) + db_group = copy.deepcopy(_INST_GROUP_DB) + mock_db_get.return_value = db_group + obj = objects.InstanceGroup(self.context, **_INST_GROUP_DB) self.assertEqual(obj.name, 'fake_name') + obj.obj_reset_changes() obj.name = 'new_name' obj.policies = ['policy1'] # Remove policy 2 obj.members = ['instance_id1'] # Remove member 2 obj.save() - mock_db_update.assert_called_once_with(self.context, _DB_UUID, - {'name': 'new_name', - 'members': ['instance_id1'], - 'policies': ['policy1']}) + self.assertEqual(set([]), obj.obj_what_changed()) + mock_policies_add.assert_called_once_with( + self.context, mock_db_get.return_value, ['policy1']) + mock_members_add.assert_called_once_with( + self.context, mock_db_get.return_value, ['instance_id1']) mock_notify.assert_called_once_with(self.context, "update", {'name': 'new_name', 'members': ['instance_id1'], @@ -108,12 +106,11 @@ class _TestInstanceGroupObject(object): 'server_group_id': _DB_UUID}) @mock.patch('nova.compute.utils.notify_about_server_group_update') - @mock.patch('nova.db.instance_group_update') - @mock.patch('nova.db.instance_group_get') - def test_save_without_hosts_main(self, mock_db_get, mock_db_update, - mock_notify): - mock_db_get.side_effect = [_INST_GROUP_DB, _INST_GROUP_DB] - obj = objects.InstanceGroup.get_by_uuid(self.context, _DB_UUID) + @mock.patch('nova.objects.InstanceGroup._get_from_db_by_uuid') + def test_save_without_hosts(self, mock_db_get, mock_notify): + mock_db_get.return_value = _INST_GROUP_DB + obj = objects.InstanceGroup(self.context, **_INST_GROUP_DB) + obj.obj_reset_changes() obj.hosts = ['fake-host1'] self.assertRaises(exception.InstanceGroupSaveException, obj.save) @@ -121,7 +118,6 @@ class _TestInstanceGroupObject(object): obj.obj_reset_changes(['hosts']) obj.save() # since hosts was the only update, there is no actual call - self.assertFalse(mock_db_update.called) self.assertFalse(mock_notify.called) @mock.patch('nova.compute.utils.notify_about_server_group_action') @@ -138,8 +134,6 @@ class _TestInstanceGroupObject(object): obj.policies = _INST_GROUP_DB['policies'] obj.updated_at = _TS_NOW obj.created_at = _TS_NOW - obj.deleted_at = None - obj.deleted = False obj.create() mock_db_create.assert_called_once_with( self.context, @@ -149,8 +143,6 @@ class _TestInstanceGroupObject(object): 'project_id': _INST_GROUP_DB['project_id'], 'created_at': _TS_NOW, 'updated_at': _TS_NOW, - 'deleted_at': None, - 'deleted': False, }, members=_INST_GROUP_DB['members'], policies=_INST_GROUP_DB['policies']) @@ -162,8 +154,6 @@ class _TestInstanceGroupObject(object): 'project_id': _INST_GROUP_DB['project_id'], 'created_at': _TS_NOW, 'updated_at': _TS_NOW, - 'deleted_at': None, - 'deleted': False, 'members': _INST_GROUP_DB['members'], 'policies': _INST_GROUP_DB['policies'], 'server_group_id': _DB_UUID}) @@ -176,8 +166,6 @@ class _TestInstanceGroupObject(object): group.project_id == _INST_GROUP_DB['project_id'] and group.created_at == _TS_NOW and group.updated_at == _TS_NOW and - group.deleted_at is None and - group.deleted is False and group.members == _INST_GROUP_DB['members'] and group.policies == _INST_GROUP_DB['policies'] and group.id == 1) @@ -296,6 +284,26 @@ class _TestInstanceGroupObject(object): obj = objects.InstanceGroup(self.context) self.assertRaises(exception.ObjectActionError, getattr, obj, 'members') + @mock.patch('nova.objects.InstanceGroup._get_from_db_by_name') + def test_get_by_name(self, mock_api_get): + db_group = copy.deepcopy(_INST_GROUP_DB) + mock_api_get.side_effect = [ + db_group, exception.InstanceGroupNotFound(group_uuid='unknown')] + ig = objects.InstanceGroup.get_by_name(self.context, 'fake_name') + mock_api_get.assert_called_once_with(self.context, 'fake_name') + self.assertEqual('fake_name', ig.name) + self.assertRaises(exception.InstanceGroupNotFound, + objects.InstanceGroup.get_by_name, + self.context, 'unknown') + + @mock.patch('nova.objects.InstanceGroup.get_by_uuid') + @mock.patch('nova.objects.InstanceGroup.get_by_name') + def test_get_by_hint(self, mock_name, mock_uuid): + objects.InstanceGroup.get_by_hint(self.context, _DB_UUID) + mock_uuid.assert_called_once_with(self.context, _DB_UUID) + objects.InstanceGroup.get_by_hint(self.context, 'name') + mock_name.assert_called_once_with(self.context, 'name') + class TestInstanceGroupObject(test_objects._LocalTest, _TestInstanceGroupObject): @@ -307,7 +315,7 @@ class TestRemoteInstanceGroupObject(test_objects._RemoteTest, pass -def _mock_db_list_get(*args): +def _mock_db_list_get(*args, **kwargs): instances = [(uuids.f1, 'f1', 'p1'), (uuids.f2, 'f2', 'p1'), (uuids.f3, 'f3', 'p2'), @@ -324,48 +332,20 @@ def _mock_db_list_get(*args): class _TestInstanceGroupListObject(object): - @mock.patch('nova.db.instance_group_get_all') @mock.patch('nova.objects.InstanceGroupList._get_from_db') - def test_list_all_main(self, mock_api_get, mock_db_get): - mock_api_get.return_value = [] - mock_db_get.side_effect = _mock_db_list_get + def test_list_all(self, mock_api_get): + mock_api_get.side_effect = _mock_db_list_get inst_list = objects.InstanceGroupList.get_all(self.context) self.assertEqual(4, len(inst_list.objects)) - mock_db_get.assert_called_once_with(self.context) + mock_api_get.assert_called_once_with(self.context) - @mock.patch('nova.db.instance_group_get_all_by_project_id') @mock.patch('nova.objects.InstanceGroupList._get_from_db') - def test_list_by_project_id_main(self, mock_api_get, mock_db_get): - mock_api_get.return_value = [] - mock_db_get.side_effect = _mock_db_list_get + def test_list_by_project_id(self, mock_api_get): + mock_api_get.side_effect = _mock_db_list_get objects.InstanceGroupList.get_by_project_id( self.context, mock.sentinel.project_id) - mock_db_get.assert_called_once_with( - self.context, mock.sentinel.project_id) - - @mock.patch('nova.db.instance_group_get_all_by_project_id') - @mock.patch('nova.objects.InstanceGroup._get_from_db_by_name') - def test_get_by_name_main(self, mock_api_get, mock_db_get): - error = exception.InstanceGroupNotFound(group_uuid='f1') - mock_api_get.side_effect = error - mock_db_get.side_effect = _mock_db_list_get - # Need the project_id value set, otherwise we'd use mock.sentinel - mock_ctx = mock.MagicMock() - mock_ctx.project_id = 'fake_project' - ig = objects.InstanceGroup.get_by_name(mock_ctx, 'f1') - mock_db_get.assert_called_once_with(mock_ctx, 'fake_project') - self.assertEqual('f1', ig.name) - self.assertRaises(exception.InstanceGroupNotFound, - objects.InstanceGroup.get_by_name, - mock_ctx, 'unknown') - - @mock.patch('nova.objects.InstanceGroup.get_by_uuid') - @mock.patch('nova.objects.InstanceGroup.get_by_name') - def test_get_by_hint(self, mock_name, mock_uuid): - objects.InstanceGroup.get_by_hint(self.context, _DB_UUID) - mock_uuid.assert_called_once_with(self.context, _DB_UUID) - objects.InstanceGroup.get_by_hint(self.context, 'name') - mock_name.assert_called_once_with(self.context, 'name') + mock_api_get.assert_called_once_with( + self.context, project_id=mock.sentinel.project_id) class TestInstanceGroupListObject(test_objects._LocalTest, |