Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / admin_socket / objecter_requests
1 #!/usr/bin/env python
2
3 import json
4 import sys
5
6
7 def main():
8     """
9     Read json output of admin socket command 'objecter_requests' from
10     stdin, and check it for internal consistency and presence of
11     fields.
12     """
13     read = sys.stdin.read()
14     reqs = json.loads(read)
15
16     op_types = ['linger_ops', 'ops', 'pool_ops', 'pool_stat_ops', 'statfs_ops', 'command_ops']
17     assert sorted(reqs.keys()) == sorted(op_types)
18
19     found_error = check_osd_ops(reqs['ops'] + reqs['linger_ops'])
20     assert not found_error, "ERRORS FOUND!"
21
22
23 def check_osd_ops(ops):
24     pg_map = {}
25     locators = {}
26     osds = {}
27     found_error = [False]
28
29     def add_to_mapping(mapping, key, value, msg):
30         if key in mapping:
31             if mapping[key] != value:
32                 print('%s != %s' % (mapping[key], value))
33                 print(msg)
34                 found_error[0] = True
35         else:
36             mapping[key] = value
37
38     for op in ops:
39         add_to_mapping(
40             mapping=pg_map,
41             key=(op['object_id'], op['object_locator']),
42             value=op['pg'],
43             msg='ERROR: two ops for the same object mapped to different pgs',
44             )
45         add_to_mapping(
46             mapping=locators,
47             key=op['object_id'],
48             value=op['object_locator'],
49             msg='ERROR: requests to the same object had different locators',
50             )
51         add_to_mapping(
52             mapping=osds,
53             key=op['pg'],
54             value=op['osd'],
55             msg='ERROR: two ops mapped a pg to different osds',
56             )
57     return found_error[0]
58
59 if __name__ == '__main__':
60     main()