* lsmcli test: new test function volume_create_raid_test().
* Plugin test: new test function test_volume_create_raid().
* C unit test: test_volume_create_raid_cap_get() and
test_volume_create_raid()
Signed-off-by: Gris Ge <fge(a)redhat.com>
---
test/cmdtest.py | 55 ++++++++++++++++++++++++++++
test/plugin_test.py | 50 ++++++++++++++++++++++++++
test/tester.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 206 insertions(+)
diff --git a/test/cmdtest.py b/test/cmdtest.py
index 97c5b88..4e1f731 100755
--- a/test/cmdtest.py
+++ b/test/cmdtest.py
@@ -713,6 +713,59 @@ def pool_raid_info_test(cap, system_id):
exit(10)
return
+def volume_create_raid_test(cap, system_id):
+ if cap['VOLUME_CREATE_RAID']:
+ out = call(
+ [cmd, '-t' + sep, 'volume-create-raid-cap', '--sys',
system_id])[1]
+
+ if 'RAID1' not in [r[1] for r in parse(out)]:
+ return
+
+ out = call([cmd, '-t' + sep, 'list', '--type',
'disks'])[1]
+ free_disk_ids = []
+ disk_list = parse(out)
+ for disk in disk_list:
+ if 'Free' in disk:
+ if len(free_disk_ids) == 2:
+ break
+ free_disk_ids.append(disk[0])
+
+ if len(free_disk_ids) != 2:
+ print "Require two free disks to test volume-create-raid"
+ exit(10)
+
+ out = call([
+ cmd, '-t' + sep, 'volume-create-raid', '--disk',
free_disk_ids[0],
+ '--disk', free_disk_ids[1], '--name',
'test_volume_create_raid',
+ '--raid-type', 'raid1'])[1]
+
+ volume = parse(out)
+ vol_id = volume[0][0]
+ pool_id = volume[0][-2]
+
+ if cap['VOLUME_RAID_INFO']:
+ out = call(
+ [cmd, '-t' + sep, 'volume-raid-info', '--vol',
vol_id])[1]
+ if parse(out)[0][1] != 'RAID1':
+ print "New volume is not RAID 1"
+ exit(10)
+
+ if cap['POOL_RAID_INFO']:
+ out = call(
+ [cmd, '-t' + sep, 'pool-raid-info', '--pool',
pool_id])[1]
+ if parse(out)[0][1] != 'RAID1':
+ print "New pool is not RAID 1"
+ exit(10)
+ for disk_id in free_disk_ids:
+ if disk_id not in [p[3] for p in parse(out)]:
+ print "New pool does not contain requested disks"
+ exit(10)
+
+ if cap['VOLUME_DELETE']:
+ volume_delete(vol_id)
+
+ return
+
def run_all_tests(cap, system_id):
test_display(cap, system_id)
@@ -729,6 +782,8 @@ def run_all_tests(cap, system_id):
pool_raid_info_test(cap,system_id)
+ volume_create_raid_test(cap, system_id)
+
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-c", "--command", action="store",
type="string",
diff --git a/test/plugin_test.py b/test/plugin_test.py
index 895bec3..ef0bbfc 100755
--- a/test/plugin_test.py
+++ b/test/plugin_test.py
@@ -1294,6 +1294,56 @@ def test_pool_raid_info(self):
self.assertTrue(type(member_type) is int)
self.assertTrue(type(member_ids) is list)
+ def _skip_current_test(self, messsage):
+ """
+ If skipTest is supported, skip this test with provided message.
+ Sliently return if not supported.
+ """
+ if hasattr(unittest.TestCase, 'skipTest') is True:
+ self.skipTest(messsage)
+ return
+
+ def test_volume_create_raid(self):
+ for s in self.systems:
+ cap = self.c.capabilities(s)
+ # TODO(Gris Ge): Add test code for other RAID type and strip size
+ if supported(cap, [Cap.VOLUME_CREATE_RAID]):
+ supported_raid_types, supported_strip_sizes = \
+ self.c.volume_create_raid_cap_get(s)
+ if lsm.Volume.RAID_TYPE_RAID1 not in supported_raid_types:
+ self._skip_current_test(
+ "Skip test: current system does not support "
+ "creating RAID1 volume")
+
+ # Find two free disks
+ free_disks = []
+ for disk in self.c.disks():
+ if len(free_disks) == 2:
+ break
+ if disk.status & lsm.Disk.STATUS_FREE:
+ free_disks.append(disk)
+
+ if len(free_disks) != 2:
+ self._skip_current_test(
+ "Skip test: Failed to find two free disks for RAID 1")
+ return
+
+ new_vol = self.c.volume_create_raid(
+ rs('v'), lsm.Volume.RAID_TYPE_RAID1, free_disks,
+ lsm.Volume.VCR_STRIP_SIZE_DEFAULT)
+
+ self.assertTrue(new_vol is not None)
+
+ # TODO(Gris Ge): Use volume_raid_info() and pool_raid_info()
+ # to verify size, raid_type, member type, member ids.
+
+ if supported(cap, [Cap.VOLUME_DELETE]):
+ self._volume_delete(new_vol)
+
+ else:
+ self._skip_current_test(
+ "Skip test: not support of VOLUME_CREATE_RAID")
+
def dump_results():
"""
unittest.main exits when done so we need to register this handler to
diff --git a/test/tester.c b/test/tester.c
index 63c2b5d..842d4e0 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -2916,6 +2916,105 @@ START_TEST(test_pool_raid_info)
}
END_TEST
+START_TEST(test_volume_create_raid_cap_get)
+{
+ if (which_plugin == 1){
+ // silently skip on simc which does not support this method yet.
+ return;
+ }
+ int rc;
+ lsm_system **sys = NULL;
+ uint32_t sys_count = 0;
+ lsm_storage_capabilities *cap = NULL;
+
+ G(rc, lsm_system_list, c, &sys, &sys_count, LSM_CLIENT_FLAG_RSVD);
+ fail_unless( sys_count >= 1, "count = %d", sys_count);
+ printf("sys_count: %d\n", sys_count);
+
+ if( sys_count > 0 ) {
+ uint32_t *supported_raid_types;
+ uint32_t supported_raid_type_count = 0;
+ uint32_t *supported_strip_sizes;
+ uint32_t supported_strip_size_count = 0;
+
+ G(
+ rc, lsm_volume_create_raid_cap_get, c, sys[0],
+ &supported_raid_types, &supported_raid_type_count,
+ &supported_strip_sizes, &supported_strip_size_count,
+ 0);
+
+ free(supported_raid_types);
+ free(supported_strip_sizes);
+
+ }
+ G(rc, lsm_system_record_array_free, sys, sys_count);
+}
+END_TEST
+
+START_TEST(test_volume_create_raid)
+{
+ if (which_plugin == 1){
+ // silently skip on simc which does not support this method yet.
+ return;
+ }
+ int rc;
+
+ lsm_disk **disks = NULL;
+ uint32_t disk_count = 0;
+
+ G(rc, lsm_disk_list, c, NULL, NULL, &disks, &disk_count, 0);
+
+ // Try to create two disks RAID 1.
+ uint32_t free_disk_count = 0;
+ lsm_disk *free_disks[2];
+ int i;
+ for (i = 0; i< disk_count; i++){
+ if (lsm_disk_status_get(disks[i]) & LSM_DISK_STATUS_FREE){
+ free_disks[free_disk_count++] = disks[i];
+ if (free_disk_count == 2){
+ break;
+ }
+ }
+ }
+ fail_unless(free_disk_count == 2, "Failed to find two free disks");
+
+ lsm_volume *new_volume = NULL;
+
+ G(rc, lsm_volume_create_raid, c, "test_volume_create_raid",
+ LSM_VOLUME_RAID_TYPE_RAID1, free_disks, free_disk_count,
+ LSM_VOLUME_VCR_STRIP_SIZE_DEFAULT, &new_volume, LSM_CLIENT_FLAG_RSVD);
+
+ char *job_del = NULL;
+ int del_rc = lsm_volume_delete(
+ c, new_volume, &job_del, LSM_CLIENT_FLAG_RSVD);
+
+ fail_unless( del_rc == LSM_ERR_OK || del_rc == LSM_ERR_JOB_STARTED,
+ "lsm_volume_delete %d (%s)", rc,
error(lsm_error_last_get(c)));
+
+ if( LSM_ERR_JOB_STARTED == del_rc ) {
+ wait_for_job_vol(c, &job_del);
+ }
+
+ G(rc, lsm_disk_record_array_free, disks, disk_count);
+ // The new pool should be automatically be deleted when volume got
+ // deleted.
+ lsm_pool **pools = NULL;
+ uint32_t count = 0;
+ G(
+ rc, lsm_pool_list, c, "id", lsm_volume_pool_id_get(new_volume),
+ &pools, &count, LSM_CLIENT_FLAG_RSVD);
+
+ fail_unless(
+ count == 0,
+ "New HW RAID pool still exists, it should be deleted along with "
+ "lsm_volume_delete()");
+
+ lsm_pool_record_array_free(pools, count);
+
+ G(rc, lsm_volume_record_free, new_volume);
+}
+END_TEST
+
Suite * lsm_suite(void)
{
Suite *s = suite_create("libStorageMgmt");
@@ -2953,6 +3052,8 @@ Suite * lsm_suite(void)
tcase_add_test(basic, test_invalid_input);
tcase_add_test(basic, test_volume_raid_info);
tcase_add_test(basic, test_pool_raid_info);
+ tcase_add_test(basic, test_volume_create_raid_cap_get);
+ tcase_add_test(basic, test_volume_create_raid);
suite_add_tcase(s, basic);
return s;
--
1.8.3.1