From dd5dbb04312664836e3e2cfc7fc36867d65c6aa7 Mon Sep 17 00:00:00 2001 From: Bala Konda Reddy M Date: Mon, 18 May 2020 19:43:59 +0530 Subject: [Libfix] Add parameter for volume create only Problem: Currently setup_volume in volume_libs.py and gluster_base_class.py are to create volume and start it. There are tests, where only volume_create is required and if the test has to run on all volume types. Any contributor have to do all the validations which are already implemented in setup_volume and classmethod of setup volume in the gluster_base_class to their test. Solution: Added a parameter in the setup_volume() function "create_only" by default it is false, unless specified this paramter setup_volume will work as it is. similarly, have added a parameter in classmethod of setup_volume in gluster_base_class.py "only_volume_create", here also defaults to false unless specified. Note: After calling "setup_volume() -> volume_stop" is not same as just "volume_create()" in the actual test. Change-Id: I76cde1b668b3afcac41dd882c2a376cb6fac88a3 Signed-off-by: Bala Konda Reddy M --- .../glustolibs/gluster/gluster_base_class.py | 14 +++++++++++-- .../glustolibs/gluster/volume_libs.py | 23 +++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) (limited to 'glustolibs-gluster/glustolibs/gluster') diff --git a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py index 65ecd139a..d27b9ad3e 100644 --- a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py +++ b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py @@ -312,7 +312,7 @@ class GlusterBaseClass(TestCase): return True @classmethod - def setup_volume(cls, volume_create_force=False): + def setup_volume(cls, volume_create_force=False, only_volume_create=False): """Setup the volume: - Create the volume, Start volume, Set volume options, enable snapshot/quota/tier if specified in the config @@ -324,6 +324,9 @@ class GlusterBaseClass(TestCase): Args: volume_create_force(bool): True if create_volume should be executed with 'force' option. + only_volume_create(bool): True, only volume creation is needed + False, by default volume creation and + start. Returns (bool): True if all the steps mentioned in the descriptions passes. False otherwise. @@ -346,12 +349,19 @@ class GlusterBaseClass(TestCase): g.log.info("Setting up volume %s", cls.volname) ret = setup_volume(mnode=cls.mnode, all_servers_info=cls.all_servers_info, - volume_config=cls.volume, force=force_volume_create) + volume_config=cls.volume, force=force_volume_create, + create_only=only_volume_create) if not ret: g.log.error("Failed to Setup volume %s", cls.volname) return False g.log.info("Successful in setting up volume %s", cls.volname) + # Returning the value without proceeding for next steps + if only_volume_create and ret: + g.log.info("Setup volume with volume creation {} " + "successful".format(cls.volname)) + return True + # Wait for volume processes to be online g.log.info("Wait for volume %s processes to be online", cls.volname) ret = wait_for_volume_process_to_be_online(cls.mnode, cls.volname) diff --git a/glustolibs-gluster/glustolibs/gluster/volume_libs.py b/glustolibs-gluster/glustolibs/gluster/volume_libs.py index 6e6defb26..6bb8d9c2f 100644 --- a/glustolibs-gluster/glustolibs/gluster/volume_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/volume_libs.py @@ -67,7 +67,7 @@ def volume_exists(mnode, volname): def setup_volume(mnode, all_servers_info, volume_config, multi_vol=False, - force=False): + force=False, create_only=False): """Setup Volume with the configuration defined in volume_config Args: @@ -115,7 +115,11 @@ def setup_volume(mnode, all_servers_info, volume_config, multi_vol=False, force (bool): If this option is set to True, then volume creation command is executed with force option. False, without force option. - By default, value is set to False + By default, value is set to False. + create_only(bool): True, if only volume creation is needed. + False, will do volume create, start, set operation + if any provided in the volume_config. + By default, value is set to False. Returns: bool : True on successful setup. False Otherwise @@ -293,6 +297,11 @@ def setup_volume(mnode, all_servers_info, volume_config, multi_vol=False, g.log.error("Unable to create volume %s", volname) return False + if create_only and (ret == 0): + g.log.info("Volume creation of {} is done successfully".format( + volname)) + return True + # Start Volume time.sleep(2) ret = volume_start(mnode, volname) @@ -424,7 +433,7 @@ def setup_volume(mnode, all_servers_info, volume_config, multi_vol=False, def bulk_volume_creation(mnode, number_of_volumes, servers_info, volume_config, vol_prefix="mult_vol_", - is_force=False): + is_force=False, is_create_only=False): """ Creates the number of volumes user has specified @@ -438,7 +447,11 @@ def bulk_volume_creation(mnode, number_of_volumes, servers_info, Kwargs: vol_prefix (str): Prefix to be added to the volume name. is_force (bool): True, If volume create command need to be executed - with force, False Otherwise. Defaults to False + with force, False Otherwise. Defaults to False. + create_only(bool): True, if only volume creation is needed. + False, will do volume create, start, set operation + if any provided in the volume_config. + By default, value is set to False. Returns: bool: True on successful bulk volume creation, False Otherwise. @@ -468,7 +481,7 @@ def bulk_volume_creation(mnode, number_of_volumes, servers_info, for volume in range(number_of_volumes): volume_config['name'] = vol_prefix + volume_name + str(volume) ret = setup_volume(mnode, servers_info, volume_config, multi_vol=True, - force=is_force) + force=is_force, create_only=is_create_only) if not ret: g.log.error("Volume creation failed for the volume %s" % volume_config['name']) -- cgit