]> git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/rados/test_large_omap_detection.py
update sources to 12.2.7
[ceph.git] / ceph / qa / workunits / rados / test_large_omap_detection.py
1 #!/usr/bin/python
2 # -*- mode:python -*-
3 # vim: ts=4 sw=4 smarttab expandtab
4 #
5 # Copyright (C) 2017 Red Hat <contact@redhat.com>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Library Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Library Public License for more details.
16 #
17
18 import json
19 import rados
20 import shlex
21 import subprocess
22 import time
23
24 def cleanup(cluster):
25 cluster.delete_pool('large-omap-test-pool')
26 cluster.shutdown()
27
28 def init():
29 # For local testing
30 #cluster = rados.Rados(conffile='./ceph.conf')
31 cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
32 cluster.connect()
33 print("\nCluster ID: " + cluster.get_fsid())
34 cluster.create_pool('large-omap-test-pool')
35 ioctx = cluster.open_ioctx('large-omap-test-pool')
36 ioctx.write_full('large-omap-test-object1', "Lorem ipsum")
37 op = ioctx.create_write_op()
38
39 keys = []
40 values = []
41 for x in range(20001):
42 keys.append(str(x))
43 values.append("X")
44
45 ioctx.set_omap(op, tuple(keys), tuple(values))
46 ioctx.operate_write_op(op, 'large-omap-test-object1', 0)
47 ioctx.release_write_op(op)
48
49 ioctx.write_full('large-omap-test-object2', "Lorem ipsum dolor")
50 op = ioctx.create_write_op()
51
52 buffer = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do "
53 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut "
54 "enim ad minim veniam, quis nostrud exercitation ullamco laboris "
55 "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in "
56 "reprehenderit in voluptate velit esse cillum dolore eu fugiat "
57 "nulla pariatur. Excepteur sint occaecat cupidatat non proident, "
58 "sunt in culpa qui officia deserunt mollit anim id est laborum.")
59
60 keys = []
61 values = []
62 for x in xrange(20000):
63 keys.append(str(x))
64 values.append(buffer)
65
66 ioctx.set_omap(op, tuple(keys), tuple(values))
67 ioctx.operate_write_op(op, 'large-omap-test-object2', 0)
68 ioctx.release_write_op(op)
69 ioctx.close()
70 return cluster
71
72 def get_deep_scrub_timestamp(pgid):
73 cmd = ['ceph', 'pg', 'dump', '--format=json-pretty']
74 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
75 out = proc.communicate()[0]
76 for stat in json.loads(out)['pg_stats']:
77 if stat['pgid'] == pgid:
78 return stat['last_deep_scrub_stamp']
79
80 def wait_for_scrub():
81 osds = set();
82 pgs = dict();
83 cmd = ['ceph', 'osd', 'map', 'large-omap-test-pool',
84 'large-omap-test-object1', '--format=json-pretty']
85 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
86 out = proc.communicate()[0]
87 osds.add(json.loads(out)['acting_primary'])
88 pgs[json.loads(out)['pgid']] = get_deep_scrub_timestamp(json.loads(out)['pgid'])
89 cmd = ['ceph', 'osd', 'map', 'large-omap-test-pool',
90 'large-omap-test-object2', '--format=json-pretty']
91 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
92 out = proc.communicate()[0]
93 osds.add(json.loads(out)['acting_primary'])
94 pgs[json.loads(out)['pgid']] = get_deep_scrub_timestamp(json.loads(out)['pgid'])
95
96 for pg in pgs:
97 command = "ceph pg deep-scrub " + str(pg)
98 subprocess.check_call(shlex.split(command))
99
100 for pg in pgs:
101 RETRIES = 0
102 while RETRIES < 60 and pgs[pg] == get_deep_scrub_timestamp(pg):
103 time.sleep(10)
104 RETRIES += 1
105
106 def check_health_output():
107 RETRIES = 0
108 result = 0
109 while RETRIES < 6 and result != 2:
110 result = 0
111 RETRIES += 1
112 output = subprocess.check_output(["ceph", "health", "detail"])
113 for line in output.splitlines():
114 result += int(line.find('2 large omap objects') != -1)
115 time.sleep(10)
116
117 if result != 2:
118 print("Error, got invalid output:")
119 print(output)
120 raise Exception
121
122 def main():
123 cluster = init()
124 wait_for_scrub()
125 check_health_output()
126
127 cleanup(cluster)
128
129 if __name__ == '__main__':
130 main()