예제 #1
0
    def test_bgpaas(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name,
                                              ['10.0.0.0/24', '1000::/16'])

        project_name = ['default-domain', 'default-project']
        project_obj = self._vnc_lib.project_read(fq_name=project_name)
        port_name = self.id() + 'p1'
        port_obj = VirtualMachineInterface(port_name, parent_obj=project_obj)
        port_obj.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port_obj)

        v6_obj = InstanceIp(name=port_name + '-v6')
        v6_obj.set_virtual_machine_interface(port_obj)
        v6_obj.set_virtual_network(vn1_obj)
        v6_obj.set_instance_ip_family('v6')
        self._vnc_lib.instance_ip_create(v6_obj)

        v4_obj = InstanceIp(name=port_name + '-v4')
        v4_obj.set_virtual_machine_interface(port_obj)
        v4_obj.set_virtual_network(vn1_obj)
        v4_obj.set_instance_ip_family('v4')
        self._vnc_lib.instance_ip_create(v4_obj)

        bgpaas_name = self.id() + 'bgp1'
        bgpaas = BgpAsAService(bgpaas_name,
                               parent_obj=project_obj,
                               autonomous_system=64512)
        bgpaas.add_virtual_machine_interface(port_obj)
        self._vnc_lib.bgp_as_a_service_create(bgpaas)

        router1_name = vn1_obj.get_fq_name_str(
        ) + ':' + vn1_name + ':' + port_name
        self.wait_to_get_object(config_db.BgpAsAServiceST,
                                bgpaas.get_fq_name_str())
        self.wait_to_get_object(config_db.BgpRouterST, router1_name)
        server_fq_name = ':'.join(self.get_ri_name(vn1_obj)) + ':bgpaas-server'
        self.wait_to_get_object(config_db.BgpRouterST, server_fq_name)
        server_router_obj = self._vnc_lib.bgp_router_read(
            fq_name_str=server_fq_name)

        router1_name = vn1_obj.get_fq_name_str(
        ) + ':' + vn1_name + ':' + port_name
        mx_bgp_router = self.create_bgp_router("mx-bgp-router", "contrail")
        mx_bgp_router_name = mx_bgp_router.get_fq_name_str()
        self.wait_to_get_object(config_db.BgpRouterST, mx_bgp_router_name)
        mx_bgp_router = self._vnc_lib.bgp_router_read(
            fq_name_str=mx_bgp_router_name)
        self.check_bgp_no_peering(server_router_obj, mx_bgp_router)

        for i in range(5):
            router1_obj = self._vnc_lib.bgp_router_read(
                fq_name_str=router1_name)
            params = router1_obj.get_bgp_router_parameters()
            if not params:
                gevent.sleep(1)
                continue
            self.assertEqual(router1_obj.get_bgp_router_parameters().address,
                             '10.0.0.252')
            self.assertEqual(
                router1_obj.get_bgp_router_parameters().identifier,
                '10.0.0.252')
        self.assertNotEqual(params, None)

        # verify ref from vmi to bgp-router is created
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(
            id=port_obj.uuid)
        self.assertEqual(port_obj_updated.bgp_router_refs[0]['to'],
                         router1_obj.fq_name)

        # remove bgp-router ref from vmi
        self._vnc_lib.ref_update(obj_uuid=port_obj_updated.uuid,
                                 obj_type='virtual_machine_interface',
                                 ref_uuid=router1_obj.uuid,
                                 ref_fq_name=router1_obj.fq_name,
                                 ref_type='bgp-router',
                                 operation='DELETE')
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(
            id=port_obj.uuid)
        self.assertIsNone(port_obj_updated.get_bgp_router_refs())

        # check bgp-router ref in vmi is restored during reinit
        config_db.VirtualMachineST._dict = {}
        config_db.BgpRouterST._dict = {}
        config_db.BgpAsAServiceST._dict = {}
        to_bgp.transformer.reinit()
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(
            id=port_obj.uuid)
        refs = port_obj_updated.get_bgp_router_refs()
        self.assertNotEqual(refs, None)
        self.assertEqual(refs[0]['to'], router1_obj.fq_name)

        # remove VMI from bgpaas and ensure
        bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name=bgpaas.fq_name)
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(
            id=port_obj.uuid)
        bgpaas.del_virtual_machine_interface(port_obj_updated)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name=bgpaas.fq_name)
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(
            id=port_obj.uuid)

        #   ensure vmi is not attached to bpgaas
        self.assertEqual(bgpaas.get_virtual_machine_interface_refs(), None)
        #   vmi loses vmi->bgp-router ref
        self.assertEqual(port_obj_updated.get_bgp_router_refs(), None)
        #   ensure VMI has no bgpaas ref
        self.assertEqual(port_obj_updated.get_bgp_as_a_service_back_refs(),
                         None)

        # add VMI back to bgpaas
        bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name=bgpaas.fq_name)
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(
            id=port_obj.uuid)
        bgpaas.add_virtual_machine_interface(port_obj_updated)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name=bgpaas.fq_name)
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(
            id=port_obj.uuid)

        #   ensure vmi is attached to bgpaas
        self.assertNotEqual(bgpaas.get_virtual_machine_interface_refs(), None)
        #   VMI has bgpaas ref
        self.assertNotEqual(port_obj_updated.get_bgp_as_a_service_back_refs(),
                            None)
        #   vmi got vmi->bgp-router ref
        for i in range(10):
            port_obj_updated = self._vnc_lib.virtual_machine_interface_read(
                id=port_obj.uuid)
            if not port_obj_updated.get_bgp_router_refs():
                gevent.sleep(1)
                print 'retrying...'
        self.assertNotEqual(port_obj_updated.get_bgp_router_refs(),
                            None,
                            msg="vmi did not get ref to bgp-router")

        self.check_bgp_peering(server_router_obj, router1_obj, 1)
        self.check_v4_bgp_gateway(router1_name, '10.0.0.254')
        self.check_v6_bgp_gateway(router1_name,
                                  '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
        # Set suppress_route_advertisement; and expect the gateways
        # to be reset to None in bgpaas-client router
        bgpaas.set_bgpaas_suppress_route_advertisement(True)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v4_bgp_gateway(router1_name, None)
        self.check_v6_bgp_gateway(router1_name, None)
        # Unset suppress_route_advertisement; and expect the gateways
        # to be set to gateway addresses in bgpaas-client router
        bgpaas.set_bgpaas_suppress_route_advertisement(False)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v4_bgp_gateway(router1_name, '10.0.0.254')
        self.check_v6_bgp_gateway(router1_name,
                                  '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
        # Set bgpaas_ipv4_mapped_ipv6_nexthop and expect the
        # ipv4-mapped ipv6 address is set as gateway
        bgpaas.set_bgpaas_ipv4_mapped_ipv6_nexthop(True)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v6_bgp_gateway(router1_name, '::ffff:10.0.0.254')
        # unset bgpaas_ipv4_mapped_ipv6_nexthop and expect the
        # subnets ipv6 gateway address is set as gateway
        bgpaas.set_bgpaas_ipv4_mapped_ipv6_nexthop(False)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v6_bgp_gateway(router1_name,
                                  '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')

        self._vnc_lib.instance_ip_delete(id=v4_obj.uuid)
        v4_obj = InstanceIp(name=port_name + '-v4')
        v4_obj.set_virtual_machine_interface(port_obj)
        v4_obj.set_virtual_network(vn1_obj)
        v4_obj.set_instance_ip_family('v4')
        v4_obj.set_instance_ip_address('10.0.0.60')
        self._vnc_lib.instance_ip_create(v4_obj)

        self.check_bgp_router_ip(router1_name, '10.0.0.60')
        self.check_bgp_router_identifier(router1_name, '10.0.0.60')

        bgpaas.set_bgpaas_ip_address('10.0.0.70')
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_bgp_router_ip(router1_name, '10.0.0.70')
        v4_obj.del_virtual_machine_interface(port_obj)
        v4_obj.del_virtual_network(vn1_obj)
        self._vnc_lib.instance_ip_delete(id=v4_obj.uuid)
        self.check_bgp_router_ip(router1_name, '10.0.0.70')
        self.check_bgp_router_identifier(router1_name, '10.0.0.70')

        port2_name = self.id() + 'p2'
        port2_obj = VirtualMachineInterface(port2_name, parent_obj=project_obj)
        port2_obj.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port2_obj)
        bgpaas.add_virtual_machine_interface(port2_obj)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        router2_name = vn1_obj.get_fq_name_str(
        ) + ':' + vn1_name + ':' + port2_name
        self.wait_to_get_object(config_db.BgpRouterST, router2_name)

        router2_obj = self._vnc_lib.bgp_router_read(fq_name_str=router2_name)
        self.check_bgp_peering(server_router_obj, router2_obj, 2)
        self.check_bgp_peering(server_router_obj, router1_obj, 2)

        bgpaas.del_virtual_machine_interface(port_obj)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.wait_to_delete_object(config_db.BgpRouterST, router1_name)
        self._vnc_lib.bgp_as_a_service_delete(id=bgpaas.uuid)
        self.wait_to_delete_object(config_db.BgpRouterST, router2_name)

        self._vnc_lib.instance_ip_delete(id=v6_obj.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port_obj.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port2_obj.uuid)
        self._vnc_lib.virtual_network_delete(fq_name=vn1_obj.get_fq_name())
        self.check_ri_is_deleted(vn1_obj.fq_name + [vn1_obj.name])
        self._vnc_lib.bgp_router_delete(id=mx_bgp_router.uuid)
예제 #2
0
    def test_bgpaas(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name,
                                              ['10.0.0.0/24', '1000::/16'])

        project_name = ['default-domain', 'default-project']
        project_obj = self._vnc_lib.project_read(fq_name=project_name)
        port_name = self.id() + 'p1'
        port_obj = VirtualMachineInterface(port_name, parent_obj=project_obj)
        port_obj.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port_obj)

        v6_obj = InstanceIp(name=port_name + '-v6')
        v6_obj.set_virtual_machine_interface(port_obj)
        v6_obj.set_virtual_network(vn1_obj)
        v6_obj.set_instance_ip_family('v6')
        self._vnc_lib.instance_ip_create(v6_obj)

        v4_obj = InstanceIp(name=port_name + '-v4')
        v4_obj.set_virtual_machine_interface(port_obj)
        v4_obj.set_virtual_network(vn1_obj)
        v4_obj.set_instance_ip_family('v4')
        self._vnc_lib.instance_ip_create(v4_obj)

        bgpaas_name = self.id() + 'bgp1'
        bgpaas = BgpAsAService(bgpaas_name,
                               parent_obj=project_obj,
                               autonomous_system=64512)
        bgpaas.add_virtual_machine_interface(port_obj)
        self._vnc_lib.bgp_as_a_service_create(bgpaas)

        router1_name = vn1_obj.get_fq_name_str(
        ) + ':' + vn1_name + ':' + port_name
        self.wait_to_get_object(config_db.BgpAsAServiceST,
                                bgpaas.get_fq_name_str())
        self.wait_to_get_object(config_db.BgpRouterST, router1_name)
        server_fq_name = ':'.join(self.get_ri_name(vn1_obj)) + ':bgpaas-server'
        self.wait_to_get_object(config_db.BgpRouterST, server_fq_name)
        server_router_obj = self._vnc_lib.bgp_router_read(
            fq_name_str=server_fq_name)

        mx_bgp_router = self.create_bgp_router("mx-bgp-router", "contrail")
        mx_bgp_router_name = mx_bgp_router.get_fq_name_str()
        self.wait_to_get_object(config_db.BgpRouterST, mx_bgp_router_name)
        mx_bgp_router = self._vnc_lib.bgp_router_read(
            fq_name_str=mx_bgp_router_name)
        self.check_bgp_no_peering(server_router_obj, mx_bgp_router)

        router1_obj = self._vnc_lib.bgp_router_read(fq_name_str=router1_name)
        self.assertEqual(router1_obj.get_bgp_router_parameters().address,
                         '10.0.0.252')
        self.assertEqual(router1_obj.get_bgp_router_parameters().identifier,
                         '10.0.0.252')

        self.check_bgp_peering(server_router_obj, router1_obj, 1)
        self.check_v4_bgp_gateway(router1_name, '10.0.0.254')
        self.check_v6_bgp_gateway(router1_name,
                                  '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
        # Set suppress_route_advertisement; and expect the gateways
        # to be reset to None in bgpaas-client router
        bgpaas.set_bgpaas_suppress_route_advertisement(True)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v4_bgp_gateway(router1_name, None)
        self.check_v6_bgp_gateway(router1_name, None)
        # Unset suppress_route_advertisement; and expect the gateways
        # to be set to gateway addresses in bgpaas-client router
        bgpaas.set_bgpaas_suppress_route_advertisement(False)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v4_bgp_gateway(router1_name, '10.0.0.254')
        self.check_v6_bgp_gateway(router1_name,
                                  '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
        # Set bgpaas_ipv4_mapped_ipv6_nexthop and expect the
        # ipv4-mapped ipv6 address is set as gateway
        bgpaas.set_bgpaas_ipv4_mapped_ipv6_nexthop(True)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v6_bgp_gateway(router1_name, '::ffff:10.0.0.254')
        # unset bgpaas_ipv4_mapped_ipv6_nexthop and expect the
        # subnets ipv6 gateway address is set as gateway
        bgpaas.set_bgpaas_ipv4_mapped_ipv6_nexthop(False)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v6_bgp_gateway(router1_name,
                                  '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')

        self._vnc_lib.instance_ip_delete(id=v4_obj.uuid)
        v4_obj = InstanceIp(name=port_name + '-v4')
        v4_obj.set_virtual_machine_interface(port_obj)
        v4_obj.set_virtual_network(vn1_obj)
        v4_obj.set_instance_ip_family('v4')
        v4_obj.set_instance_ip_address('10.0.0.60')
        self._vnc_lib.instance_ip_create(v4_obj)

        self.check_bgp_router_ip(router1_name, '10.0.0.60')
        self.check_bgp_router_identifier(router1_name, '10.0.0.60')

        bgpaas.set_bgpaas_ip_address('10.0.0.70')
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_bgp_router_ip(router1_name, '10.0.0.70')
        v4_obj.del_virtual_machine_interface(port_obj)
        v4_obj.del_virtual_network(vn1_obj)
        self._vnc_lib.instance_ip_delete(id=v4_obj.uuid)
        self.check_bgp_router_ip(router1_name, '10.0.0.70')
        self.check_bgp_router_identifier(router1_name, '10.0.0.70')

        port2_name = self.id() + 'p2'
        port2_obj = VirtualMachineInterface(port2_name, parent_obj=project_obj)
        port2_obj.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port2_obj)
        bgpaas.add_virtual_machine_interface(port2_obj)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        router2_name = vn1_obj.get_fq_name_str(
        ) + ':' + vn1_name + ':' + port2_name
        self.wait_to_get_object(config_db.BgpRouterST, router2_name)

        router2_obj = self._vnc_lib.bgp_router_read(fq_name_str=router2_name)
        self.check_bgp_peering(server_router_obj, router2_obj, 2)
        self.check_bgp_peering(server_router_obj, router1_obj, 2)

        bgpaas.del_virtual_machine_interface(port_obj)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.wait_to_delete_object(config_db.BgpRouterST, router1_name)
        self._vnc_lib.bgp_as_a_service_delete(id=bgpaas.uuid)
        self.wait_to_delete_object(config_db.BgpRouterST, router2_name)

        self._vnc_lib.instance_ip_delete(id=v6_obj.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port_obj.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port2_obj.uuid)
        self._vnc_lib.virtual_network_delete(fq_name=vn1_obj.get_fq_name())
        self.check_ri_is_deleted(vn1_obj.fq_name + [vn1_obj.name])
        self._vnc_lib.bgp_router_delete(id=mx_bgp_router.uuid)
예제 #3
0
    def test_bgpaas(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name,
                                              ['10.0.0.0/24', '1000::/16'])

        project_name = ['default-domain', 'default-project']
        project_obj = self._vnc_lib.project_read(fq_name=project_name)
        port_name = self.id() + 'p1'
        port_obj = VirtualMachineInterface(port_name, parent_obj=project_obj)
        port_obj.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port_obj)

        v6_obj = InstanceIp(name=port_name + '-v6')
        v6_obj.set_virtual_machine_interface(port_obj)
        v6_obj.set_virtual_network(vn1_obj)
        v6_obj.set_instance_ip_family('v6')
        self._vnc_lib.instance_ip_create(v6_obj)

        v4_obj = InstanceIp(name=port_name + '-v4')
        v4_obj.set_virtual_machine_interface(port_obj)
        v4_obj.set_virtual_network(vn1_obj)
        v4_obj.set_instance_ip_family('v4')
        self._vnc_lib.instance_ip_create(v4_obj)

        bgpaas_name = self.id() + 'bgp1'
        bgpaas = BgpAsAService(bgpaas_name,
                               parent_obj=project_obj,
                               autonomous_system=64512)
        bgpaas.add_virtual_machine_interface(port_obj)
        self._vnc_lib.bgp_as_a_service_create(bgpaas)

        router1_name = vn1_obj.get_fq_name_str(
        ) + ':' + vn1_name + ':' + port_name
        self.wait_to_get_object(config_db.BgpAsAServiceST,
                                bgpaas.get_fq_name_str())
        self.wait_to_get_object(config_db.BgpRouterST, router1_name)
        server_fq_name = ':'.join(self.get_ri_name(vn1_obj)) + ':bgpaas-server'
        self.wait_to_get_object(config_db.BgpRouterST, server_fq_name)
        server_router_obj = self._vnc_lib.bgp_router_read(
            fq_name_str=server_fq_name)

        mx_bgp_router = self.create_bgp_router("mx-bgp-router", "contrail")
        mx_bgp_router_name = mx_bgp_router.get_fq_name_str()
        self.wait_to_get_object(config_db.BgpRouterST, mx_bgp_router_name)
        mx_bgp_router = self._vnc_lib.bgp_router_read(
            fq_name_str=mx_bgp_router_name)
        self.check_bgp_no_peering(server_router_obj, mx_bgp_router)

        router1_obj = self._vnc_lib.bgp_router_read(fq_name_str=router1_name)
        self.assertEqual(router1_obj.get_bgp_router_parameters().address,
                         '10.0.0.252')
        self.assertEqual(router1_obj.get_bgp_router_parameters().identifier,
                         '10.0.0.252')

        self.check_bgp_peering(server_router_obj, router1_obj, 1)

        v4_obj.set_instance_ip_address('10.0.0.60')
        self._vnc_lib.instance_ip_update(v4_obj)
        self.check_bgp_router_ip(router1_name, '10.0.0.60')
        self.check_bgp_router_identifier(router1_name, '10.0.0.60')

        bgpaas.set_bgpaas_ip_address('10.0.0.70')
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_bgp_router_ip(router1_name, '10.0.0.70')
        v4_obj.del_virtual_machine_interface(port_obj)
        v4_obj.del_virtual_network(vn1_obj)
        self._vnc_lib.instance_ip_delete(id=v4_obj.uuid)
        self.check_bgp_router_ip(router1_name, '10.0.0.70')
        self.check_bgp_router_identifier(router1_name, '10.0.0.70')

        port2_name = self.id() + 'p2'
        port2_obj = VirtualMachineInterface(port2_name, parent_obj=project_obj)
        port2_obj.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port2_obj)
        bgpaas.add_virtual_machine_interface(port2_obj)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        router2_name = vn1_obj.get_fq_name_str(
        ) + ':' + vn1_name + ':' + port2_name
        self.wait_to_get_object(config_db.BgpRouterST, router2_name)

        router2_obj = self._vnc_lib.bgp_router_read(fq_name_str=router2_name)
        self.check_bgp_peering(server_router_obj, router2_obj, 2)
        self.check_bgp_peering(server_router_obj, router1_obj, 2)

        bgpaas.del_virtual_machine_interface(port_obj)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.wait_to_delete_object(config_db.BgpRouterST, router1_name)
        self._vnc_lib.bgp_as_a_service_delete(id=bgpaas.uuid)
        self.wait_to_delete_object(config_db.BgpRouterST, router2_name)

        self._vnc_lib.instance_ip_delete(id=v6_obj.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port_obj.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port2_obj.uuid)
        self._vnc_lib.virtual_network_delete(fq_name=vn1_obj.get_fq_name())
        self.check_ri_is_deleted(vn1_obj.fq_name + [vn1_obj.name])
        self._vnc_lib.bgp_router_delete(id=mx_bgp_router.uuid)
예제 #4
0
    def test_bgpaas(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name,
                                              ['10.0.0.0/24', '1000::/16'])

        project_name = ['default-domain', 'default-project']
        project_obj = self._vnc_lib.project_read(fq_name=project_name)
        port_name = self.id() + 'p1'
        port_obj = VirtualMachineInterface(port_name, parent_obj=project_obj)
        port_obj.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port_obj)

        v6_obj = InstanceIp(name=port_name+'-v6')
        v6_obj.set_virtual_machine_interface(port_obj)
        v6_obj.set_virtual_network(vn1_obj)
        v6_obj.set_instance_ip_family('v6')
        self._vnc_lib.instance_ip_create(v6_obj)

        v4_obj = InstanceIp(name=port_name+'-v4')
        v4_obj.set_virtual_machine_interface(port_obj)
        v4_obj.set_virtual_network(vn1_obj)
        v4_obj.set_instance_ip_family('v4')
        self._vnc_lib.instance_ip_create(v4_obj)

        bgpaas_name = self.id() + 'bgp1'
        bgpaas = BgpAsAService(bgpaas_name, parent_obj=project_obj,
                               autonomous_system=64512)
        bgpaas.add_virtual_machine_interface(port_obj)
        self._vnc_lib.bgp_as_a_service_create(bgpaas)

        router1_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + port_name
        self.wait_to_get_object(config_db.BgpAsAServiceST,
                                bgpaas.get_fq_name_str())
        self.wait_to_get_object(config_db.BgpRouterST, router1_name)
        server_fq_name = ':'.join(self.get_ri_name(vn1_obj)) + ':bgpaas-server'
        self.wait_to_get_object(config_db.BgpRouterST, server_fq_name)
        server_router_obj = self._vnc_lib.bgp_router_read(fq_name_str=server_fq_name)

        mx_bgp_router = self.create_bgp_router("mx-bgp-router", "contrail")
        mx_bgp_router_name = mx_bgp_router.get_fq_name_str()
        self.wait_to_get_object(config_db.BgpRouterST, mx_bgp_router_name)
        mx_bgp_router = self._vnc_lib.bgp_router_read(fq_name_str=mx_bgp_router_name)
        self.check_bgp_no_peering(server_router_obj, mx_bgp_router)

        router1_obj = self._vnc_lib.bgp_router_read(fq_name_str=router1_name)
        self.assertEqual(router1_obj.get_bgp_router_parameters().address,
                         '10.0.0.252')
        self.assertEqual(router1_obj.get_bgp_router_parameters().identifier,
                         '10.0.0.252')

        self.check_bgp_peering(server_router_obj, router1_obj, 1)
        self.check_v4_bgp_gateway(router1_name, '10.0.0.254')
        self.check_v6_bgp_gateway(router1_name,
            '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
        # Set suppress_route_advertisement; and expect the gateways
        # to be reset to None in bgpaas-client router
        bgpaas.set_bgpaas_suppress_route_advertisement(True)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v4_bgp_gateway(router1_name, None)
        self.check_v6_bgp_gateway(router1_name, None)
        # Unset suppress_route_advertisement; and expect the gateways
        # to be set to gateway addresses in bgpaas-client router
        bgpaas.set_bgpaas_suppress_route_advertisement(False)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v4_bgp_gateway(router1_name, '10.0.0.254')
        self.check_v6_bgp_gateway(router1_name,
            '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
        # Set bgpaas_ipv4_mapped_ipv6_nexthop and expect the
        # ipv4-mapped ipv6 address is set as gateway
        bgpaas.set_bgpaas_ipv4_mapped_ipv6_nexthop(True)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v6_bgp_gateway(router1_name, '::ffff:10.0.0.254')
        # unset bgpaas_ipv4_mapped_ipv6_nexthop and expect the
        # subnets ipv6 gateway address is set as gateway
        bgpaas.set_bgpaas_ipv4_mapped_ipv6_nexthop(False)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v6_bgp_gateway(router1_name,
            '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')

        v4_obj.set_instance_ip_address('10.0.0.60')
        self._vnc_lib.instance_ip_update(v4_obj)
        self.check_bgp_router_ip(router1_name, '10.0.0.60')
        self.check_bgp_router_identifier(router1_name, '10.0.0.60')

        bgpaas.set_bgpaas_ip_address('10.0.0.70')
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_bgp_router_ip(router1_name, '10.0.0.70')
        v4_obj.del_virtual_machine_interface(port_obj)
        v4_obj.del_virtual_network(vn1_obj)
        self._vnc_lib.instance_ip_delete(id=v4_obj.uuid)
        self.check_bgp_router_ip(router1_name, '10.0.0.70')
        self.check_bgp_router_identifier(router1_name, '10.0.0.70')

        port2_name = self.id() + 'p2'
        port2_obj = VirtualMachineInterface(port2_name, parent_obj=project_obj)
        port2_obj.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port2_obj)
        bgpaas.add_virtual_machine_interface(port2_obj)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        router2_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + port2_name
        self.wait_to_get_object(config_db.BgpRouterST, router2_name)

        router2_obj = self._vnc_lib.bgp_router_read(fq_name_str=router2_name)
        self.check_bgp_peering(server_router_obj, router2_obj, 2)
        self.check_bgp_peering(server_router_obj, router1_obj, 2)

        bgpaas.del_virtual_machine_interface(port_obj)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.wait_to_delete_object(config_db.BgpRouterST, router1_name)
        self._vnc_lib.bgp_as_a_service_delete(id=bgpaas.uuid)
        self.wait_to_delete_object(config_db.BgpRouterST, router2_name)

        self._vnc_lib.instance_ip_delete(id=v6_obj.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port_obj.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port2_obj.uuid)
        self._vnc_lib.virtual_network_delete(fq_name=vn1_obj.get_fq_name())
        self.check_ri_is_deleted(vn1_obj.fq_name+[vn1_obj.name])
        self._vnc_lib.bgp_router_delete(id=mx_bgp_router.uuid)
예제 #5
0
    def test_bgpaas(self):
        # create  vn1
        vn1_name = self.id() + 'vn1'
        vn1_obj = self.create_virtual_network(vn1_name,
                                              ['10.0.0.0/24', '1000::/16'])

        project_name = ['default-domain', 'default-project']
        project_obj = self._vnc_lib.project_read(fq_name=project_name)
        port_name = self.id() + 'p1'
        port_obj = VirtualMachineInterface(port_name, parent_obj=project_obj)
        port_obj.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port_obj)

        v6_obj = InstanceIp(name=port_name+'-v6')
        v6_obj.set_virtual_machine_interface(port_obj)
        v6_obj.set_virtual_network(vn1_obj)
        v6_obj.set_instance_ip_family('v6')
        self._vnc_lib.instance_ip_create(v6_obj)

        v4_obj = InstanceIp(name=port_name+'-v4')
        v4_obj.set_virtual_machine_interface(port_obj)
        v4_obj.set_virtual_network(vn1_obj)
        v4_obj.set_instance_ip_family('v4')
        self._vnc_lib.instance_ip_create(v4_obj)

        bgpaas_name = self.id() + 'bgp1'
        bgpaas = BgpAsAService(bgpaas_name, parent_obj=project_obj,
                               autonomous_system=64512)
        bgpaas.add_virtual_machine_interface(port_obj)
        self._vnc_lib.bgp_as_a_service_create(bgpaas)

        router1_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + port_name
        self.wait_to_get_object(config_db.BgpAsAServiceST,
                                bgpaas.get_fq_name_str())
        self.wait_to_get_object(config_db.BgpRouterST, router1_name)
        server_fq_name = ':'.join(self.get_ri_name(vn1_obj)) + ':bgpaas-server'
        self.wait_to_get_object(config_db.BgpRouterST, server_fq_name)
        server_router_obj = self._vnc_lib.bgp_router_read(fq_name_str=server_fq_name)

        router1_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + port_name
        mx_bgp_router = self.create_bgp_router("mx-bgp-router", "contrail")
        mx_bgp_router_name = mx_bgp_router.get_fq_name_str()
        self.wait_to_get_object(config_db.BgpRouterST, mx_bgp_router_name)
        mx_bgp_router = self._vnc_lib.bgp_router_read(fq_name_str=mx_bgp_router_name)
        self.check_bgp_no_peering(server_router_obj, mx_bgp_router)

        for i in range(5):
            router1_obj = self._vnc_lib.bgp_router_read(fq_name_str=router1_name)
            params = router1_obj.get_bgp_router_parameters()
            if not params:
                gevent.sleep(1)
                continue
            self.assertEqual(router1_obj.get_bgp_router_parameters().address,
                             '10.0.0.252')
            self.assertEqual(router1_obj.get_bgp_router_parameters().identifier,
                             '10.0.0.252')
        self.assertNotEqual(params, None)

        # verify ref from vmi to bgp-router is created
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
        self.assertEqual(port_obj_updated.bgp_router_refs[0]['to'],
                         router1_obj.fq_name)

        # remove bgp-router ref from vmi
        self._vnc_lib.ref_update(obj_uuid=port_obj_updated.uuid,
                                 obj_type='virtual_machine_interface',
                                 ref_uuid=router1_obj.uuid,
                                 ref_fq_name=router1_obj.fq_name,
                                 ref_type='bgp-router',
                                 operation='DELETE')
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
        self.assertIsNone(port_obj_updated.get_bgp_router_refs())

        # check bgp-router ref in vmi is restored during reinit
        config_db.VirtualMachineST._dict = {}
        config_db.BgpRouterST._dict = {}
        config_db.BgpAsAServiceST._dict = {}
        to_bgp.transformer.reinit()
        gevent.sleep(1)

        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
        refs = port_obj_updated.get_bgp_router_refs()
        self.assertNotEqual(refs, None)
        self.assertEqual(refs[0]['to'], router1_obj.fq_name)

        # remove VMI from bgpaas and ensure
        bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name=bgpaas.fq_name)
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
        bgpaas.del_virtual_machine_interface(port_obj_updated)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        gevent.sleep(1)

        bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name=bgpaas.fq_name)
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)

        #   ensure vmi is not attached to bpgaas
        self.assertEqual(bgpaas.get_virtual_machine_interface_refs(), None)
        #   vmi loses vmi->bgp-router ref
        self.assertEqual(port_obj_updated.get_bgp_router_refs(), None)
        #   ensure VMI has no bgpaas ref
        self.assertEqual(port_obj_updated.get_bgp_as_a_service_back_refs(), None)

        # add VMI back to bgpaas
        bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name=bgpaas.fq_name)
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
        bgpaas.add_virtual_machine_interface(port_obj_updated)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name=bgpaas.fq_name)
        port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)

        #   ensure vmi is attached to bgpaas
        self.assertNotEqual(bgpaas.get_virtual_machine_interface_refs(), None)
        #   VMI has bgpaas ref
        self.assertNotEqual(port_obj_updated.get_bgp_as_a_service_back_refs(), None)
        #   vmi got vmi->bgp-router ref
        for i in range(10):
            port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
            if not port_obj_updated.get_bgp_router_refs():
                gevent.sleep(1)
                print 'retrying...'
        self.assertNotEqual(port_obj_updated.get_bgp_router_refs(), None,
                            msg="vmi did not get ref to bgp-router")

        self.check_bgp_peering(server_router_obj, router1_obj, 1)
        self.check_v4_bgp_gateway(router1_name, '10.0.0.254')
        self.check_v6_bgp_gateway(router1_name,
            '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
        # Set suppress_route_advertisement; and expect the gateways
        # to be reset to None in bgpaas-client router
        bgpaas.set_bgpaas_suppress_route_advertisement(True)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v4_bgp_gateway(router1_name, None)
        self.check_v6_bgp_gateway(router1_name, None)
        # Unset suppress_route_advertisement; and expect the gateways
        # to be set to gateway addresses in bgpaas-client router
        bgpaas.set_bgpaas_suppress_route_advertisement(False)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v4_bgp_gateway(router1_name, '10.0.0.254')
        self.check_v6_bgp_gateway(router1_name,
            '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
        # Set bgpaas_ipv4_mapped_ipv6_nexthop and expect the
        # ipv4-mapped ipv6 address is set as gateway
        bgpaas.set_bgpaas_ipv4_mapped_ipv6_nexthop(True)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v6_bgp_gateway(router1_name, '::ffff:10.0.0.254')
        # unset bgpaas_ipv4_mapped_ipv6_nexthop and expect the
        # subnets ipv6 gateway address is set as gateway
        bgpaas.set_bgpaas_ipv4_mapped_ipv6_nexthop(False)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_v6_bgp_gateway(router1_name,
            '1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')

        self._vnc_lib.instance_ip_delete(id=v4_obj.uuid)
        v4_obj = InstanceIp(name=port_name+'-v4')
        v4_obj.set_virtual_machine_interface(port_obj)
        v4_obj.set_virtual_network(vn1_obj)
        v4_obj.set_instance_ip_family('v4')
        v4_obj.set_instance_ip_address('10.0.0.60')
        self._vnc_lib.instance_ip_create(v4_obj)

        self.check_bgp_router_ip(router1_name, '10.0.0.60')
        self.check_bgp_router_identifier(router1_name, '10.0.0.60')

        bgpaas.set_bgpaas_ip_address('10.0.0.70')
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.check_bgp_router_ip(router1_name, '10.0.0.70')
        v4_obj.del_virtual_machine_interface(port_obj)
        v4_obj.del_virtual_network(vn1_obj)
        self._vnc_lib.instance_ip_delete(id=v4_obj.uuid)
        self.check_bgp_router_ip(router1_name, '10.0.0.70')
        self.check_bgp_router_identifier(router1_name, '10.0.0.70')

        port2_name = self.id() + 'p2'
        port2_obj = VirtualMachineInterface(port2_name, parent_obj=project_obj)
        port2_obj.add_virtual_network(vn1_obj)
        self._vnc_lib.virtual_machine_interface_create(port2_obj)
        bgpaas.add_virtual_machine_interface(port2_obj)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        router2_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + port2_name
        self.wait_to_get_object(config_db.BgpRouterST, router2_name)

        router2_obj = self._vnc_lib.bgp_router_read(fq_name_str=router2_name)
        self.check_bgp_peering(server_router_obj, router2_obj, 2)
        self.check_bgp_peering(server_router_obj, router1_obj, 2)

        bgpaas.del_virtual_machine_interface(port_obj)
        self._vnc_lib.bgp_as_a_service_update(bgpaas)
        self.wait_to_delete_object(config_db.BgpRouterST, router1_name)
        self._vnc_lib.bgp_as_a_service_delete(id=bgpaas.uuid)
        self.wait_to_delete_object(config_db.BgpRouterST, router2_name)

        self._vnc_lib.instance_ip_delete(id=v6_obj.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port_obj.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port2_obj.uuid)
        self._vnc_lib.virtual_network_delete(fq_name=vn1_obj.get_fq_name())
        self.check_ri_is_deleted(vn1_obj.fq_name+[vn1_obj.name])
        self._vnc_lib.bgp_router_delete(id=mx_bgp_router.uuid)