]> git.proxmox.com Git - ceph.git/blame - ceph/qa/tasks/watch_notify_same_primary.py
bump version to 18.2.4-pve3
[ceph.git] / ceph / qa / tasks / watch_notify_same_primary.py
CommitLineData
7c673cae
FG
1
2"""
3watch_notify_same_primary task
4"""
f67539c2 5from io import StringIO
7c673cae
FG
6import contextlib
7import logging
8
9f95a23c 9
7c673cae
FG
10from teuthology.orchestra import run
11from teuthology.contextutil import safe_while
12
13log = logging.getLogger(__name__)
14
15
16@contextlib.contextmanager
17def task(ctx, config):
18 """
19 Run watch_notify_same_primary
20
21 The config should be as follows:
22
23 watch_notify_same_primary:
24 clients: [client list]
25
26 The client list should contain 1 client
27
28 The test requires 3 osds.
29
30 example:
31
32 tasks:
33 - ceph:
34 - watch_notify_same_primary:
35 clients: [client.0]
36 - interactive:
37 """
38 log.info('Beginning watch_notify_same_primary...')
39 assert isinstance(config, dict), \
40 "please list clients to run on"
41
42 clients = config.get('clients', ['client.0'])
43 assert len(clients) == 1
44 role = clients[0]
f67539c2 45 assert isinstance(role, str)
7c673cae
FG
46 PREFIX = 'client.'
47 assert role.startswith(PREFIX)
9f95a23c 48 (remote,) = ctx.cluster.only(role).remotes.keys()
7c673cae
FG
49 manager = ctx.managers['ceph']
50 manager.raw_cluster_cmd('osd', 'set', 'noout')
51
52 pool = manager.create_pool_with_unique_name()
53 def obj(n): return "foo-{num}".format(num=n)
54 def start_watch(n):
55 remote.run(
56 args = [
57 "rados",
58 "-p", pool,
59 "put",
60 obj(n),
61 "/etc/resolv.conf"],
62 logger=log.getChild('watch.{id}'.format(id=n)))
63 proc = remote.run(
64 args = [
65 "rados",
66 "-p", pool,
67 "watch",
68 obj(n)],
69 stdin=run.PIPE,
e306af50
TL
70 stdout=StringIO(),
71 stderr=StringIO(),
7c673cae
FG
72 wait=False)
73 return proc
74
75 num = 20
76
77 watches = [start_watch(i) for i in range(num)]
78
79 # wait for them all to register
80 for i in range(num):
81 with safe_while() as proceed:
82 while proceed():
9f95a23c
TL
83 lines = remote.sh(
84 ["rados", "-p", pool, "listwatchers", obj(i)])
7c673cae
FG
85 num_watchers = lines.count('watcher=')
86 log.info('i see %d watchers for %s', num_watchers, obj(i))
87 if num_watchers >= 1:
88 break
89
90 def notify(n, msg):
91 remote.run(
92 args = [
93 "rados",
94 "-p", pool,
95 "notify",
96 obj(n),
97 msg],
98 logger=log.getChild('notify.{id}'.format(id=n)))
99
100 [notify(n, 'notify1') for n in range(len(watches))]
101
102 manager.kill_osd(0)
103 manager.mark_down_osd(0)
104
105 [notify(n, 'notify2') for n in range(len(watches))]
106
107 try:
108 yield
109 finally:
110 log.info('joining watch_notify_stress')
111 for watch in watches:
112 watch.stdin.write("\n")
113
114 run.wait(watches)
115
116 for watch in watches:
117 lines = watch.stdout.getvalue().split("\n")
118 got1 = False
119 got2 = False
120 for l in lines:
121 if 'notify1' in l:
122 got1 = True
123 if 'notify2' in l:
124 got2 = True
125 log.info(lines)
126 assert got1 and got2
127
128 manager.revive_osd(0)
129 manager.remove_pool(pool)