[Kimchi-devel] [PATCH v3 5/5] test_model: test creating iSCSI storage pool

Zhou Zheng Sheng zhshzhou at linux.vnet.ibm.com
Fri Dec 27 10:20:09 UTC 2013


This patch adds iSCSI storage pool test to test_model.test_storagepool.
It firstly checks if there exists an iSCSI target named
"iqn.2013-12.localhost.kimchiUnitTest" on local host. If not, skip the
test; if yes, continue to run the test already defined in test_storagepool.

v2 -> v3
  Do not create dir for the pool, pool.build() called by
  storagepools_create() does this automatically.

Signed-off-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
---
 tests/test_model.py | 89 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 50 insertions(+), 39 deletions(-)

diff --git a/tests/test_model.py b/tests/test_model.py
index e19364f..224a983 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -38,6 +38,7 @@ import utils
 from kimchi import netinfo
 from kimchi.exception import InvalidOperation, InvalidParameter
 from kimchi.exception import NotFoundError, OperationFailed
+from kimchi.iscsi import IscsiTarget
 
 
 class ModelTests(unittest.TestCase):
@@ -115,48 +116,58 @@ class ModelTests(unittest.TestCase):
     def test_storagepool(self):
         inst = kimchi.model.Model('qemu:///system', self.tmp_store)
 
-        with utils.RollbackContext() as rollback:
-            path = '/tmp/kimchi-images'
-            name = 'test-pool'
-            if not os.path.exists(path):
-                os.mkdir(path)
+        poolDefs = [
+            {'type': 'dir',
+             'name': 'unitTestDirPool',
+             'path': '/tmp/kimchi-images'},
+            {'type': 'iscsi',
+             'name': 'unitTestISCSIPool',
+             'source': {'host': '127.0.0.1',
+                        'target': 'iqn.2013-12.localhost.kimchiUnitTest'}}]
 
-            pools = inst.storagepools_get_list()
-            num = len(pools) + 1
+        for poolDef in poolDefs:
+            with utils.RollbackContext() as rollback:
+                path = poolDef.get('path')
+                name = poolDef['name']
+
+                if poolDef['type'] == 'iscsi':
+                    if not IscsiTarget(**poolDef['source']).validate():
+                        continue
+
+                pools = inst.storagepools_get_list()
+                num = len(pools) + 1
+
+                inst.storagepools_create(poolDef)
+                rollback.prependDefer(inst.storagepool_delete, name)
+
+                pools = inst.storagepools_get_list()
+                self.assertEquals(num, len(pools))
+
+                poolinfo = inst.storagepool_lookup(name)
+                if path is not None:
+                    self.assertEquals(path, poolinfo['path'])
+                self.assertEquals('inactive', poolinfo['state'])
+                if poolinfo['type'] == 'dir':
+                    self.assertEquals(True, poolinfo['autostart'])
+                else:
+                    self.assertEquals(False, poolinfo['autostart'])
+
+                inst.storagepool_activate(name)
+                rollback.prependDefer(inst.storagepool_deactivate, name)
 
-            args = {'name': name,
-                    'path': path,
-                    'type': 'dir'}
-            inst.storagepools_create(args)
-            rollback.prependDefer(inst.storagepool_delete, name)
-
-            pools = inst.storagepools_get_list()
-            self.assertEquals(num, len(pools))
-
-            poolinfo = inst.storagepool_lookup(name)
-            self.assertEquals(path, poolinfo['path'])
-            self.assertEquals('inactive', poolinfo['state'])
-            if poolinfo['type'] == 'dir':
-                self.assertEquals(True, poolinfo['autostart'])
-            else:
-                self.assertEquals(False, poolinfo['autostart'])
-
-            inst.storagepool_activate(name)
-            rollback.prependDefer(inst.storagepool_deactivate, name)
-
-            poolinfo = inst.storagepool_lookup(name)
-            self.assertEquals('active', poolinfo['state'])
-
-            autostart = poolinfo['autostart']
-            ori_params = {'autostart': True} if autostart else {'autostart': False}
-            for i in [True, False]:
-                params = {'autostart': i}
-                inst.storagepool_update(name, params)
-                rollback.prependDefer(inst.storagepool_update, name,
-                        ori_params)
                 poolinfo = inst.storagepool_lookup(name)
-                self.assertEquals(i, poolinfo['autostart'])
-            inst.storagepool_update(name, ori_params)
+                self.assertEquals('active', poolinfo['state'])
+
+                autostart = poolinfo['autostart']
+                ori_params = {'autostart': True} if autostart else {'autostart': False}
+                for i in [True, False]:
+                    params = {'autostart': i}
+                    inst.storagepool_update(name, params)
+                    rollback.prependDefer(inst.storagepool_update, name,
+                            ori_params)
+                    poolinfo = inst.storagepool_lookup(name)
+                    self.assertEquals(i, poolinfo['autostart'])
+                inst.storagepool_update(name, ori_params)
 
         pools = inst.storagepools_get_list()
         self.assertIn('default', pools)
-- 
1.7.11.7




More information about the Kimchi-devel mailing list