summaryrefslogtreecommitdiffstats
path: root/tests/functional/arbiter/test_brick_down_cyclic.py
blob: 8639a4dc576e7d9a2c5ab78235b8535a9f407ce7 (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
#  Copyright (C) 2021  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.

# pylint: disable=too-many-statements, too-many-locals
import time
from glusto.core import Glusto as g
from glustolibs.gluster.exceptions import ExecutionError
from glustolibs.gluster.gluster_base_class import GlusterBaseClass, runs_on
from glustolibs.gluster.heal_ops import trigger_heal
from glustolibs.gluster.heal_libs import (is_volume_in_split_brain,
                                          is_heal_complete)
from glustolibs.gluster.brick_libs import (bring_bricks_offline,
                                           bring_bricks_online,
                                           are_bricks_offline,
                                           get_all_bricks,
                                           are_bricks_online)
from glustolibs.gluster.heal_libs import (
    monitor_heal_completion, are_all_self_heal_daemons_are_online)


@runs_on([['arbiter', 'distributed-arbiter'], ['glusterfs']])
class TestBrickDownHeal(GlusterBaseClass):

    @classmethod
    def setUpClass(cls):

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

        # Setup Volume and Mount Volume
        ret = cls.setup_volume_and_mount_volume(cls.mounts, True)
        if not ret:
            raise ExecutionError("Failed to Setup_Volume and Mount_Volume")

    @classmethod
    def tearDownClass(cls):
        """
        Cleanup Volume
        """
        ret = cls.unmount_volume_and_cleanup_volume(cls.mounts)
        if not ret:
            raise ExecutionError("Failed to create volume")

        cls.get_super_method(cls, 'tearDownClass')()

    def test_brick_down_heal(self):
        """
        - Run IO's from client on a single file
        - Now bring down bricks in cyclic order
        - kill brick 1, sleep for 5 seconds, bring brick 1 up, wait for 10s
        - Now repeat step3 for brick2 and brick 3
        - Repeat the cycle a few times
        - Trigger heal, check for split brain using command
        """
        # Write IO's
        self.all_mounts_procs = []
        cmd = ("for i in `seq 1 10`;"
               "do dd if=/dev/urandom of=%s/file$i bs=1K count=1;"
               "done" % self.mounts[0].mountpoint)
        proc = g.run_async(self.mounts[0].client_system, cmd)
        self.all_mounts_procs.append(proc)

        # Killing bricks in cyclic order
        bricks_list = get_all_bricks(self.mnode, self.volname)

        # Total number of cyclic brick-down cycles to be executed
        number_of_cycles = 0
        while number_of_cycles < 3:
            number_of_cycles += 1
            for brick in bricks_list:
                # Bring brick offline
                g.log.info('Bringing bricks %s offline', brick)
                ret = bring_bricks_offline(self.volname, [brick])
                self.assertTrue(ret, ("Failed to bring bricks %s offline"
                                      % brick))

                ret = are_bricks_offline(self.mnode, self.volname, [brick])
                self.assertTrue(ret, 'Bricks %s are not offline' % brick)
                g.log.info('Bringing bricks %s offline is successful', brick)

                # Introducing 5 second sleep when brick is down
                g.log.info("Waiting for 5 seconds, with ongoing IO while "
                           "brick %s is offline", brick)
                ret = time.sleep(5)

                # Bring brick online
                g.log.info('Bringing bricks %s online', brick)
                ret = bring_bricks_online(self.mnode, self.volname, [brick])
                self.assertTrue(ret, ("Failed to bring bricks %s online "
                                      % brick))
                g.log.info('Bricks %s are online', brick)

                # Introducing 10 second sleep when brick is up
                g.log.info("Waiting for 10 seconds,when "
                           "brick %s is online", brick)
                ret = time.sleep(10)

                # Check if bricks are online
                ret = are_bricks_online(self.mnode, self.volname, bricks_list)
                self.assertTrue(ret, 'Bricks %s are not online' % bricks_list)
                g.log.info('Bricks %s are online', bricks_list)

                # Check daemons
                g.log.info('Checking daemons...')
                ret = are_all_self_heal_daemons_are_online(self.mnode,
                                                           self.volname)
                self.assertTrue(ret, ("Some of the self-heal Daemons are "
                                      "offline"))
                g.log.info('All self-heal Daemons are online')

        # Trigger self heal
        ret = trigger_heal(self.mnode, self.volname)
        self.assertTrue(ret, 'Unable to trigger heal on volume')

        # Monitor heal completion
        ret = monitor_heal_completion(self.mnode, self.volname)
        self.assertTrue(ret, 'Heal has not yet completed')

        # Check if heal is completed
        ret = is_heal_complete(self.mnode, self.volname)
        self.assertTrue(ret, 'Heal is not complete')
        g.log.info('Heal is completed successfully')

        # Check for split-brain
        ret = is_volume_in_split_brain(self.mnode, self.volname)
        self.assertFalse(ret, 'Volume is in split-brain state')
        g.log.info('Volume is not in split-brain state')