]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/netsplit.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / qa / tasks / netsplit.py
1 """
2 Functions to netsplit test machines.
3
4 At present, you must specify monitors to disconnect, and it
5 drops those IP pairs. This means OSDs etc on the hosts which use
6 the same IP will also be blocked! If you are using multiple IPs on the
7 same host within the cluster, daemons on those other IPs will get
8 through.
9 """
10 import logging
11 import re
12
13 log = logging.getLogger(__name__)
14
15 def get_ip_and_ports(ctx, daemon):
16 assert daemon.startswith('mon.')
17 addr = ctx.ceph['ceph'].mons['{a}'.format(a=daemon)]
18 ips = re.findall("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[:[0-9]*]*", addr)
19 assert len(ips) > 0
20 plain_ip = re.match("[0-9\.]*", ips[0]).group()
21 assert plain_ip is not None
22 port_list = []
23 for ip in ips:
24 ip_str, port_str = re.match("([0-9\.]*)([:[0-9]*]*)", ip).groups()
25 assert ip_str == plain_ip
26 if len(port_str) > 0:
27 port_list.append(port_str)
28 return (plain_ip, port_list)
29
30 def disconnect(ctx, config):
31 assert len(config) == 2 # we can only disconnect pairs right now
32 # and we can only disconnect mons right now
33 assert config[0].startswith('mon.')
34 assert config[1].startswith('mon.')
35 (ip1, _) = get_ip_and_ports(ctx, config[0])
36 (ip2, _) = get_ip_and_ports(ctx, config[1])
37
38 (host1,) = ctx.cluster.only(config[0]).remotes.iterkeys()
39 (host2,) = ctx.cluster.only(config[1]).remotes.iterkeys()
40 assert host1 is not None
41 assert host2 is not None
42
43 host1.run(
44 args = ["sudo", "iptables", "-A", "INPUT", "-p", "tcp", "-s",
45 ip2, "-j", "DROP"]
46 )
47 host2.run(
48 args = ["sudo", "iptables", "-A", "INPUT", "-p", "tcp", "-s",
49 ip1, "-j", "DROP"]
50 )
51
52 def reconnect(ctx, config):
53 assert len(config) == 2 # we can only disconnect pairs right now
54 # and we can only disconnect mons right now
55 assert config[0].startswith('mon.')
56 assert config[1].startswith('mon.')
57
58 (ip1, _) = get_ip_and_ports(ctx, config[0])
59 (ip2, _) = get_ip_and_ports(ctx, config[1])
60
61 (host1,) = ctx.cluster.only(config[0]).remotes.iterkeys()
62 (host2,) = ctx.cluster.only(config[1]).remotes.iterkeys()
63 assert host1 is not None
64 assert host2 is not None
65
66 host1.run(
67 args = ["sudo", "iptables", "-D", "INPUT", "-p", "tcp", "-s",
68 ip2, "-j", "DROP"]
69 )
70 host2.run(
71 args = ["sudo", "iptables", "-D", "INPUT", "-p", "tcp", "-s",
72 ip1, "-j", "DROP"]
73 )