]> git.proxmox.com Git - ceph.git/blame - ceph/qa/tasks/netsplit.py
import ceph quincy 17.2.4
[ceph.git] / ceph / qa / tasks / netsplit.py
CommitLineData
f67539c2
TL
1"""
2Functions to netsplit test machines.
3
4At present, you must specify monitors to disconnect, and it
5drops those IP pairs. This means OSDs etc on the hosts which use
6the same IP will also be blocked! If you are using multiple IPs on the
7same host within the cluster, daemons on those other IPs will get
8through.
9"""
10import logging
11import re
12
13log = logging.getLogger(__name__)
14
15def 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
30def 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
20effc67
TL
38 (host1,) = ctx.cluster.only(config[0]).remotes.keys()
39 (host2,) = ctx.cluster.only(config[1]).remotes.keys()
f67539c2
TL
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
52def 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
20effc67
TL
61 (host1,) = ctx.cluster.only(config[0]).remotes.keys()
62 (host2,) = ctx.cluster.only(config[1]).remotes.keys()
f67539c2
TL
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 )