diff options
author | Ashmitha <asambast@redhat.com> | 2019-09-10 16:01:56 +0530 |
---|---|---|
committer | Ashmitha <asambast@redhat.com> | 2019-09-12 18:13:14 +0530 |
commit | ff7b40a09c4029a0a59b6fb96bbe9dc2a19e88e2 (patch) | |
tree | e7284f62eb490674742e66b426cdff120e1df931 | |
parent | 8c2db5c9894c4f7b90704143cdc97c919c4fe961 (diff) |
Add test case to try creation of storage class with duplicate name
Change-Id: If30737958bc667264fc01fe81d411f406b501918
3 files changed, 15 insertions, 3 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/baseclass.py b/openshift-storage-libs/openshiftstoragelibs/baseclass.py index 306623da..19668b17 100644 --- a/openshift-storage-libs/openshiftstoragelibs/baseclass.py +++ b/openshift-storage-libs/openshiftstoragelibs/baseclass.py @@ -153,6 +153,7 @@ class BaseClass(unittest.TestCase): def create_storage_class(self, secret_name=None, sc_name_prefix="autotests-sc", + sc_name=None, create_vol_name_prefix=False, vol_name_prefix=None, allow_volume_expansion=False, @@ -194,6 +195,7 @@ class BaseClass(unittest.TestCase): self.sc_name = oc_create_sc( self.ocp_client[0], sc_name_prefix=sc_name_prefix, + sc_name=sc_name, provisioner=provisioner, allow_volume_expansion=allow_volume_expansion, reclaim_policy=reclaim_policy, diff --git a/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py b/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py index 60748aa0..87e55806 100644 --- a/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py +++ b/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py @@ -269,7 +269,7 @@ def oc_create_secret(hostname, secret_name_prefix="autotests-secret", def oc_create_sc(hostname, sc_name_prefix="autotests-sc", provisioner="kubernetes.io/glusterfs", allow_volume_expansion=False, - reclaim_policy="Delete", **parameters): + reclaim_policy="Delete", sc_name=None, **parameters): """Create storage class using data provided as stdin input. Args: @@ -292,7 +292,8 @@ def oc_create_sc(hostname, sc_name_prefix="autotests-sc", for parameter in parameters.keys(): if parameter.lower() not in allowed_parameters: parameters.pop(parameter) - sc_name = "%s-%s" % (sc_name_prefix, utils.get_random_str()) + if not sc_name: + sc_name = "%s-%s" % (sc_name_prefix, utils.get_random_str()) sc_data = json.dumps({ "kind": "StorageClass", "apiVersion": "storage.k8s.io/v1", diff --git a/tests/functional/provisioning/test_storage_class_cases.py b/tests/functional/provisioning/test_storage_class_cases.py index cdf61d43..655565cc 100644 --- a/tests/functional/provisioning/test_storage_class_cases.py +++ b/tests/functional/provisioning/test_storage_class_cases.py @@ -3,6 +3,7 @@ from glusto.core import Glusto as g from openshiftstoragelibs.heketi_ops import ( heketi_blockvolume_info, + verify_volume_name_prefix, ) from openshiftstoragelibs.baseclass import BaseClass from openshiftstoragelibs.openshift_storage_libs import ( @@ -10,7 +11,6 @@ from openshiftstoragelibs.openshift_storage_libs import ( get_mpath_name_from_device_name, validate_multipath_pod, ) -from openshiftstoragelibs.heketi_ops import verify_volume_name_prefix from openshiftstoragelibs.openshift_ops import ( get_amount_of_gluster_nodes, get_gluster_blockvol_info_by_pvc_name, @@ -32,6 +32,7 @@ from openshiftstoragelibs.openshift_storage_version import ( get_openshift_storage_version ) from openshiftstoragelibs.openshift_version import get_openshift_version +from openshiftstoragelibs import utils @ddt.ddt @@ -344,3 +345,11 @@ class TestStorageClassCases(BaseClass): endpoint, "Failed to read Endpoints of %s on %s " % ( pv_name, self.ocp_master_node[0])) + + def test_try_to_create_sc_with_duplicated_name(self): + """Verify SC creation fails with duplicate name""" + sc_name = "test-sc-duplicated-name-" + utils.get_random_str() + self.create_storage_class(sc_name=sc_name) + self.create_and_wait_for_pvc(sc_name=sc_name) + with self.assertRaises(AssertionError): + self.create_storage_class(sc_name=sc_name) |