Skip to content

Commit 0852142

Browse files
ralonsohbbezak
authored andcommitted
Revert "Track all interfaces in Keepalived"
This reverts commit bee07de. Reason for revert: The only interfaces tracked by keepalived are the HA interfaces. The fixed IP / floating IPs / routes are linked to the internal router interfaces or the gateway interface, that are interfaces not tracked by keepalived. These IP addresses / routes should have the suffix "no_track" in the configuration entry. This is commented in [1], when the keepalived VIP HA configuration was fixed, excluding any IP address other than the VIP of the HA interface, that are placed in the "virtual_ipaddress_excluded" and belong to no tracked interfaces. [1]https://github.com/openstack/neutron/blob/ad628353da68dcbf9e6ff25c47fd6753eee22683/neutron/agent/linux/keepalived.py#L271-L281 Change-Id: I4dfd89606042ba545559eb03d47fceee3b0895fc Closes-Bug: #2097770 (cherry picked from commit 438808f)
1 parent e3df9a3 commit 0852142

File tree

3 files changed

+33
-75
lines changed

3 files changed

+33
-75
lines changed

neutron/agent/linux/keepalived.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,11 @@ class KeepalivedVirtualRoute(object):
127127
"""A virtual route entry of a keepalived configuration."""
128128

129129
def __init__(self, destination, nexthop, interface_name=None,
130-
scope=None, track=True):
130+
scope=None):
131131
self.destination = destination
132132
self.nexthop = nexthop
133133
self.interface_name = interface_name
134134
self.scope = scope
135-
self.track = track
136135

137136
def build_config(self):
138137
output = self.destination
@@ -142,7 +141,7 @@ def build_config(self):
142141
output += ' dev %s' % self.interface_name
143142
if self.scope:
144143
output += ' scope %s' % self.scope
145-
if not self.track and _is_keepalived_use_no_track_supported():
144+
if _is_keepalived_use_no_track_supported():
146145
output += ' no_track'
147146
# NOTE(mstinsky): neutron and keepalived are adding the same routes on
148147
# primary routers. With this we ensure that both are adding the routes
@@ -225,7 +224,7 @@ def set_authentication(self, auth_type, password):
225224
self.authentication = (auth_type, password)
226225

227226
def add_vip(self, ip_cidr, interface_name, scope):
228-
track = interface_name not in self.track_interfaces
227+
track = interface_name in self.track_interfaces
229228
vip = KeepalivedVipAddress(ip_cidr, interface_name, scope, track=track)
230229
if vip not in self.vips:
231230
self.vips.append(vip)

neutron/tests/functional/agent/l3/framework.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@
7171
169.254.0.1/24 dev %(ha_device_name)s
7272
}
7373
virtual_ipaddress_excluded {
74-
%(floating_ip_cidr)s dev %(ex_device_name)s
75-
%(external_device_cidr)s dev %(ex_device_name)s
76-
%(internal_device_cidr)s dev %(internal_device_name)s
77-
%(ex_port_ipv6)s dev %(ex_device_name)s scope link
78-
%(int_port_ipv6)s dev %(internal_device_name)s scope link
74+
%(floating_ip_cidr)s dev %(ex_device_name)s no_track
75+
%(external_device_cidr)s dev %(ex_device_name)s no_track
76+
%(internal_device_cidr)s dev %(internal_device_name)s no_track
77+
%(ex_port_ipv6)s dev %(ex_device_name)s scope link no_track
78+
%(int_port_ipv6)s dev %(internal_device_name)s scope link no_track
7979
}
8080
virtual_routes {
81-
0.0.0.0/0 via %(default_gateway_ip)s dev %(ex_device_name)s protocol static
82-
8.8.8.0/24 via 19.4.4.4 protocol static
83-
%(extra_subnet_cidr)s dev %(ex_device_name)s scope link protocol static
81+
0.0.0.0/0 via %(default_gateway_ip)s dev %(ex_device_name)s no_track protocol static
82+
8.8.8.0/24 via 19.4.4.4 no_track protocol static
83+
%(extra_subnet_cidr)s dev %(ex_device_name)s scope link no_track protocol static
8484
}
8585
}""" # noqa: E501 # pylint: disable=line-too-long
8686

neutron/tests/unit/agent/linux/test_keepalived.py

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_get_free_range_not_found(self):
8787

8888
class KeepalivedConfBaseMixin(object):
8989

90-
def _get_config(self, track=True):
90+
def _get_config(self):
9191
config = keepalived.KeepalivedConf()
9292

9393
instance1 = keepalived.KeepalivedInstance('MASTER', 'eth0', 1,
@@ -97,16 +97,16 @@ def _get_config(self, track=True):
9797
instance1.track_interfaces.append("eth0")
9898

9999
vip_address1 = keepalived.KeepalivedVipAddress('192.168.1.0/24',
100-
'eth1', track=track)
100+
'eth1', track=False)
101101

102102
vip_address2 = keepalived.KeepalivedVipAddress('192.168.2.0/24',
103-
'eth2', track=track)
103+
'eth2', track=False)
104104

105105
vip_address3 = keepalived.KeepalivedVipAddress('192.168.3.0/24',
106-
'eth2', track=track)
106+
'eth2', track=False)
107107

108108
vip_address_ex = keepalived.KeepalivedVipAddress('192.168.55.0/24',
109-
'eth10', track=track)
109+
'eth10', track=False)
110110

111111
instance1.vips.append(vip_address1)
112112
instance1.vips.append(vip_address2)
@@ -115,7 +115,7 @@ def _get_config(self, track=True):
115115

116116
virtual_route = keepalived.KeepalivedVirtualRoute(n_consts.IPv4_ANY,
117117
"192.168.1.1",
118-
"eth1", track=track)
118+
"eth1")
119119
instance1.virtual_routes.gateway_routes = [virtual_route]
120120

121121
instance2 = keepalived.KeepalivedInstance('MASTER', 'eth4', 2,
@@ -124,7 +124,7 @@ def _get_config(self, track=True):
124124
instance2.track_interfaces.append("eth4")
125125

126126
vip_address1 = keepalived.KeepalivedVipAddress('192.168.3.0/24',
127-
'eth6', track=track)
127+
'eth6', track=False)
128128

129129
instance2.vips.append(vip_address1)
130130
instance2.vips.append(vip_address2)
@@ -192,8 +192,7 @@ def test_config_generation(self):
192192
keepalived, '_is_keepalived_use_no_track_supported',
193193
return_value=True):
194194
config = self._get_config()
195-
self.assertEqual(self.expected.replace(' no_track', ''),
196-
config.get_config_str())
195+
self.assertEqual(self.expected, config.get_config_str())
197196

198197
def test_config_generation_no_track_not_supported(self):
199198
self._mock_no_track_supported.start().return_value = False
@@ -208,7 +207,7 @@ def test_config_with_reset(self):
208207
with mock.patch.object(
209208
keepalived, '_is_keepalived_use_no_track_supported',
210209
return_value=True):
211-
config = self._get_config(track=False)
210+
config = self._get_config()
212211
self.assertEqual(self.expected, config.get_config_str())
213212

214213
config.reset()
@@ -239,24 +238,20 @@ def test_state_exception(self):
239238

240239
class KeepalivedInstanceRoutesTestCase(KeepalivedBaseTestCase):
241240
@classmethod
242-
def _get_instance_routes(cls, track=True):
241+
def _get_instance_routes(cls):
243242
routes = keepalived.KeepalivedInstanceRoutes()
244243
default_gw_eth0 = keepalived.KeepalivedVirtualRoute(
245-
'0.0.0.0/0', '1.0.0.254', 'eth0', track=track)
244+
'0.0.0.0/0', '1.0.0.254', 'eth0')
246245
default_gw_eth1 = keepalived.KeepalivedVirtualRoute(
247-
'::/0', 'fe80::3e97:eff:fe26:3bfa/64', 'eth1',
248-
track=track)
246+
'::/0', 'fe80::3e97:eff:fe26:3bfa/64', 'eth1')
249247
routes.gateway_routes = [default_gw_eth0, default_gw_eth1]
250248
extra_routes = [
251-
keepalived.KeepalivedVirtualRoute(
252-
'10.0.0.0/8', '1.0.0.1', track=track),
253-
keepalived.KeepalivedVirtualRoute(
254-
'20.0.0.0/8', '2.0.0.2', track=track)]
249+
keepalived.KeepalivedVirtualRoute('10.0.0.0/8', '1.0.0.1'),
250+
keepalived.KeepalivedVirtualRoute('20.0.0.0/8', '2.0.0.2')]
255251
routes.extra_routes = extra_routes
256252
extra_subnets = [
257253
keepalived.KeepalivedVirtualRoute(
258-
'30.0.0.0/8', None, 'eth0', scope='link',
259-
track=track)]
254+
'30.0.0.0/8', None, 'eth0', scope='link')]
260255
routes.extra_subnets = extra_subnets
261256
return routes
262257

@@ -282,7 +277,7 @@ def test_build_config(self):
282277
with mock.patch.object(
283278
keepalived, '_is_keepalived_use_no_track_supported',
284279
return_value=True):
285-
routes = self._get_instance_routes(track=False)
280+
routes = self._get_instance_routes()
286281
self.assertEqual(expected, '\n'.join(routes.build_config()))
287282

288283
def _get_no_track_less_expected_config(self):
@@ -295,19 +290,11 @@ def _get_no_track_less_expected_config(self):
295290
}"""
296291
return expected
297292

298-
def test_build_config_without_no_track(self):
299-
with mock.patch.object(
300-
keepalived, '_is_keepalived_use_no_track_supported',
301-
return_value=True):
302-
routes = self._get_instance_routes()
303-
self.assertEqual(self._get_no_track_less_expected_config(),
304-
'\n'.join(routes.build_config()))
305-
306293
def test_build_config_no_track_not_supported(self):
307294
with mock.patch.object(
308295
keepalived, '_is_keepalived_use_no_track_supported',
309296
return_value=False):
310-
routes = self._get_instance_routes(track=False)
297+
routes = self._get_instance_routes()
311298
self.assertEqual(self._get_no_track_less_expected_config(),
312299
'\n'.join(routes.build_config()))
313300

@@ -319,14 +306,12 @@ def test_get_primary_vip(self):
319306
['169.254.192.0/18'])
320307
self.assertEqual('169.254.0.42/24', instance.get_primary_vip())
321308

322-
def _test_remove_addresses_by_interface(self, track=True):
323-
config = self._get_config(track=track)
309+
def _test_remove_addresses_by_interface(self, no_track_value):
310+
config = self._get_config()
324311
instance = config.get_instance(1)
325312
instance.remove_vips_vroutes_by_interface('eth2')
326313
instance.remove_vips_vroutes_by_interface('eth10')
327314

328-
no_track_value = ' no_track' if not track else ''
329-
330315
expected = KEEPALIVED_GLOBAL_CONFIG + textwrap.dedent("""
331316
vrrp_instance VR_1 {
332317
state MASTER
@@ -378,19 +363,13 @@ def test_remove_addresses_by_interface(self):
378363
with mock.patch.object(
379364
keepalived, '_is_keepalived_use_no_track_supported',
380365
return_value=True):
381-
self._test_remove_addresses_by_interface()
382-
383-
def test_remove_addresses_by_interface_with_no_track(self):
384-
with mock.patch.object(
385-
keepalived, '_is_keepalived_use_no_track_supported',
386-
return_value=True):
387-
self._test_remove_addresses_by_interface(track=False)
366+
self._test_remove_addresses_by_interface(" no_track")
388367

389368
def test_remove_address_by_interface_no_track_not_supported(self):
390369
with mock.patch.object(
391370
keepalived, '_is_keepalived_use_no_track_supported',
392371
return_value=False):
393-
self._test_remove_addresses_by_interface()
372+
self._test_remove_addresses_by_interface("")
394373

395374
def test_build_config_no_vips(self):
396375
expected = textwrap.dedent("""\
@@ -457,16 +436,6 @@ def test_virtual_route_with_dev(self):
457436
return_value=True):
458437
route = keepalived.KeepalivedVirtualRoute(
459438
n_consts.IPv4_ANY, '1.2.3.4', 'eth0')
460-
self.assertEqual(
461-
'0.0.0.0/0 via 1.2.3.4 dev eth0 protocol static',
462-
route.build_config())
463-
464-
def test_virtual_route_with_dev_supported_no_track(self):
465-
with mock.patch.object(
466-
keepalived, '_is_keepalived_use_no_track_supported',
467-
return_value=True):
468-
route = keepalived.KeepalivedVirtualRoute(
469-
n_consts.IPv4_ANY, '1.2.3.4', 'eth0', track=False)
470439
self.assertEqual(
471440
'0.0.0.0/0 via 1.2.3.4 dev eth0 no_track protocol static',
472441
route.build_config())
@@ -480,21 +449,11 @@ def test_virtual_route_with_dev_no_track_not_supported(self):
480449
self.assertEqual('0.0.0.0/0 via 1.2.3.4 dev eth0 protocol static',
481450
route.build_config())
482451

483-
def test_virtual_route_with_dev_no_track_not_supported_not_track(self):
484-
with mock.patch.object(
485-
keepalived, '_is_keepalived_use_no_track_supported',
486-
return_value=False):
487-
route = keepalived.KeepalivedVirtualRoute(
488-
n_consts.IPv4_ANY, '1.2.3.4', 'eth0', track=False)
489-
self.assertEqual('0.0.0.0/0 via 1.2.3.4 dev eth0 protocol static',
490-
route.build_config())
491-
492452
def test_virtual_route_without_dev(self):
493453
with mock.patch.object(
494454
keepalived, '_is_keepalived_use_no_track_supported',
495455
return_value=True):
496-
route = keepalived.KeepalivedVirtualRoute(
497-
'50.0.0.0/8', '1.2.3.4', track=False)
456+
route = keepalived.KeepalivedVirtualRoute('50.0.0.0/8', '1.2.3.4')
498457
self.assertEqual('50.0.0.0/8 via 1.2.3.4 no_track protocol static',
499458
route.build_config())
500459

0 commit comments

Comments
 (0)