Revision 09e69b8a snf-pithos-app/pithos/api/management/commands/pithos-set-usage.py

b/snf-pithos-app/pithos/api/management/commands/pithos-set-usage.py
46 46
Statistics = namedtuple('Statistics', ('node', 'path', 'size', 'cluster'))
47 47

  
48 48
ResetHoldingPayload = namedtuple('ResetHoldingPayload', (
49
                                 'entity', 'resource', 'key',
50
                                 'imported', 'exported', 'returned', 'released')
51
)
52
ENTITY_KEY= '1'
49
                'entity', 'resource', 'key',
50
                'imported', 'exported', 'returned', 'released'))
51
ENTITY_KEY = '1'
53 52

  
54 53
backend = get_backend()
55 54
table = {}
......
59 58
table['policy'] = backend.node.policy
60 59
conn = backend.node.conn
61 60

  
61

  
62 62
def _compute_statistics(nodes):
63 63
    statistics = []
64 64
    append = statistics.append
65 65
    for path, node in nodes:
66 66
        select_children = select(
67
            [table['nodes'].c.node]).where(table['nodes'].c.parent==node)
67
            [table['nodes'].c.node]).where(table['nodes'].c.parent == node)
68 68
        select_descendants = select([table['nodes'].c.node]).where(
69 69
            or_(table['nodes'].c.parent.in_(select_children),
70 70
                table['nodes'].c.node.in_(select_children)))
......
87 87
                cluster=cluster))
88 88
    return statistics
89 89

  
90

  
90 91
def _get_verified_usage(statistics):
91
    """ Verify statistics and set quotaholder account usage """
92
    """Verify statistics and set quotaholder account usage"""
92 93
    reset_holding = []
93 94
    append = reset_holding.append
94 95
    for item in statistics:
......
100 101
            continue
101 102
        try:
102 103
            assert item.size == db_item.size, \
103
                '%d[%s][%d], size: %d != %d' % (
104
                    item.node, item.path, item.cluster, item.size, db_item.size)
104
                    '%d[%s][%d], size: %d != %d' % (
105
                            item.node, item.path, item.cluster,
106
                            item.size, db_item.size)
105 107
        except AssertionError, e:
106 108
            print e
107 109
        if item.cluster == CLUSTER_NORMAL:
......
152 154
                self.stdout.write(
153 155
                        'Unknown quotaholder accounts: %s\n' %
154 156
                        ','.join(missing_entities))
155
                self.stdout.write('Retrying sending quota usage for the rest...\n')
157
                m = 'Retrying sending quota usage for the rest...\n'
158
                self.stdout.write(m)
156 159
                missing_indexes = set(result)
157 160
                reset_holding = [x for i, x in enumerate(reset_holding)
158 161
                                 if i not in missing_indexes]

Also available in: Unified diff