def setup_ha_routers(self, router_public_ip, private_net_cidr):
        """Setup HA master router on agent1 and backup router on agent2"""
        router_info = self._generate_info(router_public_ip,
            private_net_cidr, enable_ha=True)
        get_ns_name = mock.patch.object(
            namespaces.RouterNamespace, '_get_ns_name').start()
        get_ns_name.return_value = "qrouter-{0}-{1}".format(
            router_info['id'], self.vpn_agent.host)

        router1 = self.manage_router(self.vpn_agent, router_info)

        router_info_2 = copy.deepcopy(router_info)
        router_info_2[l3_constants.HA_INTERFACE_KEY] = (
            l3_test_common.get_ha_interface(ip='169.254.192.2',
                                            mac='22:22:22:22:22:22'))
        get_ns_name.return_value = "qrouter-{0}-{1}".format(
            router_info['id'], self.failover_agent.host)
        router2 = self.manage_router(self.failover_agent, router_info_2)

        linux_utils.wait_until_true(lambda: router1.ha_state == 'master')
        linux_utils.wait_until_true(lambda: router2.ha_state == 'backup')

        port_namespace, port_ip = self.port_setup(router1)

        vpn_service = self.prepare_vpn_service_info(
            router1.router_id, router_public_ip, private_net_cidr)
        return {"router1": router1, "router2": router2,
                "port_namespace": port_namespace, "port_ip": port_ip,
                "vpn_service": vpn_service}
    def setup_ha_routers(self, router_public_ip, private_net_cidr):
        """Setup HA master router on agent1 and backup router on agent2"""
        router_info = self._generate_info(router_public_ip,
            private_net_cidr, enable_ha=True)
        get_ns_name = mock.patch.object(
            namespaces.RouterNamespace, '_get_ns_name').start()
        get_ns_name.return_value = "qrouter-{0}-{1}".format(
            router_info['id'], self.vpn_agent.host)

        router1 = self.manage_router(self.vpn_agent, router_info)

        router_info_2 = copy.deepcopy(router_info)
        router_info_2[l3_constants.HA_INTERFACE_KEY] = (
            l3_test_common.get_ha_interface(ip='169.254.192.2',
                                            mac='22:22:22:22:22:22'))
        get_ns_name.return_value = "qrouter-{0}-{1}".format(
            router_info['id'], self.failover_agent.host)
        router2 = self.manage_router(self.failover_agent, router_info_2)

        linux_utils.wait_until_true(lambda: router1.ha_state == 'master')
        linux_utils.wait_until_true(lambda: router2.ha_state == 'backup')

        port_namespace, port_ip = self.port_setup(router1)

        vpn_service = self.prepare_vpn_service_info(
            router1.router_id, router_public_ip, private_net_cidr)
        return {"router1": router1, "router2": router2,
                "port_namespace": port_namespace, "port_ip": port_ip,
                "vpn_service": vpn_service}
Example #3
0
    def test_ha_router_failover(self):
        router_info = self.generate_router_info(enable_ha=True)
        get_ns_name = mock.patch.object(
            namespaces.RouterNamespace, '_get_ns_name').start()
        get_ns_name.return_value = "%s%s%s" % (
            'qrouter-' + router_info['id'],
            self.NESTED_NAMESPACE_SEPARATOR, self.agent.host)
        router1 = self.manage_router(self.agent, router_info)

        router_info_2 = copy.deepcopy(router_info)
        router_info_2[l3_constants.HA_INTERFACE_KEY] = (
            l3_test_common.get_ha_interface(ip='169.254.192.2',
                                            mac='22:22:22:22:22:22'))

        get_ns_name.return_value = "%s%s%s" % (
            namespaces.RouterNamespace._get_ns_name(router_info_2['id']),
            self.NESTED_NAMESPACE_SEPARATOR, self.failover_agent.host)
        router2 = self.manage_router(self.failover_agent, router_info_2)

        utils.wait_until_true(lambda: router1.ha_state == 'master')
        utils.wait_until_true(lambda: router2.ha_state == 'backup')

        self.fail_ha_router(router1)

        utils.wait_until_true(lambda: router2.ha_state == 'master')
        utils.wait_until_true(lambda: router1.ha_state == 'backup')
Example #4
0
    def test_ha_router_failover(self):
        router_info = self.generate_router_info(enable_ha=True)
        get_ns_name = mock.patch.object(namespaces.RouterNamespace,
                                        '_get_ns_name').start()
        get_ns_name.return_value = "%s%s%s" % ('qrouter-' + router_info['id'],
                                               self.NESTED_NAMESPACE_SEPARATOR,
                                               self.agent.host)
        router1 = self.manage_router(self.agent, router_info)

        router_info_2 = copy.deepcopy(router_info)
        router_info_2[constants.HA_INTERFACE_KEY] = (
            l3_test_common.get_ha_interface(ip='169.254.192.2',
                                            mac='22:22:22:22:22:22'))

        get_ns_name.return_value = "%s%s%s" % (
            namespaces.RouterNamespace._get_ns_name(router_info_2['id']),
            self.NESTED_NAMESPACE_SEPARATOR, self.failover_agent.host)
        router2 = self.manage_router(self.failover_agent, router_info_2)

        common_utils.wait_until_true(lambda: router1.ha_state == 'master')
        common_utils.wait_until_true(lambda: router2.ha_state == 'backup')

        self.fail_ha_router(router1)

        common_utils.wait_until_true(lambda: router2.ha_state == 'master')
        common_utils.wait_until_true(lambda: router1.ha_state == 'backup')
Example #5
0
 def generate_router_info(self):
     super(SiteInfoWithHaRouter, self).generate_router_info()
     self.info["ha"] = True
     self.info["ha_vr_id"] = 1
     self.info[l3_constants.HA_INTERFACE_KEY] = l3_test_common.get_ha_interface()
     # Mock router namespace name, for when router is created
     self.get_ns_name.return_value = "qrouter-{0}-{1}".format(self.info["id"], self.host)
Example #6
0
    def test_ha_router_failover(self):
        router_info = self.generate_router_info(enable_ha=True)
        get_ns_name = mock.patch.object(namespaces.RouterNamespace, "_get_ns_name").start()
        get_ns_name.return_value = "%s%s%s" % (
            "qrouter-" + router_info["id"],
            self.NESTED_NAMESPACE_SEPARATOR,
            self.agent.host,
        )
        router1 = self.manage_router(self.agent, router_info)

        router_info_2 = copy.deepcopy(router_info)
        router_info_2[l3_constants.HA_INTERFACE_KEY] = l3_test_common.get_ha_interface(
            ip="169.254.192.2", mac="22:22:22:22:22:22"
        )

        get_ns_name.return_value = "%s%s%s" % (
            namespaces.RouterNamespace._get_ns_name(router_info_2["id"]),
            self.NESTED_NAMESPACE_SEPARATOR,
            self.failover_agent.host,
        )
        router2 = self.manage_router(self.failover_agent, router_info_2)

        utils.wait_until_true(lambda: router1.ha_state == "master")
        utils.wait_until_true(lambda: router2.ha_state == "backup")

        self.fail_ha_router(router1)

        utils.wait_until_true(lambda: router2.ha_state == "master")
        utils.wait_until_true(lambda: router1.ha_state == "backup")
Example #7
0
 def generate_router_info(self):
     super(SiteInfoWithHaRouter, self).generate_router_info()
     self.info['ha'] = True
     self.info['ha_vr_id'] = 1
     self.info[constants.HA_INTERFACE_KEY] = (
         l3_test_common.get_ha_interface())
     # Mock router namespace name, for when router is created
     self.get_ns_name.return_value = "qrouter-{0}-{1}".format(
         self.info['id'], self.host)
Example #8
0
 def generate_backup_router_info(self):
     # Clone router info, using different HA interface (using same ID)
     info = copy.deepcopy(self.info)
     info[l3_constants.HA_INTERFACE_KEY] = (l3_test_common.get_ha_interface(
         ip='169.254.192.2', mac='22:22:22:22:22:22'))
     # Mock router namespace name, for when router is created
     self.get_ns_name.return_value = "qrouter-{0}-{1}".format(
         info['id'], self.failover_host)
     return info
Example #9
0
 def generate_backup_router_info(self):
     # Clone router info, using different HA interface (using same ID)
     info = copy.deepcopy(self.info)
     info[l3_constants.HA_INTERFACE_KEY] = l3_test_common.get_ha_interface(
         ip="169.254.192.2", mac="22:22:22:22:22:22"
     )
     # Mock router namespace name, for when router is created
     self.get_ns_name.return_value = "qrouter-{0}-{1}".format(info["id"], self.failover_host)
     return info
Example #10
0
    def create_ha_routers(self):
        router_info = self.generate_router_info(enable_ha=True)
        router1 = self._create_router(router_info, self.agent)
        self._add_fip(router1, '192.168.111.12')

        r1_br = ip_lib.IPDevice(router1.driver.conf.external_network_bridge)
        r1_br.addr.add('19.4.4.1/24')
        r1_br.link.set_up()

        router_info_2 = copy.deepcopy(router_info)
        router_info_2[constants.HA_INTERFACE_KEY] = (
            l3_test_common.get_ha_interface(ip='169.254.192.2',
                                            mac='22:22:22:22:22:22'))
        router2 = self._create_router(router_info_2, self.failover_agent)

        r2_br = ip_lib.IPDevice(router2.driver.conf.external_network_bridge)
        r2_br.addr.add('19.4.4.1/24')
        r2_br.link.set_up()

        return (router1, router2)
Example #11
0
    def create_ha_routers(self):
        router_info = self.generate_router_info(enable_ha=True)
        router1 = self._create_router(router_info, self.agent)
        self._add_fip(router1, '192.168.111.12')

        r1_br = ip_lib.IPDevice(router1.driver.conf.ovs_integration_bridge)
        r1_br.addr.add('19.4.4.1/24')
        r1_br.link.set_up()

        router_info_2 = copy.deepcopy(router_info)
        router_info_2[constants.HA_INTERFACE_KEY] = (
            l3_test_common.get_ha_interface(ip='169.254.192.2',
                                            mac='22:22:22:22:22:22'))
        router2 = self._create_router(router_info_2, self.failover_agent)

        r2_br = ip_lib.IPDevice(router2.driver.conf.ovs_integration_bridge)
        r2_br.addr.add('19.4.4.1/24')
        r2_br.link.set_up()

        return (router1, router2)
 def _generate_info(self, public_ip, private_cidr, enable_ha=False):
     """Generate router info"""
     info = copy.deepcopy(FAKE_ROUTER)
     info['id'] = _uuid()
     info['_interfaces'][0]['id'] = _uuid()
     (info['_interfaces'][0]
      ['mac_address']) = common_utils.get_random_mac(MAC_BASE)
     (info['_interfaces'][0]['fixed_ips'][0]
      ['ip_address']) = str(private_cidr[4])
     info['_interfaces'][0]['subnets'][0].update({
         'cidr': str(private_cidr),
         'gateway_ip': str(private_cidr[1])})
     info['gw_port']['id'] = _uuid()
     info['gw_port']['fixed_ips'][0]['ip_address'] = str(public_ip)
     info['gw_port']['mac_address'] = common_utils.get_random_mac(MAC_BASE)
     if enable_ha:
         info['ha'] = True
         info['ha_vr_id'] = 1
         info[l3_constants.HA_INTERFACE_KEY] = (
             l3_test_common.get_ha_interface())
     else:
         info['ha'] = False
     return info
 def _generate_info(self, public_ip, private_cidr, enable_ha=False):
     """Generate router info"""
     info = copy.deepcopy(FAKE_ROUTER)
     info['id'] = _uuid()
     info['_interfaces'][0]['id'] = _uuid()
     (info['_interfaces'][0]
      ['mac_address']) = common_utils.get_random_mac(MAC_BASE)
     (info['_interfaces'][0]['fixed_ips'][0]
      ['ip_address']) = str(private_cidr[4])
     info['_interfaces'][0]['subnets'][0].update({
         'cidr': str(private_cidr),
         'gateway_ip': str(private_cidr[1])})
     info['gw_port']['id'] = _uuid()
     info['gw_port']['fixed_ips'][0]['ip_address'] = str(public_ip)
     info['gw_port']['mac_address'] = common_utils.get_random_mac(MAC_BASE)
     if enable_ha:
         info['ha'] = True
         info['ha_vr_id'] = 1
         info[l3_constants.HA_INTERFACE_KEY] = (
             l3_test_common.get_ha_interface())
     else:
         info['ha'] = False
     return info