-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_floating_ip.py
More file actions
215 lines (149 loc) · 6.61 KB
/
test_floating_ip.py
File metadata and controls
215 lines (149 loc) · 6.61 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
"""
Floating IP Acceptance Tests
============================
Using Floating IP, customers can implement high availability on the software
level using the cloudscale.ch cloud.
"""
from util import assert_takes_no_longer_than
from util import in_parallel
def test_floating_ip_connectivity(prober, server, floating_ip):
""" Floating IPs can be assigned to servers after they have been started.
"""
# Assign the Floating IP to the server
floating_ip.assign(server)
# Configure the Floating IP on the server
server.configure_floating_ip(floating_ip)
# Check if the Floating IP is reachable (wait up to 10 seconds)
prober.ping(floating_ip, count=1, tries=10)
# Expect 30 successful pings within 15 seconds
prober.ping(floating_ip, count=30, interval=0.5)
def test_multiple_floating_ips(prober, server, create_floating_ip):
""" A server may have up to fifteen Floating IPs assigned to it. """
# Create and assign Floating IPs
ips = [
create_floating_ip(
ip_version=4,
server=server.uuid
) for _ in range(15)
]
# Configure the Floating IPs on the server
for ip in ips:
server.configure_floating_ip(ip)
# Make sure each Floating IP can be pinged from the prober
for ip in ips:
# Wait up to 15 seconds for the change to propagate
prober.ping(ip, timeout=1, tries=15)
def test_floating_ip_stability(prober, create_server, server_group,
floating_ipv4, floating_ipv6):
""" Floating IPs can be moved between servers for high availability.
Here we test a manual Floating IP move where the configuration of both
servers is changed as the Floating IP is moved. We ensure that after this
has happened, no packets are lost.
"""
# Create two server to assign the Floating IPs
s1, s2 = in_parallel(create_server, instances=(
{'name': 's1', 'server_groups': [server_group.uuid]},
{'name': 's2', 'server_groups': [server_group.uuid]},
))
for floating_ip in floating_ipv4, floating_ipv6:
# Configure the Floating IP on each server
for s in s1, s2:
# Assign the address to one server
floating_ip.assign(s)
# Configure the address on that server
s.configure_floating_ip(floating_ip)
# Wait up to 15 seconds for the change to propagate
prober.ping(floating_ip, timeout=1, tries=15)
# Expect 60 successful pings in 30 seconds
prober.ping(floating_ip, interval=0.5, count=60)
# Make sure the DHCP assigned IP still works
prober.ping(s.ip('public', floating_ip.version))
# Drop the interface to ensure the next test hits the right target
s.unconfigure_floating_ip(floating_ip)
# Check that the Floating IP is no longer reachable
prober.ping(floating_ip, expect_failure=True)
def test_floating_ip_failover(prober, create_server, server_group,
floating_ipv4, floating_ipv6):
""" Floating IPs can be moved between servers for high availability.
Here we test a manual Floating IP move, where only the API is changed and
the servers are not informed of the change.
"""
# Create two server to assign the Floating IPs
s1, s2 = in_parallel(create_server, instances=(
{'name': 's1', 'server_groups': [server_group.uuid]},
{'name': 's2', 'server_groups': [server_group.uuid]},
))
# Install nginx on the two servers to get unique content for each server
for s in s1, s2:
s.assert_run('sudo apt update --allow-releaseinfo-change')
s.assert_run('sudo apt install -y nginx')
# Set unique content for each server
s1.assert_run('echo s1 | sudo dd of=/var/www/html/index.html')
s2.assert_run('echo s2 | sudo dd of=/var/www/html/index.html')
for floating_ip in floating_ipv4, floating_ipv6:
# Point the Floating IP to the first server
floating_ip.assign(s1)
# Configure the Floating IP on both servers
for s in s1, s2:
s.configure_floating_ip(floating_ip)
# Try to get the content within ten seconds
prober.wait_for_http_content(floating_ip, 's1', seconds=10)
# Point the Floating IP to the second server
floating_ip.assign(s2)
# Try to get the content within ten seconds
prober.wait_for_http_content(floating_ip, 's2', seconds=10)
def test_floating_ip_mass_failover(prober, create_server, server_group,
create_floating_ip):
""" Floating IP addresses can be re-assigned en masse. """
# Create two server to assign the Floating IPs
s1, s2 = in_parallel(create_server, instances=(
{'name': 's1', 'server_groups': [server_group.uuid]},
{'name': 's2', 'server_groups': [server_group.uuid]},
))
# Create, assign, and configure 15 Floating IPs
ips = [
create_floating_ip(
ip_version=4,
server=s1.uuid
) for _ in range(10)
]
for ip in ips:
s1.configure_floating_ip(ip)
s2.configure_floating_ip(ip)
assert s1.reachable_via_ip(*ips, timeout=15)
# Move the Floating IPs to s2
with assert_takes_no_longer_than(seconds=40):
for ip in ips:
ip.assign(s2)
assert s2.reachable_via_ip(*ips, timeout=15)
# Move the Floating IPs to s1
with assert_takes_no_longer_than(seconds=40):
for ip in ips:
ip.assign(s1)
assert s1.reachable_via_ip(*ips, timeout=15)
def test_floating_network(prober, server, floating_network):
""" Floating Networks (IPv6) can be used to assign a large number
of addresses to a single server to act as a firewall for the other
instances.
"""
# Assign the floating network to the server
floating_network.assign(server)
# The Floating Network has a prefix length of 56
assert floating_network.network.prefixlen == 56
# We can now ping any address in the network
test_addresses = (
floating_network.network[0],
floating_network.network[1000],
floating_network.network[-1],
)
for address in test_addresses:
# Configure the address
server.configure_floating_ip(address)
# Wait up to 10 seconds for the change to propagate
prober.ping(address, timeout=1, tries=10)
# Expect twenty successful pings in 10 seconds
prober.ping(address, interval=0.5, count=20)
# Take it down
server.unconfigure_floating_ip(address)
# Make sure it is gone
prober.ping(address, expect_failure=True)