Project

General

Profile

test_volumes_thread.py

Nikola Ciprich, 08/20/2019 04:07 PM

Download (1.38 KB)

 
1
try:
2
        import rbd
3
        import rados
4
except Exception as err:
5
        print(err)
6
import time
7
import argparse
8
import threading
9

    
10
global counter
11
global end
12
global vols
13

    
14
def tester(r):
15
        global counter
16
        global vols
17
        global end
18

    
19
        while not end:
20
                for volume in volumes:
21
                        vols.append(volume)
22
                        try:
23
                                with rados.Rados(conffile='/etc/ceph/ceph.conf') as cluster:
24
                                        with cluster.open_ioctx("sata") as ioctx:
25
                                                try:
26
                                                        with rbd.Image(ioctx, name=volume, read_only=True) as rbdi:
27
                                                                counter += 1
28
                                                except rbd.ImageNotFound:
29
                                                        print("%s volume not found" % (volume))
30
                                                except rbd.ImageBusy:
31
                                                        print("%s volume busy" % (volume))
32
                                                except Exception as err:
33
                                                        print("%s %s" % (volume, err))
34
                        except Exception as err:
35
                                print("%s %s" % (volume, err))
36
                        vols.remove(volume)
37

    
38
if __name__ == "__main__":
39
        counter = 0
40
        vols = []
41
        end = False
42

    
43
        try:
44
                r = rbd.RBD()
45

    
46
                with rados.Rados(conffile='/etc/ceph/ceph.conf') as cluster:
47
                        with cluster.open_ioctx("sata") as ioctx:
48
                                volumes = r.list(ioctx)
49
        except Exception as err:
50
                print(err)
51

    
52
        threads = []
53

    
54
        for i in xrange(10):
55
                threads.append(threading.Thread(target=tester, args=(r,)))
56

    
57
        for thread in threads:
58
                thread.setDaemon(True)
59
                thread.start()
60

    
61
        while True:
62
                try:
63
                        time.sleep(5)
64
                        print("Volumes tested: %s" % (counter))
65
                except Exception as err:
66
                        print(vols, err)
67
                        end = True
68

    
69
                        for thread in threads:
70
                                thread.join()