From 34e649e065099626d0b1b8ccc1f0e9da1b64fa1d Mon Sep 17 00:00:00 2001 From: Yuriy Zveryanskyy Date: Tue, 4 Jun 2013 15:56:54 +0300 Subject: [PATCH] Add missing tests for iscsi_* methods There was no tests in test_db_api for iscsi_* methods. Bug 1187367 found. blueprint db-api-tests Change-Id: Ia554e6030307a0c4f0510ab74fe0881ee160f743 --- cinder/tests/test_db_api.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cinder/tests/test_db_api.py b/cinder/tests/test_db_api.py index c7580dffa..edd1ef9b5 100644 --- a/cinder/tests/test_db_api.py +++ b/cinder/tests/test_db_api.py @@ -539,3 +539,32 @@ class DBAPIQuotaTestCase(BaseTest): 'res2': {'in_use': 2, 'reserved': 2}} self.assertEqual(expected, db.quota_usage_get_all_by_project( self.ctxt, 'p1')) + + +class DBAPIIscsiTargetTestCase(BaseTest): + + """Unit tests for cinder.db.api.iscsi_target_*.""" + + def _get_base_values(self): + return {'target_num': 10, 'host': 'fake_host'} + + def test_iscsi_target_create_safe(self): + target = db.iscsi_target_create_safe(self.ctxt, + self._get_base_values()) + self.assertTrue(target['id']) + self.assertEqual(target['host'], 'fake_host') + self.assertEqual(target['target_num'], 10) + + def test_iscsi_target_count_by_host(self): + for i in range(3): + values = self._get_base_values() + values['target_num'] += i + db.iscsi_target_create_safe(self.ctxt, values) + self.assertEqual(db.iscsi_target_count_by_host(self.ctxt, 'fake_host'), + 3) + + @test.testtools.skip("bug 1187367") + def test_integrity_error(self): + db.iscsi_target_create_safe(self.ctxt, self._get_base_values()) + self.assertFalse(db.iscsi_target_create_safe(self.ctxt, + self._get_base_values())) -- 2.45.2