super(InvalidAuthenticationTypeException, self).__init__(**kwargs)
+class VIPDuplicateAddressException(exceptions.NeutronException):
+ message = _('Attempted to add duplicate VIP address, '
+ 'existing vips are: %(existing_vips)s, '
+ 'duplicate vip is: %(duplicate_vip)s')
+
+ def __init__(self, **kwargs):
+ kwargs['existing_vips'] = ', '.join(str(vip) for vip in
+ kwargs['existing_vips'])
+ super(VIPDuplicateAddressException, self).__init__(**kwargs)
+
+
class KeepalivedVipAddress(object):
"""A virtual address entry of a keepalived configuration."""
self.interface_name = interface_name
self.scope = scope
+ def __eq__(self, other):
+ return (isinstance(other, KeepalivedVipAddress) and
+ self.ip_address == other.ip_address)
+
+ def __str__(self):
+ return '[%s, %s, %s]' % (self.ip_address,
+ self.interface_name,
+ self.scope)
+
def build_config(self):
result = '%s dev %s' % (self.ip_address, self.interface_name)
if self.scope:
self.authentication = (auth_type, password)
def add_vip(self, ip_cidr, interface_name, scope):
- self.vips.append(KeepalivedVipAddress(ip_cidr, interface_name, scope))
+ vip = KeepalivedVipAddress(ip_cidr, interface_name, scope)
+ if vip in self.vips:
+ raise VIPDuplicateAddressException(existing_vips=self.vips,
+ duplicate_vip=vip)
+ self.vips.append(vip)
def remove_vips_vroutes_by_interface(self, interface_name):
self.vips = [vip for vip in self.vips
self.assertEqual('fe80::3e97:eff:fe26:3bfa/64 dev eth1 scope link',
vip.build_config())
+ def test_add_vip_returns_exception_on_duplicate_ip(self):
+ instance = keepalived.KeepalivedInstance('MASTER', 'eth0', 1,
+ ['169.254.192.0/18'])
+ instance.add_vip('192.168.222.1/32', 'eth11', None)
+ self.assertRaises(keepalived.VIPDuplicateAddressException,
+ instance.add_vip, '192.168.222.1/32', 'eth12',
+ 'link')
+
class KeepalivedVirtualRouteTestCase(base.BaseTestCase):
def test_virtual_route_with_dev(self):