From 84ad8f0d8c313ebdb4ab3a64ff408b438bb3c3c4 Mon Sep 17 00:00:00 2001 From: Sergey Skripnick Date: Fri, 16 Aug 2013 15:33:28 +0300 Subject: [PATCH] Improve db_sqlalchemy_api test coverage Added new tests and improved coverage for methods: instance_group_* migration_* task_log_* agent_build_* Blueprint: db-api-tests Change-Id: Idbf704b3e6aa8df1d4f927e67d108e6a8489b9d2 --- nova/tests/db/test_db_api.py | 38 ++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/nova/tests/db/test_db_api.py b/nova/tests/db/test_db_api.py index 9c311373d142..be605feb3ee9 100644 --- a/nova/tests/db/test_db_api.py +++ b/nova/tests/db/test_db_api.py @@ -788,6 +788,10 @@ class MigrationTestCase(test.TestCase): db.migration_update(self.ctxt, migration['id'], {"status": "CONFIRMED"}) + def test_migration_update_not_found(self): + self.assertRaises(exception.MigrationNotFound, + db.migration_update, self.ctxt, 42, {}) + class ModelsObjectComparatorMixin(object): def _dict_from_object(self, obj, ignored_keys): @@ -4075,10 +4079,14 @@ class TaskLogTestCase(test.TestCase): result = db.task_log_get_all(self.context, self.task_name, self.begin, self.end, host=self.host) self.assertEqual(len(result), 1) + result = db.task_log_get_all(self.context, self.task_name, self.begin, + self.end, host=self.host, state='') + self.assertEqual(len(result), 0) def test_task_log_begin_task(self): db.task_log_begin_task(self.context, 'fake', self.begin, - self.end, self.host, message=self.message) + self.end, self.host, task_items=42, + message=self.message) result = db.task_log_get(self.context, 'fake', self.begin, self.end, self.host) self.assertEqual(result['task_name'], 'fake') @@ -4098,6 +4106,12 @@ class TaskLogTestCase(test.TestCase): self.end, self.host) self.assertEqual(result['errors'], 1) + def test_task_log_end_task_task_not_running(self): + self.assertRaises(exception.TaskNotRunning, + db.task_log_end_task, self.context, 'nonexistent', + self.begin, self.end, self.host, 42, + message=self.message) + class BlockDeviceMappingTestCase(test.TestCase): def setUp(self): @@ -4331,6 +4345,13 @@ class AgentBuildTestCase(test.TestCase, ModelsObjectComparatorMixin): self.assertRaises(exception.AgentBuildExists, db.agent_build_create, self.ctxt, values) + def test_agent_build_get_all_by_hypervisor(self): + values = {'hypervisor': 'kvm', 'os': 'FreeBSD', + 'architecture': 'x86_64'} + created = db.agent_build_create(self.ctxt, values) + actual = db.agent_build_get_all(self.ctxt, hypervisor='kvm') + self._assertEqualListsOfObjects([created], actual) + class VirtualInterfaceTestCase(test.TestCase, ModelsObjectComparatorMixin): def setUp(self): @@ -6219,7 +6240,20 @@ class InstanceGroupDBApiTestCase(test.TestCase, ModelsObjectComparatorMixin): result = self._create_instance_group(self.context, values) db.instance_group_delete(self.context, result['uuid']) self.assertRaises(exception.InstanceGroupNotFound, - db.instance_group_get, self.context, result['uuid']) + db.instance_group_delete, self.context, + result['uuid']) + + def test_instance_group_get_nonexistent(self): + self.assertRaises(exception.InstanceGroupNotFound, + db.instance_group_get, + self.context, + 'nonexistent') + + def test_instance_group_delete_nonexistent(self): + self.assertRaises(exception.InstanceGroupNotFound, + db.instance_group_delete, + self.context, + 'nonexistent') def test_instance_group_get_all(self): groups = db.instance_group_get_all(self.context)