def _create_prerequisites(self, enterprise_style_flag=True,
                              create_second_pr=False):
        # Create project first
        proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(proj_obj)

        # Create Fabric with enterprise style flag set to false
        fabric_obj = Fabric('%s-fabric' % (self.id()))
        fabric_obj.set_fabric_enterprise_style(enterprise_style_flag)
        fabric_uuid = self.api.fabric_create(fabric_obj)
        fabric_obj = self.api.fabric_read(id=fabric_uuid)

        # Create physical router
        pr_name = self.id() + '_physical_router'
        pr = PhysicalRouter(pr_name)
        pr_uuid = self._vnc_lib.physical_router_create(pr)
        pr_obj = self._vnc_lib.physical_router_read(id=pr_uuid)

        if create_second_pr:
            pr_name_2 = self.id() + '_physical_router_2'
            pr = PhysicalRouter(pr_name_2)
            pr_uuid_2 = self._vnc_lib.physical_router_create(pr)
            pr_obj_2 = self._vnc_lib.physical_router_read(id=pr_uuid_2)
            return proj_obj, fabric_obj, [pr_obj, pr_obj_2]

        return proj_obj, fabric_obj, pr_obj
示例#2
0
    def test_virtual_port_group_delete(self):
        proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(proj_obj)

        fabric_obj = Fabric('%s-fabric' % (self.id()))
        self.api.fabric_create(fabric_obj)

        vn = VirtualNetwork('vn-%s' % (self.id()), parent_obj=proj_obj)
        self.api.virtual_network_create(vn)

        vpg_name = "vpg-" + self.id()
        vpg_obj = VirtualPortGroup(vpg_name, parent_obj=fabric_obj)
        self.api.virtual_port_group_create(vpg_obj)

        vmi_id_list = []
        for i in range(self.VMI_NUM):
            vmi_obj = VirtualMachineInterface(self.id() + str(i),
                                              parent_obj=proj_obj)
            vmi_obj.set_virtual_network(vn)
            vmi_id_list.append(
                self.api.virtual_machine_interface_create(vmi_obj))
            vpg_obj.add_virtual_machine_interface(vmi_obj)
            self.api.virtual_port_group_update(vpg_obj)
            self.api.ref_relax_for_delete(vpg_obj.uuid, vmi_id_list[i])

        # Make sure when VPG doesn't get deleted, since associated VMIs
        # still refers it.
        with ExpectedException(BadRequest):
            self.api.virtual_port_group_delete(id=vpg_obj.uuid)

        # Cleanup
        for i in range(self.VMI_NUM):
            self.api.virtual_machine_interface_delete(id=vmi_id_list[i])

        self.api.virtual_port_group_delete(id=vpg_obj.uuid)
示例#3
0
    def setUp(self):
        super(TestVMIVirtualPortGroupRelation, self).setUp()
        if six.PY3:
            self.assertItemsEqual = self.assertCountEqual

        # Create project
        self.proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(self.proj_obj)

        # Create Fabric
        self.fabric_obj = Fabric('%s-fabric' % (self.id()))
        _ = self.api.fabric_create(self.fabric_obj)
        self.fabric_name = self.fabric_obj.get_fq_name()

        # Create physical router
        pr_name = self.id() + '_physical_router'
        pr = PhysicalRouter(pr_name)
        pr_uuid = self.api.physical_router_create(pr)
        self.pr_obj = self.api.physical_router_read(id=pr_uuid)

        # Create Physical interface
        esi_id = '00:11:22:33:44:55:66:77:88:99'
        pi_name = self.id() + '_physical_interface1'
        pi = PhysicalInterface(name=pi_name,
                               parent_obj=self.pr_obj,
                               ethernet_segment_identifier=esi_id)
        self.pi_uuid = self.api.physical_interface_create(pi)
        pi_obj = self.api.physical_interface_read(id=self.pi_uuid)
        self.pi_fq_name = pi_obj.get_fq_name()

        # Create VN
        self.vn = VirtualNetwork('vn-%s' % (self.id()),
                                 parent_obj=self.proj_obj)
        self.vn_uuid = self.api.virtual_network_create(self.vn)

        # Create VPG
        self.vpg_name = "vpg-%s" % self.id()
        vpg = VirtualPortGroup(self.vpg_name, parent_obj=self.fabric_obj)
        self.vpg_uuid = self.api.virtual_port_group_create(vpg)
        vpg_obj = self.api.virtual_port_group_read(id=self.vpg_uuid)
        self.vpg_name = vpg_obj.get_fq_name()
 def mockFabricObj(self):
     fabric_obj = Fabric(name='fab01')
     fabric_obj.uuid = FAB_UUID1
     fabric_obj.fq_name = [DGSC, 'fab01']
     cred = UserCredentials(username='******',
                            password='******')
     credentials = DeviceCredential(credential=cred)
     fabric_credentials = DeviceCredentialList(
         device_credential=[credentials])
     fabric_obj.set_fabric_credentials(fabric_credentials)
     fabric_obj.set_annotations(KeyValuePairs([
         KeyValuePair(key='cli_sync_input',
                      value=mock_job_template_input_schema)]))
     return fabric_obj
示例#5
0
    def test_virtual_port_group_name_with_internal_negative(self):
        proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(proj_obj)

        fabric_obj = Fabric('%s-fabric' % (self.id()))
        self.api.fabric_create(fabric_obj)

        vn = VirtualNetwork('vn-%s' % (self.id()), parent_obj=proj_obj)
        self.api.virtual_network_create(vn)

        vpg_name_err = "vpg-internal-" + self.id()
        vpg_obj_err = VirtualPortGroup(vpg_name_err, parent_obj=fabric_obj)

        # Make sure that api server throws an error if
        # VPG is created externally with prefix vpg-internal in the name.
        with ExpectedException(BadRequest):
            self.api.virtual_port_group_create(vpg_obj_err)
 def mockFabric(self):
     try:
         fabric_obj = Fabric(name='fab01')
         fabric_obj.uuid = FAB_UUID1
         fabric_obj.fq_name = [DGSC, 'fab01']
         cred = UserCredentials(username='******',
                                password='******')
         credentials = DeviceCredential(credential=cred)
         fabric_credentials = DeviceCredentialList(
             device_credential=[credentials])
         fabric_obj.set_fabric_credentials(fabric_credentials)
         fabric_obj.set_annotations(KeyValuePairs([
             KeyValuePair(key='cli_sync_input',
                          value=mock_job_template_input_schema)]))
         self._vnc_lib.fabric_create(fabric_obj)
     except RefsExistError:
         logger.info("Fabric {} already exists".format('fab01'))
     except Exception as ex:
         logger.error("ERROR creating fabric {}: {}".format('fab01', ex))
示例#7
0
    def test_fabric_create(self):
        fabric_credentials = DeviceCredentialList(device_credential=[
            DeviceCredential(
                credential=UserCredentials(username='******', password='******'),
                vendor='juniper',
                device_family='juniper')])
        prop_map = {'name': 'f-{}'.format(self.id()),
                    'display_name': 'fabric test',
                    'parent_obj': self.gsc,
                    'parent_type': 'global-system-config',
                    'fabric_ztp': True,
                    'fabric_os_version': 'junos',
                    'fabric_credentials': fabric_credentials,
                    'fabric_enterprise_style': False,
                    'annotations': {}}

        obj = self.set_properties(Fabric(), prop_map)
        self.assertSchemaObjCreateOrUpdate(obj)
示例#8
0
    def _create_vpg_prerequisites(self,
                                  enterprise_style_flag=True,
                                  create_second_pr=False,
                                  disable_vlan_vn_uniqueness_check=False):
        # Create project first
        proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(proj_obj)

        # Create Fabric with enterprise style flag set to false
        fabric_obj = Fabric('%s-fabric' % (self.id()))
        fabric_obj.set_fabric_enterprise_style(enterprise_style_flag)
        fabric_obj.set_disable_vlan_vn_uniqueness_check(
            disable_vlan_vn_uniqueness_check)
        fabric_uuid = self.api.fabric_create(fabric_obj)
        fabric_obj = self.api.fabric_read(id=fabric_uuid)

        # Create physical router
        pr_name = self.id() + '_physical_router'
        pr = PhysicalRouter(pr_name)
        pr_uuid = self._vnc_lib.physical_router_create(pr)
        pr_obj = self._vnc_lib.physical_router_read(id=pr_uuid)

        # Create physical interface
        esi_id = '00:11:22:33:44:55:66:77:88:99'
        pi_name = self.id() + '__phy_intf_1'
        pi = PhysicalInterface(name=pi_name,
                               parent_obj=pr_obj,
                               ethernet_segment_identifier=esi_id)
        pi_uuid = self.api.physical_interface_create(pi)
        pi_obj = self.api.physical_interface_read(id=pi_uuid)

        # Create VN
        vn_name = 'vn-%s-1' % self.id()
        vn = VirtualNetwork(vn_name, parent_obj=proj_obj)
        vn_uuid = self.api.virtual_network_create(vn)
        vn_obj = self.api.virtual_network_read(id=vn_uuid)

        return proj_obj, fabric_obj, pr_obj, pi_obj, vn_obj
示例#9
0
 def _pre_create_fabric(self):
     fabric = Fabric(name="test-fabric")
     fabric_uuid = self.api.fabric_create(fabric)
     self.fabric = self.api.fabric_read(id=fabric_uuid)
示例#10
0
class TestVMIVirtualPortGroupRelation(test_case.ApiServerTestCase):
    @classmethod
    def setUpClass(cls, *args, **kwargs):
        cls.console_handler = logging.StreamHandler()
        cls.console_handler.setLevel(logging.DEBUG)
        logger.addHandler(cls.console_handler)
        super(TestVMIVirtualPortGroupRelation, cls).setUpClass(*args, **kwargs)

    @classmethod
    def tearDownClass(cls, *args, **kwargs):
        logger.removeHandler(cls.console_handler)
        super(TestVMIVirtualPortGroupRelation,
              cls).tearDownClass(*args, **kwargs)

    @property
    def api(self):
        return self._vnc_lib

    def setUp(self):
        super(TestVMIVirtualPortGroupRelation, self).setUp()
        if six.PY3:
            self.assertItemsEqual = self.assertCountEqual

        # Create project
        self.proj_obj = Project('%s-project' % (self.id()))
        self.api.project_create(self.proj_obj)

        # Create Fabric
        self.fabric_obj = Fabric('%s-fabric' % (self.id()))
        _ = self.api.fabric_create(self.fabric_obj)
        self.fabric_name = self.fabric_obj.get_fq_name()

        # Create physical router
        pr_name = self.id() + '_physical_router'
        pr = PhysicalRouter(pr_name)
        pr_uuid = self.api.physical_router_create(pr)
        self.pr_obj = self.api.physical_router_read(id=pr_uuid)

        # Create Physical interface
        esi_id = '00:11:22:33:44:55:66:77:88:99'
        pi_name = self.id() + '_physical_interface1'
        pi = PhysicalInterface(name=pi_name,
                               parent_obj=self.pr_obj,
                               ethernet_segment_identifier=esi_id)
        self.pi_uuid = self.api.physical_interface_create(pi)
        pi_obj = self.api.physical_interface_read(id=self.pi_uuid)
        self.pi_fq_name = pi_obj.get_fq_name()

        # Create VN
        self.vn = VirtualNetwork('vn-%s' % (self.id()),
                                 parent_obj=self.proj_obj)
        self.vn_uuid = self.api.virtual_network_create(self.vn)

        # Create VPG
        self.vpg_name = "vpg-%s" % self.id()
        vpg = VirtualPortGroup(self.vpg_name, parent_obj=self.fabric_obj)
        self.vpg_uuid = self.api.virtual_port_group_create(vpg)
        vpg_obj = self.api.virtual_port_group_read(id=self.vpg_uuid)
        self.vpg_name = vpg_obj.get_fq_name()

    def tearDown(self):
        self.api.physical_interface_delete(id=self.pi_uuid)
        self.api.physical_router_delete(id=self.pr_obj.uuid)
        self.api.virtual_port_group_delete(id=self.vpg_uuid)
        self.api.fabric_delete(id=self.fabric_obj.uuid)
        self.api.virtual_network_delete(id=self.vn_uuid)
        self.api.project_delete(id=self.proj_obj.uuid)
        super(TestVMIVirtualPortGroupRelation, self).tearDown()

    def create_vmi_bindings(self,
                            pi_fq_name,
                            fabric_name,
                            vpg_name,
                            tor_port_vlan_id=0):
        # Populate binding profile to be used in VMI create
        binding_profile = {'local_link_information': []}
        if isinstance(pi_fq_name[0], type([])):
            for pi_name in pi_fq_name:
                binding_profile['local_link_information'].append({
                    'port_id':
                    pi_name[2],
                    'switch_id':
                    pi_name[2],
                    'fabric':
                    fabric_name[-1],
                    'switch_info':
                    pi_name[1]
                })
        else:
            binding_profile['local_link_information'].append({
                'port_id':
                pi_fq_name[2],
                'switch_id':
                pi_fq_name[2],
                'fabric':
                fabric_name[-1],
                'switch_info':
                pi_fq_name[1]
            })

        if tor_port_vlan_id != 0:
            kv_pairs = KeyValuePairs([
                KeyValuePair(key='vpg', value=vpg_name[-1]),
                KeyValuePair(key='vif_type', value='vrouter'),
                KeyValuePair(key='tor_port_vlan_id', value=tor_port_vlan_id),
                KeyValuePair(key='vnic_type', value='baremetal'),
                KeyValuePair(key='profile', value=json.dumps(binding_profile))
            ])
        else:
            kv_pairs = KeyValuePairs([
                KeyValuePair(key='vpg', value=vpg_name[-1]),
                KeyValuePair(key='vif_type', value='vrouter'),
                KeyValuePair(key='vnic_type', value='baremetal'),
                KeyValuePair(key='profile', value=json.dumps(binding_profile))
            ])

        return kv_pairs

    def test_untagged_vmi_to_vpg_ref_create_during_vmi_create(self):
        # Create vmi with bindings
        vmi_obj = VirtualMachineInterface('vmi' + self.id(),
                                          parent_obj=self.proj_obj)
        vmi_obj.set_virtual_network(self.vn)
        bindings = self.create_vmi_bindings(self.pi_fq_name,
                                            self.fabric_name,
                                            self.vpg_name,
                                            tor_port_vlan_id='4094')
        vmi_obj.set_virtual_machine_interface_bindings(bindings)
        vmi_uuid = self.api.virtual_machine_interface_create(vmi_obj)

        # Validate
        vmi_obj = self.api.virtual_machine_interface_read(id=vmi_uuid)
        vpg_refs = vmi_obj.get_virtual_port_group_refs()
        self.assertEqual(len(vpg_refs), 1)
        self.assertEqual(vpg_refs[0]['attr'].native_vlan_tag, '4094')
        self.assertIsNone(vpg_refs[0]['attr'].vlan_tag)

        # Cleanup
        self.api.virtual_machine_interface_delete(id=vmi_uuid)

    def test_tagged_vmi_to_vpg_ref_create_during_vmi_update(self):
        # Create vmi without bindings
        vmi_obj = VirtualMachineInterface('vmi' + self.id(),
                                          parent_obj=self.proj_obj)
        vmi_obj.set_virtual_network(self.vn)
        vmi_uuid = self.api.virtual_machine_interface_create(vmi_obj)

        # Validate
        db_vmi_obj = self.api.virtual_machine_interface_read(id=vmi_uuid)
        vpg_refs = db_vmi_obj.get_virtual_port_group_refs()
        self.assertIsNone(vpg_refs)

        # update VMI with bindings
        bindings = self.create_vmi_bindings(self.pi_fq_name, self.fabric_name,
                                            self.vpg_name)
        vmi_obj.set_virtual_machine_interface_bindings(bindings)
        vmi_obj.set_virtual_machine_interface_properties(
            VMIPT(sub_interface_vlan_tag='4094'))
        self.api.virtual_machine_interface_update(vmi_obj)

        # Validate
        db_vmi_obj = self.api.virtual_machine_interface_read(id=vmi_uuid)
        vpg_refs = db_vmi_obj.get_virtual_port_group_refs()
        self.assertEqual(len(vpg_refs), 1)
        self.assertIsNone(vpg_refs[0]['attr'].native_vlan_tag)
        self.assertEqual(vpg_refs[0]['attr'].vlan_tag, 4094)

        # Cleanup
        self.api.virtual_machine_interface_delete(id=vmi_uuid)

    def test_vmi_to_vpg_ref_create_during_dbe_resync(self):
        # Create vmi with bindings
        vmi_obj = VirtualMachineInterface('vmi' + self.id(),
                                          parent_obj=self.proj_obj)
        vmi_obj.set_virtual_network(self.vn)
        bindings = self.create_vmi_bindings(self.pi_fq_name,
                                            self.fabric_name,
                                            self.vpg_name,
                                            tor_port_vlan_id='4094')
        vmi_obj.set_virtual_machine_interface_bindings(bindings)
        vmi_uuid = self.api.virtual_machine_interface_create(vmi_obj)

        # Validate
        vmi_obj = self.api.virtual_machine_interface_read(id=vmi_uuid)
        vpg_refs = vmi_obj.get_virtual_port_group_refs()
        self.assertEqual(len(vpg_refs), 1)
        self.assertEqual(vpg_refs[0]['attr'].native_vlan_tag, '4094')
        self.assertIsNone(vpg_refs[0]['attr'].vlan_tag)

        # Remove VMI to VPG ref, to mock upgrade case
        self.api.ref_update("virtual-machine-interface", vmi_uuid,
                            "virtual-port-group", self.vpg_uuid, None,
                            "DELETE", None)
        # Validate, make sure rhe vmi--->vpg ref is removed
        vmi_obj = self.api.virtual_machine_interface_read(id=vmi_uuid)
        vpg_refs = vmi_obj.get_virtual_port_group_refs()
        self.assertIsNone(vpg_refs)

        # Simulate api-server restart by DB reinit
        self._api_server._db_init_entries()

        # Validate, Make sure vmi--->vpg ref is created
        vmi_obj = self.api.virtual_machine_interface_read(id=vmi_uuid)
        vpg_refs = vmi_obj.get_virtual_port_group_refs()
        self.assertEqual(len(vpg_refs), 1)
        self.assertEqual(vpg_refs[0]['attr'].native_vlan_tag, '4094')
        self.assertIsNone(vpg_refs[0]['attr'].vlan_tag)

        # Cleanup
        self.api.virtual_machine_interface_delete(id=vmi_uuid)
示例#11
0
    def test_l2_dci_mode(self):
        """Validate l2 mode dci object create and edit operation.

        It executes following steps:
        - Create 3 fabric, each one with one PR, all PR except one PR
        should be marked not DCI-gateway.
        - Create 3 VN, two tenant VN and one routed VN

        Validate l2 mode dci create failure by doing following operation:
        - Remove two fabrics from dci and keep only one fabric in dci
        and verify create dci fails as not having two fabrics.
        - Remove all VN from dci and verify create dci fails as not
        having at least one VN.
        - Create l2 mode dci with 3 fabric and 2 tenant vn, verify it
        fails with Error of fabric does not have DCI-gateway RB role PR.
        - Remove faulty fabric. and add 3rd routed vn to dci. verify
        create operation fails with error routed vn not allowed.

        Create successfully l2 dci with 2 fabrics and 2 vn. execute
        following edit operation verification:
        - Add fabric to dci having no DCI-gw role PR, verify error.
        - Add routed vnto dci, verify error.
        : Args:
        : return:
        : it generates exception on failure
        :
        """
        dict_fabrics = {}
        dict_prs = {}
        dict_vns = {}
        non_dci_fabric_name = ''
        routed_vn_name = ''
        ipam_obj = self.create_vn_ipam(self.id())
        subnetmask = 24
        vn_starting_index = 21
        for i in range(1, 4):
            fabric_name = '%s-fabric%s' % (self.id(), str(i))
            fabric_obj = Fabric(fabric_name)
            dict_fabrics[fabric_name] = fabric_obj
            fabric_uuid = self._vnc_lib.fabric_create(fabric_obj)
            self._vnc_lib.fabric_read(id=fabric_uuid)

            pr_name = '%s-PR%s' % (self.id(), str(i))
            pr = PhysicalRouter(pr_name)
            pr.set_fabric(fabric_obj)
            if i != 3:
                pr.set_routing_bridging_roles(
                    RoutingBridgingRolesType(rb_roles=['DCI-Gateway']))
            else:
                non_dci_fabric_name = fabric_name
                pr.set_routing_bridging_roles(
                    RoutingBridgingRolesType(rb_roles=['DC-Gateway']))
            dict_prs[pr_name] = pr
            pr_uuid = self._vnc_lib.physical_router_create(pr)
            self._vnc_lib.physical_router_read(id=pr_uuid)

            subnet = "%s.0.0.0" % vn_starting_index
            vn_starting_index += 1
            vn_name = self.make_vn_name(i)
            vn_category = 'tenant'
            if i == 3:
                routed_vn_name = vn_name
                vn_category = 'routed'
            dict_vns[vn_name] = self.create_vn_with_subnets(
                i, vn_name, ipam_obj, subnet, subnetmask, vn_category)

        vn_list = []
        for vnname, obj in dict_vns.items():
            if vnname != routed_vn_name:
                vn_list.append(obj)
        fabric_list = []
        for fname, obj in dict_fabrics.items():
            if fname != non_dci_fabric_name:
                fabric_list.append(obj)

        dci_obj, dci_uuid = self._verify_l2_dci_create_edit(
            'l2_dci', dict_fabrics, dict_vns, non_dci_fabric_name,
            routed_vn_name, vn_list, fabric_list, None)

        # validate Edit Operation
        dci_obj, dci_uuid = self._verify_l2_dci_create_edit(
            'l2_dci', dict_fabrics, dict_vns, non_dci_fabric_name,
            routed_vn_name, vn_list, fabric_list, dci_obj)

        # cleanup
        self._vnc_lib.data_center_interconnect_delete(id=dci_uuid)
        for name, obj in dict_vns.items():
            self._vnc_lib.virtual_network_delete(id=obj.get_uuid())
        self._vnc_lib.network_ipam_delete(id=ipam_obj.uuid)
        for name, obj in dict_prs.items():
            self._vnc_lib.physical_router_delete(id=obj.get_uuid())
        for name, obj in dict_fabrics.items():
            self._vnc_lib.fabric_delete(id=obj.get_uuid())
    def basic_setup(self):
        proj_obj = Project('project')
        self.api.project_create(proj_obj)

        fabric_obj = Fabric('fabric')
        self.api.fabric_create(fabric_obj)