summaryrefslogtreecommitdiffstats
path: root/tests/functional/glusterd/test_volume_create_with_glusterd_restarts.py
blob: 1a7fe8a1be2478f4037e694309c1305543855ee2 (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
#  Copyright (C) 2017-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.

from time import sleep
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.volume_ops import (volume_create, volume_start)
from glustolibs.gluster.volume_libs import cleanup_volume
from glustolibs.gluster.peer_ops import is_peer_connected
from glustolibs.gluster.lib_utils import form_bricks_list


@runs_on([['distributed'], ['glusterfs']])
class TestVolumeCreateWithGlusterdRestarts(GlusterBaseClass):

    def tearDown(self):

        # wait till peers are in connected state
        count = 0
        while count < 60:
            ret = is_peer_connected(self.mnode, self.servers)
            if ret:
                break
            sleep(3)
            count += 1

        # clean up volumes
        ret = cleanup_volume(self.mnode, self.volname)
        if not ret:
            raise ExecutionError("Unable to delete volume % s" % self.volname)
        g.log.info("Volume deleted successfully : %s", self.volname)

        self.get_super_method(self, 'tearDown')()

    def test_volume_create_with_glusterd_restarts(self):
        # pylint: disable=too-many-statements
        """
        Test case:
        1) Create a cluster.
        2) Create volume using the first three nodes say N1, N2 and N3.
        3) While the create is happening restart the fourth node N4.
        4) Check if glusterd has crashed on any node.
        5) While the volume start is happening restart N4.
        6) Check if glusterd has crashed on any node.
        """

        # Fetching all the parameters for volume_create
        list_of_three_servers = []
        server_info_for_three_nodes = {}

        for server in self.servers[0:3]:
            list_of_three_servers.append(server)
            server_info_for_three_nodes[server] = self.all_servers_info[server]

        bricks_list = form_bricks_list(self.mnode, self.volname,
                                       3, list_of_three_servers,
                                       server_info_for_three_nodes)
        # Restarting glusterd in a loop
        restart_cmd = ("for i in `seq 1 5`; do "
                       "service glusterd restart; "
                       "systemctl reset-failed glusterd; "
                       "sleep 3; "
                       "done")
        proc1 = g.run_async(self.servers[3], restart_cmd)

        # After running restart in g.async adding 10 sec sleep
        sleep(10)

        # Creating volumes using 3 servers
        ret, _, _ = volume_create(self.mnode, self.volname,
                                  bricks_list)
        self.assertEqual(ret, 0, "Volume creation failed")
        g.log.info("Volume %s created successfully", self.volname)

        ret, _, _ = proc1.async_communicate()
        self.assertEqual(ret, 0, "Glusterd restart not working.")

        # Checking if peers are connected or not.
        count = 0
        while count < 60:
            ret = is_peer_connected(self.mnode, self.servers)
            if ret:
                break
            sleep(3)
            count += 1
        self.assertTrue(ret, "Peers are not in connected state.")
        g.log.info("Peers are in connected state.")

        # Restarting glusterd in a loop
        restart_cmd = ("for i in `seq 1 5`; do "
                       "service glusterd restart; "
                       "systemctl reset-failed glusted; "
                       "sleep 3; "
                       "done")
        proc1 = g.run_async(self.servers[3], restart_cmd)

        # After running restart in g.async adding 10 sec sleep
        sleep(10)

        # Start the volume created.
        ret, _, _ = volume_start(self.mnode, self.volname)
        self.assertEqual(ret, 0, "Volume start failed")
        g.log.info("Volume %s started successfully", self.volname)

        ret, _, _ = proc1.async_communicate()
        self.assertEqual(ret, 0, "Glusterd restart not working.")

        # Checking if peers are connected or not.
        count = 0
        while count < 60:
            ret = is_peer_connected(self.mnode, self.servers)
            if ret:
                break
            sleep(3)
            count += 1
        self.assertTrue(ret, "Peers are not in connected state.")
        g.log.info("Peers are in connected state.")