def test_create_logical_router(self):
        lr_name = 'lr-' + self.id()
        lr_fq_name = ['default-domain', 'default-project', lr_name]
        lr = LogicalRouter(fq_name=lr_fq_name,
                           parent_type='project',
                           logical_router_type='vxlan-routing',
                           vxlan_network_identifier='5000')
        lr.set_physical_router(self.pr1)
        self._vnc_lib.logical_router_create(lr)
        self.check_trans_info('Logical Router',
                              'Create',
                              lr_name,
                              pr_name=self.pr1.name)

        lr.add_virtual_machine_interface(self.vmi)

        self._vnc_lib.logical_router_update(lr)
        self.check_trans_info('Logical Router',
                              'Update',
                              lr_name,
                              pr_name=self.pr1.name)

        self._vnc_lib.logical_router_delete(id=lr.uuid)
        self.check_trans_info('Logical Router',
                              'Delete',
                              lr_name,
                              pr_name=self.pr1.name)
示例#2
0
    def test_vm_port_not_added_to_lr(self):
        project = self._vnc_lib.project_read(
            ['default-domain', 'default-project'])
        ipam = self._vnc_lib.network_ipam_read(
            ['default-domain', 'default-project', 'default-network-ipam'])

        # Create subnets
        ipam_sn_v4_vn = IpamSubnetType(subnet=SubnetType('11.1.1.0', 24))

        # Create VN my-vn
        vn = VirtualNetwork('%s-vn' % self.id(), project)
        vn.add_network_ipam(ipam, VnSubnetsType([ipam_sn_v4_vn]))
        self._vnc_lib.virtual_network_create(vn)
        net_obj = self._vnc_lib.virtual_network_read(id=vn.uuid)

        # Create v4 Ip object
        ip_obj = InstanceIp(name=str(uuid.uuid4()), instance_ip_family='v4')
        ip_obj.uuid = ip_obj.name

        # Create VM
        vm_inst_obj = VirtualMachine(str(uuid.uuid4()))
        vm_inst_obj.uuid = vm_inst_obj.name
        self._vnc_lib.virtual_machine_create(vm_inst_obj)

        id_perms = IdPermsType(enable=True)
        vm_port_obj = VirtualMachineInterface(str(uuid.uuid4()),
                                              vm_inst_obj,
                                              id_perms=id_perms)
        vm_port_obj.uuid = vm_port_obj.name
        vm_port_obj.set_virtual_network(vn)
        ip_obj.set_virtual_machine_interface(vm_port_obj)
        ip_obj.set_virtual_network(net_obj)
        self._vnc_lib.virtual_machine_interface_create(vm_port_obj)

        self._vnc_lib.instance_ip_create(ip_obj)

        # Create Logical Router
        lr = LogicalRouter('router-test-v4-%s' % self.id(), project)
        self._vnc_lib.logical_router_create(lr)

        # Add Router Interface
        lr.add_virtual_machine_interface(vm_port_obj)
        with ExpectedException(RefsExistError):
            self._vnc_lib.logical_router_update(lr)
        lr.del_virtual_machine_interface(vm_port_obj)

        # Create Port
        port_obj = self.create_port(project, net_obj)
        lr.add_virtual_machine_interface(port_obj)
        self._vnc_lib.logical_router_update(lr)
        with ExpectedException(BadRequest):
            port_obj.add_virtual_machine(vm_inst_obj)
            self._vnc_lib.virtual_machine_interface_update(port_obj)
        self._vnc_lib.logical_router_delete(id=lr.uuid)
    def test_delete_lr_missing_vn_refs(self):
        # Get Project Ref
        project = self._vnc_lib.project_read(
            fq_name=['default-domain', 'default-project'])
        lr = LogicalRouter('router-test-missing_vn_refs-%s' % (self.id()),
                           project)

        lr.set_logical_router_type('vxlan-routing')
        lr_uuid = self._vnc_lib.logical_router_create(lr)
        lr = self._vnc_lib.logical_router_read(id=lr_uuid)
        logger.debug('Created Logical Router ')

        # Create a VN Object
        vn = VirtualNetwork('%s-vn' % self.id(), project)
        self._vnc_lib.virtual_network_create(vn)
        # Create a Virtual Machine Interface that does not have VN Ref
        id_perms = IdPermsType(enable=True)
        vmi_no_vn_ref = VirtualMachineInterface(str(uuid.uuid4()),
                                                parent_obj=project,
                                                id_perms=id_perms)

        vmi_no_vn_ref.set_virtual_network(vn)
        vmi_uuid = self._vnc_lib.virtual_machine_interface_create(
            vmi_no_vn_ref)
        # Do not associate VN Ref to VMI and create
        lr.add_virtual_machine_interface(vmi_no_vn_ref)
        self._vnc_lib.logical_router_update(lr)
        vmi_obj = self._vnc_lib.virtual_machine_interface_read(id=vmi_uuid)
        vn_refs = vmi_obj.get_virtual_network_refs()
        vn_uuid = vn_refs[0]['uuid']
        self._vnc_lib.ref_update('virtual_machine_interface', vmi_uuid,
                                 'virtual_network', vn_uuid, None, 'DELETE')
        vmi_obj = self._vnc_lib.virtual_machine_interface_read(id=vmi_uuid)
        vn_refs = vmi_obj.get_virtual_network_refs()
        self.assertIsNone(vn_refs)

        # Create a VN Object
        vn2 = VirtualNetwork('%s-vn2' % self.id(), project)
        self._vnc_lib.virtual_network_create(vn2)
        # Create a Virtual Machine Interface that does not have VN Ref
        vmi_no_vn_ref_2 = VirtualMachineInterface(str(uuid.uuid4()),
                                                  parent_obj=project,
                                                  id_perms=id_perms)

        vmi_no_vn_ref_2.set_virtual_network(vn2)
        self._vnc_lib.virtual_machine_interface_create(vmi_no_vn_ref_2)
        # Do not associate VN Ref to VMI and create
        lr.add_virtual_machine_interface(vmi_no_vn_ref_2)
        self._vnc_lib.logical_router_update(lr)
        # Deleting directly from api-server as api server
        # will not allow deletion
        self._vnc_lib.logical_router_delete(id=lr.uuid)
示例#4
0
    def test_same_network_not_attached_to_lr(self):
        project = self._vnc_lib.project_read(
            ['default-domain', 'default-project'])
        ipam = self._vnc_lib.network_ipam_read(
            ['default-domain', 'default-project', 'default-network-ipam'])

        # Create subnets
        ipam_sn_v4_vn = IpamSubnetType(subnet=SubnetType('11.1.1.0', 24))

        # Create VN my-vn
        vn = VirtualNetwork('%s-vn' % self.id(), project)
        vn.add_network_ipam(ipam, VnSubnetsType([ipam_sn_v4_vn]))
        self._vnc_lib.virtual_network_create(vn)
        net_obj = self._vnc_lib.virtual_network_read(id=vn.uuid)

        # Create v4 Ip object
        ip_obj = InstanceIp(name=str(uuid.uuid4()), instance_ip_family='v4')
        ip_obj.uuid = ip_obj.name

        # Create Port
        port_obj = self.create_port(project, net_obj)

        # Create Logical Router
        lr = LogicalRouter('router-test-v4-%s' % self.id(), project)
        lr.set_logical_router_type('snat-routing')
        self._vnc_lib.logical_router_create(lr)

        # Add Router Interface
        lr.add_virtual_machine_interface(port_obj)
        self._vnc_lib.logical_router_update(lr)

        # set router_external
        net_obj.set_router_external(True)
        self._vnc_lib.virtual_network_update(net_obj)

        with ExpectedException(BadRequest):
            lr.add_virtual_network(net_obj)
            self._vnc_lib.logical_router_update(lr)
        lr.del_virtual_network(net_obj)

        lr.del_virtual_machine_interface(port_obj)
        self._vnc_lib.logical_router_update(lr)
        lr.add_virtual_network(net_obj)
        self._vnc_lib.logical_router_update(lr)

        # Create Port
        port_obj = self.create_port(project, net_obj)
        with ExpectedException(BadRequest):
            lr.add_virtual_machine_interface(port_obj)
            self._vnc_lib.logical_router_update(lr)
        self._vnc_lib.logical_router_delete(id=lr.uuid)
示例#5
0
 def create_lr(self, lrname, vns, prs, vmis):
     lr_fq_name = ['default-domain', 'default-project', lrname]
     lr = LogicalRouter(fq_name=lr_fq_name,
                        parent_type='project',
                        logical_router_type='vxlan-routing')
     for pr in prs:
         probj = self._vnc_lib.physical_router_read(id=pr.get_uuid())
         lr.add_physical_router(probj)
     for vn in vns:
         vminame = 'vmi-lr-to-vn' + vn.get_display_name()
         fq_name1 = ['default-domain', 'default-project', vminame]
         vmi = VirtualMachineInterface(fq_name=fq_name1,
                                       parent_type='project')
         vmi.set_virtual_network(vn)
         self._vnc_lib.virtual_machine_interface_create(vmi)
         vmis[vminame] = vmi
         lr.add_virtual_machine_interface(vmi)
     lr_uuid = self._vnc_lib.logical_router_create(lr)
     return lr, self._vnc_lib.logical_router_read(id=lr_uuid)
class TestTransactionsDM(TestAnsibleCommonDM):
    def setUp(self, extra_config_knobs=None):
        super(TestTransactionsDM,
              self).setUp(extra_config_knobs=extra_config_knobs)
        self.create_all()

    def tearDown(self):
        self.delete_all()
        super(TestTransactionsDM, self).tearDown()

    @retries(5, hook=retry_exc_handler)
    def chk_trans_info(self,
                       trans_id=None,
                       pr_name=None,
                       trans_descr=None,
                       allow_update=False):
        if pr_name:
            t_id, t_descr = FakeJobHandler.get_dev_transaction_info(pr_name)
        else:
            t_id, t_descr = FakeJobHandler.get_transaction_info()

        if allow_update and 'Create' in trans_descr and 'Update' in t_descr:
            trans_descr = trans_descr.replace('Create', 'Update')
        if 'DCI' in trans_descr and trans_descr != t_descr and pr_name:
            print("Transaction mistmatch {} != {}".format(
                trans_descr, t_descr))
            # sometimes due to timing, PR transaction gets updated.
            trans_descr = "Bgp Router '{}' Update".format(pr_name)

        self.assertEqual(trans_descr, t_descr)
        if trans_id:
            self.assertEqual(trans_id, t_id)
        print("TRANSACTION: {}".format(trans_descr))
        return t_id, t_descr

    def check_trans_info(self,
                         obj_type=None,
                         oper=None,
                         obj_name=None,
                         trans_id=None,
                         pr_name=None,
                         trans_descr=None,
                         allow_update=False):
        trans_descr = trans_descr or "{} '{}' {}".format(
            obj_type, obj_name, oper)
        time.sleep(1)
        return self.chk_trans_info(trans_id=trans_id,
                                   pr_name=pr_name,
                                   trans_descr=trans_descr,
                                   allow_update=allow_update)

    def test_update_bgp_router(self):
        self.bgp_router1.set_display_name("foo")
        self._vnc_lib.bgp_router_update(self.bgp_router1)
        self.check_trans_info('Bgp Router',
                              'Update',
                              self.bgp_router1.name,
                              pr_name=self.bgp_router1.name)

    def test_create_logical_router(self):
        lr_name = 'lr-' + self.id()
        lr_fq_name = ['default-domain', 'default-project', lr_name]
        lr = LogicalRouter(fq_name=lr_fq_name,
                           parent_type='project',
                           logical_router_type='vxlan-routing',
                           vxlan_network_identifier='5000')
        lr.set_physical_router(self.pr1)
        self._vnc_lib.logical_router_create(lr)
        self.check_trans_info('Logical Router',
                              'Create',
                              lr_name,
                              pr_name=self.pr1.name)

        lr.add_virtual_machine_interface(self.vmi)

        self._vnc_lib.logical_router_update(lr)
        self.check_trans_info('Logical Router',
                              'Update',
                              lr_name,
                              pr_name=self.pr1.name)

        self._vnc_lib.logical_router_delete(id=lr.uuid)
        self.check_trans_info('Logical Router',
                              'Delete',
                              lr_name,
                              pr_name=self.pr1.name)

    def test_create_vpg(self):
        device_name = self.pr1.get_fq_name()[-1]
        fabric_name = self.fabric.get_fq_name()[-1]
        phy_int_name = self.pi1_0.get_fq_name()[-1]

        vpg_name = "vpg-" + self.id()
        vlan_tag = 10

        vmi = VirtualMachineInterface(vpg_name + "-tagged-" + str(vlan_tag),
                                      parent_type='project',
                                      fq_name=[
                                          "default-domain", "default-project",
                                          vpg_name + "-tagged-" + str(vlan_tag)
                                      ])

        vmi_profile = \
            "{\"local_link_information\":[{\"switch_id\":\"%s\",\"port_id\":"\
            "\"%s\",\"switch_info\":\"%s\",\"fabric\":\"%s\"}]}" % \
            (phy_int_name, phy_int_name, device_name, fabric_name)

        vmi_bindings = {
            "key_value_pair": [{
                "key": "vnic_type",
                "value": "baremetal"
            }, {
                "key": "vif_type",
                "value": "vrouter"
            }, {
                "key": "vpg",
                "value": vpg_name
            }, {
                "key": "profile",
                "value": vmi_profile
            }]
        }
        vmi.set_virtual_machine_interface_bindings(vmi_bindings)
        vmi_properties = {"sub_interface_vlan_tag": vlan_tag}
        vmi.set_virtual_machine_interface_properties(vmi_properties)

        vmi.set_virtual_network(self.vn1)

        sg_name = 'sg-1' + self.id()
        project = self._vnc_lib.project_read(
            ['default-domain', 'default-project'])
        sg = SecurityGroup(name=sg_name, parent_obj=project)
        self._vnc_lib.security_group_create(sg)

        # now create a VPG
        vpg = VirtualPortGroup(vpg_name, parent_obj=self.fabric)
        vpg.set_security_group(sg)
        self._vnc_lib.virtual_port_group_create(vpg)
        self._vnc_lib.virtual_machine_interface_create(vmi)
        self.check_trans_info('Virtual Port Group',
                              'Create',
                              vpg_name,
                              allow_update=True)
        # Update VPG
        vpg.set_virtual_machine_interface_list([{'uuid': vmi.get_uuid()}])
        self._vnc_lib.virtual_port_group_update(vpg)
        self.check_trans_info('Virtual Port Group', 'Update', vpg_name)

        # Update Security Group
        sg = self._vnc_lib.security_group_read(sg.get_fq_name())
        rule1 = self.build_acl_rule(0, 65535, 'egress', 'icmp', 'IPv4')
        sg_rule1 = self._security_group_rule_build(rule1, sg.get_fq_name_str())
        self._security_group_rule_append(sg, sg_rule1)
        self._vnc_lib.security_group_update(sg)
        self.check_trans_info('Security Group', 'Update', sg_name)

        self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
        self.check_trans_info('Virtual Port Group', 'Delete', vpg_name)

        self._vnc_lib.virtual_port_group_delete(id=vpg.uuid)

    def test_create_dci(self):
        dci_name = "test-dci" + self.id()
        dci = DataCenterInterconnect(dci_name)
        dci.add_logical_router(self.lr1)
        self._vnc_lib.data_center_interconnect_create(dci)
        self.check_trans_info('DCI', 'Create', dci_name, pr_name=self.pr1.name)

        dci.del_logical_router(self.lr1)
        self._vnc_lib.data_center_interconnect_update(dci)
        self.check_trans_info('DCI', 'Update', dci_name, pr_name=self.pr1.name)

        dci.add_logical_router(self.lr1)
        self._vnc_lib.data_center_interconnect_update(dci)
        self._vnc_lib.data_center_interconnect_delete(id=dci.uuid)
        self.check_trans_info('DCI', 'Delete', dci_name, pr_name=self.pr1.name)

    def test_create_service_instance(self):
        sas_name = 'sas-1' + self.id()
        sas_fq_name = ['default-global-system-config', sas_name]
        sas = ServiceApplianceSet(
            fq_name=sas_fq_name,
            parent_type='global-system-config',
            service_appliance_set_virtualization_type='physical-device')
        self._vnc_lib.service_appliance_set_create(sas)

        sa_name = 'sa-1' + self.id()
        sa_fq_name = ['default-global-system-config', sas_name, sa_name]
        sa = ServiceAppliance(
            fq_name=sa_fq_name,
            parent_type='service-appliance-set',
            service_appliance_virtualization_type='physical-device')

        sa.set_service_appliance_properties(
            KeyValuePairs([
                KeyValuePair(key='left-attachment-point', value=self.pi1_0_fq),
                KeyValuePair(key='right-attachment-point', value=self.pi1_1_fq)
            ]))
        attr = ServiceApplianceInterfaceType(interface_type='left')
        sa.add_physical_interface(self.pi2_0, attr)
        attr = ServiceApplianceInterfaceType(interface_type='right')
        sa.add_physical_interface(self.pi2_1, attr)
        self._vnc_lib.service_appliance_create(sa)
        tid, td = self.check_trans_info('Service Appliance',
                                        'Create',
                                        sa_name,
                                        pr_name=self.pr1.name)

        st_name = 'st-1' + self.id()
        st_fq_name = ['default-domain', st_name]
        st = ServiceTemplate(fq_name=st_fq_name)
        st.set_service_appliance_set(sas)
        st.set_service_config_managed(False)
        svc_properties = ServiceTemplateType()
        svc_properties.set_service_virtualization_type('physical-device')
        if_type = ServiceTemplateInterfaceType(interface_type='left')
        svc_properties.add_interface_type(if_type)
        if_type = ServiceTemplateInterfaceType(interface_type='right')
        svc_properties.add_interface_type(if_type)
        st.set_service_template_properties(svc_properties)
        self._vnc_lib.service_template_create(st)
        self.check_trans_info(trans_id=tid,
                              trans_descr=td,
                              pr_name=self.pr1.name)

        si_name = 'si-' + self.id()
        si_fqn = ['default-domain', 'default-project', si_name]
        si = ServiceInstance(fq_name=si_fqn)
        si.fq_name = si_fqn
        si.add_service_template(st)
        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.set_annotations(kvps)
        props = ServiceInstanceType()
        props.set_service_virtualization_type('physical-device')
        props.set_ha_mode("active-standby")
        si.set_service_instance_properties(props)
        self._vnc_lib.service_instance_create(si)
        self.check_trans_info(trans_id=tid,
                              trans_descr=td,
                              pr_name=self.pr1.name)

        pt_name = 'pt-' + self.id()
        pt = PortTuple(pt_name, parent_obj=si)
        pt.add_logical_router(self.lr1)
        pt.add_logical_router(self.lr2)
        kvp_array = []
        kvp = KeyValuePair("left-lr", self.lr1.uuid)
        kvp_array.append(kvp)
        kvp = KeyValuePair("right-lr", self.lr2.uuid)
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)
        pt.set_annotations(kvps)
        self._vnc_lib.port_tuple_create(pt)
        self.check_trans_info('Service Instance',
                              'Create',
                              si_name,
                              pr_name=self.pr1.name)

        self._vnc_lib.port_tuple_delete(id=pt.uuid)
        self.check_trans_info('Service Instance',
                              'Delete',
                              si_name,
                              pr_name=self.pr1.name)

        self._vnc_lib.service_appliance_delete(fq_name=sa.fq_name)
        self.check_trans_info('Service Appliance',
                              'Delete',
                              sa_name,
                              pr_name=self.pr1.name)

    def create_all(self):
        self.create_features([
            'underlay-ip-clos', 'overlay-bgp', 'l2-gateway', 'l3-gateway',
            'vn-interconnect'
        ])
        self.create_physical_roles(['leaf', 'spine', 'pnf'])
        self.create_overlay_roles(['crb-gateway', 'pnf-servicechain'])
        self.create_role_definitions([
            AttrDict({
                'name': 'crb-gateway-spine',
                'physical_role': 'spine',
                'overlay_role': 'crb-gateway',
                'features': ['l3-gateway', 'vn-interconnect'],
                'feature_configs': None
            }),
            AttrDict({
                'name': 'pnf-service-chain',
                'physical_role': 'pnf',
                'overlay_role': 'pnf-servicechain',
                'features': ['l3-gateway', 'vn-interconnect'],
                'feature_configs': None
            })
        ])

        self.jt = self.create_job_template('job-template-1' + self.id())
        self.fabric = self.create_fabric('fabric-1' + self.id())
        self.np1, self.rc1 = self.create_node_profile(
            'node-profile-1' + self.id(),
            device_family='junos-qfx',
            role_mappings=[
                AttrDict({
                    'physical_role': 'spine',
                    'rb_roles': ['crb-gateway']
                })
            ],
            job_template=self.jt)
        self.np2, self.rc2 = self.create_node_profile(
            'node-profile-2' + self.id(),
            device_family='junos-srx',
            role_mappings=[
                AttrDict({
                    'physical_role': 'pnf',
                    'rb_roles': ['pnf-servicechain']
                })
            ],
            job_template=self.jt)

        rtr1_name = 'router1' + self.id()
        self.bgp_router1, self.pr1 = self.create_router(
            rtr1_name,
            '1.1.1.1',
            product='qfx10008',
            family='junos-qfx',
            role='spine',
            rb_roles=['crb-gateway', 'DCI-Gateway'],
            physical_role=self.physical_roles['spine'],
            overlay_role=self.overlay_roles['crb-gateway'],
            fabric=self.fabric,
            node_profile=self.np1)
        rtr2_name = 'router2' + self.id()
        self.bgp_router2, self.pr2 = self.create_router(
            rtr2_name,
            '1.1.1.2',
            product='qfx10008',
            family='junos-qfx',
            role='pnf',
            rb_roles=['PNF-Servicechain'],
            physical_role=self.physical_roles['pnf'],
            overlay_role=self.overlay_roles['pnf-servicechain'],
            fabric=self.fabric,
            node_profile=self.np2)

        pi1_0_name = "xe-0/0/0"
        self.pi1_0 = PhysicalInterface(pi1_0_name, parent_obj=self.pr1)
        self.pi1_0_fq = ':'.join(self.pi1_0.fq_name)
        self._vnc_lib.physical_interface_create(self.pi1_0)

        pi1_1_name = "xe-0/0/1"
        self.pi1_1 = PhysicalInterface(pi1_1_name, parent_obj=self.pr1)
        self.pi1_1_fq = ':'.join(self.pi1_1.fq_name)
        self._vnc_lib.physical_interface_create(self.pi1_1)

        pi2_0_name = "xe-0/0/0"
        self.pi2_0 = PhysicalInterface(pi2_0_name, parent_obj=self.pr2)
        self._vnc_lib.physical_interface_create(self.pi2_0)

        pi2_1_name = "xe-0/0/1"
        self.pi2_1 = PhysicalInterface(pi2_1_name, parent_obj=self.pr2)
        self._vnc_lib.physical_interface_create(self.pi2_1)

        self.vn1 = self.create_vn('1', '1.1.1.0')

        lr1_name = 'lr1-' + self.id()
        lr1_fq_name = ['default-domain', 'default-project', lr1_name]
        self.lr1 = LogicalRouter(fq_name=lr1_fq_name,
                                 parent_type='project',
                                 logical_router_type='vxlan-routing',
                                 vxlan_network_identifier='3000')
        self.lr1.set_physical_router(self.pr1)
        self._vnc_lib.logical_router_create(self.lr1)

        lr2_name = 'lr2-' + self.id()
        lr2_fq_name = ['default-domain', 'default-project', lr2_name]
        self.lr2 = LogicalRouter(fq_name=lr2_fq_name,
                                 parent_type='project',
                                 logical_router_type='vxlan-routing',
                                 vxlan_network_identifier='4000')
        self.lr2.set_physical_router(self.pr2)
        self._vnc_lib.logical_router_create(self.lr2)

        fq_name = ['default-domain', 'default-project', 'vmi-' + self.id()]
        self.vmi = VirtualMachineInterface(fq_name=fq_name,
                                           parent_type='project')
        self.vmi.set_virtual_network(self.vn1)
        self._vnc_lib.virtual_machine_interface_create(self.vmi)

        self.lr1.add_virtual_machine_interface(self.vmi)
        self._vnc_lib.logical_router_update(self.lr1)

    def delete_all(self):
        self._vnc_lib.logical_router_delete(id=self.lr1.uuid)
        self._vnc_lib.logical_router_delete(id=self.lr2.uuid)

        self._vnc_lib.virtual_machine_interface_delete(id=self.vmi.uuid)

        self._vnc_lib.physical_interface_delete(id=self.pi1_0.uuid)
        self._vnc_lib.physical_interface_delete(id=self.pi1_1.uuid)
        self._vnc_lib.physical_interface_delete(id=self.pi2_0.uuid)
        self._vnc_lib.physical_interface_delete(id=self.pi2_1.uuid)

        self.delete_routers(None, self.pr1)
        self.wait_for_routers_delete(None, self.pr1.get_fq_name())
        self._vnc_lib.bgp_router_delete(id=self.bgp_router1.uuid)

        self.delete_routers(None, self.pr2)
        self.wait_for_routers_delete(None, self.pr2.get_fq_name())
        self._vnc_lib.bgp_router_delete(id=self.bgp_router2.uuid)

        self._vnc_lib.virtual_network_delete(id=self.vn1.uuid)
        self._vnc_lib.role_config_delete(id=self.rc1.uuid)
        self._vnc_lib.role_config_delete(id=self.rc2.uuid)
        self._vnc_lib.node_profile_delete(id=self.np1.uuid)
        self._vnc_lib.node_profile_delete(id=self.np2.uuid)
        self._vnc_lib.fabric_delete(id=self.fabric.uuid)
        self._vnc_lib.job_template_delete(id=self.jt.uuid)

        self.delete_role_definitions()
        self.delete_overlay_roles()
        self.delete_physical_roles()
        self.delete_features()
        self.wait_for_features_delete()

    def build_acl_rule(self, pmin, pmax, direction, proto, etype):
        rule = {}
        rule['port_min'] = pmin
        rule['port_max'] = pmax
        rule['direction'] = direction
        rule['ip_prefix'] = None
        rule['protocol'] = proto
        rule['ether_type'] = etype
        return rule
示例#7
0
    def test_lr_v4_subnets(self):
        # Create Domain
        domain = Domain('my-lr-domain')
        self._vnc_lib.domain_create(domain)

        # Create Project
        project = Project('my-lr-proj', domain)
        self._vnc_lib.project_create(project)

        # Create NetworkIpam
        ipam = NetworkIpam('default-network-ipam', project, IpamType("dhcp"))
        self._vnc_lib.network_ipam_create(ipam)

        ipam = self._vnc_lib.network_ipam_read(
            ['my-lr-domain', 'my-lr-proj', 'default-network-ipam'])

        # Create subnets
        ipam_sn_v4_vn1 = IpamSubnetType(subnet=SubnetType('11.1.1.0', 24))
        ipam_sn_v6_vn1 = IpamSubnetType(subnet=SubnetType('fd11::', 120))
        ipam_sn_v4_vn2 = IpamSubnetType(subnet=SubnetType('11.1.2.0', 24))
        ipam_sn_v6_vn2 = IpamSubnetType(subnet=SubnetType('fd12::', 120))

        # Create VN my-vn-1
        vn1 = VirtualNetwork('my-vn-1', project)
        vn1.add_network_ipam(ipam,
                             VnSubnetsType([ipam_sn_v4_vn1, ipam_sn_v6_vn1]))
        self._vnc_lib.virtual_network_create(vn1)
        net_obj1 = self._vnc_lib.virtual_network_read(id=vn1.uuid)

        # Create VN my-vn-2
        vn2 = VirtualNetwork('my-vn-2', project)
        vn2.add_network_ipam(ipam,
                             VnSubnetsType([ipam_sn_v4_vn2, ipam_sn_v6_vn2]))
        self._vnc_lib.virtual_network_create(vn2)
        net_obj2 = self._vnc_lib.virtual_network_read(id=vn2.uuid)

        # Create Logical Router
        lr = LogicalRouter('router-test-v4-%s' % self.id(), project)
        lr_uuid = self._vnc_lib.logical_router_create(lr)

        # Create a Virtual Machine Interface belonging to my-vn-1
        id_perms = IdPermsType(enable=True)
        port_obj1 = VirtualMachineInterface(str(uuid.uuid4()),
                                            parent_obj=project,
                                            id_perms=id_perms)
        port_obj1.uuid = port_obj1.name
        port_obj1.set_virtual_network(vn1)
        port_obj1.set_virtual_machine_interface_device_owner(
            'DEVICE_OWNER_ROUTER_INTF')
        # Assign gateway ip
        ipam_refs = net_obj1.get_network_ipam_refs()
        for ipam_ref in ipam_refs:
            subnets = ipam_ref['attr'].get_ipam_subnets()
            for subnet in subnets:
                cidr = '%s/%s' % (subnet.subnet.get_ip_prefix(),
                                  subnet.subnet.get_ip_prefix_len())
                if IPNetwork(cidr).version == 4:
                    gateway_ip = subnet.get_default_gateway()
        self._vnc_lib.virtual_machine_interface_create(port_obj1)

        # Create v4 Ip object
        ip_obj1 = InstanceIp(name=str(uuid.uuid4()),
                             instance_ip_address=gateway_ip,
                             instance_ip_family='v4')
        ip_obj1.uuid = ip_obj1.name
        ip_obj1.set_virtual_machine_interface(port_obj1)
        ip_obj1.set_virtual_network(net_obj1)
        ip_id1 = self._vnc_lib.instance_ip_create(ip_obj1)

        # Add Router Interface (test being subnet)
        lr.add_virtual_machine_interface(port_obj1)
        self._vnc_lib.logical_router_update(lr)

        # Create a Virtual Machine Interface belonging to my-vn-2
        port_obj2 = VirtualMachineInterface(str(uuid.uuid4()),
                                            parent_obj=project,
                                            id_perms=id_perms)
        port_obj2.uuid = port_obj2.name
        port_obj2.set_virtual_network(vn2)
        port_obj2.set_virtual_machine_interface_device_owner(
            'DEVICE_OWNER_ROUTER_INTF')
        # Assign gateway ip
        ipam_refs = net_obj2.get_network_ipam_refs()
        for ipam_ref in ipam_refs:
            subnets = ipam_ref['attr'].get_ipam_subnets()
            for subnet in subnets:
                cidr = '%s/%s' % (subnet.subnet.get_ip_prefix(),
                                  subnet.subnet.get_ip_prefix_len())
                if IPNetwork(cidr).version == 4:
                    gateway_ip = subnet.get_default_gateway()
        self._vnc_lib.virtual_machine_interface_create(port_obj2)

        # Create v4 Ip object
        ip_obj2 = InstanceIp(name=str(uuid.uuid4()),
                             instance_ip_address=gateway_ip,
                             instance_ip_family='v4')
        ip_obj2.uuid = ip_obj2.name
        ip_obj2.set_virtual_machine_interface(port_obj2)
        ip_obj2.set_virtual_network(net_obj2)
        ip_id2 = self._vnc_lib.instance_ip_create(ip_obj2)

        # Add Router Interface (test being subnet)
        lr.add_virtual_machine_interface(port_obj2)
        self._vnc_lib.logical_router_update(lr)

        # TODO: Schema transformer not integrated in the tests,
        #       hence route-target refs not set yet
        # Verify Route Target Creation
        rt_refs = lr.get_route_target_refs()
        for rt_ref in rt_refs or []:
            rt_obj = self._vnc_lib.route_target_read(id=rt_ref['uuid'])
            ri_refs = rt_obj.get_routing_instance_back_refs()
            for ri_ref in ri_refs:
                ri_obj = self.vnc_lib.routing_instance_read(id=ri_ref['uuid'])
                ri_name = ri_obj.get_display_name()
                if ri_name != 'my-vn-1' and ri_name != 'my-vn-2':
                    pass

        # cleanup
        self._vnc_lib.instance_ip_delete(id=ip_id1)
        self._vnc_lib.instance_ip_delete(id=ip_id2)
        self._vnc_lib.logical_router_delete(id=lr_uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port_obj1.uuid)
        self._vnc_lib.virtual_machine_interface_delete(id=port_obj2.uuid)
        self._vnc_lib.virtual_network_delete(id=vn1.uuid)
        self._vnc_lib.virtual_network_delete(id=vn2.uuid)
        self._vnc_lib.network_ipam_delete(id=ipam.uuid)
        self._vnc_lib.project_delete(id=project.uuid)
        self._vnc_lib.domain_delete(id=domain.uuid)