Пример #1
0
    def update_vrrp_conf(self, loadbalancer, amphorae_network_config):
        """Update amphorae of the loadbalancer with a new VRRP configuration

        :param loadbalancer: loadbalancer object
        :param amphorae_network_config: amphorae network configurations
        """
        templater = jinja_cfg.KeepalivedJinjaTemplater()

        LOG.debug("Update loadbalancer %s amphora VRRP configuration.",
                  loadbalancer.id)

        for amp in six.moves.filter(
                lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
                loadbalancer.amphorae):

            self._populate_amphora_api_version(amp)
            # Get the VIP subnet prefix for the amphora
            # For amphorav2 amphorae_network_config will be list of dicts
            try:
                vip_cidr = amphorae_network_config[amp.id].vip_subnet.cidr
            except AttributeError:
                vip_cidr = amphorae_network_config[amp.id][
                    constants.VIP_SUBNET][constants.CIDR]

            # Generate Keepalived configuration from loadbalancer object
            config = templater.build_keepalived_config(loadbalancer, amp,
                                                       vip_cidr)
            self.clients[amp.api_version].upload_vrrp_config(amp, config)
Пример #2
0
    def update_vrrp_conf(self, loadbalancer):
        """Update amphorae of the loadbalancer with a new VRRP configuration

        :param loadbalancer: loadbalancer object
        """
        templater = jinja_cfg.KeepalivedJinjaTemplater()

        LOG.debug("Update loadbalancer %s amphora VRRP configuration.",
                  loadbalancer.id)

        for amp in six.moves.filter(
                lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
                loadbalancer.amphorae):
            # Generate Keepalived configuration from loadbalancer object
            config = templater.build_keepalived_config(loadbalancer, amp)
            self.client.upload_vrrp_config(amp, config)
Пример #3
0
    def update_vrrp_conf(self, loadbalancer, amphorae_network_config):
        """Update amphorae of the loadbalancer with a new VRRP configuration

        :param loadbalancer: loadbalancer object
        :param amphorae_network_config: amphorae network configurations
        """
        templater = jinja_cfg.KeepalivedJinjaTemplater()

        LOG.debug("Update loadbalancer %s amphora VRRP configuration.",
                  loadbalancer.id)

        for amp in six.moves.filter(
                lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
                loadbalancer.amphorae):

            # Get the VIP subnet prefix for the amphora
            vip_cidr = amphorae_network_config[amp.id].vip_subnet.cidr

            # Generate Keepalived configuration from loadbalancer object
            config = templater.build_keepalived_config(loadbalancer, amp,
                                                       vip_cidr)
            self.client.upload_vrrp_config(amp, config)
Пример #4
0
    def update_vrrp_conf(self,
                         loadbalancer,
                         amphorae_network_config,
                         amphora,
                         timeout_dict=None):
        """Update amphora of the loadbalancer with a new VRRP configuration

        :param loadbalancer: loadbalancer object
        :param amphorae_network_config: amphorae network configurations
        :param amphora: The amphora object to update.
        :param timeout_dict: Dictionary of timeout values for calls to the
                             amphora. May contain: req_conn_timeout,
                             req_read_timeout, conn_max_retries,
                             conn_retry_interval
        """
        if amphora.status != constants.AMPHORA_ALLOCATED:
            LOG.debug(
                'update_vrrp_conf called for un-allocated amphora %s. '
                'Ignoring.', amphora.id)
            return

        templater = jinja_cfg.KeepalivedJinjaTemplater()

        LOG.debug("Update amphora %s VRRP configuration.", amphora.id)

        self._populate_amphora_api_version(amphora)
        # Get the VIP subnet prefix for the amphora
        # For amphorav2 amphorae_network_config will be list of dicts
        try:
            vip_cidr = amphorae_network_config[amphora.id].vip_subnet.cidr
        except AttributeError:
            vip_cidr = amphorae_network_config[amphora.id][
                constants.VIP_SUBNET][constants.CIDR]

        # Generate Keepalived configuration from loadbalancer object
        config = templater.build_keepalived_config(loadbalancer, amphora,
                                                   vip_cidr)
        self.clients[amphora.api_version].upload_vrrp_config(amphora, config)
Пример #5
0
    def setUp(self):
        super().setUp()
        conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
        conf.config(group="haproxy_amphora", base_path='/tmp/test')
        conf.config(group="keepalived_vrrp", vrrp_garp_refresh_interval=5)
        conf.config(group="keepalived_vrrp", vrrp_garp_refresh_count=2)
        conf.config(group="keepalived_vrrp", vrrp_check_interval=5)
        conf.config(group="keepalived_vrrp", vrrp_fail_count=2)
        conf.config(group="keepalived_vrrp", vrrp_success_count=2)

        self.templater = jinja_cfg.KeepalivedJinjaTemplater()

        self.amphora1 = mock.MagicMock()
        self.amphora1.status = constants.AMPHORA_ALLOCATED
        self.amphora1.vrrp_ip = '10.0.0.1'
        self.amphora1.role = constants.ROLE_MASTER
        self.amphora1.vrrp_interface = 'eth1'
        self.amphora1.vrrp_id = 1
        self.amphora1.vrrp_priority = 100

        self.amphora2 = mock.MagicMock()
        self.amphora2.status = constants.AMPHORA_ALLOCATED
        self.amphora2.vrrp_ip = '10.0.0.2'
        self.amphora2.role = constants.ROLE_BACKUP
        self.amphora2.vrrp_interface = 'eth1'
        self.amphora2.vrrp_id = 1
        self.amphora2.vrrp_priority = 90

        self.lb = mock.MagicMock()
        self.lb.amphorae = [self.amphora1, self.amphora2]
        self.lb.vrrp_group.vrrp_group_name = 'TESTGROUP'
        self.lb.vrrp_group.vrrp_auth_type = constants.VRRP_AUTH_DEFAULT
        self.lb.vrrp_group.vrrp_auth_pass = '******'
        self.lb.vip.ip_address = '10.1.0.5'
        self.lb.vrrp_group.advert_int = 10

        self.ref_conf = ("vrrp_script check_script {\n"
                         "  script /tmp/test/vrrp/check_script.sh\n"
                         "  interval 5\n"
                         "  fall 2\n"
                         "  rise 2\n"
                         "}\n"
                         "\n"
                         "vrrp_instance TESTGROUP {\n"
                         "  state MASTER\n"
                         "  interface eth1\n"
                         "  virtual_router_id 1\n"
                         "  priority 100\n"
                         "  nopreempt\n"
                         "  accept\n"
                         "  garp_master_refresh 5\n"
                         "  garp_master_refresh_repeat 2\n"
                         "  advert_int 10\n"
                         "  authentication {\n"
                         "    auth_type PASS\n"
                         "    auth_pass TESTPASSWORD\n"
                         "  }\n"
                         "\n"
                         "  unicast_src_ip 10.0.0.1\n"
                         "  unicast_peer {\n"
                         "    10.0.0.2\n"
                         "  }\n"
                         "\n"
                         "  virtual_ipaddress {\n"
                         "    10.1.0.5\n"
                         "  }\n\n"
                         "  virtual_routes {\n"
                         "    10.1.0.0/24 dev eth1 src 10.1.0.5 scope link "
                         "table 1\n"
                         "  }\n\n"
                         "  virtual_rules {\n"
                         "    from 10.1.0.5/32 table 1 priority 100\n"
                         "  }\n\n"
                         "  track_script {\n"
                         "    check_script\n"
                         "  }\n"
                         "}")

        self.amphora1v6 = copy.deepcopy(self.amphora1)
        self.amphora1v6.vrrp_ip = '2001:db8::10'
        self.amphora2v6 = copy.deepcopy(self.amphora2)
        self.amphora2v6.vrrp_ip = '2001:db8::11'
        self.lbv6 = copy.deepcopy(self.lb)
        self.lbv6.amphorae = [self.amphora1v6, self.amphora2v6]
        self.lbv6.vip.ip_address = '2001:db8::15'

        self.ref_v6_conf = ("vrrp_script check_script {\n"
                            "  script /tmp/test/vrrp/check_script.sh\n"
                            "  interval 5\n"
                            "  fall 2\n"
                            "  rise 2\n"
                            "}\n"
                            "\n"
                            "vrrp_instance TESTGROUP {\n"
                            "  state MASTER\n"
                            "  interface eth1\n"
                            "  virtual_router_id 1\n"
                            "  priority 100\n"
                            "  nopreempt\n"
                            "  accept\n"
                            "  garp_master_refresh 5\n"
                            "  garp_master_refresh_repeat 2\n"
                            "  advert_int 10\n"
                            "  authentication {\n"
                            "    auth_type PASS\n"
                            "    auth_pass TESTPASSWORD\n"
                            "  }\n"
                            "\n"
                            "  unicast_src_ip 2001:db8::10\n"
                            "  unicast_peer {\n"
                            "    2001:db8::11\n"
                            "  }\n"
                            "\n"
                            "  virtual_ipaddress {\n"
                            "    2001:db8::15\n"
                            "  }\n\n"
                            "  virtual_routes {\n"
                            "    2001:db8::/64 dev eth1 src "
                            "2001:db8::15 scope link table 1\n"
                            "  }\n\n"
                            "  virtual_rules {\n"
                            "    from 2001:db8::15/128 table 1 "
                            "priority 100\n"
                            "  }\n\n"
                            "  track_script {\n"
                            "    check_script\n"
                            "  }\n"
                            "}")
Пример #6
0
    def setUp(self):
        super(TestVRRPRestDriver, self).setUp()
        self.templater = jinja_cfg.KeepalivedJinjaTemplater()

        self.amphora1 = mock.MagicMock()
        self.amphora1.status = constants.AMPHORA_ALLOCATED
        self.amphora1.vrrp_ip = '10.0.0.1'
        self.amphora1.role = constants.ROLE_MASTER
        self.amphora1.vrrp_interface = 'eth1'
        self.amphora1.vrrp_id = 1
        self.amphora1.vrrp_priority = 100

        self.amphora2 = mock.MagicMock()
        self.amphora2.status = constants.AMPHORA_ALLOCATED
        self.amphora2.vrrp_ip = '10.0.0.2'
        self.amphora2.role = constants.ROLE_BACKUP
        self.amphora2.vrrp_interface = 'eth1'
        self.amphora2.vrrp_id = 1
        self.amphora2.vrrp_priority = 90

        self.lb = mock.MagicMock()
        self.lb.amphorae = [self.amphora1, self.amphora2]
        self.lb.vrrp_group.vrrp_group_name = 'TESTGROUP'
        self.lb.vrrp_group.vrrp_auth_type = constants.VRRP_AUTH_DEFAULT
        self.lb.vrrp_group.vrrp_auth_pass = '******'
        self.lb.vip.ip_address = '10.1.0.5'
        self.lb.vrrp_group.advert_int = 10

        self.ref_conf = ("\n"
                         "\n"
                         "vrrp_script check_script {\n"
                         "  script /tmp/test/vrrp/check_script.sh\n"
                         "  interval 5\n"
                         "  fall 2\n"
                         "  rise 2\n"
                         "}\n"
                         "\n"
                         "vrrp_instance TESTGROUP {\n"
                         " state MASTER\n"
                         " interface eth1\n"
                         " virtual_router_id 1\n"
                         " priority 100\n"
                         " nopreempt\n"
                         " garp_master_refresh 5\n"
                         " garp_master_refresh_repeat 2\n"
                         " advert_int 10\n"
                         " authentication {\n"
                         "  auth_type PASS\n"
                         "  auth_pass TESTPASSWORD\n"
                         " }\n"
                         "\n"
                         " unicast_src_ip 10.0.0.1\n"
                         " unicast_peer {\n"
                         "       10.0.0.2\n"
                         "\n"
                         " }\n"
                         "\n"
                         " virtual_ipaddress {\n"
                         "  10.1.0.5\n"
                         " }\n"
                         " track_script {\n"
                         "    check_script\n"
                         " }\n"
                         "}\n")