def test_context_undo_vxlan_id_fail_db_create(self): # enable vxlan routing on project proj = self._vnc_lib.project_read( fq_name=["default-domain", "default-project"]) proj.set_vxlan_routing(True) self._vnc_lib.project_update(proj) mock_zk = self._api_server._db_conn._zk_db vn_obj = VirtualNetwork('%s-vn' % self.id()) vn_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn_obj_properties.set_vxlan_network_identifier(6000) vn_obj.set_virtual_network_properties(vn_obj_properties) def stub(*args, **kwargs): return (False, (500, "Fake error")) zk_alloc_count_start = mock_zk._vn_id_allocator.get_alloc_count() with ExpectedException(HttpError): with test_common.flexmocks( [(self._api_server._db_conn, 'dbe_create', stub)]): self.api.virtual_network_create(vn_obj) # make sure allocation counter stays the same zk_alloc_count_current = mock_zk._vn_id_allocator.get_alloc_count() self.assertEqual(zk_alloc_count_start, zk_alloc_count_current)
def test_deallocate_vxlan_id(self): # enable vxlan routing on project proj = self._vnc_lib.project_read( fq_name=["default-domain", "default-project"]) proj.set_vxlan_routing(True) self._vnc_lib.project_update(proj) mock_zk = self._api_server._db_conn._zk_db vn_obj = VirtualNetwork('%s-vn' % self.id()) vn_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn_obj_properties.set_vxlan_network_identifier(6002) vn_obj.set_virtual_network_properties(vn_obj_properties) self.api.virtual_network_create(vn_obj) # VN created, now read back the VN data to check if vxlan_id is set vn_obj = self.api.virtual_network_read(id=vn_obj.uuid) vn_obj_properties = vn_obj.get_virtual_network_properties() if not vn_obj_properties: self.fail("VN properties are not set") vxlan_id = vn_obj_properties.get_vxlan_network_identifier() self.assertEqual(vxlan_id, 6002) self.api.virtual_network_delete(id=vn_obj.uuid) self.assertNotEqual(vn_obj.get_fq_name_str() + "_vxlan", mock_zk.get_vn_from_id(vxlan_id)) logger.debug('PASS - test_deallocate_vxlan_id')
def test_update_auto_vxlan_id_with_the_same_value(self): """ Test case. 1. Set VxLAN identifier mode to 'automatic'. 2. Create new VirtualNetwork. 3. Set VxLAN identifier mode to 'configured'. 4. Update VirtualNetwork with vxlan network identifier equal to network id. """ gvc_fq_name = [ 'default-global-system-config', 'default-global-vrouter-config' ] vxlan_id_mode = {'auto': 'automatic', 'user': '******'} # Set VxLAN identifier mode to 'automatic' gvc = self.api.global_vrouter_config_read(fq_name=gvc_fq_name) gvc.set_vxlan_network_identifier_mode(vxlan_id_mode['auto']) self.api.global_vrouter_config_update(gvc) gvc = self.api.global_vrouter_config_read(fq_name=gvc_fq_name) # verify vxlan id mode has been set self.assertEqual(gvc.vxlan_network_identifier_mode, vxlan_id_mode['auto']) # Create new VirtualNetwork vn = VirtualNetwork('%s-vn' % self.id()) self.api.virtual_network_create(vn) vn = self.api.virtual_network_read(fq_name=vn.fq_name) # verify vn_network_id has been set vn_network_id = vn.get_virtual_network_network_id() self.assertTrue(vn_network_id > 0) # Set VxLAN identifier mode to 'configured' (user defined) gvc.set_vxlan_network_identifier_mode(vxlan_id_mode['user']) self.api.global_vrouter_config_update(gvc) gvc = self.api.global_vrouter_config_read(fq_name=gvc_fq_name) # verify vxlan id mode has been set self.assertEqual(gvc.vxlan_network_identifier_mode, vxlan_id_mode['user']) # Update VirtualNetwork with vxlan network identifier # equal to network id vn_properties = VirtualNetworkType() vn_properties.set_vxlan_network_identifier(vn_network_id) vn.set_virtual_network_properties(vn_properties) self.api.virtual_network_update(vn) # verify vn_network_id is the same as vxlan_network_id vn = self.api.virtual_network_read(fq_name=vn.fq_name) vxlan_id = vn.get_virtual_network_properties() \ .get_vxlan_network_identifier() self.assertEqual(vn_network_id, vxlan_id)
def create_vn_with_subnets(self, id, vn_name, ipam_obj, subnet, subnetmask=24): vn_obj = VirtualNetwork(vn_name) vn_obj_properties = VirtualNetworkType() vn_obj_properties.set_vxlan_network_identifier(2000 + id) vn_obj_properties.set_forwarding_mode('l2_l3') vn_obj.set_virtual_network_properties(vn_obj_properties) vn_obj.add_network_ipam( ipam_obj, VnSubnetsType([IpamSubnetType(SubnetType(subnet, subnetmask))])) vn_uuid = self._vnc_lib.virtual_network_create(vn_obj) return self._vnc_lib.virtual_network_read(id=vn_uuid)
def test_context_undo_vn_to_vxlan_id_fail_db_update(self): # Enable vxlan routing on project proj = self._vnc_lib.project_read( fq_name=["default-domain", "default-project"]) proj.set_vxlan_routing(True) self._vnc_lib.project_update(proj) mock_zk = self._api_server._db_conn._zk_db vn_obj = VirtualNetwork('%s-vn' % self.id()) self.api.virtual_network_create(vn_obj) vn_fqname = mock_zk.get_vn_from_id(vn_obj.virtual_network_network_id) vn_id = vn_obj.virtual_network_network_id # Change vn to vxlan type vxlan_id = 6000 vn_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn_obj_properties.set_vxlan_network_identifier(vxlan_id) vn_obj_properties.set_forwarding_mode('l2_l3') vn_obj.set_virtual_network_properties(vn_obj_properties) def stub(*args, **kwargs): return (False, (500, "Fake error")) zk_alloc_count_start = mock_zk._vn_id_allocator.get_alloc_count() with ExpectedException(HttpError): with test_common.flexmocks( [(self._api_server._db_conn, 'dbe_update', stub)]): self.api.virtual_network_update(vn_obj) # Make sure vxlan_id was dealocated new_vxlan_fqname = mock_zk.get_vn_from_id(vxlan_id) self.assertEqual(new_vxlan_fqname, None) # Make sure vn id is the same new_vn_id = vn_obj.virtual_network_network_id self.assertEqual(vn_id, new_vn_id) # Make sure fqname is the same fot vn_id update_vn_fqname = mock_zk.get_vn_from_id( vn_obj.virtual_network_network_id) self.assertEqual(vn_fqname, update_vn_fqname) # Make sure allocation counter stays the same zk_alloc_count_current = mock_zk._vn_id_allocator.get_alloc_count() self.assertEqual(zk_alloc_count_start, zk_alloc_count_current)
def create_vn_with_subnets(self, id, vn_name, ipam_obj, subnet, subnetmask=24): vn_obj = VirtualNetwork(vn_name) vn_obj_properties = VirtualNetworkType() vn_obj_properties.set_vxlan_network_identifier(2000 + id) vn_obj_properties.set_forwarding_mode('l2_l3') vn_obj.set_virtual_network_properties(vn_obj_properties) vn_obj.add_network_ipam(ipam_obj, VnSubnetsType( [IpamSubnetType(SubnetType(subnet, subnetmask))])) vn_uuid = self._vnc_lib.virtual_network_create(vn_obj) vn_obj_rd = self._vnc_lib.virtual_network_read(id=vn_uuid) # make sure RT for vn is created rt = [] try: rt = self._get_route_target(vn_obj_rd) except Exception: pass return vn_obj, self._vnc_lib.virtual_network_read(id=vn_uuid), rt
def test_cannot_allocate_vxlan_id(self): # enable vxlan routing on project proj = self._vnc_lib.project_read( fq_name=["default-domain", "default-project"]) proj.set_vxlan_routing(True) self._vnc_lib.project_update(proj) mock_zk = self._api_server._db_conn._zk_db vn1_obj = VirtualNetwork('%s-vn' % self.id()) vn1_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn1_obj_properties.set_vxlan_network_identifier(6001) vn1_obj_properties.set_forwarding_mode('l2_l3') vn1_obj.set_virtual_network_properties(vn1_obj_properties) self.api.virtual_network_create(vn1_obj) # VN created, now read back the VN data to check if vxlan_id is set vn1_obj = self.api.virtual_network_read(id=vn1_obj.uuid) vn1_obj_properties = vn1_obj.get_virtual_network_properties() if not vn1_obj_properties: self.fail("VN properties are not set") vxlan_id = vn1_obj_properties.get_vxlan_network_identifier() self.assertEqual(vxlan_id, 6001) # Verified vxlan_id for VN1, now create VN2 with same vxlan_id vn2_obj = VirtualNetwork('%s-vn2' % self.id()) vn2_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn2_obj_properties.set_vxlan_network_identifier(6001) vn2_obj_properties.set_forwarding_mode('l2_l3') vn2_obj.set_virtual_network_properties(vn2_obj_properties) with ExpectedException(BadRequest): self.api.virtual_network_create(vn2_obj) self.assertEqual(vn1_obj.get_fq_name_str() + "_vxlan", mock_zk.get_vn_from_id(vxlan_id)) self.assertGreaterEqual(vxlan_id, VNID_MIN_ALLOC) self.api.virtual_network_delete(id=vn1_obj.uuid) logger.debug('PASS - test_cannot_allocate_vxlan_id')
def test_update_vxlan_id(self): # enable vxlan routing on project proj = self._vnc_lib.project_read( fq_name=["default-domain", "default-project"]) proj.set_vxlan_routing(True) self._vnc_lib.project_update(proj) mock_zk = self._api_server._db_conn._zk_db vn_obj = VirtualNetwork('%s-vn' % self.id()) vn_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn_obj_properties.set_vxlan_network_identifier(6003) vn_obj_properties.set_forwarding_mode('l2_l3') vn_obj.set_virtual_network_properties(vn_obj_properties) self.api.virtual_network_create(vn_obj) #VN created, now read back the VN data to check if vxlan_id is set vn_obj_read = self.api.virtual_network_read(id=vn_obj.uuid) vn_obj_properties_read = vn_obj_read.get_virtual_network_properties() if not vn_obj_properties_read: self.fail("VN properties are not set") vxlan_id = vn_obj_properties_read.get_vxlan_network_identifier() self.assertEqual(vxlan_id, 6003) #Created VN. Now Update it with a different vxlan_id vn_obj_properties.set_vxlan_network_identifier(6004) vn_obj.set_virtual_network_properties(vn_obj_properties) self.api.virtual_network_update(vn_obj) vn_obj_read = self.api.virtual_network_read(id=vn_obj.uuid) vn_obj_properties_read = vn_obj_read.get_virtual_network_properties() if not vn_obj_properties_read: self.fail("VN properties are not set") vxlan_id = vn_obj_properties_read.get_vxlan_network_identifier() self.assertEqual(vxlan_id, 6004) self.api.virtual_network_delete(id=vn_obj.uuid) logger.debug('PASS - test_update_vxlan_id')
def test_update_vxlan_id(self): # enable vxlan routing on project proj = self._vnc_lib.project_read( fq_name=["default-domain", "default-project"]) proj.set_vxlan_routing(True) self._vnc_lib.project_update(proj) vn_obj = VirtualNetwork('%s-vn' % self.id()) vn_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn_obj_properties.set_vxlan_network_identifier(6003) vn_obj_properties.set_forwarding_mode('l2_l3') vn_obj.set_virtual_network_properties(vn_obj_properties) self.api.virtual_network_create(vn_obj) # VN created, now read back the VN data to check if vxlan_id is set vn_obj_read = self.api.virtual_network_read(id=vn_obj.uuid) vn_obj_properties_read = vn_obj_read.get_virtual_network_properties() if not vn_obj_properties_read: self.fail("VN properties are not set") vxlan_id = vn_obj_properties_read.get_vxlan_network_identifier() self.assertEqual(vxlan_id, 6003) # Created VN. Now Update it with a different vxlan_id vn_obj_properties.set_vxlan_network_identifier(6004) vn_obj.set_virtual_network_properties(vn_obj_properties) self.api.virtual_network_update(vn_obj) vn_obj_read = self.api.virtual_network_read(id=vn_obj.uuid) vn_obj_properties_read = vn_obj_read.get_virtual_network_properties() if not vn_obj_properties_read: self.fail("VN properties are not set") vxlan_id = vn_obj_properties_read.get_vxlan_network_identifier() self.assertEqual(vxlan_id, 6004) self.api.virtual_network_delete(id=vn_obj.uuid) logger.debug('PASS - test_update_vxlan_id')
def test_cannot_update_vxlan_id(self): # enable vxlan routing on project proj = self._vnc_lib.project_read( fq_name=["default-domain", "default-project"]) proj.set_vxlan_routing(True) self._vnc_lib.project_update(proj) mock_zk = self._api_server._db_conn._zk_db vn1_obj = VirtualNetwork('%s-vn1' % self.id()) vn1_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn1_obj_properties.set_vxlan_network_identifier(6005) vn1_obj_properties.set_forwarding_mode('l2_l3') vn1_obj.set_virtual_network_properties(vn1_obj_properties) self.api.virtual_network_create(vn1_obj) #VN created, create second VN with different vxlan_id vn2_obj = VirtualNetwork('%s-vn2' % self.id()) vn2_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn2_obj_properties.set_vxlan_network_identifier(6006) vn2_obj_properties.set_forwarding_mode('l2_l3') vn2_obj.set_virtual_network_properties(vn2_obj_properties) self.api.virtual_network_create(vn2_obj) #Created Two VNs. Now Update it second VN with 1st VNs VXLAN_ID vn2_obj_properties.set_vxlan_network_identifier(6005) vn2_obj.set_virtual_network_properties(vn2_obj_properties) with ExpectedException(cfgm_common.exceptions.BadRequest) as e: self.api.virtual_network_update(vn2_obj) vn_obj_read = self.api.virtual_network_read(id=vn2_obj.uuid) vn_obj_properties_read = vn_obj_read.get_virtual_network_properties() if not vn_obj_properties_read: self.fail("VN properties are not set") vxlan_id = vn_obj_properties_read.get_vxlan_network_identifier() self.assertEqual(vxlan_id, 6006) self.api.virtual_network_delete(id=vn2_obj.uuid) self.api.virtual_network_delete(id=vn1_obj.uuid) logger.debug('PASS - test_cannot_update_vxlan_id')
def test_cannot_update_vxlan_id(self): # enable vxlan routing on project proj = self._vnc_lib.project_read( fq_name=["default-domain", "default-project"]) proj.set_vxlan_routing(True) self._vnc_lib.project_update(proj) vn1_obj = VirtualNetwork('%s-vn1' % self.id()) vn1_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn1_obj_properties.set_vxlan_network_identifier(6005) vn1_obj_properties.set_forwarding_mode('l2_l3') vn1_obj.set_virtual_network_properties(vn1_obj_properties) self.api.virtual_network_create(vn1_obj) # VN created, create second VN with different vxlan_id vn2_obj = VirtualNetwork('%s-vn2' % self.id()) vn2_obj_properties = VirtualNetworkType(forwarding_mode='l3') vn2_obj_properties.set_vxlan_network_identifier(6006) vn2_obj_properties.set_forwarding_mode('l2_l3') vn2_obj.set_virtual_network_properties(vn2_obj_properties) self.api.virtual_network_create(vn2_obj) # Created Two VNs. Now Update it second VN with 1st VNs VXLAN_ID vn2_obj_properties.set_vxlan_network_identifier(6005) vn2_obj.set_virtual_network_properties(vn2_obj_properties) with ExpectedException(BadRequest): self.api.virtual_network_update(vn2_obj) vn_obj_read = self.api.virtual_network_read(id=vn2_obj.uuid) vn_obj_properties_read = vn_obj_read.get_virtual_network_properties() if not vn_obj_properties_read: self.fail("VN properties are not set") vxlan_id = vn_obj_properties_read.get_vxlan_network_identifier() self.assertEqual(vxlan_id, 6006) self.api.virtual_network_delete(id=vn2_obj.uuid) self.api.virtual_network_delete(id=vn1_obj.uuid) logger.debug('PASS - test_cannot_update_vxlan_id')