summaryrefslogtreecommitdiffstats
path: root/tests/functional/glusterd/test_volume_status_show_bricks_online_though_brickpath_deleted.py
blob: 05bb47c40ad5fc3ac8de14b50acd3daea5acf0a7 (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
#  Copyright (C) 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.

""" Description:
      Volume status when one of the brickpath is not available.
"""

import random
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.brick_libs import (are_bricks_online, get_all_bricks,
                                           bring_bricks_online,
                                           bring_bricks_offline,
                                           are_bricks_offline)
from glustolibs.gluster.volume_ops import (volume_start)


@runs_on([['distributed', 'replicated', 'distributed-replicated',
           'dispersed', 'distributed-dispersed', 'arbiter',
           'distributed-arbiter'], ['glusterfs']])
class TestVolumeStatusShowBrickOnlineThoughBrickpathDeleted(GlusterBaseClass):
    def setUp(self):
        # calling GlusterBaseClass setUp
        self.get_super_method(self, 'setUp')()

        ret = self.setup_volume()
        if not ret:
            raise ExecutionError("Volume creation failed: %s"
                                 % self.volname)
        g.log.info("Volume created successfully : %s", self.volname)

    def tearDown(self):
        # Stopping the volume and Cleaning up the volume
        if self.check_for_remount:
            ret, _, _ = g.run(self.brick_node, 'mount %s' % self.node_brick)
            if ret:
                raise ExecutionError('Failed to remount brick %s'
                                     % self.node_brick)
            g.log.info('Successfully remounted %s with read-write option',
                       self.node_brick)
        ret = self.cleanup_volume()
        if not ret:
            raise ExecutionError("Failed to cleanup the volume %s"
                                 % self.volname)
        g.log.info("Volume deleted successfully: %s", self.volname)

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

    def test_volume_status_show_brick_online_though_brickpath_deleted(self):
        """
        Test Case:
        1) Create a volume and start it.
        2) Fetch the brick list
        3) Bring any one brick down umount the brick
        4) Force start the volume and check that all the bricks are not online
        5) Remount the removed brick and bring back the brick online
        6) Force start the volume and check if all the bricks are online
        """
        # Fetching the brick list
        brick_list = get_all_bricks(self.mnode, self.volname)
        self.assertIsNotNone(brick_list, "Failed to get the bricks in"
                             " the volume")

        # Bringing one brick down
        random_brick = random.choice(brick_list)
        ret = bring_bricks_offline(self.volname, random_brick)
        self.assertTrue(ret, "Failed to bring offline")

        # Creating a list of bricks to be removed
        remove_bricks_list = []
        remove_bricks_list.append(random_brick)

        # Checking if the brick is offline or not
        ret = are_bricks_offline(self.mnode, self.volname,
                                 remove_bricks_list)
        self.assertTrue(ret, 'Bricks %s are not offline'
                        % random_brick)
        g.log.info('Brick %s is offline as expected', random_brick)

        # umounting the brick which was made offline
        self.brick_node, volume_brick = random_brick.split(':')
        self.node_brick = '/'.join(volume_brick.split('/')[0:3])
        g.log.info('Start umount brick %s...', self.node_brick)
        ret, _, _ = g.run(self.brick_node, 'umount %s' % self.node_brick)
        self.assertFalse(ret, 'Failed to umount brick %s' % self.node_brick)
        g.log.info('Successfully umounted brick %s', self.node_brick)

        self.check_for_remount = True

        # Force starting the volume
        ret, _, _ = volume_start(self.mnode, self.volname, True)
        self.assertEqual(ret, 0, "Faile to force start volume")
        g.log.info("Successfully force start volume")

        # remounting the offline brick
        g.log.info('Start remount brick %s with read-write option...',
                   self.node_brick)
        ret, _, _ = g.run(self.brick_node, 'mount %s' % self.node_brick)
        self.assertFalse(ret, 'Failed to remount brick %s' % self.node_brick)
        g.log.info('Successfully remounted %s with read-write option',
                   self.node_brick)

        self.check_for_remount = False

        # Checking that all the bricks shouldn't be online
        ret = are_bricks_online(self.mnode, self.volname, brick_list)
        self.assertFalse(ret, "Unexpected: All the bricks are online")
        g.log.info("Expected: All the bricks are not online")

        # Bringing back the offline brick online
        ret = bring_bricks_online(self.mnode, self.volname, remove_bricks_list)
        self.assertTrue(ret, "Failed to bring bricks online")
        g.log.info("Successfully brought bricks online")

        # Force starting the volume
        ret, _, _ = volume_start(self.mnode, self.volname, True)
        self.assertEqual(ret, 0, "Faile to force start volume")
        g.log.info("Successfully force start volume")

        # Checking if all the bricks are online or not
        ret = are_bricks_online(self.mnode, self.volname, brick_list)
        self.assertTrue(ret, "Unexpected: All the bricks are not online")
        g.log.info("Expected: All the bricks are online")