From c9ed3914657747baa27cbb8e0eb963133c79dd23 Mon Sep 17 00:00:00 2001 From: Sanoj Unnikrishnan Date: Fri, 8 Jun 2018 14:52:20 +0530 Subject: Quota: Fixing quota libs in glusto - added quota_libs.py with quota_validate library - Removed redundant function in quota_ops. - changed naming of quota_ops to be consistent and intutive w.r.t cli Change-Id: I4faf448ea308c9e04b548d6174d900fcf56978a5 Signed-off-by: Sanoj Unnikrishnan --- .../glustolibs/gluster/quota_libs.py | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 glustolibs-gluster/glustolibs/gluster/quota_libs.py (limited to 'glustolibs-gluster/glustolibs/gluster/quota_libs.py') diff --git a/glustolibs-gluster/glustolibs/gluster/quota_libs.py b/glustolibs-gluster/glustolibs/gluster/quota_libs.py new file mode 100644 index 000000000..fc4275c18 --- /dev/null +++ b/glustolibs-gluster/glustolibs/gluster/quota_libs.py @@ -0,0 +1,63 @@ +# Copyright (C) 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. + +""" Description: Module for gluster quota related helper functions. """ + + +from glusto.core import Glusto as g +from glustolibs.gluster.quota_ops import (quota_fetch_list) + + +def quota_validate(mnode, volname, path, **kwargs): + """ Validate if the hard limit, soft limit, usage match the expected values. + If any of the arguments are None, they are not verified. + + Args: + mnode (str) : Node on which command has to be executed. + volname (str) : volume name. + path (str) : Path to be verified. + kwargs + hard_limit(int) : hard limit is verified with this value. + soft_limit_percent(int) : soft limit (in %) is verified with this value + used_space(int) : if set, usage as displayed in quota list is + verified with expected value. + avail_space(int) : if set, usage as displayed in quota list is + verified with expected value. + sl_exceeded(bool) : expected value of soft limit flag. + hl_exceeded(bool) : expected value of hard limit flag. + + """ + + if kwargs is None: + g.log.error("No arguments given for validation") + return False + + quotalist = quota_fetch_list(mnode, volname, path) + + if path not in quotalist: + g.log.error("Path not found (script issue)") + return False + else: + listinfo = quotalist[path] + + ret = True + for key, value in kwargs.iteritems(): + if key and listinfo[key] != value: + g.log.error("%s = %s does not match with expected value %s", + key, str(listinfo[key]), str(value)) + ret = False + + return ret -- cgit