예제 #1
0
    def _get_config(self):
        config = keepalived.KeepalivedConf()

        group1 = keepalived.KeepalivedGroup(1)
        group2 = keepalived.KeepalivedGroup(2)

        group1.set_notify('master', '/tmp/script.sh')

        instance1 = keepalived.KeepalivedInstance('MASTER',
                                                  'eth0',
                                                  1,
                                                  advert_int=5)
        instance1.set_authentication('AH', 'pass123')
        instance1.track_interfaces.append("eth0")

        vip_address1 = keepalived.KeepalivedVipAddress('192.168.1.0/24',
                                                       'eth1')

        vip_address2 = keepalived.KeepalivedVipAddress('192.168.2.0/24',
                                                       'eth2')

        vip_address3 = keepalived.KeepalivedVipAddress('192.168.3.0/24',
                                                       'eth2')

        vip_address_ex = keepalived.KeepalivedVipAddress(
            '192.168.55.0/24', 'eth10')

        instance1.vips.append(vip_address1)
        instance1.vips.append(vip_address2)
        instance1.vips.append(vip_address3)
        instance1.vips.append(vip_address_ex)

        virtual_route = keepalived.KeepalivedVirtualRoute(
            "0.0.0.0/0", "192.168.1.1", "eth1")
        instance1.virtual_routes.append(virtual_route)

        group1.add_instance(instance1)

        instance2 = keepalived.KeepalivedInstance('MASTER',
                                                  'eth4',
                                                  2,
                                                  mcast_src_ip='224.0.0.1')
        instance2.track_interfaces.append("eth4")

        vip_address1 = keepalived.KeepalivedVipAddress('192.168.3.0/24',
                                                       'eth6')

        instance2.vips.append(vip_address1)
        instance2.vips.append(vip_address2)
        instance2.vips.append(vip_address_ex)

        group2.add_instance(instance2)

        config.add_group(group1)
        config.add_instance(instance1)
        config.add_group(group2)
        config.add_instance(instance2)

        return config
예제 #2
0
    def _init_keepalived_manager(self, ri):
        ri.keepalived_manager = keepalived.KeepalivedManager(
            ri.router['id'],
            keepalived.KeepalivedConf(),
            conf_path=self.conf.ha_confs_path,
            namespace=ri.ns_name,
            root_helper=self.root_helper)

        config = ri.keepalived_manager.config

        interface_name = self.get_ha_device_name(ri.ha_port['id'])
        ha_port_cidr = ri.ha_port['subnet']['cidr']
        instance = keepalived.KeepalivedInstance(
            'BACKUP',
            interface_name,
            ri.ha_vr_id,
            ha_port_cidr,
            nopreempt=True,
            advert_int=self.conf.ha_vrrp_advert_int,
            priority=ri.ha_priority)
        instance.track_interfaces.append(interface_name)

        if self.conf.ha_vrrp_auth_password:
            # TODO(safchain): use oslo.config types when it will be available
            # in order to check the validity of ha_vrrp_auth_type
            instance.set_authentication(self.conf.ha_vrrp_auth_type,
                                        self.conf.ha_vrrp_auth_password)

        group = keepalived.KeepalivedGroup(ri.ha_vr_id)
        group.add_instance(instance)

        config.add_group(group)
        config.add_instance(instance)
예제 #3
0
    def test_state_exception(self):
        group = keepalived.KeepalivedGroup('group2')

        invalid_notify_state = 'a seal walks'
        self.assertRaises(keepalived.InvalidNotifyStateException,
                          group.set_notify, invalid_notify_state,
                          '/tmp/script.sh')

        invalid_vrrp_state = 'into a club'
        self.assertRaises(keepalived.InvalidInstanceStateException,
                          keepalived.KeepalivedInstance, invalid_vrrp_state,
                          'eth0', 33)

        invalid_auth_type = '[hip, hip]'
        instance = keepalived.KeepalivedInstance('MASTER', 'eth0', 1)
        self.assertRaises(keepalived.InvalidAuthenticationTypeExecption,
                          instance.set_authentication, invalid_auth_type,
                          'some_password')