summaryrefslogtreecommitdiffstats
path: root/tests/functional/glusterd/test_volume_delete.py
blob: 6f885f9a807150dd93f3b496d1bbaecc3aae1e58 (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
#  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.

import re
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.volume_libs import (cleanup_volume, get_volume_list,
                                            setup_volume)
from glustolibs.gluster.volume_ops import (volume_stop, volume_start)
from glustolibs.gluster.brick_libs import get_all_bricks
from glustolibs.gluster.gluster_init import stop_glusterd, start_glusterd
from glustolibs.gluster.peer_ops import (
    peer_probe_servers, wait_for_peers_to_connect)


@runs_on([['distributed', 'replicated', 'distributed-replicated', 'dispersed',
           'distributed-dispersed'], ['glusterfs']])
class TestVolumeDelete(GlusterBaseClass):

    @classmethod
    def setUpClass(cls):

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

        # check whether peers are in connected state
        ret = cls.validate_peers_are_connected()
        if not ret:
            raise ExecutionError("Peers are not in connected state")

    def tearDown(self):

        # start the volume, it should succeed
        ret, _, _ = volume_start(self.mnode, self.volname)
        self.assertEqual(ret, 0, "Volume stop failed")

        # start glusterd on all servers
        ret = start_glusterd(self.servers)
        if not ret:
            raise ExecutionError("Failed to start glusterd on all servers")

        for server in self.servers:
            ret = wait_for_peers_to_connect(server, self.servers)
            if not ret:
                ret = peer_probe_servers(server, self.servers)
                if not ret:
                    raise ExecutionError("Failed to peer probe all "
                                         "the servers")

        # clean up all volumes
        vol_list = get_volume_list(self.mnode)
        if vol_list is None:
            raise ExecutionError("Failed to get the volume list")

        for volume in vol_list:
            ret = cleanup_volume(self.mnode, volume)
            if not ret:
                raise ExecutionError("Unable to delete volume % s" % volume)
            g.log.info("Volume deleted successfully : %s", volume)

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

    @classmethod
    def tearDownClass(cls):

        # Calling GlusterBaseClass tearDown
        cls.get_super_method(cls, 'tearDownClass')()

    def test_vol_delete_when_one_of_nodes_is_down(self):

        # create a volume and start it
        ret = setup_volume(self.mnode, self.all_servers_info, self.volume)
        self.assertTrue(ret, "Failed to create and start the volume")
        g.log.info("Successfully created and started the volume")

        # get the bricks list
        bricks_list = get_all_bricks(self.mnode, self.volname)
        self.assertIsNotNone(bricks_list, "Failed to get the bricks list")

        # get a random node other than self.mnode
        if len(bricks_list) >= len(self.servers):
            random_index = random.randint(1, len(self.servers) - 1)
        else:
            random_index = random.randint(1, len(bricks_list) - 1)

        # stop glusterd on the random node

        node_to_stop_glusterd = self.servers[random_index]
        ret = stop_glusterd(node_to_stop_glusterd)
        self.assertTrue(ret, "Failed to stop glusterd")

        # stop the volume, it should succeed
        ret, _, _ = volume_stop(self.mnode, self.volname)
        self.assertEqual(ret, 0, "Volume stop failed")

        # try to delete the volume, it should fail
        ret, _, err = g.run(self.mnode, "gluster volume delete %s "
                            "--mode=script" % self.volname)
        self.assertNotEqual(ret, 0, "Volume delete succeeded when one of the"
                            " brick node is down")
        if re.search(r'Some of the peers are down', err):
            g.log.info("Volume delete failed with expected error message")
        else:
            g.log.info("Volume delete failed with unexpected error message")