|
3 | 3 | holds API for running all the IO commands.
|
4 | 4 | """
|
5 | 5 | import os
|
| 6 | +import re |
6 | 7 | from common.ops.abstract_ops import AbstractOps
|
7 | 8 |
|
8 | 9 |
|
@@ -126,6 +127,90 @@ def create_deep_dirs_with_files(self, path: str, dir_start_no: int,
|
126 | 127 | f"--num-of-files {no_files} {path}")
|
127 | 128 | return self.execute_command_async(cmd, node)
|
128 | 129 |
|
| 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 | + |
129 | 214 | def collect_mounts_arequal(self, mounts: dict, path=''):
|
130 | 215 | """
|
131 | 216 | Collects arequal from all the mounts
|
|
0 commit comments