Skip to content

Commit 888db6c

Browse files
Added check_core_file_exists and test_probe_glusterd (#456)
* Added check_core_file_exists Added the function check_core_file_exists. Fixes: #359 Signed-off-by: Ayush Ujjwal <[email protected]> * replaced run and modified the output Signed-off-by: Ayush Ujjwal <[email protected]> * Rebased and removved the conflicts Signed-off-by: Ayush Ujjwal <[email protected]> * fixed lint issues Signed-off-by: Ayush Ujjwal <[email protected]> * added try except to prevent failure even when ls cannot access the file Signed-off-by: Ayush Ujjwal <[email protected]> * added a test case Signed-off-by: Ayush Ujjwal <[email protected]> * indentation modified Signed-off-by: Ayush Ujjwal <[email protected]> * changed the nature of test case Signed-off-by: Ayush Ujjwal <[email protected]> * multiple values in ret[msg] handled; modified the boolean values Signed-off-by: Ayush Ujjwal <[email protected]>
1 parent bdbf63b commit 888db6c

File tree

3 files changed

+162
-1
lines changed

3 files changed

+162
-1
lines changed

.pylintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ disable=print-statement,
163163
F811,
164164
F841,
165165
C901,
166-
R0915
166+
R0915,
167+
W0102
167168

168169
# Enable the message, report, category or checker with the given id(s). You can
169170
# either give multiple identifier separated by comma (,) or put this option

common/ops/support_ops/io_ops.py

+85
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
holds API for running all the IO commands.
44
"""
55
import os
6+
import re
67
from common.ops.abstract_ops import AbstractOps
78

89

@@ -126,6 +127,90 @@ def create_deep_dirs_with_files(self, path: str, dir_start_no: int,
126127
f"--num-of-files {no_files} {path}")
127128
return self.execute_command_async(cmd, node)
128129

130+
def check_core_file_exists(self, nodes: list, testrun_timestamp,
131+
paths=['/', '/var/log/core',
132+
'/tmp', '/var/crash', '~/']):
133+
'''
134+
Listing directories and files in "/", /var/log/core, /tmp,
135+
"/var/crash", "~/" directory for checking if the core file
136+
created or not
137+
138+
Args:
139+
140+
nodes(list):
141+
List of nodes need to pass from test method
142+
testrun_timestamp:
143+
This time stamp need to pass from test method
144+
test case running started time, time format is EPOCH
145+
time format, use below command for getting timestamp
146+
of test case 'date +%s'
147+
paths(list):
148+
By default core file will be verified in "/","/tmp",
149+
"/var/log/core", "/var/crash", "~/"
150+
Return:
151+
bool : True if core file was created
152+
else False
153+
If test case need to verify core file in specific path,
154+
need to pass path from test method
155+
'''
156+
count = 0
157+
cmd_list = []
158+
for path in paths:
159+
cmd = ' '.join(['cd', path, '&&', 'ls', 'core*'])
160+
cmd_list.append(cmd)
161+
162+
# Checks for core file in "/", "/var/log/core", "/tmp" "/var/crash",
163+
# "~/" directory
164+
for node in nodes:
165+
cmd = 'grep -r "time of crash" /var/log/glusterfs/'
166+
try:
167+
ret = self.execute_abstract_op_node(cmd, node)
168+
logfiles = " ".join(ret['msg'])
169+
if ret['error_code'] == 0:
170+
self.logger.error(" Seems like there was a crash,"
171+
" kindly check the logfiles, "
172+
"even if you don't see a core file")
173+
for logfile in logfiles.strip('\n').split('\n'):
174+
self.logger.error(f"Core was found in "
175+
f"{logfile.split(':')[0]}")
176+
except Exception as error:
177+
self.logger.info(f"Error: {error}")
178+
179+
for cmd in cmd_list:
180+
try:
181+
ret = self.execute_abstract_op_node(cmd, node)
182+
out = " ".join(ret['msg'])
183+
self.logger.info("storing all files and directory "
184+
"names into list")
185+
dir_list = re.split(r'\s+', out)
186+
187+
# checking for core file created or not in "/"
188+
# "/var/log/core", "/tmp" directory
189+
self.logger.info("checking core file created or not")
190+
for file1 in dir_list:
191+
if re.search(r'\bcore\.[\S]+\b', file1):
192+
file_path_list = re.split(r'[\s]+', cmd)
193+
file_path = file_path_list[1] + '/' + file1
194+
time_cmd = 'stat ' + '-c ' + '%X ' + file_path
195+
ret = self.execute_abstract_op_node(time_cmd, node)
196+
file_timestamp = ret['msg'][0].rstrip('\n')
197+
file_timestamp = file_timestamp.strip()
198+
if file_timestamp > testrun_timestamp:
199+
count += 1
200+
self.logger.error(f"New core file was created "
201+
f"and found at {file1}")
202+
else:
203+
self.logger.info("Old core file Found")
204+
except Exception as error:
205+
self.logger.info(f"Error: {error}")
206+
# return the status of core file
207+
if count >= 1:
208+
self.logger.error("Core file created glusterd crashed")
209+
return True
210+
else:
211+
self.logger.info("No core files found ")
212+
return False
213+
129214
def collect_mounts_arequal(self, mounts: dict, path=''):
130215
"""
131216
Collects arequal from all the mounts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
Copyright (C) 2020 Red Hat, Inc. <http://www.redhat.com>
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; either version 2 of the License, or
6+
any later version.
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
You should have received a copy of the GNU General Public License along
12+
with this program; if not, write to the Free Software Foundation, Inc.,
13+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14+
15+
Description:
16+
Test Cases in this module related to peer probe invalid ip,
17+
non existing ip, non existing host.
18+
"""
19+
# disruptive;
20+
21+
from tests.nd_parent_test import NdParentTest
22+
23+
24+
class TestCase(NdParentTest):
25+
26+
def run_test(self, redant):
27+
'''
28+
Test script to verify peer probe non existing ip,
29+
non_exsting_host and invalid-ip, peer probe has to
30+
be fail for invalid-ip, non-existing-ip and
31+
non existing host, verify Glusterd services up and
32+
running or not after invalid peer probe,
33+
and core file should not get created
34+
under "/", /var/log/core and /tmp directory
35+
'''
36+
ret = redant.execute_abstract_op_node('date +%s', self.server_list[0])
37+
test_timestamp = ret['msg'][0].strip()
38+
# Assigning non existing ip to variable
39+
non_exist_ip = '256.256.256.256'
40+
41+
# Assigning invalid ip to variable
42+
invalid_ip = '10.11.a'
43+
44+
# Assigning non existing host to variable
45+
non_exist_host = 'abc.lab.eng.blr.redhat.com'
46+
47+
# Peer probe checks for non existing host
48+
try:
49+
ret = redant.peer_probe(non_exist_host, self.server_list[0])
50+
except Exception as error:
51+
redant.logger.info("Peer probe failed for non-existing server")
52+
redant.logger.info(f"Error: {error}")
53+
54+
try:
55+
ret = redant.peer_probe(invalid_ip, self.server_list[0])
56+
except Exception as error:
57+
redant.logger.info("Peer probe failed for invalid IP")
58+
redant.logger.info(f"Error: {error}")
59+
60+
try:
61+
ret = redant.peer_probe(non_exist_ip, self.server_list[0])
62+
except Exception as error:
63+
redant.logger.info("Peer probe failed for non-existing IP")
64+
redant.logger.info(f"Error: {error}")
65+
66+
# Checks Glusterd services running or not after peer probe
67+
# to invalid host and non existing host
68+
69+
redant.is_glusterd_running(self.server_list[0])
70+
71+
# Chekcing core file created or not in "/", "/tmp" and
72+
# "/var/log/core" directory
73+
ret = redant.check_core_file_exists(self.server_list, test_timestamp)
74+
if ret:
75+
raise Exception('Core file found')

0 commit comments

Comments
 (0)