summaryrefslogtreecommitdiffstats
path: root/tests/functional/snapshot/test_validate_snap_del_gd_down.py
blob: fa14b1e1f2c7b589dafa64501bae895f6e0fc94d (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
#  Copyright (C) 2017-2018  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:

This test cases will validate snapshot delete behaviour
when glusterd is down on one node.

"""
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.gluster_init import stop_glusterd, start_glusterd
from glustolibs.gluster.snap_ops import (get_snap_list, snap_delete,
                                         snap_delete_all, snap_create)


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

    def setUp(self):

        # Setting and Mounting the volume
        GlusterBaseClass.setUp.im_func(self)
        g.log.info("Starting to Set and Mount Volume")
        ret = self.setup_volume_and_mount_volume(mounts=self.mounts)
        if not ret:
            raise ExecutionError("Failed to setup volume %s" % self.volname)
        g.log.info("Volume %s has been setup successfully", self.volname)

    def tearDown(self):
        # deleting created snapshots
        ret, _, _ = snap_delete_all(self.mnode)
        if ret != 0:
            raise ExecutionError("Failed to delete snapshot of volume"
                                 "%s" % self.volname)
        g.log.info("Successfully deleted snapshots of volume %s", self.volname)

        # Unmount and volume cleanup
        g.log.info("Starting to Unmount and cleanup volume")
        ret = self.unmount_volume_and_cleanup_volume(mounts=self.mounts)
        if not ret:
            raise ExecutionError("Failed to Unmount and Clean Volume")
        g.log.info("Successful in Unmount and Clean Volume")

    def test_snap_del_gd_down(self):

        """
        Steps:
        1. Create volumes
        2. Create 5 snapshots
        3. Bring one node down
        4. Delete one snapshot
        5. list snapshot and validate delete
        6. Bring up the downed node
        7. Validate number of snaps after handshake on the
           brought down node.
        """
        # Create 5 snapshot
        g.log.info("Creating 5 snapshots for volume %s", self.volname)
        for i in range(0, 5):
            ret, _, _ = snap_create(self.mnode, self.volname, "snapy%s" % i)
            self.assertEqual(ret, 0, ("Failed to create snapshot for %s"
                                      % self.volname))
            g.log.info("Snapshot %s created successfully for volume  %s",
                       "snapy%s" % i, self.volname)

        # Check for no of snaps using snap_list it should be 5 now
        snap_list = get_snap_list(self.mnode)
        self.assertEqual(5, len(snap_list), "No of snaps not consistent "
                         "for volume %s" % self.volname)
        g.log.info("Successfully validated number of snaps.")

        # Stopping glusterd service on server[1]
        ret = stop_glusterd(self.servers[1])
        self.assertTrue(ret, "Failed to stop glusterd service on node : %s"
                        % self.servers[1])
        g.log.info("Stopped glusterd services successfully on: %s",
                   self.servers[1])

        # Delete one snapshot snapy1
        ret, _, _ = snap_delete(self.servers[0], "snapy1")
        self.assertEqual(ret, 0, "Failed to delete snapshot snapy1")
        g.log.info("Successfully deleted snapshot of snapy1")

        # Check for no of snaps using snap_list it should be 4 now
        snap_list = get_snap_list(self.mnode)
        self.assertEqual(4, len(snap_list), "No of snaps not consistent "
                         "for volume %s" % self.volname)
        g.log.info("Successfully validated number of snaps.")

        # Starting glusterd services on server[1]
        ret = start_glusterd(self.servers[1])
        self.assertTrue(ret, "Failed to start glusterd on node "
                             ": %s" % self.servers[1])
        g.log.info("Started glusterd services successfully on: %s",
                   self.servers[1])

        # Check for no of snaps using snap_list it should be 4 for server[1]
        count = 0
        # putting wait here for glusterd handshake
        while count < 60:
            snap_list = get_snap_list(self.servers[1])
            if len(snap_list) == 4:
                break
            time.sleep(2)
            count += 2
        self.assertEqual(4, len(snap_list), "No of snaps not consistent "
                         "for volume %s" % self.volname)
        g.log.info("Successfully validated number of snaps.")