From 78826c43f8d01e0c8e5c3ca637fcd03302a1136d Mon Sep 17 00:00:00 2001 From: Valerii Ponomarov Date: Mon, 24 Dec 2018 18:01:37 +0530 Subject: Fix CNS-550 test case This test case has fragile logic. It doesn't assume we expect new block hosting volumes to be created when we calculate the size for block volume. So, fix it by doing 2 things: - Use total block hosting volume size, not it's 'free space'. - Get info of block hosting vol if block vol gets created unexpectedly, and read it's size. If the size is bigger than block vol's size, then pass the test. Here, we assume that existing, during calculation, block hosting volumes were not the biggest possible and autocreation is enabled in addition to the presence of the available size on the Heketi devices. Change-Id: Ic7d5325b1144dce0e56999617f3c6d7c0829e42d --- .../heketi_tests/test_heketi_create_volume.py | 43 +++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py b/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py index 7963413b..af9d2b44 100644 --- a/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py +++ b/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py @@ -1,5 +1,3 @@ -import time - from glusto.core import Glusto as g from glustolibs.gluster.volume_ops import get_volume_list, get_volume_info import six @@ -206,33 +204,31 @@ class TestHeketiVolume(HeketiBaseClass): heketi_blockvolume_delete, self.heketi_client_node, self.heketi_server_url, blockvol1['id']) - # Sleep for couple of seconds to avoid races - time.sleep(2) - - # Get info about block hosting volume available space + # Get info about block hosting volumes file_volumes = heketi_volume_list( self.heketi_client_node, self.heketi_server_url, json=True) self.assertTrue(file_volumes) - max_freesize = 0 - file_volumes_debug_info = [] + self.assertIn("volumes", file_volumes) + self.assertTrue(file_volumes["volumes"]) + max_block_hosting_vol_size, file_volumes_debug_info = 0, [] for vol_id in file_volumes["volumes"]: vol = heketi_volume_info( self.heketi_client_node, self.heketi_server_url, vol_id, json=True) - current_freesize = vol.get("blockinfo", {}).get("freesize", 0) - if current_freesize > max_freesize: - max_freesize = current_freesize - if current_freesize: + current_block_hosting_vol_size = vol.get('size', 0) + if current_block_hosting_vol_size > max_block_hosting_vol_size: + max_block_hosting_vol_size = current_block_hosting_vol_size + if current_block_hosting_vol_size: file_volumes_debug_info.append(six.text_type({ 'id': vol.get('id', '?'), 'name': vol.get('name', '?'), - 'size': vol.get('size', '?'), + 'size': current_block_hosting_vol_size, 'blockinfo': vol.get('blockinfo', '?'), })) - self.assertGreater(max_freesize, 0) + self.assertGreater(max_block_hosting_vol_size, 0) # Try to create blockvolume with size bigger than available - too_big_vol_size = max_freesize + 1 + too_big_vol_size = max_block_hosting_vol_size + 1 try: blockvol2 = heketi_blockvolume_create( self.heketi_client_node, self.heketi_server_url, @@ -244,9 +240,14 @@ class TestHeketiVolume(HeketiBaseClass): self.addCleanup( heketi_blockvolume_delete, self.heketi_client_node, self.heketi_server_url, blockvol2['id']) - self.assertFalse( - blockvol2, - "Volume unexpectedly was created. Calculated 'max free size' is " - "'%s'.\nBlock volume info is: %s \n" - "Block hosting volumes which were considered: \n%s" % ( - max_freesize, blockvol2, '\n'.join(file_volumes_debug_info))) + block_hosting_vol = heketi_volume_info( + self.heketi_client_node, self.heketi_server_url, + blockvol2.get('blockhostingvolume'), json=True) + self.assertGreater( + block_hosting_vol.get('size', -2), blockvol2.get('size', -1), + ("Block volume unexpectedly was created. " + "Calculated 'max free size' is '%s'.\nBlock volume info is: %s \n" + "File volume info, which hosts block volume: \n%s," + "Block hosting volumes which were considered: \n%s" % ( + max_block_hosting_vol_size, blockvol2, block_hosting_vol, + '\n'.join(file_volumes_debug_info)))) -- cgit