def test():
    global curr_deploy_conf
    global test_obj_dict
    global l3_name
    global l3
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(
        test_lib.deploy_config)
    delete_policy = test_lib.lib_set_delete_policy('vm', 'Delay')
    l3_name = os.environ.get('l3VlanNetworkName1')
    l3 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name)[0]
    vm = test_stub.create_vlan_vm(l3_name)
    vm.check()
    test_obj_dict.add_vm(vm)
    net_ops.delete_l3(l3.uuid)
    if test_lib.lib_get_l3_by_uuid(l3.uuid):
        test_util.test_fail(
            'l3 should not be found when associated L3 is deleted')
    #vm_nic_uuid = vm.vm.vmNics[0].uuid
    #net_ops.detach_l3(vm_nic_uuid)

    vm.destroy()
    vm.set_state(vm_header.DESTROYED)
    vm.check()

    vm.recover()
    vm.set_state(vm_header.STOPPED)
    vm.check()

    test_lib.lib_set_delete_policy('vm', delete_policy)

    try:
        vm.start()
    except Exception, e:
        #if "please attach a nic and try again" in str(e):
        test_util.test_pass('test detach l3 check vm passed.')
def error_cleanup():
    if project_uuid:
        iam2_ops.delete_iam2_project(project_uuid)
        iam2_ops.expunge_iam2_project(project_uuid)
    if project_operator_uuid:
        iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    if l2_vxlan_network_uuid:
        net_ops.delete_l2(l2_vxlan_network_uuid)
    if vni_range_uuid:
        vxlan_ops.delete_vni_range(vni_range_uuid)
    if vxlan_pool_uuid:
        net_ops.delete_l2(vxlan_pool_uuid)
    if l3_vpc_network_uuid:
        net_ops.delete_l3(l3_vpc_network_uuid)
def error_cleanup():
    if project_uuid:
        iam2_ops.delete_iam2_project(project_uuid)
        iam2_ops.expunge_iam2_project(project_uuid)
    if project_operator_uuid:
        iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    if l2_vxlan_network_uuid:
            net_ops.delete_l2(l2_vxlan_network_uuid)
    if vni_range_uuid:
        vxlan_ops.delete_vni_range(vni_range_uuid)
    if vxlan_pool_uuid:
        net_ops.delete_l2(vxlan_pool_uuid)
    if l3_vr_network_uuid:
        net_ops.delete_l3(l3_vr_network_uuid)
def test():

    # create l3 network
    global l3, l2

    name = 'mini_network_test'
    test_util.test_dsc('create L2_vlan network mini_l2_network_test')
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    cluster_uuid = res_ops.query_resource(res_ops.CLUSTER)[0].uuid
    l2 = net_ops.create_l2_vlan('l2_vlan', 'zsn0', zone_uuid, '1998')
    l2_uuid = l2.inventory.uuid
    net_ops.attach_l2(l2_uuid, cluster_uuid)

    type='L3BasicNetwork'
    categry='Private'
    l3=net_ops.create_l3(name, l2_uuid, category=categry, Type=type)

    # add dns to l3 network
    l3_dns = '223.5.5.5'
    net_ops.add_dns_to_l3(l3.uuid, l3_dns)
    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')

    # add ip range to l3 network
    ip_range_option = test_util.IpRangeOption()
    ip_range_option.set_l3_uuid(l3.uuid)
    ip_range_option.set_startIp('192.168.40.2')
    ip_range_option.set_endIp('192.168.40.20')
    ip_range_option.set_gateway('192.168.40.1')
    ip_range_option.set_netmask('255.255.255.0')
    ip_range_option.set_name('ip_range_test')

    net_ops.add_ip_range(ip_range_option)

    #attach network service to l3 network
    cond = res_ops.gen_query_conditions('type', '=', 'flat')
    provider1_uuid = res_ops.query_resource(res_ops.NETWORK_SERVICE_PROVIDER, cond)[0].uuid
    cond = res_ops.gen_query_conditions('type', '=', 'SecurityGroup')
    provider2_uuid = res_ops.query_resource(res_ops.NETWORK_SERVICE_PROVIDER, cond)[0].uuid
    providers = {provider1_uuid:['DHCP','Eip'], provider2_uuid:['SecurityGroup']}
    attach_network_service_to_l3network(l3.uuid, providers)
    test_util.test_dsc('a network with dns, ip range and network services has been created successfully')
    net_ops.delete_l3(l3.uuid)
    net_ops.delete_l2(l2_uuid)
    test_util.test_dsc('delete l3 network after test')
Esempio n. 5
0
def test():
    global curr_deploy_conf
    global l3_name
    global l3
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config)
    test_util.test_dsc('Create test vm and delete l3.')
    l3_name = os.environ.get('l3VlanNetworkName1')
    l3 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name)[0]
    vm = test_stub.create_vlan_vm(l3_name)
    test_obj_dict.add_vm(vm)
    vm.check()
    net_ops.delete_l3(l3.uuid)
    if len(test_lib.lib_find_vr_by_l3_uuid(l3.uuid)) != 0:
        test_util.test_fail('VR VM should be delete when associated L3 is deleted')

    vm.destroy()
    net_ops.add_l3_resource(curr_deploy_conf, l3_name)

    test_util.test_pass('Create VirtualRouter VM delete l3 Test Success')
def test():
    global curr_deploy_conf
    global l3_1
    l3_1 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name1)[0]
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(
        test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING,
                                                    conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm_creation_option.set_l3_uuids([l3_1.uuid])

    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)

    test_util.test_dsc('Delete l3_1')
    net_ops.delete_l3(l3_1.uuid)

    #Since 0.8, delete L3 won't delete VM. It will just detach L3 nic.
    #test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.DESTROYED)
    #test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.DESTROYED)

    #vm1.set_state(vm_header.DESTROYED)
    #vm2.set_state(vm_header.DESTROYED)

    vm1.check()
    vm2.check()

    net_ops.add_l3_resource(curr_deploy_conf, l3_name=l3_1.name)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete L3 Test 2 Success')
def test():
    global curr_deploy_conf
    global l3_1
    l3_1 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name1)[0]
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm_creation_option.set_l3_uuids([l3_1.uuid])

    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)

    test_util.test_dsc('Delete l3_1')
    net_ops.delete_l3(l3_1.uuid)

    #Since 0.8, delete L3 won't delete VM. It will just detach L3 nic. 
    #test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.DESTROYED)
    #test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.DESTROYED)

    #vm1.set_state(vm_header.DESTROYED)
    #vm2.set_state(vm_header.DESTROYED)

    vm1.check()
    vm2.check()

    net_ops.add_l3_resource(curr_deploy_conf, l3_name = l3_1.name)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete L3 Test 2 Success')
def test():
    global curr_deploy_conf
    global l3_2
    l3_2 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name2)[0]
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(
        test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    #pick up l3
    l3_1 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name1)[0]

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING,
                                                    conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm_creation_option.set_l3_uuids([l3_1.uuid, l3_2.uuid])

    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)

    test_util.test_dsc('Delete l3_2')
    net_ops.delete_l3(l3_2.uuid)

    #Since 0.8, delete L3 won't delete VM. It will just detach L3 nic.
    #test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED)
    #test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.STOPPED)
    vm1.update()
    #vm1.set_state(vm_header.STOPPED)
    vm2.update()
    #vm2.set_state(vm_header.STOPPED)

    vm1.check()
    vm2.check()

    #test_util.test_dsc('start vm again. vm should remove the deleted l3')
    #vm1.start()
    #vm2.start()

    net_ops.add_l3_resource(curr_deploy_conf, l3_name=l3_2.name)

    #update l3_2, since it is readded.
    l3_2 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name2)[0]
    vm_creation_option.set_l3_uuids([l3_1.uuid, l3_2.uuid])

    vm3 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm3)

    #check vm1 vm2 status.
    vm1.check()
    vm2.check()

    if not len(vm1.get_vm().vmNics) == 1:
        test_util.test_fail(
            'vm1 vmNics still have L3: %s, even if it is deleted' % l3_2.uuid)

    if not len(vm2.get_vm().vmNics) == 1:
        test_util.test_fail(
            'vm2 vmNics still have L3: %s, even if it is deleted' % l3_2.uuid)

    #check vm3 status
    vm3.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete L3 Test Success')
def test():
    global curr_deploy_conf
    global l3_2
    l3_2 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name2)[0]
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    #pick up l3
    l3_1 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name1)[0]

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm_creation_option.set_l3_uuids([l3_1.uuid, l3_2.uuid])

    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)

    test_util.test_dsc('Delete l3_2')
    net_ops.delete_l3(l3_2.uuid)

    #Since 0.8, delete L3 won't delete VM. It will just detach L3 nic. 
    #test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED)
    #test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.STOPPED)
    vm1.update()
    #vm1.set_state(vm_header.STOPPED)
    vm2.update()
    #vm2.set_state(vm_header.STOPPED)

    vm1.check()
    vm2.check()

    #test_util.test_dsc('start vm again. vm should remove the deleted l3')
    #vm1.start()
    #vm2.start()

    net_ops.add_l3_resource(curr_deploy_conf, l3_name = l3_2.name)

    #update l3_2, since it is readded.
    l3_2 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name2)[0]
    vm_creation_option.set_l3_uuids([l3_1.uuid, l3_2.uuid])

    vm3 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm3)

    #check vm1 vm2 status.
    vm1.check()
    vm2.check()

    if not len(vm1.get_vm().vmNics) == 1:
        test_util.test_fail('vm1 vmNics still have L3: %s, even if it is deleted' % l3_2.uuid)

    if not len(vm2.get_vm().vmNics) == 1:
        test_util.test_fail('vm2 vmNics still have L3: %s, even if it is deleted' % l3_2.uuid)

    #check vm3 status
    vm3.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete L3 Test Success')
def test():
    global project_uuid, project_admin_uuid, virtual_id_uuid, project_operator_uuid, plain_user_uuid

    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    # 1 create project
    if flavor['target_role'] != 'system_admin':
        project_name = 'test_project'
        project = iam2_ops.create_iam2_project(project_name)
        project_uuid = project.uuid
        project_linked_account_uuid = project.linkedAccountUuid

    if flavor['target_role'] == 'project_admin':
        # 2 create virtual id
        project_admin_name = 'username'
        project_admin_password = '******'
        project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, project_admin_password).uuid
        virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid
    
        # 3 create project admin
        iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],project_uuid)
        attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}]
        iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes)

        # login in project by project admin
        project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name, project_admin_password)
        project_login_uuid = iam2_ops.login_iam2_project(project_name, session_uuid=project_admin_session_uuid).uuid
        # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes)
    elif flavor['target_role'] == 'project_operator':
        project_operator_name = 'username2'
        project_operator_password = '******'
        attributes = [{"name": "__ProjectOperator__", "value": project_uuid}]
        project_operator_uuid = iam2_ops.create_iam2_virtual_id(project_operator_name,project_operator_password,attributes=attributes).uuid
        virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernamethree','password').uuid

        # login in project by project operator
        iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],project_uuid)
        project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(project_operator_name,project_operator_password)
        project_login_uuid = iam2_ops.login_iam2_project(project_name,session_uuid=project_operator_session_uuid).uuid
    elif flavor['target_role'] == 'project_member':
	plain_user_name = 'username'
	plain_user_password = '******'
	plain_user_uuid = iam2_ops.create_iam2_virtual_id(plain_user_name, plain_user_password,
	                                                  project_uuid=project_uuid).uuid
	# 3 add virtual id to project
	iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid],project_uuid)

	# 4 login in project by plain user
	plain_user_session_uuid = iam2_ops.login_iam2_virtual_id(plain_user_name, plain_user_password)

	# 4 login in project
	#project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid)
	project_login_uuid = iam2_ops.login_iam2_project(project_name, plain_user_session_uuid).uuid
    elif flavor['target_role'] == 'system_admin':
        username = "******"
        password = '******'
        vid_tst_obj = test_vid.ZstackTestVid()
        test_stub.create_system_admin(username, password, vid_tst_obj)
        virtual_id_uuid = vid_tst_obj.get_vid().uuid
        project_login_uuid = acc_ops.login_by_account(username, password)

    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid

    try:
        l2 = net_ops.create_l2_novlan('l2_for_pm', 'eth0', zone_uuid, session_uuid=project_login_uuid)
        test_util.test_fail("Expect exception: project admin not allowed to create Novlan L2 except vxlan")
    except:
        pass

    try:
        l2 = net_ops.create_l2_vlan('l2_for_pm', 'eth0', zone_uuid, 1234, session_uuid=project_login_uuid)
        test_util.test_fail("Expect exception: project admin not allowed to create vlan L2 except vxlan")
    except:
        pass
    if flavor['target_role'] == 'project_member':
        statements = [{"effect": "Allow", "actions": ["org.zstack.network.l2.**"]}, {"effect": "Allow", "actions": ["org.zstack.header.network.l3.**"]}]
        role_uuid = iam2_ops.create_role('test_role', statements).uuid
        iam2_ops.add_roles_to_iam2_virtual_id([role_uuid], plain_user_uuid)

    vxlan_pool = res_ops.get_resource(res_ops.L2_VXLAN_NETWORK_POOL)
    if vxlan_pool == None or len(vxlan_pool) == 0:
        test_util.test_skip('Vxlan is required for testing')
    vxlan_pool_uuid = vxlan_pool[0].uuid
    if flavor['target_role'] != 'system_admin':
        acc_ops.share_resources([project_linked_account_uuid], [vxlan_pool_uuid])
    vxlan_pool_uuid = res_ops.get_resource(res_ops.L2_VXLAN_NETWORK_POOL, session_uuid=project_login_uuid)[0].uuid
    vxlan_l2_uuid = vxlan_ops.create_l2_vxlan_network('vxlan_for_pm', vxlan_pool_uuid, zone_uuid, session_uuid=project_login_uuid).uuid
    l3_uuid = net_ops.create_l3('l3_for_pm', vxlan_l2_uuid, session_uuid=project_login_uuid).uuid
    net_ops.delete_l3(l3_uuid, session_uuid=project_login_uuid)
    net_ops.delete_l2(vxlan_l2_uuid, session_uuid=project_login_uuid)

    # 11 delete
    acc_ops.logout(project_login_uuid)
    if virtual_id_uuid != None:
        iam2_ops.delete_iam2_virtual_id(virtual_id_uuid)
    if project_admin_uuid != None:
        iam2_ops.delete_iam2_virtual_id(project_admin_uuid)
    if project_operator_uuid != None:
        iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    if plain_user_uuid != None:
        iam2_ops.delete_iam2_virtual_id(plain_user_uuid)

    if flavor['target_role'] != 'system_admin':
        iam2_ops.delete_iam2_project(project_uuid)
        iam2_ops.expunge_iam2_project(project_uuid)

    test_util.test_pass('success test iam2 login in by project admin!')
def test():
    global project_uuid, project_admin_uuid, virtual_id_uuid, project_operator_uuid, plain_user_uuid

    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    # 1 create project
    project_name = 'test_project'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    project_linked_account_uuid = project.linkedAccountUuid

    if flavor['target_role'] == 'project_admin':
        # 2 create virtual id
        project_admin_name = 'username'
        project_admin_password = '******'
        project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, project_admin_password).uuid
        virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid
    
        # 3 create project admin
        iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],project_uuid)
        attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}]
        iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes)

        # login in project by project admin
        project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name, project_admin_password)
        project_login_uuid = iam2_ops.login_iam2_project(project_name, session_uuid=project_admin_session_uuid).uuid
        # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes)
    elif flavor['target_role'] == 'project_operator':
        project_operator_name = 'username2'
        project_operator_password = '******'
        attributes = [{"name": "__ProjectOperator__", "value": project_uuid}]
        project_operator_uuid = iam2_ops.create_iam2_virtual_id(project_operator_name,project_operator_password,attributes=attributes).uuid
        virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernamethree','password').uuid

        # login in project by project operator
        iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],project_uuid)
        project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(project_operator_name,project_operator_password)
        project_login_uuid = iam2_ops.login_iam2_project(project_name,session_uuid=project_operator_session_uuid).uuid
    elif flavor['target_role'] == 'project_member':
	plain_user_name = 'username'
	plain_user_password = '******'
	plain_user_uuid = iam2_ops.create_iam2_virtual_id(plain_user_name, plain_user_password,
	                                                  project_uuid=project_uuid).uuid
	# 3 add virtual id to project
	iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid],project_uuid)

	# 4 login in project by plain user
	plain_user_session_uuid = iam2_ops.login_iam2_virtual_id(plain_user_name, plain_user_password)

	# 4 login in project
	#project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid)
	project_login_uuid = iam2_ops.login_iam2_project(project_name, plain_user_session_uuid).uuid

    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid

    try:
        l2 = net_ops.create_l2_novlan('l2_for_pm', 'eth0', zone_uuid, session_uuid=project_login_uuid)
        test_util.test_fail("Expect exception: project admin not allowed to create Novlan L2 except vxlan")
    except:
        pass

    try:
        l2 = net_ops.create_l2_vlan('l2_for_pm', 'eth0', zone_uuid, 1234, session_uuid=project_login_uuid)
        test_util.test_fail("Expect exception: project admin not allowed to create vlan L2 except vxlan")
    except:
        pass
    if flavor['target_role'] == 'project_member':
        statements = [{"effect": "Allow", "actions": ["org.zstack.network.l2.**"]}, {"effect": "Allow", "actions": ["org.zstack.header.network.l3.**"]}]
        role_uuid = iam2_ops.create_role('test_role', statements).uuid
        iam2_ops.add_roles_to_iam2_virtual_id([role_uuid], plain_user_uuid)

    vxlan_pool = res_ops.get_resource(res_ops.L2_VXLAN_NETWORK_POOL)
    if vxlan_pool == None or len(vxlan_pool) == 0:
        test_util.test_skip('Vxlan is required for testing')
    vxlan_pool_uuid = vxlan_pool[0].uuid
    acc_ops.share_resources([project_linked_account_uuid], [vxlan_pool_uuid])
    vxlan_pool_uuid = res_ops.get_resource(res_ops.L2_VXLAN_NETWORK_POOL, session_uuid=project_login_uuid)[0].uuid
    vxlan_l2_uuid = vxlan_ops.create_l2_vxlan_network('vxlan_for_pm', vxlan_pool_uuid, zone_uuid, session_uuid=project_login_uuid).uuid
    l3_uuid = net_ops.create_l3('l3_for_pm', vxlan_l2_uuid, session_uuid=project_login_uuid).uuid
    net_ops.delete_l3(l3_uuid, session_uuid=project_login_uuid)
    net_ops.delete_l2(vxlan_l2_uuid, session_uuid=project_login_uuid)

    # 11 delete
    acc_ops.logout(project_login_uuid)
    if virtual_id_uuid != None:
        iam2_ops.delete_iam2_virtual_id(virtual_id_uuid)
    if project_admin_uuid != None:
        iam2_ops.delete_iam2_virtual_id(project_admin_uuid)
    if project_operator_uuid != None:
        iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    if plain_user_uuid != None:
        iam2_ops.delete_iam2_virtual_id(plain_user_uuid)

    iam2_ops.delete_iam2_project(project_uuid)
    iam2_ops.expunge_iam2_project(project_uuid)

    test_util.test_pass('success test iam2 login in by project admin!')
def error_cleanup():
    global l3, l2
    if l2:
        net_ops.delete_l2(l2.inventory.uuid)
    if l3:
        net_ops.delete_l3(l3.uuid)