summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster/quota_libs.py
blob: fc4275c18273d9043175cefcfa50e594e0eee680 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#  Copyright (C) 2018  Red Hat, Inc. <http://www.redhat.com>
#
#  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