]> git.proxmox.com Git - ceph.git/blame - ceph/qa/workunits/rados/test_large_omap_detection.py
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / qa / workunits / rados / test_large_omap_detection.py
CommitLineData
28e407b8
AA
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
18import json
19import rados
20import shlex
21import subprocess
22import time
23
24def cleanup(cluster):
25 cluster.delete_pool('large-omap-test-pool')
26 cluster.shutdown()
27
28def 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
72def 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]
11fdf7f2
TL
76 try:
77 pgstats = json.loads(out)['pg_map']['pg_stats']
78 except KeyError:
79 pgstats = json.loads(out)['pg_stats']
80 for stat in pgstats:
28e407b8
AA
81 if stat['pgid'] == pgid:
82 return stat['last_deep_scrub_stamp']
83
84def wait_for_scrub():
85 osds = set();
86 pgs = dict();
87 cmd = ['ceph', 'osd', 'map', 'large-omap-test-pool',
88 'large-omap-test-object1', '--format=json-pretty']
89 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
90 out = proc.communicate()[0]
91 osds.add(json.loads(out)['acting_primary'])
92 pgs[json.loads(out)['pgid']] = get_deep_scrub_timestamp(json.loads(out)['pgid'])
93 cmd = ['ceph', 'osd', 'map', 'large-omap-test-pool',
94 'large-omap-test-object2', '--format=json-pretty']
95 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
96 out = proc.communicate()[0]
97 osds.add(json.loads(out)['acting_primary'])
98 pgs[json.loads(out)['pgid']] = get_deep_scrub_timestamp(json.loads(out)['pgid'])
99
100 for pg in pgs:
101 command = "ceph pg deep-scrub " + str(pg)
102 subprocess.check_call(shlex.split(command))
103
104 for pg in pgs:
105 RETRIES = 0
106 while RETRIES < 60 and pgs[pg] == get_deep_scrub_timestamp(pg):
107 time.sleep(10)
108 RETRIES += 1
109
110def check_health_output():
111 RETRIES = 0
112 result = 0
113 while RETRIES < 6 and result != 2:
114 result = 0
115 RETRIES += 1
116 output = subprocess.check_output(["ceph", "health", "detail"])
117 for line in output.splitlines():
118 result += int(line.find('2 large omap objects') != -1)
119 time.sleep(10)
120
121 if result != 2:
122 print("Error, got invalid output:")
123 print(output)
124 raise Exception
125
126def main():
127 cluster = init()
128 wait_for_scrub()
129 check_health_output()
130
131 cleanup(cluster)
132
133if __name__ == '__main__':
134 main()