Esempio n. 1
0
 def is_system_log_file(self, log_file=""):
     if not log_file:
         return False
     try:
         out, err = shell_command(['head -n 30 "%s"' % (log_file)])
     except Exception:
         return False
     if err or not out:
         return False
     lines = out.strip().split('\n')
     found = False
     for line in lines:
         try:
             if self.system_log_file_identifier_key in line:
                 found = True
                 break
         except Exception:
             pass
     if not found:
         return False
     for search_string in self.system_log_file_identifiers:
         try:
             out, err = shell_command(
                 ['grep -m 1 "%s" "%s"' % (search_string, log_file)])
         except Exception:
             continue
         if err or not out:
             continue
         else:
             return True
     return False
Esempio n. 2
0
    def get_server_node_id(self,
                           file,
                           fetch_end="tail",
                           read_block_size=SERVER_ID_FETCH_READ_SIZE):
        if not fetch_end or fetch_end not in FILE_READ_ENDS:
            fetch_end = "tail"
        if not read_block_size:
            read_block_size = SERVER_ID_FETCH_READ_SIZE
        not_found = ""
        # pattern for logs of old server (< 3.9) is "node id "
        # pattern for logs of new server (>= 3.9) is "NODE-ID "
        server_log_node_identifiers = ["node id ", "NODE-ID "]
        server_node_id_pattern = "%s([0-9a-fA-F]+(\s|$))"

        block_to_check = 100

        if not file:
            return not_found
        try:
            out, err = shell_command(
                ['%s -n %d "%s"' % (fetch_end, read_block_size, file)])
        except Exception:
            return not_found
        if err or not out:
            return not_found
        lines = out.strip().split('\n')
        try:
            if lines:
                fetched_line_count = len(lines)
                end_index = fetched_line_count
                start_index = end_index - \
                    (block_to_check if block_to_check <
                     end_index else end_index)
                while start_index >= 0 and start_index < end_index:
                    one_string = " ".join(lines[start_index:end_index])
                    if any(id in one_string
                           for id in server_log_node_identifiers):
                        for line in reversed(lines[start_index:end_index]):
                            for id in server_log_node_identifiers:
                                if id in line:
                                    try:
                                        node_id = re.search(
                                            server_node_id_pattern % (id),
                                            line.strip()).group(1)
                                        if node_id:
                                            return node_id
                                    except Exception:
                                        pass
                    end_index = start_index
                    start_index = end_index - \
                        (block_to_check if block_to_check <
                         end_index else end_index)
        except Exception:
            pass
        if fetch_end == "tail":
            return self.get_server_node_id(file=file,
                                           fetch_end="head",
                                           read_block_size=read_block_size)
        return not_found
Esempio n. 3
0
def get_version():
    if __version__.startswith('$$'):
        import string
        vfile = string.join(sys.argv[0].split('/')[:-1], '/') + "/version.txt"
        output = util.shell_command(["cat " + vfile])
        return str(output[0])
    else:
        return __version__
Esempio n. 4
0
    def get_server_node_id(self, file, fetch_end="tail",
                           read_block_size=SERVER_ID_FETCH_READ_SIZE):
        if not fetch_end or fetch_end not in FILE_READ_ENDS:
            fetch_end = "tail"
        if not read_block_size:
            read_block_size = SERVER_ID_FETCH_READ_SIZE
        not_found = ""
        # pattern for logs of old server (< 3.9) is "node id "
        # pattern for logs of new server (>= 3.9) is "NODE-ID "
        server_log_node_identifiers = ["node id ", "NODE-ID "]
        server_node_id_pattern = "%s([0-9a-fA-F]+(\s|$))"

        block_to_check = 100

        if not file:
            return not_found
        try:
            out, err = shell_command(
                ['%s -n %d "%s"' % (fetch_end, read_block_size, file)])
        except Exception:
            return not_found
        if err or not out:
            return not_found
        lines = out.strip().split('\n')
        try:
            if lines:
                fetched_line_count = len(lines)
                end_index = fetched_line_count
                start_index = end_index - \
                    (block_to_check if block_to_check <
                     end_index else end_index)
                while start_index >= 0 and start_index < end_index:
                    one_string = " ".join(lines[start_index:end_index])
                    if any(id in one_string for id in server_log_node_identifiers):
                        for line in reversed(lines[start_index:end_index]):
                            for id in server_log_node_identifiers:
                                if id in line:
                                    try:
                                        node_id = re.search(
                                            server_node_id_pattern % (id), line.strip()).group(1)
                                        if node_id:
                                            return node_id
                                    except Exception:
                                        pass
                    end_index = start_index
                    start_index = end_index - \
                        (block_to_check if block_to_check <
                         end_index else end_index)
        except Exception:
            pass
        if fetch_end == "tail":
            return self.get_server_node_id(file=file, fetch_end="head",
                                           read_block_size=read_block_size)
        return not_found
Esempio n. 5
0
 def is_server_log_file(self, file=""):
     if not file:
         return False
     try:
         out, err = shell_command(['head -n 10 "%s"' % (file)])
     except Exception:
         return False
     if err or not out:
         return False
     lines = out.strip().split('\n')
     matched_count = 0
     for line in lines:
         try:
             if re.search(self.server_log_file_identifier_pattern, line):
                 matched_count += 1
         except Exception:
             pass
     if matched_count > (len(lines)/2):
         return True
     return False
Esempio n. 6
0
 def is_server_log_file(self, file=""):
     if not file:
         return False
     try:
         out, err = shell_command(['head -n 10 "%s"' % (file)])
     except Exception:
         return False
     if err or not out:
         return False
     lines = out.strip().split('\n')
     matched_count = 0
     for line in lines:
         try:
             if re.search(self.server_log_file_identifier_pattern, line):
                 matched_count += 1
         except Exception:
             pass
     if matched_count > (len(lines)/2):
         return True
     return False