# Copyright (C) 2017-2018 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from glusto.core import Glusto as g from glustolibs.gluster.gluster_base_class import (GlusterBaseClass, runs_on) from glustolibs.gluster.quota_ops import (quota_enable, quota_limit_usage, quota_fetch_list) from glustolibs.io.utils import list_all_files_and_dirs_mounts from glustolibs.gluster.exceptions import ExecutionError from glustolibs.misc.misc_libs import upload_scripts from glustolibs.io.utils import validate_io_procs @runs_on([['distributed'], ['glusterfs', 'nfs', 'cifs']]) class QuotaListPathValues(GlusterBaseClass): @classmethod def setUpClass(cls): """ setup volume, mount volume and initialize necessary variables which is used in tests """ # calling GlusterBaseClass setUpClass GlusterBaseClass.setUpClass.im_func(cls) # Upload io scripts for running IO on mounts g.log.info("Upload io scripts to clients %s for running IO on mounts", cls.clients) script_local_path = ("/usr/share/glustolibs/io/scripts/" "file_dir_ops.py") cls.script_upload_path = ("/usr/share/glustolibs/io/scripts/" "file_dir_ops.py") ret = upload_scripts(cls.clients, [script_local_path]) if not ret: raise ExecutionError("Failed to upload IO scripts to clients") g.log.info("Successfully uploaded IO scripts to clients %s", cls.clients) # Overriding the volume type to specifically test the volume type if cls.volume_type == "distributed": cls.volume['voltype'] = { 'type': 'distributed', 'dist_count': 1, 'transport': 'tcp'} # Setup Volume and Mount Volume g.log.info("Starting to Setup and Mount Volume %s", cls.volname) ret = cls.setup_volume_and_mount_volume(mounts=cls.mounts) if not ret: raise ExecutionError("Failed to Setup_Volume and Mount_Volume") g.log.info("Successful in Setup and Mount Volume %s", cls.volname) @classmethod def tearDownClass(cls): """ Clean up the volume and umount volume from client """ # stopping the volume g.log.info("Starting to Unmount Volume and Cleanup Volume") ret = cls.unmount_volume_and_cleanup_volume(mounts=cls.mounts) if not ret: raise ExecutionError("Failed to Unmount Volume and Cleanup Volume") g.log.info("Successful in Unmount Volume and Cleanup Volume") # calling GlusterBaseClass tearDownClass GlusterBaseClass.tearDownClass.im_func(cls) def test_quota_single_brick_volume(self): """ Verifying directory quota functionality on a single brick volume. * Create a volume with single brick (1x1) start and mount it * Enable quota on the volume * Set a limit of 1GB on this volume * Create some directories and files in the mount point * Execute a quota list command """ # Enable Quota g.log.info("Enabling quota on the volume %s", self.volname) ret, _, _ = quota_enable(self.mnode, self.volname) self.assertEqual(ret, 0, ("Failed to enable quota on the " "volume %s", self.volname)) g.log.info("Successfully enabled quota on the volume %s", self.volname) # Path to set quota limit path = "/" # Set Quota limit on the root of the volume g.log.info("Set Quota Limit on the path %s of the volume %s", path, self.volname) ret, _, _ = quota_limit_usage(self.mnode, self.volname, path=path, limit="1GB") self.assertEqual(ret, 0, ("Failed to set quota limit on path %s of " "the volume %s", path, self.volname)) g.log.info("Successfully set the Quota limit on %s of the volume %s", path, self.volname) # Starting IO on the mounts all_mounts_procs = [] count = 1 for mount_obj in self.mounts: g.log.info("Starting IO on %s:%s", mount_obj.client_system, mount_obj.mountpoint) cmd = ("python %s create_deep_dirs_with_files " "--dirname-start-num %d " "--dir-depth 2 " "--dir-length 20 " "--max-num-of-dirs 5 " "--num-of-files 5 %s" % (self.script_upload_path, count, mount_obj.mountpoint)) proc = g.run_async(mount_obj.client_system, cmd, user=mount_obj.user) all_mounts_procs.append(proc) count = count + 10 # Validate IO g.log.info("Validating IO's") ret = validate_io_procs(all_mounts_procs, self.mounts) self.assertTrue(ret, "IO failed on some of the clients") g.log.info("Successfully validated all io's") # Get Quota list on Volume g.log.info("Get Quota list for the volume %s", self.volname) quota_list1 = quota_fetch_list(self.mnode, self.volname) self.assertIsNotNone(quota_list1, ("Failed to get the quota list for " "the volume %s", self.volname)) self.assertIn(path, quota_list1.keys(), ("%s not part of the ""quota list %s even if " "it is set on the volume %s", path, quota_list1, self.volname)) g.log.info("Successfully listed quota list %s of the " "volume %s", quota_list1, self.volname) # List all files and dirs created g.log.info("List all files and directories:") ret = list_all_files_and_dirs_mounts(self.mounts) self.assertTrue(ret, "Failed to list all files and dirs") g.log.info("Listing all files and directories is successful")