summaryrefslogtreecommitdiffstats
path: root/tests/functional/fuse_subdir/test_quota_limits_fusesubdir_.py
blob: 69daa8a91819575bb8f3223b40bc2f396841254b (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) 2017-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.
import copy
from glusto.core import Glusto as g
from glustolibs.gluster.gluster_base_class import (GlusterBaseClass,
                                                   runs_on)
from glustolibs.gluster.exceptions import ExecutionError
from glustolibs.gluster.quota_ops import (quota_enable,
                                          quota_limit_usage,
                                          is_quota_enabled,
                                          quota_fetch_list)
from glustolibs.gluster.glusterdir import mkdir
from glustolibs.gluster.auth_ops import set_auth_allow


@runs_on([['distributed-replicated', 'replicated', 'distributed',
           'dispersed', 'distributed-dispersed'],
          ['glusterfs']])
class FuseSubdirQuotaTest(GlusterBaseClass):
    """
    Test case validates fuse subdir functionality when quota is enabled
    on subdir
    """
    @classmethod
    def setUpClass(cls):
        """
        setup volume and mount volume
        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)

    def test_subdir_with_quota_limit(self):

        # pylint: disable=too-many-statements
        """
        Mount the volume
        Create 2 subdir on mount point
        dir1-> /level1/subdir1 dir2->/dlevel1/dlevel2/dlevel3/subdir2
        Auth allow - Client1(/level1/subdir1),
        Client2(/dlevel1/dlevel2/dlevel3/subdir2)
        Mount the subdir1 on client 1 and subdir2 on client2
        Enable Quota
        Verify Quota is enabled on volume
        Set quota limit as 1GB and 2GB on both subdirs respectively
        Perform a quota list operation
        Perform IO's on both subdir until quota limit is almost hit for subdir1
        Again Perform a quota list operation
        Run IO's on Client 1.This should fail
        Run IO's on Client2.This should pass
        """

        # Create deep subdirectories  subdir1 and subdir2 on mount point
        ret = mkdir(self.mounts[0].client_system, "%s/level1/subdir1"
                    % self.mounts[0].mountpoint, parents=True)
        self.assertTrue(ret, ("Failed to create directory '/level1/subdir1' on"
                              "volume %s from client %s"
                              % (self.mounts[0].volname,
                                 self.mounts[0].client_system)))
        ret = mkdir(self.mounts[0].client_system,
                    "%s/dlevel1/dlevel2/dlevel3/subdir2"
                    % self.mounts[0].mountpoint, parents=True)
        self.assertTrue(ret, ("Failed to create directory "
                              "'/dlevel1/dlevel2/dlevel3/subdir2' on"
                              "volume %s from client %s"
                              % (self.mounts[0].volname,
                                 self.mounts[0].client_system)))
        # unmount volume
        ret = self.unmount_volume(self.mounts)
        self.assertTrue(ret, "Volumes Unmount failed")
        g.log.info("Volumes Unmounted successfully")

        # Set authentication on the subdirectory subdir1
        # and subdir2
        g.log.info('Setting authentication on directories subdir1 and subdir2'
                   'for client %s and %s', self.clients[0], self.clients[1])
        ret = set_auth_allow(self.volname, self.mnode,
                             {'/level1/subdir1': [self.clients[0]],
                              '/dlevel1/dlevel2/dlevel3/subdir2':
                              [self.clients[1]]})
        self.assertTrue(ret,
                        'Failed to set Authentication on volume %s'
                        % self.volume)

        # Creating mount list for subdirectories
        self.subdir_mounts = [copy.deepcopy(self.mounts[0]),
                              copy.deepcopy(self.mounts[1])]
        self.subdir_mounts[0].volname = "%s/level1/subdir1" % self.volname
        self.subdir_mounts[1].volname = ("%s/dlevel1/dlevel2/dlevel3/subdir2"
                                         % self.volname)

        # Mount Subdirectory "subdir1" on client 1 and "subdir2" on client 2
        for mount_obj in self.subdir_mounts:
            ret = mount_obj.mount()
            self.assertTrue(ret, ("Failed to mount  %s on client"
                                  " %s" % (mount_obj.volname,
                                           mount_obj.client_system)))
            g.log.info("Successfully mounted %s on client %s",
                       mount_obj.volname,
                       mount_obj.client_system)
        g.log.info("Successfully mounted subdirectories on client1"
                   "and clients 2")

        # Enable quota on volume
        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)

        # Check if quota is enabled
        g.log.info("Validate Quota is enabled on the volume %s", self.volname)
        ret = is_quota_enabled(self.mnode, self.volname)
        self.assertTrue(ret, ("Quota is not enabled on the volume %s",
                              self.volname))
        g.log.info("Successfully Validated quota is enabled on volume %s",
                   self.volname)

        # Setting up path to set quota limit

        path1 = "/level1/subdir1"
        path2 = "/dlevel1/dlevel2/dlevel3/subdir2"

        # Set Quota limit on the subdirectory "subdir1"

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

        # Set Quota limit on the subdirectory "subdir2"

        g.log.info("Set Quota Limit on the path %s of the volume %s",
                   path2, self.volname)
        ret, _, _ = quota_limit_usage(self.mnode, self.volname,
                                      path2, limit="2GB")
        self.assertEqual(ret, 0, ("Failed to set quota limit on path %s of "
                                  " the volume %s", path2, self.volname))
        g.log.info("Successfully set the Quota limit on %s of the volume "
                   "%s", path2, self.volname)

        # Get Quota List on the volume

        g.log.info("Get Quota list on the volume %s",
                   self.volname)
        quota_list = quota_fetch_list(self.mnode, self.volname)

        self.assertIsNotNone(quota_list, ("Failed to get the quota list "
                                          "of the volume %s",
                                          self.volname))

        # Check for subdir1 path in quota list

        self.assertIn(path1, quota_list.keys(),
                      ("%s not part of the quota list %s even if "
                       "it is set on the volume %s", path1,
                       quota_list, self.volname))

        # Check for subdir2 path in quota list

        self.assertIn(path2, quota_list.keys(),
                      ("%s not part of the quota list %s even if "
                       "it is set on the volume %s", path2,
                       quota_list, self.volname))
        g.log.info("Successfully listed quota list %s of the "
                   "volume %s", quota_list, self.volname)

        # Create near to 1GB of data on both subdir mounts

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

        # Again Get Quota List on the volume

        g.log.info("Get Quota list on the volume %s",
                   self.volname)
        quota_list = quota_fetch_list(self.mnode, self.volname)

        self.assertIsNotNone(quota_list, ("Failed to get the quota list "
                                          "of the volume %s",
                                          self.volname))

        # Check for subdir1 path in quota list

        self.assertIn(path1, quota_list.keys(),
                      ("%s not part of the quota list %s even if "
                       "it is set on the volume %s", path1,
                       quota_list, self.volname))

        # Check for subdir2 path in quota list

        self.assertIn(path2, quota_list.keys(),
                      ("%s not part of the quota list %s even if "
                       "it is set on the volume %s", path2,
                       quota_list, self.volname))
        g.log.info("Successfully listed quota list %s of the "
                   "volume %s", quota_list, self.volname)

        # Again run IO's to check if quota limit is adhere for subdir1

        # Start IO's on subdir1
        g.log.info("Creating Files on %s:%s", self.clients[0],
                   self.subdir_mounts[0].mountpoint)
        cmd = ("cd %s ; for i in `seq 1024 1500` ;"
               "do dd if=/dev/urandom of=file$i bs=1M "
               "count=1;done" % (self.subdir_mounts[0].mountpoint))
        ret, _, _ = g.run(self.clients[0], cmd)
        if ret == 0:
            raise ExecutionError("IO was expected to Fail."
                                 "But it got passed")
        else:
            g.log.info("IO's failed as expected on %s:%s as quota "
                       "limit reached already",
                       self.clients[0], self.subdir_mounts[0].mountpoint)

        # Start IO's on subdir2
        g.log.info("Creating Files on %s:%s", self.clients[1],
                   self.subdir_mounts[1].mountpoint)
        cmd = ("cd %s ; for i in `seq 1024 1500` ;"
               "do dd if=/dev/urandom of=file$i bs=1M "
               "count=1;done" % (self.subdir_mounts[1].mountpoint))
        ret, _, _ = g.run(self.clients[1], cmd)
        self.assertEqual(ret, 0, ("Failed to create files on %s"
                                  % self.clients[1]))
        g.log.info("Files created successfully on %s:%s",
                   self.clients[1], self.subdir_mounts[1].mountpoint)

    def tearDown(self):
        """
        Clean up the volume and umount subdirectories from client
        """

        # Unmount sub-directories from client
        # Test needs to continue if  unmount fail.Not asserting here.
        ret = self.unmount_volume(self.subdir_mounts)
        if ret:
            g.log.info("Successfully unmounted all the subdirectories")
        else:
            g.log.error("Failed to unmount sub-directories")

        # cleanup-volume
        ret = self.cleanup_volume()
        if not ret:
            raise ExecutionError("Failed to Cleanup Volume")
        g.log.info("Cleanup volume %s Completed Successfully", self.volname)