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
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)
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
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 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)
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))
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 _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
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)
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)