summaryrefslogtreecommitdiffstats
path: root/tests/functional/quota/test_deem_statfs.py
blob: 92cc44e74a242f23349dc262fff57535bb9a1846 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#  Copyright (C) 2015-2020 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.

from glusto.core import Glusto as g
from glustolibs.gluster.gluster_base_class import (GlusterBaseClass,
                                                   runs_on)
from glustolibs.gluster.lib_utils import get_size_of_mountpoint
from glustolibs.gluster.quota_ops import (quota_enable,
                                          quota_limit_usage,
                                          quota_remove)
from glustolibs.gluster.exceptions import ExecutionError


@runs_on([['distributed-replicated', 'replicated', 'dispersed', 'distributed',
           'distributed-dispersed'],
          ['glusterfs', 'nfs']])
class QuotaStatvfs(GlusterBaseClass):

    @classmethod
    def setUpClass(cls):
        """
        setup volume, mount volume and initialize necessary variables
        which is used in tests
        """

        # calling GlusterBaseClass setUpClass
        cls.get_super_method(cls, 'setUpClass')()

        # 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 %s"
                                 % cls.volname)
        g.log.info("Successful in Setup and Mount Volume %s", cls.volname)

    def tearDown(self):

        # Unmount and cleanup original volume
        g.log.info("Starting to Unmount Volume and Cleanup Volume")
        ret = self.unmount_volume_and_cleanup_volume(mounts=self.mounts)
        if not ret:
            raise ExecutionError("Failed to umount the vol & cleanup Volume")
        g.log.info("Successful in umounting the volume and Cleanup")

        # Calling GlusterBaseClass tearDown
        self.get_super_method(self, 'tearDown')()

    def test_quota_statvfs(self):
        """
        Test statvfs calls return appropriate avaialable size with quota.

        * Enable Quota
        * Save the result from statvfs call
        * Set Quota limit of 1 GB on the root of the volume
        * Validate statvfs call honors quota
        * Remove quota limit from the Volume
        * Validate statvfs call reports old value of avialable space
        """
        # 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)

        mount_dir = self.mounts[0].mountpoint
        client = self.mounts[0].client_system

        # Save the result from statvfs call
        orig_avail_space = int(get_size_of_mountpoint(client, mount_dir))

        # Set Quota limit of 1 GB on the root of the volume
        g.log.info("Set Quota Limit on the path '/'")
        ret, _, _ = quota_limit_usage(self.mnode, self.volname,
                                      path='/', limit="1GB")
        self.assertEqual(ret, 0, ("Failed to set quota limit on path '/'"))
        g.log.info("Successfully set the Quota limit on '/'")

        # Validate statvfs call honors quota
        avail_space_after_limit = int(get_size_of_mountpoint(client,
                                                             mount_dir))
        g.log.info("space %s", avail_space_after_limit)
        self.assertEqual(avail_space_after_limit * 1024, 1073741824,
                         "avialable space reported by statvfs does not honor \
                          quota limit on '/'")
        g.log.info("successfully validated statvfs honor quota limit on '/'")

        # Remove Quota limit from the Volume
        g.log.info("Remove Quota Limit set on path '/'")
        ret, _, _ = quota_remove(self.mnode, self.volname, path='/')
        self.assertEqual(ret, 0, ("Failed to remove quota limit on path '/' "))
        g.log.info("Successfully removed the Quota limit on path '/'")

        # Validate statvfs call reports old value of avialable space
        avail_space_after_remove = int(get_size_of_mountpoint(client,
                                                              mount_dir))
        g.log.info("space %s", avail_space_after_remove)
        self.assertEqual(avail_space_after_remove, orig_avail_space,
                         "avialable space reported by statvfs not restored \
                          after quota limit is removed on '/'")
        g.log.info("successfully validated statvfs shows original value")