Discussion:
[Libstoragemgmt-devel] [PATCH 1/2] Get both simc and sim to work with plugin_test.py
Tony Asleson
2014-08-22 22:39:24 UTC
Permalink
Ensure that the simulated plug-ins work with the plug-in test.

Signed-off-by: Tony Asleson <***@redhat.com>
---
plugin/simc/simc_lsmplugin.c | 13 +++--
test/plugin_test.py | 112 ++++++++++++++++++++++++++-----------------
2 files changed, 78 insertions(+), 47 deletions(-)

diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index 6b2ddb7..145a499 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -353,10 +353,11 @@ static int cap(lsm_plugin_ptr c, lsm_system *system,
LSM_CAP_VOLUME_MASK,
LSM_CAP_VOLUME_UNMASK,
LSM_CAP_ACCESS_GROUPS,
- LSM_CAP_ACCESS_GROUP_CREATE_WWPN,
+ LSM_CAP_ACCESS_GROUP_CREATE_ISCSI_IQN,
LSM_CAP_ACCESS_GROUP_CREATE_WWPN,
LSM_CAP_ACCESS_GROUP_INITIATOR_ADD_WWPN,
LSM_CAP_ACCESS_GROUP_INITIATOR_DELETE,
+ LSM_CAP_ACCESS_GROUP_DELETE,
LSM_CAP_VOLUMES_ACCESSIBLE_BY_ACCESS_GROUP,
LSM_CAP_ACCESS_GROUPS_GRANTED_TO_VOLUME,
LSM_CAP_VOLUME_CHILD_DEPENDENCY,
@@ -727,7 +728,8 @@ static int volume_create(lsm_plugin_ptr c, lsm_pool *pool,
/* We create one to return and a copy to store in memory */

lsm_volume *v = lsm_volume_record_alloc(id, volume_name,
- "VPD", BS, allocated_size/BS, 0, sys_id,
+ "60a980003246694a412b45673342616e",
+ BS, allocated_size/BS, 0, sys_id,
lsm_pool_id_get(pool), NULL);

lsm_volume *to_store = lsm_volume_record_copy(v);
@@ -2071,7 +2073,9 @@ int load( lsm_plugin_ptr c, const char *uri, const char *password,
"LSM simulated storage plug-in",
LSM_SYSTEM_STATUS_OK, "", NULL);

- p = lsm_pool_record_alloc("POOL_3", "lsm_test_aggr", 0,
+ p = lsm_pool_record_alloc("POOL_3", "lsm_test_aggr",
+ LSM_POOL_ELEMENT_TYPE_FS|
+ LSM_POOL_ELEMENT_TYPE_VOLUME,
UINT64_MAX, UINT64_MAX,
LSM_POOL_STATUS_OK, "",
sys_id, NULL);
@@ -2085,7 +2089,8 @@ int load( lsm_plugin_ptr c, const char *uri, const char *password,
char name[32];
snprintf(name, sizeof(name), "POOL_%d", i);

- p = lsm_pool_record_alloc(name, name, 0, UINT64_MAX,
+ p = lsm_pool_record_alloc(name, name, LSM_POOL_ELEMENT_TYPE_FS|
+ LSM_POOL_ELEMENT_TYPE_VOLUME, UINT64_MAX,
UINT64_MAX, LSM_POOL_STATUS_OK, "",
sys_id, NULL);

diff --git a/test/plugin_test.py b/test/plugin_test.py
index 9d23844..e836a69 100755
--- a/test/plugin_test.py
+++ b/test/plugin_test.py
@@ -310,15 +310,29 @@ class TestPlugin(unittest.TestCase):
return False

def test_volume_list(self):
+ vol = None
+ volumes = self.c.volumes()
+ if len(volumes) == 0:
+ for s in self.systems:
+ cap = self.c.capabilities(s)
+
+ if supported(cap, [lsm.Capabilities.VOLUME_CREATE,
+ lsm.Capabilities.VOLUME_DELETE]):
+ vol, pool = self._volume_create(s.id)
+ break
+
volumes = self.c.volumes()

for v in volumes:
self.assertTrue(TestPlugin._vpd_correct(v.vpd83),
- "VPD is not as expected %s for volume id: %s" %
+ "VPD is not as expected '%s' for volume id: '%s'" %
(v.vpd83, v.id))

self.assertTrue(len(volumes) > 0, "We need at least 1 volume to test")

+ if vol is not None:
+ self._volume_delete(vol)
+
def test_disks_list(self):
disks = self.c.disks()
self.assertTrue(len(disks) > 0, "We need at least 1 disk to test")
@@ -342,15 +356,18 @@ class TestPlugin(unittest.TestCase):

def _fs_create(self, system_id):
if system_id in self.pool_by_sys_id:
+ fs = None
pool = self._get_pool_by_usage(system_id,
lsm.Pool.ELEMENT_TYPE_FS)

- fs_size = self._object_size(pool)
- fs = self.c.fs_create(pool, rs('fs'), fs_size)[1]
- self.assertTrue(self._fs_exists(fs.id))
+ if pool is not None:
+ fs_size = self._object_size(pool)
+ fs = self.c.fs_create(pool, rs('fs'), fs_size)[1]
+ self.assertTrue(self._fs_exists(fs.id))
+
+ self.assertTrue(fs is not None)
+ self.assertTrue(pool is not None)

- self.assertTrue(fs is not None)
- self.assertTrue(pool is not None)
return fs, pool

def _volume_delete(self, volume):
@@ -538,25 +555,27 @@ class TestPlugin(unittest.TestCase):
cap = self.c.capabilities(s)

if supported(cap, [lsm.Capabilities.FS_CREATE]):
- fs = self._fs_create(s.id)[0]
+ fs, pool = self._fs_create(s.id)

- if supported(cap, [lsm.Capabilities.FS_DELETE]):
- self._fs_delete(fs)
+ if fs is not None:
+ if supported(cap, [lsm.Capabilities.FS_DELETE]):
+ self._fs_delete(fs)

def test_fs_resize(self):
for s in self.systems:
cap = self.c.capabilities(s)

if supported(cap, [lsm.Capabilities.FS_CREATE]):
- fs = self._fs_create(s.id)[0]
+ fs, pool = self._fs_create(s.id)

- if supported(cap, [lsm.Capabilities.FS_RESIZE]):
- fs_size = fs.total_space * 1.10
- fs_resized = self.c.fs_resize(fs, fs_size)[1]
- self.assertTrue(fs_resized.total_space)
+ if fs is not None:
+ if supported(cap, [lsm.Capabilities.FS_RESIZE]):
+ fs_size = fs.total_space * 1.10
+ fs_resized = self.c.fs_resize(fs, fs_size)[1]
+ self.assertTrue(fs_resized.total_space)

- if supported(cap, [lsm.Capabilities.FS_DELETE]):
- self._fs_delete(fs)
+ if supported(cap, [lsm.Capabilities.FS_DELETE]):
+ self._fs_delete(fs)

def test_fs_clone(self):
for s in self.systems:
@@ -564,12 +583,14 @@ class TestPlugin(unittest.TestCase):

if supported(cap, [lsm.Capabilities.FS_CREATE,
lsm.Capabilities.FS_CLONE]):
- fs = self._fs_create(s.id)[0]
- fs_clone = self.c.fs_clone(fs, rs('fs_c'))[1]
+ fs, pool = self._fs_create(s.id)
+
+ if fs is not None:
+ fs_clone = self.c.fs_clone(fs, rs('fs_c'))[1]

- if supported(cap, [lsm.Capabilities.FS_DELETE]):
- self._fs_delete(fs_clone)
- self._fs_delete(fs)
+ if supported(cap, [lsm.Capabilities.FS_DELETE]):
+ self._fs_delete(fs_clone)
+ self._fs_delete(fs)

def test_fs_snapshot(self):
for s in self.systems:
@@ -578,14 +599,15 @@ class TestPlugin(unittest.TestCase):
if supported(cap, [lsm.Capabilities.FS_CREATE,
lsm.Capabilities.FS_SNAPSHOT_CREATE]):

- fs = self._fs_create(s.id)[0]
+ fs, pool = self._fs_create(s.id)

- ss = self.c.fs_snapshot_create(fs, rs('ss'))[1]
- self.assertTrue(self._fs_snapshot_exists(fs, ss.id))
+ if fs is not None:
+ ss = self.c.fs_snapshot_create(fs, rs('ss'))[1]
+ self.assertTrue(self._fs_snapshot_exists(fs, ss.id))

- # Delete snapshot
- if supported(cap, [lsm.Capabilities.FS_SNAPSHOT_DELETE]):
- self._fs_snapshot_delete(fs, ss)
+ # Delete snapshot
+ if supported(cap, [lsm.Capabilities.FS_SNAPSHOT_DELETE]):
+ self._fs_snapshot_delete(fs, ss)

def test_target_ports(self):
for s in self.systems:
@@ -670,7 +692,7 @@ class TestPlugin(unittest.TestCase):
if init_type == lsm.AccessGroup.INIT_TYPE_ISCSI_IQN:
ag_created = self.c.access_group_create(
name,
- 'iqn.1994-05.com.domain:01.89bd01',
+ 'iqn.1994-05.com.domain:01.' + rs('', 6),
lsm.AccessGroup.INIT_TYPE_ISCSI_IQN, s)

elif init_type == lsm.AccessGroup.INIT_TYPE_WWPN:
@@ -844,33 +866,37 @@ class TestPlugin(unittest.TestCase):
ag_name = rs('ag_dupe')

cap = self.c.capabilities(s)
- if supported(cap, [lsm.Capabilities.ACCESS_GROUPS]):
+ if supported(cap, [lsm.Capabilities.ACCESS_GROUPS,
+ lsm.Capabilities.ACCESS_GROUP_DELETE]):
ag_list = self.c.access_groups('system_id', s.id)

if supported(
- cap, [lsm.Capabilities.ACCESS_GROUP_CREATE_ISCSI_IQN,
- lsm.Capabilities.ACCESS_GROUP_DELETE]):
+ cap, [lsm.Capabilities.ACCESS_GROUP_CREATE_ISCSI_IQN]):
ag_type = lsm.AccessGroup.INIT_TYPE_ISCSI_IQN

- elif supported(cap, [lsm.Capabilities.ACCESS_GROUP_CREATE_WWPN,
- lsm.Capabilities.ACCESS_GROUP_DELETE]):
+ elif supported(cap,
+ [lsm.Capabilities.ACCESS_GROUP_CREATE_WWPN]):
ag_type = lsm.AccessGroup.INIT_TYPE_WWPN

+ else:
+ return
+
ag_created = self._create_access_group(
cap, ag_name, s, ag_type)

- # Try to create a duplicate
- got_exception = False
- try:
- ag_dupe = self._create_access_group(
- cap, ag_name, s, ag_type)
- except LsmError as le:
- got_exception = True
- self.assertTrue(le.code == ErrorNumber.NAME_CONFLICT)
+ if ag_created is not None:
+ # Try to create a duplicate
+ got_exception = False
+ try:
+ ag_dupe = self._create_access_group(
+ cap, ag_name, s, ag_type)
+ except LsmError as le:
+ got_exception = True
+ self.assertTrue(le.code == ErrorNumber.NAME_CONFLICT)

- self.assertTrue(got_exception)
+ self.assertTrue(got_exception)

- self._delete_access_group(ag_created)
+ self._delete_access_group(ag_created)


def dump_results():
--
1.8.2.1
Tony Asleson
2014-08-22 22:39:25 UTC
Permalink
Was creating invalid IQNs.

Signed-off-by: Tony Asleson <***@redhat.com>
---
test/plugin_test.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/test/plugin_test.py b/test/plugin_test.py
index e836a69..4c7cd28 100755
--- a/test/plugin_test.py
+++ b/test/plugin_test.py
@@ -71,8 +71,11 @@ def rs(component, l=4):
"""
Generate a random string
"""
- return 'lsm_%s_' % component + ''.join(
- random.choice(string.ascii_uppercase) for x in range(l))
+ rp = ''.join(random.choice(string.ascii_uppercase) for x in range(l))
+
+ if component is not None:
+ return 'lsm_%s_' % component + rp
+ return rp


def r_fcpn():
@@ -692,7 +695,7 @@ class TestPlugin(unittest.TestCase):
if init_type == lsm.AccessGroup.INIT_TYPE_ISCSI_IQN:
ag_created = self.c.access_group_create(
name,
- 'iqn.1994-05.com.domain:01.' + rs('', 6),
+ 'iqn.1994-05.com.domain:01.' + rs(None, 6),
lsm.AccessGroup.INIT_TYPE_ISCSI_IQN, s)

elif init_type == lsm.AccessGroup.INIT_TYPE_WWPN:
--
1.8.2.1
Loading...