Esempio n. 1
0
    def create_fabric(self, fab_name, prouter_passwords):
        """create fabric with list of device passwords"""
        self._logger.info('Creating fabric: %s', fab_name)
        fq_name = ['default-global-system-config', fab_name]
        fab = Fabric(name=fab_name,
                     fq_name=fq_name,
                     parent_type='global-system-config',
                     fabric_credentials={
                         'device_credential': [{
                             'credential': {
                                 'username': '******',
                                 'password': passwd
                             },
                             'vendor': 'Juniper',
                             'device_family': None
                         } for passwd in prouter_passwords]
                     })
        try:
            fab_uuid = self._api.fabric_create(fab)
            fab = self._api.fabric_read(id=fab_uuid)
        except RefsExistError:
            self._logger.warn("Fabric '%s' already exists", fab_name)
            fab = self._api.fabric_read(fq_name=fq_name)

        self._logger.debug(
            "Fabric created:\n%s",
            pprint.pformat(self._api.obj_to_dict(fab), indent=4))
        return fab
 def _create_fabric(self, fabric_name):
     # create test fabric object
     fabric = Fabric(name=fabric_name,
                     fq_name=["default-global-system-config", fabric_name],
                     parent_type='global-system-config',
                     fabric_credentials={
                         'device_credential': [{
                             'credential': {
                                 'username': "******",
                                 'password': "******"
                             }
                         }]
                     })
     fabric_uuid = self._vnc_lib.fabric_create(fabric)
     fabric_obj = self._vnc_lib.fabric_read(id=fabric_uuid)
     return fabric_obj
Esempio n. 3
0
    def test_ibgp_auto_mesh_fab(self):
        config_db.GlobalSystemConfigST.ibgp_auto_mesh = False
        self.assertEqual(config_db.GlobalSystemConfigST.get_ibgp_auto_mesh(),
                         False, "ibgp_auto_mesh_toggle_test")

        # Fabric 1 has 1 RR,spine + 2 leafs
        fab1 = self._vnc_lib.fabric_create(Fabric('fab1'))
        fab1 = self._vnc_lib.fabric_read(id=fab1)

        bgp_router1_fab1, pr1_fab1 = self.create_router('router1_fab1' +
                                                        self.id(),
                                                        '1.1.1.1',
                                                        product="qfx1000",
                                                        role="spine",
                                                        cluster_id=1000,
                                                        fabric=fab1)

        bgp_router2_fab1, pr2_fab1 = self.create_router('router2_fab1' +
                                                        self.id(),
                                                        '1.1.1.2',
                                                        product="qfx1000",
                                                        role="leaf",
                                                        fabric=fab1)
        bgp_router3_fab1, pr3_fab1 = self.create_router('router3_fab1' +
                                                        self.id(),
                                                        '1.1.1.3',
                                                        product="qfx1000",
                                                        role="leaf",
                                                        fabric=fab1)
        # Fabric 2 has 1 RR, spine + 2 leafs
        fab2 = self._vnc_lib.fabric_create(Fabric('fab2'))
        fab2 = self._vnc_lib.fabric_read(id=fab2)

        bgp_router1_fab2, pr1_fab2 = self.create_router('router1_fab2' +
                                                        self.id(),
                                                        '2.1.1.1',
                                                        product="qfx1000",
                                                        role="spine",
                                                        cluster_id=2000,
                                                        fabric=fab2)

        bgp_router2_fab2, pr2_fab2 = self.create_router('router2_fab2' +
                                                        self.id(),
                                                        '2.1.1.2',
                                                        product="qfx1000",
                                                        role="leaf",
                                                        fabric=fab2)
        bgp_router3_fab2, pr3_fab2 = self.create_router('router3_fab2' +
                                                        self.id(),
                                                        '2.1.1.3',
                                                        product="qfx1000",
                                                        role="leaf",
                                                        fabric=fab2)

        # Enable auto-mesh and then trigger update peering
        config_db.GlobalSystemConfigST.ibgp_auto_mesh = True
        self.assertEqual(config_db.GlobalSystemConfigST.get_ibgp_auto_mesh(),
                         True, "ibgp_auto_mesh_toggle_test")

        for router in config_db.BgpRouterST._dict.values():
            router.update()

        for router in config_db.BgpRouterST._dict.values():
            router.update_peering()

        # router1 and router2 should not be connected, both of them should be
        # connected to router3
        self.check_bgp_peering(bgp_router2_fab1, bgp_router1_fab1, 1)
        self.check_bgp_peering(bgp_router3_fab1, bgp_router1_fab1, 1)
        self.check_bgp_peering(bgp_router1_fab1, bgp_router2_fab1, 3)
        self.check_bgp_peering(bgp_router1_fab1, bgp_router3_fab1, 3)

        self.check_bgp_peering(bgp_router2_fab2, bgp_router1_fab2, 1)
        self.check_bgp_peering(bgp_router3_fab2, bgp_router1_fab2, 1)
        self.check_bgp_peering(bgp_router1_fab2, bgp_router2_fab2, 3)
        self.check_bgp_peering(bgp_router1_fab2, bgp_router3_fab2, 3)

        self.delete_routers(bgp_router1_fab1, pr1_fab1)
        self.delete_routers(bgp_router2_fab1, pr2_fab1)
        self.delete_routers(bgp_router3_fab1, pr3_fab1)
        self.delete_routers(bgp_router1_fab2, pr1_fab2)
        self.delete_routers(bgp_router2_fab2, pr2_fab2)
        self.delete_routers(bgp_router3_fab2, pr3_fab2)
        self.delete_fabric(fab1)
        self.delete_fabric(fab2)

        gevent.sleep(1)
Esempio n. 4
0
    def setUp(self):
        def _carve_out_subnets(subnets, cidr):
            carved_subnets = []
            for subnet in subnets:
                slash_x_subnets = IPNetwork(subnet.get('cidr')).subnet(cidr)
                for slash_x_sn in slash_x_subnets:
                    carved_subnets.append({'cidr': str(slash_x_sn)})
            return carved_subnets
        # end _carve_out_subnets

        def _get_network_ipam(ipam_name, subnets, subnetting):
            def _new_subnet(cidr):
                split_cidr = cidr.split('/')
                return SubnetType(
                    ip_prefix=split_cidr[0],
                    ip_prefix_len=split_cidr[1])
            # end _new_subnet
            ipam = NetworkIpam(
                name=ipam_name,
                ipam_subnets=IpamSubnets([
                    IpamSubnetType(
                        subnet=_new_subnet(sn.get('cidr')),
                        default_gateway=sn.get('gateway'),
                        subnet_uuid=str(uuid.uuid1())
                    ) for sn in subnets if int(
                        sn.get('cidr').split('/')[-1]) < 31
                ]),
                ipam_subnet_method='flat-subnet',
                ipam_subnetting=subnetting
            )
            return ipam
        # end _add_network_ipam
        super(TestPnfPortTuple, self).setUp()
        logger.debug("setUp called")
        # Create Global objects
        default_gsc_name = 'default-global-system-config'
        gsc_obj = self.api.global_system_config_read(
            GlobalSystemConfig().fq_name)
        proj_obj = self.api.project_read(Project().fq_name)
        # Create PNF and spine Physical Router
        pnf_obj = PhysicalRouter('pnf-' + self.id(), gsc_obj)
        pnf_obj.set_physical_router_role('pnf')
        self.pnf_uuid = self.api.physical_router_create(pnf_obj)
        # Create spine Physical Router
        spine_obj = PhysicalRouter('spine-' + self.id(), gsc_obj)
        self.spine_uuid = self.api.physical_router_create(spine_obj)
        # Create left/right LR
        left_lr_name = 'left_lr-' + self.id()
        left_lr_obj = LogicalRouter(name=left_lr_name, parent_obj=proj_obj)
        left_lr_obj.add_physical_router(spine_obj)
        self.left_lr_uuid = self.api.logical_router_create(left_lr_obj)
        right_lr_name = 'right_lr-' + self.id()
        right_lr_obj = LogicalRouter(name=right_lr_name, parent_obj=proj_obj)
        right_lr_obj.add_physical_router(spine_obj)
        self.right_lr_uuid = self.api.logical_router_create(right_lr_obj)
        # create left, right PNF PI
        left_pnf_pi_obj = PhysicalInterface(
            'ge-0/0/1-' + self.id(), parent_obj=pnf_obj)
        right_pnf_pi_obj = PhysicalInterface(
            'ge-0/0/2-' + self.id(), parent_obj=pnf_obj)
        lo_pnf_pi_obj = PhysicalInterface('lo0', parent_obj=pnf_obj)
        self.left_pnf_pi_uuid = self.api.physical_interface_create(
            left_pnf_pi_obj)
        self.right_pnf_pi_uuid = self.api.physical_interface_create(
            right_pnf_pi_obj)
        self.lo_pnf_pi_uuid = self.api.physical_interface_create(lo_pnf_pi_obj)
        # create left, right spine PI
        left_spine_pi_obj = PhysicalInterface(
            'xe-0/0/1-' + self.id(), parent_obj=spine_obj)
        right_spine_pi_obj = PhysicalInterface(
            'xe-0/0/2-' + self.id(), parent_obj=spine_obj)
        self.left_spine_pi_uuid = self.api.physical_interface_create(
            left_spine_pi_obj)
        self.right_spine_pi_uuid = self.api.physical_interface_create(
            right_spine_pi_obj)
        # Create Service Appliance Set
        sas_obj = ServiceApplianceSet('sas-' + self.id(), gsc_obj)
        sas_obj.set_service_appliance_set_virtualization_type(
            'physical-device')
        self.sas_uuid = self.api.service_appliance_set_create(sas_obj)
        # Create Service template
        st_obj = ServiceTemplate(name='st-' + self.id())
        st_obj.set_service_appliance_set(sas_obj)
        svc_properties = ServiceTemplateType()
        svc_properties.set_service_virtualization_type('physical-device')
        if_type = ServiceTemplateInterfaceType()
        if_type.set_service_interface_type('left')
        svc_properties.add_interface_type(if_type)
        if_type = ServiceTemplateInterfaceType()
        if_type.set_service_interface_type('right')
        svc_properties.add_interface_type(if_type)
        st_obj.set_service_template_properties(svc_properties)
        self.st_uuid = self.api.service_template_create(st_obj)
        # Create Service Instance object
        si_fqn = ['default-domain', 'default-project', 'si-' + self.id()]
        si_obj = ServiceInstance(fq_name=si_fqn)
        si_obj.fq_name = si_fqn
        si_obj.add_service_template(st_obj)
        kvp_array = []
        kvp = KeyValuePair("left-svc-vlan", "100")
        kvp_array.append(kvp)
        kvp = KeyValuePair("right-svc-vlan", "101")
        kvp_array.append(kvp)
        kvp = KeyValuePair("left-svc-asns", "66000,66001")
        kvp_array.append(kvp)
        kvp = KeyValuePair("right-svc-asns", "66000,66002")
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)
        si_obj.set_annotations(kvps)
        props = ServiceInstanceType()
        props.set_service_virtualization_type('physical-device')
        props.set_ha_mode("active-standby")
        si_obj.set_service_instance_properties(props)
        self.si_uuid = self.api.service_instance_create(si_obj)
        # Create service appliance
        sa_obj = ServiceAppliance('sa-' + self.id(), parent_obj=sas_obj)
        kvp_array = []
        kvp = KeyValuePair(
            "left-attachment-point",
            default_gsc_name +
            ':' +
            'spine-' +
            self.id() +
            ':' +
            'xe-0/0/1-' +
            self.id())
        kvp_array.append(kvp)
        kvp = KeyValuePair(
            "right-attachment-point",
            default_gsc_name +
            ':' +
            'spine-' +
            self.id() +
            ':' +
            'xe-0/0/2-' +
            self.id())
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)
        sa_obj.set_service_appliance_properties(kvps)
        sa_obj.set_service_appliance_virtualization_type('physical-device')
        attr = ServiceApplianceInterfaceType(interface_type='left')
        sa_obj.add_physical_interface(left_pnf_pi_obj, attr)
        attr = ServiceApplianceInterfaceType(interface_type='right')
        sa_obj.add_physical_interface(right_pnf_pi_obj, attr)
        self.sa_uuid = self.api.service_appliance_create(sa_obj)
        # Create fabric and add it to spine and PNF
        fab_obj = Fabric('fab-' + self.id())
        self.fab_uuid = self.api.fabric_create(fab_obj)
        pnf_obj.add_fabric(fab_obj)
        self.api.physical_router_update(pnf_obj)
        spine_obj.add_fabric(fab_obj)
        self.api.physical_router_update(spine_obj)
        fab_obj = self.api.fabric_read(id=self.fab_uuid)
        # Create PNF service chain IPAM/network
        pnf_cidr = [{'cidr': "10.1.1.0/28"}]
        peer_subnets = _carve_out_subnets(pnf_cidr, 29)
        pnf_vn_obj = VirtualNetwork(
            name='fab-' + self.id() + '-pnf-servicechain-network',
            virtual_network_properties=VirtualNetworkType(
                forwarding_mode='l3'),
            address_allocation_mode='flat-subnet-only')
        self.pnf_vn_uuid = self.api.virtual_network_create(pnf_vn_obj)
        pnf_ipam_obj = _get_network_ipam(
            'fab-' +
            self.id() +
            '-pnf-servicechain-network-ipam',
            peer_subnets,
            True)
        self.pnf_ipam_uuid = self.api.network_ipam_create(pnf_ipam_obj)
        pnf_vn_obj.add_network_ipam(pnf_ipam_obj, VnSubnetsType([]))
        self.api.virtual_network_update(pnf_vn_obj)
        fab_obj = self.api.fabric_read(id=self.fab_uuid)
        fab_obj.add_virtual_network(
            pnf_vn_obj, FabricNetworkTag(
                network_type='pnf-servicechain'))
        self.api.fabric_update(fab_obj)
        # Create loopback IPAM/network
        lo_cidr = [{'cidr': "100.100.100.0/28"}]
        peer_subnets = _carve_out_subnets(lo_cidr, 28)
        lo_vn_obj = VirtualNetwork(
            name='fab-' + self.id() + '-loopback-network',
            virtual_network_properties=VirtualNetworkType(
                forwarding_mode='l3'),
            address_allocation_mode='flat-subnet-only')
        self.lo_vn_uuid = self.api.virtual_network_create(lo_vn_obj)
        lo_ipam_obj = _get_network_ipam(
            'fab-' +
            self.id() +
            '-loopback-network-ipam',
            peer_subnets,
            False)
        self.lo_ipam_uuid = self.api.network_ipam_create(lo_ipam_obj)
        lo_vn_obj.add_network_ipam(lo_ipam_obj, VnSubnetsType([]))
        self.api.virtual_network_update(lo_vn_obj)
        fab_obj = self.api.fabric_read(id=self.fab_uuid)
        fab_obj.add_virtual_network(
            lo_vn_obj, FabricNetworkTag(
                network_type='loopback'))
        self.api.fabric_update(fab_obj)