summaryrefslogtreecommitdiffstats
path: root/tests/functional/bvt/test_sosreport_interoperability.py
blob: 76e1a023f826021082f734f71483d6286e2dc2c8 (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
#  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.

# pylint: disable=too-many-statements, too-many-locals

from unittest import SkipTest
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.glusterdir import get_dir_contents


@runs_on([['arbiter', 'distributed-replicated', 'distributed-dispersed'],
          ['glusterfs', 'cifs']])
class ValidateSosreportBehavior(GlusterBaseClass):
    """
    This testcase validates sosreport behavior with glusterfs
    """
    def setUp(self):
        # Calling GlusterBaseClass setUp
        self.get_super_method(self, 'setUp')()

        self.all_mounts_procs = []
        self.io_validation_complete = False

        # Setup Volume and Mount Volume
        ret = self.setup_volume_and_mount_volume(mounts=[self.mounts[0]],
                                                 volume_create_force=False)
        if not ret:
            raise ExecutionError("Failed to Setup_Volume and Mount_Volume")
        g.log.info("Successful in Setup Volume and Mount Volume")

    def tearDown(self):
        """tearDown"""
        ret = self.unmount_volume_and_cleanup_volume(mounts=[self.mounts[0]])
        if not ret:
            raise ExecutionError("Failed to umount the vol & cleanup Volume")
        g.log.info("Successful in umounting the volume and Cleanup")
        self.get_super_method(self, 'tearDown')()

    def test_sosreport_behavior_for_glusterfs(self):
        '''
        Test Steps:
        1) Download sos package if not installed
        2) Fetch Sos version for reference
        3) Note down all files in below locations before taking sosreport:
            a) /var/run/gluster
            b) /run/gluster
            c) /var/lib/glusterd
            d) /var/log/glusterfs
        4) Take the sosreport
        5) Again note down the list of all gluster file in locations mentioned
        in step#3. The list of files in this step should match step#3
        6) untar the sosreport to see if gluster files are packaged
        '''

        # Fetching sosreport version for information
        ret, version, _ = g.run(self.servers[1], 'rpm -qa|grep sos')
        if version[4:9] in ('3.8-6', '3.8-7', '3.8-8'):
            raise SkipTest("Skipping testcase as bug is fixed in "
                           "sosreport version 3.8.9")
        g.log.info("sos version is %s", version)

        # Noting down list of entries in gluster directories before sos
        gluster_contents_before_sos = []
        gluster_dirs = ('/var/run/gluster*', '/run/gluster*',
                        '/var/lib/glusterd', '/var/log/glusterfs')
        for gdir in gluster_dirs:
            ret = get_dir_contents(self.servers[1], gdir, recursive=True)
            gluster_contents_before_sos.append(ret)

        # Check for any existing sosreport
        var_tmp_dircontents_before_sos = get_dir_contents(self.servers[1],
                                                          '/var/tmp/')

        # Collect sosreport
        ret, _, err = g.run(self.servers[1],
                            'sosreport --batch --name=$HOSTNAME')
        self.assertEqual(ret, 0, "failed to fetch sosreport due to {}"
                         .format(err))

        # Checking /var/tmp contents
        var_tmp_dircontents_after_sos = get_dir_contents(self.servers[1],
                                                         '/var/tmp/')

        # Recheck if all gluster files still exist
        gluster_contents_after_sos = []
        for gdir in gluster_dirs:
            ret = get_dir_contents(self.servers[1], gdir, recursive=True)
            gluster_contents_after_sos.append(ret)

        # Compare glusterfiles before and after taking sosreport
        # There should be no difference in contents
        # Ignoring /var/log/glusterfs ie last element of the list, to avoid
        # false negatives as sosreport triggers heal which creates new logs
        # and obvious difference in list of entries post sos
        self.assertTrue((gluster_contents_before_sos[:-1] ==
                         gluster_contents_after_sos[:-1]),
                        "Gluster files not matching before and after "
                        " sosreport generation {} and {}"
                        .format(gluster_contents_before_sos,
                                gluster_contents_after_sos))

        # Untar sosreport to check if gluster files are captured
        sosfile = list(set(var_tmp_dircontents_after_sos) -
                       set(var_tmp_dircontents_before_sos))
        sosfile.sort()
        untar_sosfile_cmd = 'tar -xvf /var/tmp/' + sosfile[0] + ' -C /var/tmp/'
        ret, _, err = g.run(self.servers[1], untar_sosfile_cmd)
        self.assertEqual(ret, 0, "Untar failed due to {}".format(err))
        dirchecks = ('/var/lib/glusterd', '/var/log/glusterfs')
        olddirs = [gluster_contents_after_sos[2],
                   gluster_contents_after_sos[3]]
        ret = {}
        for after, before in zip(dirchecks, olddirs):
            untar_dirpath = '/var/tmp/' + sosfile[0][0:-7]
            untardir = untar_dirpath + after
            _ = get_dir_contents(self.servers[1], untardir, recursive=True)
            ret[after] = list(x.split(untar_dirpath, 1)[-1] for x in _)
            if before == gluster_contents_after_sos[2]:
                self.assertTrue(bool(before == ret[after]), 'gluster '
                                ' sosreport may be missing as they dont match '
                                'with actual contents')
            else:
                # Need this logic for var/log/glusterfs entries as rotated(.gz)
                # logs are not collected by sos
                self.assertTrue(all(entry in before for entry in ret[after]),
                                'var-log-glusterfs entries in sosreport may be'
                                ' missing as they dont match with actual '
                                'contents')