From f75cf7f58dc17d45ab93aeedbbbbfe9cd9134d03 Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Mon, 2 Dec 2019 11:54:40 +0530 Subject: Add TC create two heketi volumes with same name Add TC where it creates two volumes with the same name via heketi and verifies that first one gets successfully created and the second one gets failed. Change-Id: I36e9bb1ed93b807458fcbdf8d417ada1cbc7b943 --- tests/functional/heketi/test_volume_creation.py | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/functional/heketi') diff --git a/tests/functional/heketi/test_volume_creation.py b/tests/functional/heketi/test_volume_creation.py index 6fbd2a7d..354f7889 100644 --- a/tests/functional/heketi/test_volume_creation.py +++ b/tests/functional/heketi/test_volume_creation.py @@ -6,6 +6,7 @@ import six from openshiftstoragelibs.baseclass import BaseClass from openshiftstoragelibs import heketi_ops from openshiftstoragelibs import podcmd +from openshiftstoragelibs import utils class TestVolumeCreationTestCases(BaseClass): @@ -368,3 +369,35 @@ class TestVolumeCreationTestCases(BaseClass): msg = ("Volume %s does not have bricks count multiple of 3. It has %s" % (vol_name, gluster_v_info['brickCount'])) self.assertFalse(int(gluster_v_info['brickCount']) % 3) + + def test_create_volume_with_same_name(self): + """Test create two volumes with the same name and verify that 2nd one + is failing with the appropriate error. + """ + h_node, h_url = self.heketi_client_node, self.heketi_server_url + vol_name = "autovol-%s" % utils.get_random_str() + + # Create volume for the first time + vol_info = heketi_ops.heketi_volume_create( + h_node, h_url, size=1, name=vol_name, json=True) + self.addCleanup( + heketi_ops.heketi_volume_delete, h_node, h_url, vol_info['id']) + + vol_info_new = None + try: + # Try to create volume for 2nd time + vol_info_new = heketi_ops.heketi_volume_create( + h_node, h_url, size=1, name=vol_name, json=True) + self.addCleanup( + heketi_ops.heketi_volume_delete, + h_node, h_url, vol_info_new['id']) + except AssertionError as err: + # Verify msg in error + msg = "Volume name '%s' already in use" % vol_name + if msg not in six.text_type(err): + raise + + # Raise exception if there is no error raised by heketi + msg = ('Volume %s and %s got created two times with the same name ' + 'unexpectedly.' % (vol_info, vol_info_new)) + self.assertFalse(vol_info_new, msg) -- cgit