summaryrefslogtreecommitdiffstats
path: root/tests/functional/snapshot/test_activate_on_create.py
blob: 3494bc332bc35612d68d000d08dc1ec7f4e05aae (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#  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:
       Enable snapshot activate-on-create and
       validate with multiple snapshot creation
"""
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.snap_ops import (snap_create,
                                         snap_delete_all,
                                         get_snap_info_by_snapname,
                                         get_snap_status_by_snapname,
                                         get_snap_config, set_snap_config)


@runs_on([['replicated', 'distributed', 'distributed-replicated',
           'dispersed', 'distributed-dispersed'],
          ['glusterfs']])
class TestActivateOnCreate(GlusterBaseClass):
    @classmethod
    def setUpClass(cls):
        """
        setup volume and initialize necessary variables
        """

        GlusterBaseClass.setUpClass.im_func(cls)
        g.log.info("Starting %s:", cls.__name__)
        # Setup volume and mount
        g.log.info("Starting to Setup Volume")
        ret = cls.setup_volume()
        if not ret:
            raise ExecutionError("Failed to Setup_Volume")
        g.log.info("Successful in Setup Volume")
        cls.option_enable = {'activate-on-create': 'enable'}
        cls.option_disable = {'activate-on-create': 'disable'}

    def tearDown(self):
        """
        tearDown for every test
        """
        ret, _, _ = snap_delete_all(self.mnode)
        if ret != 0:
            raise ExecutionError("Snapshot Delete Failed")
        ret, _, _ = set_snap_config(self.mnode, self.option_disable)
        if ret != 0:
            raise ExecutionError("Failed to execute set_snap_config")
        ret = get_snap_config(self.mnode, self.volname)
        if ret is None:
            raise ExecutionError("Failed to execute get_snap_config")
        if 'disable' not in ret['systemConfig']['activateOnCreate']:
            raise ExecutionError("Failed to disable activate-on-create")
        g.log.info("set_snap_config Success to disable "
                   "activate-on-create")

        # Calling GlusterBaseClass tearDown
        GlusterBaseClass.tearDown.im_func(self)

    @classmethod
    def tearDownClass(cls):
        """
        Clean up the volume & mount
        """
        # stopping the volume and clean up the volume
        g.log.info("Starting to Cleanup Volume")
        ret = cls.cleanup_volume()
        if not ret:
            raise ExecutionError("Failed to Cleanup Volume and mount")
        g.log.info("Successful in Cleanup Volume and mount")

        # calling GlusterBaseClass tearDownClass
        GlusterBaseClass.tearDownClass.im_func(cls)

    def test_activate_on_create(self):
        # pylint: disable=too-many-branches, too-many-statements
        """
        Verifying Snapshot activate on create

        * Create a default snapshot
        * Enable activate-on-create snapshot config option
        * Create more snapshots
            * Validate snapshot info after snapshot create. It should be in
              started state.
            * Validate snapshot status after snapshot create. It should be in
              started state.
        * Validate the default snapshot info and status. It should be in
          stopped state
        """

        # Create Default Snapshot
        g.log.info("Starting to Create Snapshot one")
        snap_default = "snap_%s" % self.volname
        ret, _, _ = snap_create(self.mnode, self.volname, snap_default)
        self.assertEqual(ret, 0, ("Snapshot Creation failed for %s",
                                  snap_default))
        g.log.info("Successfully created Snapshot %s of volume %s",
                   snap_default, self.volname)

        # Enable activate_on_create snapshot
        g.log.info("Enabling snapshot activate-on-create config option")
        ret, _, _ = set_snap_config(self.mnode, self.option_enable)
        self.assertEqual(ret, 0, "Failed to execute set_snap_config")
        g.log.info("Validating the value of activate-on-create")
        ret = get_snap_config(self.mnode, self.volname)
        self.assertIsNotNone(ret, ("Failed to execute get_snap_config"))
        self.assertIn('enable', (ret['systemConfig']['activateOnCreate']),
                      ("Failed to validate activate-on-create value as "
                       "'enabled'"))
        g.log.info("Successfully enabled activate-on-create")

        # Create Snapshots after enabling activate-on-create
        g.log.info("Starting to Create Snapshots")
        for snap_count in range(1, 5):
            snap_name = "snap_%s" % snap_count
            ret, _, _ = snap_create(self.mnode, self.volname, snap_name)
            self.assertEqual(ret, 0, ("Snapshot Creation failed for %s",
                                      snap_name))
            g.log.info("Successfully created Snapshot %s of volume %s",
                       snap_name, self.volname)

            # Validate Snapshot Info After Snapshot Create
            g.log.info("Validating 'snapshot info' after enabling "
                       "activate-on-create")
            ret = get_snap_info_by_snapname(self.mnode, snap_name)
            self.assertIsNotNone(ret, ("Failed to Fetch Snapshot info after "
                                       "activation for %s", snap_name))
            g.log.info("Snapshot info Success for %s",
                       ret['snapVolume']['status'])
            self.assertEqual(ret['snapVolume']['status'], 'Started',
                             ("Activated Snapshot is in Stopped State %s",
                              (ret['snapVolume']['status'])))
            g.log.info("Snapshot %s is Activated By Default - %s state",
                       snap_name, (ret['snapVolume']['status']))

            # Validate Snaphot Status After Snapshot Create
            g.log.info("Validating 'snapshot status' after enabling "
                       "activate-on-create")
            ret = get_snap_status_by_snapname(self.mnode, snap_name)
            self.assertIsNotNone("Failed to Fetch Snapshot status for %s",
                                 snap_name)
            g.log.info("Snapshot Status Success for %s", snap_name)
            for brick in ret['volume']['brick']:
                self.assertNotEqual(brick['pid'], 'N/A',
                                    ("Brick Path %s  Not Available for "
                                     "Activated Snapshot %s",
                                     (brick['path'], snap_name)))
            g.log.info("Success: Snapshot Brick Path Available")

        # Validate Snapshot Info for the 'default' snapshot
        # Expected to be Stopped
        g.log.info("Validating 'snapshot info' of the 'default' snapshot")
        ret = get_snap_info_by_snapname(self.mnode, snap_default)
        self.assertIsNotNone(ret, ("Failed to Fetch Snapshot info for %s",
                                   snap_default))
        g.log.info("Snapshot info Success for %s", ret['snapVolume']['status'])
        self.assertEqual(ret['snapVolume']['status'], 'Stopped',
                         ("Snapshot Status is not in Stopped State"))
        g.log.info("Snapshot %s is in Stopped state as it "
                   "is not Activated", snap_default)

        # Validate Snapshot Status for the 'default' snapshot
        # Expected to be N/A
        g.log.info("Validating 'snapshot status' of the 'default' snapshot")
        ret = get_snap_status_by_snapname(self.mnode, snap_default)
        self.assertIsNotNone(ret, ("Failed to Fetch Snapshot status for %s",
                                   snap_default))
        g.log.info("Snapshot Status Success for %s", snap_default)
        for brick in ret['volume']['brick']:
            self.assertEqual(brick['pid'], 'N/A',
                             ("Brick Pid available for %s", brick['path']))
        g.log.info("Success: Snapshot %s Brick PID is 'N/A'", snap_default)