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