summaryrefslogtreecommitdiffstats
path: root/tests/functional/nfs_ganesha/test_nfs_ganesha_volume_exports.py
blob: 700bd0ffe13daba590ee5877790bf1f75b3a05e7 (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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
#  Copyright (C) 2016-2017  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:
        Test Cases in this module tests the nfs ganesha exports,
        refresh configs, cluster enable/disable functionality.
"""

from copy import deepcopy
import os
import re
import sys
from time import sleep

from glusto.core import Glusto as g

from glustolibs.gluster.gluster_base_class import runs_on
from glustolibs.gluster.nfs_ganesha_libs import (
    NfsGaneshaClusterSetupClass,
    wait_for_nfs_ganesha_volume_to_get_exported,
    wait_for_nfs_ganesha_volume_to_get_unexported)
from glustolibs.gluster.nfs_ganesha_ops import (
    is_nfs_ganesha_cluster_in_healthy_state, set_acl, refresh_config,
    enable_nfs_ganesha, disable_nfs_ganesha, export_nfs_ganesha_volume,
    unexport_nfs_ganesha_volume)
from glustolibs.gluster.volume_ops import (volume_stop, volume_start)
from glustolibs.gluster.volume_libs import (
    get_volume_options, setup_volume, cleanup_volume,
    log_volume_info_and_status, wait_for_volume_process_to_be_online,
    volume_exists)
from glustolibs.io.utils import validate_io_procs
from glustolibs.gluster.exceptions import ExecutionError
from glustolibs.misc.misc_libs import upload_scripts
from glustolibs.gluster.lib_utils import get_servers_unused_bricks_dict


@runs_on([['replicated', 'distributed', 'distributed-replicated',
           'dispersed', 'distributed-dispersed'],
          ['nfs']])
class TestNfsGaneshaVolumeExports(NfsGaneshaClusterSetupClass):
    """
        Tests to verify Nfs Ganesha exports, cluster enable/disable
        functionality.
    """
    @classmethod
    def setUpClass(cls):
        """
        Setup nfs-ganesha if not exists.
        """
        cls.get_super_method(cls, 'setUpClass')()

        # Setup nfs-ganesha if not exists.
        ret = cls.setup_nfs_ganesha()
        if not ret:
            raise ExecutionError("Failed to setup nfs-ganesha cluster")
        g.log.info("nfs-ganesha cluster is healthy")

    def setUp(self):
        """
        Setup and mount volume
        """
        g.log.info("Starting to setup and mount volume %s", self.volname)
        ret = self.setup_volume_and_mount_volume(mounts=self.mounts)
        if not ret:
            raise ExecutionError("Failed to setup and mount volume %s"
                                 % self.volname)
        g.log.info("Successful in setup and mount volume %s", self.volname)

    def test_nfs_ganesha_export_after_vol_restart(self):
        """
        Tests script to check nfs-ganesha volume gets exported after
        multiple volume restarts.
        """
        for i in range(1, 6):
            g.log.info("Testing nfs ganesha export after volume stop/start."
                       "Count : %s", str(i))

            # Stopping volume
            ret = volume_stop(self.mnode, self.volname)
            self.assertTrue(ret, ("Failed to stop volume %s" % self.volname))

            # Waiting for few seconds for volume unexport. Max wait time is
            # 120 seconds.
            ret = wait_for_nfs_ganesha_volume_to_get_unexported(self.mnode,
                                                                self.volname)
            self.assertTrue(ret, ("Failed to unexport volume %s after "
                                  "stopping volume" % self.volname))

            # Starting volume
            ret = volume_start(self.mnode, self.volname)
            self.assertTrue(ret, ("Failed to start volume %s" % self.volname))

            # Waiting for few seconds for volume export. Max wait time is
            # 120 seconds.
            ret = wait_for_nfs_ganesha_volume_to_get_exported(self.mnode,
                                                              self.volname)
            self.assertTrue(ret, ("Failed to export volume %s after "
                                  "starting volume" % self.volname))

    def test_nfs_ganesha_enable_disable_cluster(self):
        """
        Tests script to check nfs-ganehsa volume gets exported after
        multiple enable/disable of cluster.
        """
        for i in range(1, 6):
            g.log.info("Executing multiple enable/disable of nfs ganesha "
                       "cluster. Count : %s ", str(i))

            ret, _, _ = disable_nfs_ganesha(self.mnode)
            self.assertEqual(ret, 0, "Failed to disable nfs-ganesha cluster")

            sleep(2)
            vol_option = get_volume_options(self.mnode, self.volname,
                                            option='ganesha.enable')
            if vol_option is None:
                self.assertEqual(ret, 0, ("Failed to get ganesha.enable volume"
                                          " option for %s " % self.volume))

            self.assertEqual(vol_option.get('ganesha.enable'), 'off', "Failed "
                             "to unexport volume by default after disabling "
                             "cluster")

            ret, _, _ = enable_nfs_ganesha(self.mnode)
            self.assertEqual(ret, 0, "Failed to enable nfs-ganesha cluster")

            # Check nfs-ganesha status
            for itr in range(5):
                ret = is_nfs_ganesha_cluster_in_healthy_state(self.mnode)
                if ret:
                    g.log.info("nfs-ganesha cluster is healthy")
                    break
                g.log.warning("nfs-ganesha cluster is not healthy. "
                              "Iteration: %s", str(itr))
                self.assertEqual(itr, 4, "Wait timeout: nfs-ganesha cluster "
                                         "is not healthy")
                sleep(3)

            vol_option = get_volume_options(self.mnode, self.volname,
                                            option='ganesha.enable')
            if vol_option is None:
                self.assertEqual(ret, 0, ("Failed to get ganesha.enable volume"
                                          " option for %s " % self.volume))

            self.assertEqual(vol_option.get('ganesha.enable'), 'off', "Volume "
                             "%s is exported by default after disable and "
                             "enable of cluster which is unexpected." %
                             self.volname)

            # Export volume after disable and enable of cluster
            ret, _, _ = export_nfs_ganesha_volume(mnode=self.mnode,
                                                  volname=self.volname)
            self.assertEqual(ret, 0, ("Failed to export volume %s "
                                      "after disable and enable of cluster"
                                      % self.volname))

            # Wait for volume to get exported
            ret = wait_for_nfs_ganesha_volume_to_get_exported(self.mnode,
                                                              self.volname)
            self.assertTrue(ret, "Volume %s is not exported after setting "
                                 "ganesha.enable 'on'" % self.volname)
            g.log.info("Exported volume after enabling nfs-ganesha cluster")

    def tearDown(self):
        """
        Unexport volume
        Unmount and cleanup volume
        """
        # Unexport volume
        unexport_nfs_ganesha_volume(self.mnode, self.volname)
        ret = wait_for_nfs_ganesha_volume_to_get_unexported(self.mnode,
                                                            self.volname)
        if not ret:
            raise ExecutionError("Volume %s is not unexported" % self.volname)

        # Unmount volume
        ret = self.unmount_volume(self.mounts)
        if ret:
            g.log.info("Successfully unmounted the volume")
        else:
            g.log.error("Failed to unmount volume")

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

    @classmethod
    def tearDownClass(cls):
        cls.get_super_method(cls, 'tearDownClass')(
            delete_nfs_ganesha_cluster=False)


@runs_on([['replicated', 'distributed', 'distributed-replicated',
           'dispersed', 'distributed-dispersed'],
          ['nfs']])
class TestNfsGaneshaVolumeExportsWithIO(NfsGaneshaClusterSetupClass):
    """
    Tests to verify nfs ganesha features when IO is in progress.
    """
    @classmethod
    def setUpClass(cls):
        """
        Setup nfs-ganesha if not exists.
        Upload IO scripts to clients
        """
        cls.get_super_method(cls, 'setUpClass')()

        # Setup nfs-ganesha if not exists.
        ret = cls.setup_nfs_ganesha()
        if not ret:
            raise ExecutionError("Failed to setup nfs-ganesha cluster")
        g.log.info("nfs-ganesha cluster is healthy")

        # Upload IO scripts for running IO on mounts
        g.log.info("Upload io scripts to clients %s for running IO on "
                   "mounts", cls.clients)
        cls.script_upload_path = ("/usr/share/glustolibs/io/scripts/"
                                  "file_dir_ops.py")
        ret = upload_scripts(cls.clients, cls.script_upload_path)
        if not ret:
            raise ExecutionError("Failed to upload IO scripts to clients %s" %
                                 cls.clients)
        g.log.info("Successfully uploaded IO scripts to clients %s",
                   cls.clients)

    def setUp(self):
        """
        Setup and mount volume
        """
        g.log.info("Starting to setup and mount volume %s", self.volname)
        ret = self.setup_volume_and_mount_volume(mounts=self.mounts)
        if not ret:
            raise ExecutionError("Failed to setup and mount volume %s"
                                 % self.volname)
        g.log.info("Successful in setup and mount volume %s", self.volname)

    def test_nfs_ganesha_multiple_refresh_configs(self):
        """
        Tests script to check nfs-ganehsa volume gets exported and IOs
        are running after running multiple refresh configs.
        """
        self.acl_check_flag = False

        # Starting IO on the mounts
        all_mounts_procs = []
        count = 1
        for mount_obj in self.mounts:
            g.log.info("Starting IO on %s:%s", mount_obj.client_system,
                       mount_obj.mountpoint)
            cmd = ("/usr/bin/env python%d %s create_deep_dirs_with_files "
                   "--dirname-start-num %d "
                   "--dir-depth 2 "
                   "--dir-length 10 "
                   "--max-num-of-dirs 5 "
                   "--num-of-files 5 %s" % (
                       sys.version_info.major, self.script_upload_path, count,
                       mount_obj.mountpoint))
            proc = g.run_async(mount_obj.client_system, cmd,
                               user=mount_obj.user)
            all_mounts_procs.append(proc)
            count = count + 10

        for itr in range(1, 7):
            # Enabling/Disabling ACLs to modify the export configuration
            # before running refresh config
            if itr % 2 == 0:
                # Disable ACL
                ret = set_acl(self.mnode, self.volname, False, False)
                self.assertTrue(ret, ("Failed to disable acl on %s"
                                      % self.volname))
                self.acl_check_flag = False
            else:
                # Enable ACL
                ret = set_acl(self.mnode, self.volname, True, False)
                self.assertTrue(ret, ("Failed to enable acl on %s"
                                      % self.volname))
                self.acl_check_flag = True

            ret = refresh_config(self.mnode, self.volname)
            self.assertTrue(ret, ("Failed to run refresh config"
                                  "for volume %s" % self.volname))
            g.log.info("Refresh-config completed. Iteration:%s", str(itr))

        # Check nfs-ganesha cluster status
        ret = is_nfs_ganesha_cluster_in_healthy_state(self.mnode)
        self.assertTrue(ret, "nfs-ganesha cluster is not healthy after "
                             "multiple refresh-config operations")

        # Validate IO
        g.log.info("Validating IO")
        ret = validate_io_procs(all_mounts_procs, self.mounts)
        self.assertTrue(ret, "IO failed on some of the clients")
        g.log.info("Successfully validated all IO")

    def tearDown(self):
        """
        Disbale ACL if enabled
        Unexport volume
        Unmount and cleanup volume
        """
        if self.acl_check_flag:
            ret = set_acl(self.mnode, self.volname, False)
            if not ret:
                raise ExecutionError("Failed to disable acl on %s"
                                     % self.volname)
            self.acl_check_flag = False

        # Unexport volume
        unexport_nfs_ganesha_volume(self.mnode, self.volname)
        ret = wait_for_nfs_ganesha_volume_to_get_unexported(self.mnode,
                                                            self.volname)
        if not ret:
            raise ExecutionError("Volume %s is not unexported." % self.volname)

        # Unmount volume
        ret = self.unmount_volume(self.mounts)
        if ret:
            g.log.info("Successfully unmounted the volume")
        else:
            g.log.error("Failed to unmount volume")

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

    @classmethod
    def tearDownClass(cls):
        cls.get_super_method(cls, 'tearDownClass')(
            delete_nfs_ganesha_cluster=False)


@runs_on([['replicated', 'distributed', 'distributed-replicated',
           'dispersed', 'distributed-dispersed'],
          ['nfs']])
class TestNfsGaneshaMultiVolumeExportsWithIO(NfsGaneshaClusterSetupClass):
    """
    Tests to verify multiple volumes gets exported when IO is in progress.
    """
    @classmethod
    def setUpClass(cls):
        """
        Setup nfs-ganesha if not exists.
        Upload IO scripts to clients
        """
        cls.get_super_method(cls, 'setUpClass')()

        # Setup nfs-ganesha if not exists.
        ret = cls.setup_nfs_ganesha()
        if not ret:
            raise ExecutionError("Failed to setup nfs-ganesha cluster")
        g.log.info("nfs-ganesha cluster is healthy")

        # Upload IO scripts for running IO on mounts
        g.log.info("Upload io scripts to clients %s for running IO on "
                   "mounts", cls.clients)
        cls.script_upload_path = ("/usr/share/glustolibs/io/scripts/"
                                  "file_dir_ops.py")
        ret = upload_scripts(cls.clients, cls.script_upload_path)
        if not ret:
            raise ExecutionError("Failed to upload IO scripts to clients %s" %
                                 cls.clients)
        g.log.info("Successfully uploaded IO scripts to clients %s",
                   cls.clients)

    def setUp(self):
        """
        Setup and mount volume
        """
        g.log.info("Starting to setup and mount volume %s", self.volname)
        ret = self.setup_volume_and_mount_volume(mounts=self.mounts)
        if not ret:
            raise ExecutionError("Failed to setup and mount volume %s"
                                 % self.volname)
        g.log.info("Successful in setup and mount volume %s", self.volname)

    def test_nfs_ganesha_export_with_multiple_volumes(self):
        """
        Test case to verify multiple volumes gets exported when IO is in
        progress.
        """
        # Starting IO on the mounts
        all_mounts_procs = []
        count = 1
        for mount_obj in self.mounts:
            g.log.info("Starting IO on %s:%s", mount_obj.client_system,
                       mount_obj.mountpoint)
            cmd = ("/usr/bin/env python%d %s create_deep_dirs_with_files "
                   "--dirname-start-num %d "
                   "--dir-depth 2 "
                   "--dir-length 10 "
                   "--max-num-of-dirs 5 "
                   "--num-of-files 5 %s" % (
                       sys.version_info.major, self.script_upload_path, count,
                       mount_obj.mountpoint))
            proc = g.run_async(mount_obj.client_system, cmd,
                               user=mount_obj.user)
            all_mounts_procs.append(proc)
            count = count + 10

        # Create and export five new volumes
        for i in range(5):
            # Check availability of bricks to create new volume
            num_of_unused_bricks = 0

            servers_unused_bricks_dict = get_servers_unused_bricks_dict(
                self.mnode, self.all_servers, self.all_servers_info)
            for each_server_unused_bricks_list in list(
                    servers_unused_bricks_dict.values()):
                num_of_unused_bricks = (num_of_unused_bricks +
                                        len(each_server_unused_bricks_list))

            if num_of_unused_bricks < 2:
                self.assertNotEqual(i, 0, "New volume cannot be created due "
                                          "to unavailability of bricks.")
                g.log.warning("Tried to create five new volumes. But could "
                              "create only %s volume due to unavailability "
                              "of bricks.", str(i))
                break

            self.volume['name'] = "nfsvol" + str(i)
            self.volume['voltype']['type'] = 'distributed'
            self.volume['voltype']['replica_count'] = 1
            self.volume['voltype']['dist_count'] = 2

            new_vol = self.volume['name']

            # Create volume
            ret = setup_volume(mnode=self.mnode,
                               all_servers_info=self.all_servers_info,
                               volume_config=self.volume, force=True)
            if not ret:
                self.assertTrue(ret, "Setup volume [%s] failed" % self.volume)

            g.log.info("Wait for volume processes to be online")
            ret = wait_for_volume_process_to_be_online(self.mnode, new_vol)
            self.assertTrue(ret, "Volume %s process not online despite "
                                 "waiting for 300 seconds" % new_vol)

            # Export volume with nfs ganesha
            ret, _, _ = export_nfs_ganesha_volume(mnode=self.mnode,
                                                  volname=new_vol)
            self.assertEqual(ret, 0, ("Failed to export volume %s "
                                      "using nfs-ganesha" % new_vol))

            # Wait for volume to get exported
            ret = wait_for_nfs_ganesha_volume_to_get_exported(self.mnode,
                                                              new_vol)
            self.assertTrue(ret, "Volume %s is not exported after setting "
                                 "ganesha.enable 'on'" % new_vol)
            g.log.info("Exported nfs-ganesha volume %s", new_vol)

            # Log Volume Info and Status
            ret = log_volume_info_and_status(self.mnode, new_vol)
            self.assertTrue(ret, "Logging volume %s info and status failed"
                            % new_vol)

        # Validate IO
        g.log.info("Validating IO")
        ret = validate_io_procs(all_mounts_procs, self.mounts)
        self.assertTrue(ret, "IO failed on some of the clients")
        g.log.info("Successfully validated all IO")

    def tearDown(self):
        """
        Unexport volumes
        Unmount and cleanup volumes
        """
        # Cleanup volumes created in test case
        for i in range(5):
            vol = "nfsvol" + str(i)
            # Unexport and cleanup volume if exists
            if volume_exists(self.mnode, vol):
                unexport_nfs_ganesha_volume(self.mnode, vol)
                ret = wait_for_nfs_ganesha_volume_to_get_unexported(
                    self.mnode, vol)
                if not ret:
                    raise ExecutionError("Volume %s is not unexported." % vol)

                ret = cleanup_volume(mnode=self.mnode, volname=vol)
                if not ret:
                    raise ExecutionError("Cleanup volume %s failed" % vol)

        # Unexport pre existing volume
        unexport_nfs_ganesha_volume(self.mnode, self.volname)
        ret = wait_for_nfs_ganesha_volume_to_get_unexported(self.mnode,
                                                            self.volname)
        if not ret:
            raise ExecutionError("Volume %s is not unexported." % self.volname)

        # Unmount pre existing volume
        ret = self.unmount_volume(self.mounts)
        if ret:
            g.log.info("Successfully unmounted the volume")
        else:
            g.log.error("Failed to unmount volume")

        # Cleanup pre existing volume
        ret = self.cleanup_volume()
        if not ret:
            raise ExecutionError("Failed to cleanup volume")
        g.log.info("Cleanup volume %s completed successfully", self.volname)

    @classmethod
    def tearDownClass(cls):
        cls.get_super_method(cls, 'tearDownClass')(
            delete_nfs_ganesha_cluster=False)


@runs_on([['replicated', 'distributed', 'distributed-replicated',
           'dispersed', 'distributed-dispersed'],
          ['nfs']])
class TestNfsGaneshaSubDirExportsWithIO(NfsGaneshaClusterSetupClass):
    """
    Tests to verify nfs-ganesha sub directory exports.
    """
    @classmethod
    def setUpClass(cls):
        """
        Setup nfs-ganesha if not exists.
        Upload IO scripts to clients
        """
        cls.get_super_method(cls, 'setUpClass')()

        # Setup nfs-ganesha if not exists.
        ret = cls.setup_nfs_ganesha()
        if not ret:
            raise ExecutionError("Failed to setup nfs-ganesha cluster")
        g.log.info("nfs-ganesha cluster is healthy")

        # Upload IO scripts for running IO on mounts
        g.log.info("Upload io scripts to clients %s for running IO on "
                   "mounts", cls.clients)
        script_local_path = ("/usr/share/glustolibs/io/scripts/"
                             "file_dir_ops.py")
        cls.script_upload_path = ("/usr/share/glustolibs/io/scripts/"
                                  "file_dir_ops.py")
        ret = upload_scripts(cls.clients, script_local_path)
        if not ret:
            raise ExecutionError("Failed to upload IO scripts to clients %s" %
                                 cls.clients)
        g.log.info("Successfully uploaded IO scripts to clients %s",
                   cls.clients)

    def start_and_wait_for_io_to_complete(self, mount_objs):
        """
        This module start IO on clients and wait for io to complete.
        Args:
            mount_objs (lis): List of mounts
        Returns:
            True if IO is success, False otherwise.
        """
        # Start IO on mounts
        g.log.info("Starting IO on all mounts.")
        self.all_mounts_procs = []
        for mount_obj in mount_objs:
            cmd = ("/usr/bin/env python%d %s create_deep_dirs_with_files "
                   "--dirname-start-num %d "
                   "--dir-depth 2 "
                   "--dir-length 15 "
                   "--max-num-of-dirs 5 "
                   "--num-of-files 10 %s" % (
                       sys.version_info.major, self.script_upload_path,
                       self.dir_start, mount_obj.mountpoint))
            proc = g.run_async(mount_obj.client_system, cmd,
                               user=mount_obj.user)
            self.all_mounts_procs.append(proc)
            self.dir_start += 10

        # Adding a delay of 15 seconds giving some time to fill data
        sleep(15)

        # Validate IO
        ret = validate_io_procs(self.all_mounts_procs, self.mounts)
        if not ret:
            g.log.error("IO failed on some of the clients")
            return False
        return True

    def setUp(self):
        """
        Setup and mount volume
        Write data on mounts and select sub-directory required for the test
        and unmount the existing mounts.
        """
        # Counter for directory start number
        self.dir_start = 1

        g.log.info("Starting to setup and mount volume %s", self.volname)
        ret = self.setup_volume_and_mount_volume(mounts=self.mounts)
        if not ret:
            raise ExecutionError("Failed to setup and mount volume %s"
                                 % self.volname)
        g.log.info("Successful in setup and mount volume %s", self.volname)

        ret = self.start_and_wait_for_io_to_complete(self.mounts)
        self.assertTrue(ret, "IO failed on one or more clients")

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

        # Select the subdirectory required for the test.
        cmd = "find %s -type d -links 2 | grep -ve '.trashcan'" % mountpoint
        ret, out, _ = g.run(client, cmd)
        if ret != 0:
            raise ExecutionError("Failed to list the deep level directories")
        self.subdir_path = out.split("\n")[0]

        _rc = True
        for mount_obj in self.mounts:
            ret = mount_obj.unmount()
            if not ret:
                g.log.error("Unable to unmount volume '%s:%s' on '%s:%s'",
                            mount_obj.server_system, mount_obj.volname,
                            mount_obj.client_system, mount_obj.mountpoint)
                _rc = False
        if not _rc:
            raise ExecutionError("Unmount of all mounts are not successful")

        # Mount objects for sub-directory mount
        self.sub_dir_mounts = deepcopy(self.mounts)

    def test_nfs_ganesha_subdirectory_mount_from_client_side(self):
        """
        Tests script to verify nfs-ganesha subdirectory mount from client side
        succeeds and able to write IOs.
        """
        for mount_obj in self.sub_dir_mounts:
            subdir_to_mount = self.subdir_path.replace(mount_obj.mountpoint,
                                                       '')
            if not subdir_to_mount.startswith(os.path.sep):
                subdir_to_mount = os.path.sep + subdir_to_mount

            mount_obj.volname = mount_obj.volname + subdir_to_mount
            if not mount_obj.is_mounted():
                ret = mount_obj.mount()
                self.assertTrue(ret, ("Unable to mount volume '%s:%s' "
                                      "on '%s:%s'"
                                      % (mount_obj.server_system,
                                         mount_obj.volname,
                                         mount_obj.client_system,
                                         mount_obj.mountpoint)))

        ret = self.start_and_wait_for_io_to_complete(self.sub_dir_mounts)
        self.assertTrue(ret, ("Failed to write IOs when sub directory is"
                              " mounted from client side"))
        g.log.info("IO successful on all clients")

    def test_nfs_ganesha_subdirectory_mount_from_server_side(self):
        """
        Tests script to verify nfs ganesha subdirectory mount from server
        side succeeds and able to write IOs.
        """
        subdir_to_mount = self.subdir_path.replace(self.mounts[0].mountpoint,
                                                   '')
        if not subdir_to_mount.startswith(os.path.sep):
            subdir_to_mount = os.path.sep + subdir_to_mount

        subdir = self.volname + subdir_to_mount

        for mount_obj in self.sub_dir_mounts:
            mount_obj.volname = subdir

        export_file = ("/var/run/gluster/shared_storage/nfs-ganesha/exports/"
                       "export.%s.conf" % self.volname)
        cmd = (r"sed -i  s/'Path = .*'/'Path = \"\/%s\";'/g %s"
               % (re.escape(subdir), export_file))
        ret, _, _ = g.run(self.mnode, cmd)
        self.assertEqual(ret, 0, ("Unable to change Path info to %s in %s"
                                  % ("/" + subdir, export_file)))

        cmd = ("sed -i  's/volume=.*/& \\n volpath=\"%s\";/g' %s"
               % (re.escape(subdir_to_mount), export_file))
        ret, _, _ = g.run(self.mnode, cmd)
        self.assertEqual(ret, 0, ("Unable to add volpath info to %s in %s"
                                  % ("/" + subdir, export_file)))

        cmd = (r"sed -i  s/'Pseudo=.*'/'Pseudo=\"\/%s\";'/g %s"
               % (re.escape(subdir), export_file))
        ret, _, _ = g.run(self.mnode, cmd)
        self.assertEqual(ret, 0, ("Unable to change pseudo Path info to "
                                  "%s in %s" % ("/" + subdir, export_file)))

        # Stop and start volume to take the modified export file to effect.
        # Stopping volume
        ret = volume_stop(self.mnode, self.volname)
        self.assertTrue(ret, ("Failed to stop volume %s" % self.volname))

        # Waiting for few seconds for volume unexport. Max wait time is
        # 120 seconds.
        ret = wait_for_nfs_ganesha_volume_to_get_unexported(self.mnode,
                                                            self.volname)
        self.assertTrue(ret, ("Failed to unexport volume %s after "
                              "stopping volume" % self.volname))

        # Starting volume
        ret = volume_start(self.mnode, self.volname)
        self.assertTrue(ret, ("Failed to start volume %s" % self.volname))

        # Waiting for few seconds for volume export. Max wait time is
        # 120 seconds.
        ret = wait_for_nfs_ganesha_volume_to_get_exported(self.mnode, subdir)
        self.assertTrue(ret, ("Failed to export sub directory %s after "
                              "starting volume" % subdir))

        for mount_obj in self.sub_dir_mounts:
            if not mount_obj.is_mounted():
                ret = mount_obj.mount()
                self.assertTrue(ret, ("Unable to mount volume '%s:%s' "
                                      "on '%s:%s'"
                                      % (mount_obj.server_system,
                                         mount_obj.volname,
                                         mount_obj.client_system,
                                         mount_obj.mountpoint)))

        ret = self.start_and_wait_for_io_to_complete(self.sub_dir_mounts)
        self.assertTrue(ret, ("Failed to write IOs when sub directory is"
                              " mounted from server side"))
        g.log.info("IO successful on clients")

    def tearDown(self):
        """
        Unexport volume
        Unmount and cleanup volume
        """
        # Unexport volume
        ret, _, _ = unexport_nfs_ganesha_volume(self.mnode, self.volname)
        if ret != 0:
            raise ExecutionError("Failed to unexport volume %s" % self.volname)

        # Unmount volume
        ret = self.unmount_volume(self.sub_dir_mounts)
        if ret:
            g.log.info("Successfully unmounted the volume")
        else:
            g.log.error("Failed to unmount volume")

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

    @classmethod
    def tearDownClass(cls):
        cls.get_super_method(cls, 'tearDownClass')(
            delete_nfs_ganesha_cluster=False)