Пример #1
0
    def account_audit(self, path):
        """
        Audits the given account path

        :param path: the path to an account db
        """
        start_time = time.time()
        try:
            broker = AccountBroker(path)
            if not broker.is_deleted():
                self.validate_per_policy_counts(broker)
                self.logger.increment('passes')
                self.account_passes += 1
                self.logger.debug(_('Audit passed for %s'), broker)
        except InvalidAccountInfo as e:
            self.logger.increment('failures')
            self.account_failures += 1
            self.logger.error(
                _('Audit Failed for %(path)s: %(err)s'),
                {'path': path, 'err': str(e)})
        except (Exception, Timeout):
            self.logger.increment('failures')
            self.account_failures += 1
            self.logger.exception(_('ERROR Could not get account info %s'),
                                  path)
        self.logger.timing_since('timing', start_time)
Пример #2
0
    def account_audit(self, path):
        """
        Audits the given account path

        :param path: the path to an account db
        """
        start_time = time.time()
        try:
            broker = AccountBroker(path)
            if not broker.is_deleted():
                self.validate_per_policy_counts(broker)
                self.logger.increment('passes')
                self.account_passes += 1
                self.logger.debug('Audit passed for %s' % broker)
        except InvalidAccountInfo as e:
            self.logger.increment('failures')
            self.account_failures += 1
            self.logger.error(
                _('Audit Failed for %(path)s: %(err)s'),
                {'path': path, 'err': str(e)})
        except (Exception, Timeout):
            self.logger.increment('failures')
            self.account_failures += 1
            self.logger.exception(_('ERROR Could not get account info %s'),
                                  path)
        self.logger.timing_since('timing', start_time)
    def get_data(self, db_path):
        """
        Data for generated csv has the following columns:
        Account Hash, Container Count, Object Count, Bytes Used

        :raises sqlite3.Error: does not catch errors connecting to db
        """
        line_data = None
        broker = AccountBroker(db_path)
        if not broker.is_deleted():
            info = broker.get_info()
            line_data = '"%s",%d,%d,%d\n' % (
                info['account'], info['container_count'], info['object_count'],
                info['bytes_used'])
        return line_data
Пример #4
0
    def get_data(self, db_path):
        """
        Data for generated csv has the following columns:
        Account Hash, Container Count, Object Count, Bytes Used

        :raises sqlite3.Error: does not catch errors connecting to db
        """
        line_data = None
        broker = AccountBroker(db_path)
        if not broker.is_deleted():
            info = broker.get_info()
            line_data = '"%s",%d,%d,%d\n' % (info['account'],
                                             info['container_count'],
                                             info['object_count'],
                                             info['bytes_used'])
        return line_data
Пример #5
0
def print_info(db_type,
               db_file,
               swift_dir='/etc/swift',
               stale_reads_ok=False,
               drop_prefixes=False,
               verbose=False):
    if db_type not in ('account', 'container'):
        print("Unrecognized DB type: internal error")
        raise InfoSystemExit()
    if not os.path.exists(db_file) or not db_file.endswith('.db'):
        print("DB file doesn't exist")
        raise InfoSystemExit()
    if not db_file.startswith(('/', './')):
        db_file = './' + db_file  # don't break if the bare db file is given
    if db_type == 'account':
        broker = AccountBroker(db_file, stale_reads_ok=stale_reads_ok)
        datadir = ABDATADIR
    else:
        broker = ContainerBroker(db_file, stale_reads_ok=stale_reads_ok)
        datadir = CBDATADIR
    try:
        info = broker.get_info()
    except sqlite3.OperationalError as err:
        if 'no such table' in str(err):
            print("Does not appear to be a DB of type \"%s\": %s" %
                  (db_type, db_file))
            raise InfoSystemExit()
        raise
    account = info['account']
    container = None
    info['is_deleted'] = broker.is_deleted()
    if db_type == 'container':
        container = info['container']
        info['is_root'] = broker.is_root_container()
        sranges = broker.get_shard_ranges()
        if sranges:
            info['shard_ranges'] = sranges
    print_db_info_metadata(db_type, info, broker.metadata, drop_prefixes,
                           verbose)
    try:
        ring = Ring(swift_dir, ring_name=db_type)
    except Exception:
        ring = None
    else:
        print_ring_locations(ring, datadir, account, container)
Пример #6
0
    def account_audit(self, path):
        """
        Audits the given account path

        :param path: the path to an account db
        """
        start_time = time.time()
        try:
            broker = AccountBroker(path)
            if not broker.is_deleted():
                broker.get_info()
                self.logger.increment('passes')
                self.account_passes += 1
                self.logger.debug(_('Audit passed for %s') % broker)
        except (Exception, Timeout):
            self.logger.increment('failures')
            self.account_failures += 1
            self.logger.exception(_('ERROR Could not get account info %s'),
                                  path)
        self.logger.timing_since('timing', start_time)
Пример #7
0
    def account_crawl(self, path):
        """
        Crawls the given account path

        :param path: the path to an account db
        """
        #start_time = time.time()
        metaDict = {}
        try:
            broker = AccountBroker(path)
            if not broker.is_deleted():
                #reportedTime = broker.get_info()['put_timestamp']
                #if normalize_timestamp(self.crawled_time) <
                #reportedTime < normalize_timestamp(start_time):
                metaDict = broker.get_info()
                metaDict.update((key, value)
                       for key, (value, timestamp) in
                       broker.metadata.iteritems() if value != '')
        except (Exception, Timeout):
            self.logger.increment('failures')
        return metaDict
Пример #8
0
    def account_crawl(self, path):
        """
        Crawls the given account path

        :param path: the path to an account db
        """
        #start_time = time.time()
        metaDict = {}
        try:
            broker = AccountBroker(path)
            if not broker.is_deleted():
                #reportedTime = broker.get_info()['put_timestamp']
                #if normalize_timestamp(self.crawled_time) <
                #reportedTime < normalize_timestamp(start_time):
                metaDict = broker.get_info()
                metaDict.update(
                    (key, value)
                    for key, (value, timestamp) in broker.metadata.iteritems()
                    if value != '')
        except (Exception, Timeout):
            self.logger.increment('failures')
        return metaDict