summaryrefslogtreecommitdiffstats
path: root/tests/functional/quota/test_multi_value_limit.py
blob: 3991c614bb4cee22effafc536e592d3cc04a2ea0 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#  Copyright (C) 2015-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.

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_set_soft_timeout,
                                          quota_set_hard_timeout,
                                          quota_limit_usage,
                                          quota_remove)
from glustolibs.gluster.quota_libs import quota_validate
from glustolibs.gluster.exceptions import ExecutionError


@runs_on([['distributed-replicated', 'replicated', 'dispersed', 'distributed',
           'distributed-dispersed'],
          ['glusterfs', 'nfs', 'cifs']])
class QuotaMultiValueLimits(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)

        # 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)

    @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_multi_value_limits(self):
        # pylint: disable=too-many-statements
        """
        Verifying directory quota functionality with respect to
        the limit-usage option. Set limits of various values being
        big, small and decimal values. eg. 1GB, 10GB, 2.5GB, etc.
        Set limits on various directories and check for the quota
        list of all the directories.

        * Enable Quota.
        * Create some data on mount point.
        * Set limit of 1 GB on path "/" , perform some I/O from mount
          such that the hard limit is reached and validate with quota list.
        * Set limit of 1.5 GB on path "/" , perform some I/O from mounts
          such that the hard limit is reached and validate with quota list.
        * Set limit of 10 GB on path "/" , perform some I/O from mounts
          such that the hard limit is reached and validate with quota list.
        """

        # 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)

        # Perform some I/O on mounts
        mount_obj = self.mounts[0]
        mount_dir = mount_obj.mountpoint
        client = mount_obj.client_system

        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s ; "
               "for i in `seq 1 10` ; "
               "do dd if=/dev/zero of=foo$i "
               "bs=10M "
               "count=1 ; "
               "done" % mount_dir)
        ret, _, _ = g.run(client, cmd)
        self.assertEqual(ret, 0, "Failed to create files on mountpoint")
        g.log.info("Files created successfully on mountpoint")

        # Set soft timeout to 1 second
        g.log.info("Set quota soft timeout:")
        ret, _, _ = quota_set_soft_timeout(self.mnode, self.volname, '1sec')
        self.assertEqual(ret, 0, ("Failed to set soft timeout"))
        g.log.info("Quota soft timeout set successfully")

        # Set hard timeout to 0 second
        g.log.info("Set quota hard timeout:")
        ret, _, _ = quota_set_hard_timeout(self.mnode, self.volname, '0sec')
        self.assertEqual(ret, 0, ("Failed to set hard timeout"))
        g.log.info("Quota hard timeout set successfully")

        # Path to set quota limit
        path = "/"

        # Set Quota limit of 1 GB 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)

        # Create data such that soft limit is crossed but not the hard limit
        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s ; "
               "for i in `seq 11 102` ; "
               "do dd if=/dev/zero of=foo$i "
               "bs=10M "
               "count=1 ; "
               "done" % mount_dir)
        ret, _, _ = g.run(client, cmd)
        self.assertEqual(ret, 0, "Failed to create files on mountpoint")
        g.log.info("Files created successfully on mountpoint")

        # Create data such that hard limit is crossed
        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s ; "
               "for i in `seq 1 10` ; "
               "do dd if=/dev/zero of=small$i "
               "bs=3M "
               "count=1 ; "
               "done" % mount_dir)
        ret, _, _ = g.run(client, cmd)
        self.assertEqual(ret, 1, "Failed: Files created successfully in spite "
                                 "of crossing hard-limit")
        g.log.info("Files creation stopped on mountpoint once exceeded "
                   "hard limit")

        # Validate if the Quota limit set is correct and hard limit is reached
        # by checking the quota list
        g.log.info("Validate if the Quota limit set is correct for the "
                   "volume %s", self.volname)
        ret = quota_validate(self.mnode, self.volname, path=path,
                             hard_limit=1073741824, avail_space=0,
                             sl_exceeded=True, hl_exceeded=True)
        self.assertTrue(ret, ("Quota Limit of 1 GB was not set properly on the"
                              " volume %s", self.volname))
        g.log.info("Successfully Validated Quota Limit of 1 GB is set on "
                   "volume %s", self.volname)

        # Set Quota limit as decimal value eg. 1.5 GB 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="1.5GB")
        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)

        # Create data such that soft limit is crossed but not the hard limit
        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s ; "
               "for i in `seq 103 152` ; "
               "do dd if=/dev/zero of=foo$i "
               "bs=10M "
               "count=1 ; "
               "done" % mount_dir)
        ret, _, _ = g.run(client, cmd)
        self.assertEqual(ret, 0, "Failed to create files on mountpoint")
        g.log.info("Files created successfully on mountpoint")

        # Create data such that hard limit is crossed
        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s ; "
               "for i in `seq 1 10` ; "
               "do dd if=/dev/zero of=medium$i "
               "bs=5M "
               "count=1 ; "
               "done" % mount_dir)
        ret, _, _ = g.run(client, cmd)
        self.assertEqual(ret, 1, "Failed: Files created successfully in spite "
                                 "of crossing hard-limit")
        g.log.info("Files creation stopped on mountpoint once exceeded "
                   "hard limit")

        # Validate if the Quota limit set is correct and hard limit is reached
        # by checking the quota list
        g.log.info("Validate if the Quota limit set is correct for the "
                   "volume %s", self.volname)
        ret = quota_validate(self.mnode, self.volname, path=path,
                             hard_limit=1610612736, avail_space=0,
                             sl_exceeded=True, hl_exceeded=True)
        self.assertTrue(ret, ("Quota Limit of 1.5GB was not set properly on "
                              "the volume %s", self.volname))
        g.log.info("Successfully Validated Quota Limit of 1.5 GB is set on "
                   "volume %s", self.volname)

        # Set Quota limit of 10 GB 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="10GB")
        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)

        # Create data such that soft limit is crossed but not the hard limit
        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s ; "
               "for i in `seq 1 17` ; "
               "do dd if=/dev/zero of=large$i "
               "bs=500M "
               "count=1 ; "
               "done" % mount_dir)
        ret, _, _ = g.run(client, cmd)
        self.assertEqual(ret, 0, "Failed to create files on mountpoint")
        g.log.info("Files created successfully on mountpoint")

        # Create data such that hard limit is crossed
        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s ; "
               "for i in `seq 1 30` ; "
               "do dd if=/dev/zero of=largelimit$i "
               "bs=10M "
               "count=1 ; "
               "done" % mount_dir)
        ret, _, _ = g.run(client, cmd)
        self.assertEqual(ret, 1, "Failed: Files created successfully in spite "
                                 "of crossing hard-limit")
        g.log.info("Files creation stopped on mountpoint once exceeded "
                   "hard limit")

        # Validate if the Quota limit set is correct and hard limit is reached
        # by checking the quota list
        g.log.info("Validate if the Quota limit set is correct for the "
                   "volume %s", self.volname)
        ret = quota_validate(self.mnode, self.volname, path=path,
                             hard_limit=10737418240, avail_space=0,
                             sl_exceeded=True, hl_exceeded=True)
        self.assertTrue(ret, ("Quota Limit of 10GB was not set properly on the"
                              " volume %s", self.volname))
        g.log.info("Successfully Validated Quota Limit of 10 GB is set on "
                   "volume %s", self.volname)

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