def get_swiftconfmd5(self, hosts, printfn=print): """ Compare swift.conf md5sum with that on remote hosts :param hosts: set of hosts to check. in the format of: set([('127.0.0.1', 6020), ('127.0.0.2', 6030)]) :param printfn: function to print text; defaults to print() """ matches = 0 errors = 0 conf_sum = md5_hash_for_file(SWIFT_CONF_FILE) recon = Scout("swiftconfmd5", self.verbose, self.suppress_errors, self.timeout) printfn("[%s] Checking swift.conf md5sum" % self._ptime()) if self.verbose: printfn("-> On disk swift.conf md5sum: %s" % (conf_sum, )) for url, response, status, ts_start, ts_end in self.pool.imap( recon.scout, hosts): if status == 200: if response[SWIFT_CONF_FILE] != conf_sum: printfn("!! %s (%s) doesn't match on disk md5sum" % (url, response[SWIFT_CONF_FILE])) else: matches = matches + 1 if self.verbose: printfn("-> %s matches." % url) else: errors = errors + 1 printfn("%s/%s hosts matched, %s error[s] while checking hosts." % (matches, len(hosts), errors)) printfn("=" * 79)
def get_swiftconfmd5(self, hosts, printfn=print): """ Compare swift.conf md5sum with that on remote hosts :param hosts: set of hosts to check. in the format of: set([('127.0.0.1', 6020), ('127.0.0.2', 6030)]) :param printfn: function to print text; defaults to print() """ matches = 0 errors = 0 conf_sum = md5_hash_for_file(SWIFT_CONF_FILE) recon = Scout("swiftconfmd5", self.verbose, self.suppress_errors, self.timeout) printfn("[%s] Checking swift.conf md5sum" % self._ptime()) if self.verbose: printfn("-> On disk swift.conf md5sum: %s" % (conf_sum,)) for url, response, status, ts_start, ts_end in self.pool.imap( recon.scout, hosts): if status == 200: if response[SWIFT_CONF_FILE] != conf_sum: printfn("!! %s (%s) doesn't match on disk md5sum" % (url, response[SWIFT_CONF_FILE])) else: matches = matches + 1 if self.verbose: printfn("-> %s matches." % url) else: errors = errors + 1 printfn("%s/%s hosts matched, %s error[s] while checking hosts." % (matches, len(hosts), errors)) printfn("=" * 79)
def get_swift_conf_md5(self): """get md5 of swift.conf""" hexsum = None try: hexsum = md5_hash_for_file(SWIFT_CONF_FILE) except IOError as err: if err.errno != errno.ENOENT: self.logger.exception(_('Error reading swift.conf')) return {SWIFT_CONF_FILE: hexsum}
def get_ring_md5(self): """get all ring md5sum's""" sums = {} for ringfile in self.rings: if os.path.exists(ringfile): try: sums[ringfile] = md5_hash_for_file(ringfile) except IOError as err: sums[ringfile] = None if err.errno != errno.ENOENT: self.logger.exception(_('Error reading ringfile')) return sums
def get_ringmd5(self, hosts, swift_dir): """ Compare ring md5sum's with those on remote host :param hosts: set of hosts to check. in the format of: set([('127.0.0.1', 6020), ('127.0.0.2', 6030)]) :param swift_dir: The local directory with the ring files. """ matches = 0 errors = 0 ring_names = set() if self.server_type == 'object': for ring_name in os.listdir(swift_dir): if ring_name.startswith('object') and \ ring_name.endswith('.ring.gz'): ring_names.add(ring_name) else: ring_name = '%s.ring.gz' % self.server_type ring_names.add(ring_name) rings = {} for ring_name in ring_names: rings[ring_name] = md5_hash_for_file( os.path.join(swift_dir, ring_name)) recon = Scout("ringmd5", self.verbose, self.suppress_errors, self.timeout) print("[%s] Checking ring md5sums" % self._ptime()) if self.verbose: for ring_file, ring_sum in rings.items(): print("-> On disk %s md5sum: %s" % (ring_file, ring_sum)) for url, response, status, ts_start, ts_end in self.pool.imap( recon.scout, hosts): if status != 200: errors = errors + 1 continue success = True for remote_ring_file, remote_ring_sum in response.items(): remote_ring_name = os.path.basename(remote_ring_file) if not remote_ring_name.startswith(self.server_type): continue ring_sum = rings.get(remote_ring_name, None) if remote_ring_sum != ring_sum: success = False print("!! %s (%s => %s) doesn't match on disk md5sum" % (url, remote_ring_name, remote_ring_sum)) if not success: errors += 1 continue matches += 1 if self.verbose: print("-> %s matches." % url) print("%s/%s hosts matched, %s error[s] while checking hosts." % (matches, len(hosts), errors)) print("=" * 79)
def get_ringmd5(self, hosts, swift_dir): """ Compare ring md5sum's with those on remote host :param hosts: set of hosts to check. in the format of: set([('127.0.0.1', 6020), ('127.0.0.2', 6030)]) :param swift_dir: The local directory with the ring files. """ matches = 0 errors = 0 ring_names = set() if self.server_type == 'object': for ring_name in os.listdir(swift_dir): if ring_name.startswith('object') and \ ring_name.endswith('.ring.gz'): ring_names.add(ring_name) else: ring_name = '%s.ring.gz' % self.server_type ring_names.add(ring_name) rings = {} for ring_name in ring_names: rings[ring_name] = md5_hash_for_file( os.path.join(swift_dir, ring_name)) recon = Scout("ringmd5", self.verbose, self.suppress_errors, self.timeout) print("[%s] Checking ring md5sums" % self._ptime()) if self.verbose: for ring_file, ring_sum in rings.items(): print("-> On disk %s md5sum: %s" % (ring_file, ring_sum)) for url, response, status, ts_start, ts_end in self.pool.imap( recon.scout, hosts): if status != 200: errors = errors + 1 continue success = True for remote_ring_file, remote_ring_sum in response.items(): remote_ring_name = os.path.basename(remote_ring_file) if not remote_ring_name.startswith(self.server_type): continue ring_sum = rings.get(remote_ring_name, None) if remote_ring_sum != ring_sum: success = False print("!! %s (%s => %s) doesn't match on disk md5sum" % ( url, remote_ring_name, remote_ring_sum)) if not success: errors += 1 continue matches += 1 if self.verbose: print("-> %s matches." % url) print("%s/%s hosts matched, %s error[s] while checking hosts." % ( matches, len(hosts), errors)) print("=" * 79)