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_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')
Ejemplo n.º 3
0
    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 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_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')