def test():
    global vm
    global schd_job1
    global schd_job2
    global schd_trigger1
    global schd_trigger2
    global new_account

    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    start_date = int(time.time())
    schd_job1 = schd_ops.create_scheduler_job('simple_stop_vm_scheduler', 'simple_stop_vm_scheduler', vm.get_vm().uuid, 'stopVm', None)
    schd_trigger1 = schd_ops.create_scheduler_trigger('simple_stop_vm_scheduler', start_date+30, None, 60, 'simple')
    schd_ops.add_scheduler_job_to_trigger(schd_trigger1.uuid, schd_job1.uuid)
    #schd1 = vm_ops.stop_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_stop_vm_scheduler', start_date+30, 60)

    schd_job2 = schd_ops.create_scheduler_job('simple_start_vm_scheduler', 'simple_start_vm_scheduler', vm.get_vm().uuid, 'startVm', None)
    schd_trigger2 = schd_ops.create_scheduler_trigger('simple_start_vm_scheduler', start_date+60, None, 60, 'simple')
    schd_ops.add_scheduler_job_to_trigger(schd_trigger2.uuid, schd_job2.uuid)
    #schd2 = vm_ops.start_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_start_vm_scheduler', start_date+60, 60)

    test_stub.sleep_util(start_date+130)

    test_util.test_dsc('check scheduler state after creating scheduler')
    check_scheduler_state(schd_job1, 'Enabled')
    check_scheduler_state(schd_job2, 'Enabled')
    if not check_scheduler_msg('run scheduler for job: StopVmInstanceJob', start_date+30):
        test_util.test_fail('StopVmInstanceJob not executed at expected timestamp range')
    if not check_scheduler_msg('run scheduler for job: StartVmInstanceJob', start_date+60):
        test_util.test_fail('StartVmInstanceJob not executed at expected timestamp range')
    
#    vm.check();
    new_account = account_operations.create_account('new_account', 'password', 'Normal')

    res_ops.change_recource_owner(new_account.uuid, vm.vm.uuid)

    current_time = int(time.time())
    except_start_time =  start_date + 60 * (((current_time - start_date) % 60) + 1)
    test_stub.sleep_util(except_start_time + 130)
 
    test_util.test_dsc('check scheduler state after changing the owner of vm')
    check_scheduler_state(schd_job1, 'Disabled')
    check_scheduler_state(schd_job2, 'Disabled')
    if check_scheduler_msg('run scheduler for job: StopVmInstanceJob', except_start_time+30):
        test_util.test_fail('StopVmInstanceJob executed at unexpected timestamp range')
    if check_scheduler_msg('run scheduler for job: StartVmInstanceJob', except_start_time+60):
        test_util.test_fail('StartVmInstanceJob executed at unexpected timestamp range')

    schd_ops.del_scheduler_job(schd_job1.uuid)
    schd_ops.del_scheduler_trigger(schd_trigger1.uuid)
    schd_ops.del_scheduler_job(schd_job2.uuid)
    schd_ops.del_scheduler_trigger(schd_trigger2.uuid)
    vm.destroy()
    account_operations.delete_account(new_account.uuid)

    test_util.test_pass('Check Scheduler State after Changing VM Owner Success')
def test():
    global vm
    global schd1
    global schd2
    global new_account

    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    start_date = int(time.time())
    schd1 = vm_ops.stop_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_stop_vm_scheduler', start_date+30, 60)
    schd2 = vm_ops.start_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_start_vm_scheduler', start_date+60, 60)

    test_stub.sleep_util(start_date+130)

    test_util.test_dsc('check scheduler state after creating scheduler')
    check_scheduler_state(schd1, 'Enabled')
    check_scheduler_state(schd2, 'Enabled')
    if not check_scheduler_msg('run scheduler for job: StopVmInstanceJob', start_date+30):
        test_util.test_fail('StopVmInstanceJob not executed at expected timestamp range')
    if not check_scheduler_msg('run scheduler for job: StartVmInstanceJob', start_date+60):
        test_util.test_fail('StartVmInstanceJob not executed at expected timestamp range')
    
#    vm.check();
    new_account = account_operations.create_account('new_account', 'password', 'Normal')

    res_ops.change_recource_owner(new_account.uuid, vm.vm.uuid)

    current_time = int(time.time())
    except_start_time =  start_date + 60 * (((current_time - start_date) % 60) + 1)
    test_stub.sleep_util(except_start_time + 130)
 
    test_util.test_dsc('check scheduler state after changing the owner of vm')
    check_scheduler_state(schd1, 'Disabled')
    check_scheduler_state(schd2, 'Disabled')
    if check_scheduler_msg('run scheduler for job: StopVmInstanceJob', except_start_time+30):
        test_util.test_fail('StopVmInstanceJob executed at unexpected timestamp range')
    if check_scheduler_msg('run scheduler for job: StartVmInstanceJob', except_start_time+60):
        test_util.test_fail('StartVmInstanceJob executed at unexpected timestamp range')

    schd_ops.delete_scheduler(schd1.uuid)
    schd_ops.delete_scheduler(schd2.uuid)
    vm.destroy()
    account_operations.delete_account(new_account.uuid)

    test_util.test_pass('Check Scheduler State after Changing VM Owner Success')
def common_operations(vm,bss,status):

   vm_uuid = vm.get_vm().uuid 
   #image operations
   vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
   root_volume_uuid = vm_root_volume_inv.uuid
   image_option = test_util.ImageOption()
   image_option.set_root_volume_uuid(root_volume_uuid)
   image_option.set_name('image_base_on_%s_vm' % status)
   image_option.set_backup_storage_uuid_list([bss[0].uuid])
   image = img_ops.create_root_volume_template(image_option)
   test_util.test_logger('create image success')
   image_base_on_stopped_vm_uuid = test_lib.lib_get_image_by_name("image_base_on_%s_vm" % status).uuid
   base_on_image_vm = test_stub.create_vm(image_uuid=image_base_on_stopped_vm_uuid)
   vm_ops.destroy_vm(base_on_image_vm.get_vm().uuid)
   vm_ops.expunge_vm(base_on_image_vm.get_vm().uuid)

   #volume operations
   volume = test_stub.create_volume()
   vol_uuid = volume.get_volume().uuid
   test_lib.lib_attach_volume(vol_uuid, vm_uuid)
   test_util.test_logger('attach volume success')
   vm_ops.set_vm_disk_qos(vol_uuid,'20480')
   test_util.test_logger('set volume qos success')
   vm_ops.del_vm_disk_qos(vol_uuid)
   test_util.test_logger('delete volume qos success')
   test_lib.lib_detach_volume(vol_uuid)
   test_util.test_logger('detach volume success')
   test_lib.lib_delete_volume(vol_uuid)
   test_util.test_logger('delete volume success')

   #network operations
   nic_uuid = vm.get_vm().vmNics[0].uuid
   l3_uuid = test_lib.lib_get_random_l3(zone_uuid = vm.get_vm().zoneUuid).uuid
   test_util.test_logger("l3_uuid:%s"% l3_uuid)
   net_ops.detach_l3(nic_uuid)
   test_util.test_logger("l3_uuid:%s"% l3_uuid)
   net_ops.attach_l3(l3_uuid,vm_uuid)

   vm_uuid = vm.get_vm().uuid
   #set/del console password
   console_ops.set_vm_console_password(vm_uuid,'testpassword')
   console_ops.delete_vm_console_password(vm_uuid)

   #add/del sshkey
   sshkeyimage_uuid = test_lib.lib_get_image_by_name('sshkeyimage').uuid
   sshkey_vm = test_stub.create_vm(image_uuid = sshkeyimage_uuid)
   sshkey_vm_uuid = sshkey_vm.get_vm().uuid
   test_lib.lib_add_vm_sshkey(sshkey_vm_uuid,'testsshkey')
   vm_ops.delete_vm_ssh_key(sshkey_vm_uuid)
   vm_ops.destroy_vm(sshkey_vm_uuid)
   vm_ops.expunge_vm(sshkey_vm_uuid)

   #change owner
   account_name = uuid.uuid1().get_hex()
   account_pass = uuid.uuid1().get_hex()
   #account_pass = hashlib.sha512(account_name).hexdigest()
   test_account = account_operations.create_normal_account(account_name,account_pass)
   test_account_uuid = test_account.uuid
   admin_uuid = res_ops.get_resource_owner([vm_uuid])
   res_ops.change_recource_owner(test_account_uuid,vm_uuid)
   res_ops.change_recource_owner(admin_uuid,vm_uuid)
   account_operations.delete_account(test_account_uuid)

   #create/delete user tag
   tag = tag_ops.create_user_tag('VmInstanceVO',vm_uuid,'a simulator vm')
   tag_ops.delete_tag(tag.uuid)
      
   #set vm monitor number
   vm_ops.set_vm_monitor_number(vm_uuid,'2')

   #set vm usb redirect
   vm_ops.set_vm_usb_redirect(vm_uuid,'true')
   vm_ops.set_vm_usb_redirect(vm_uuid,'false')

   #set vm rdp
   vm_ops.set_vm_rdp(vm_uuid,'true')
   vm_ops.set_vm_rdp(vm_uuid,'false')
def common_operations(vm, bss, status):

    vm_uuid = vm.get_vm().uuid
    #image operations
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    root_volume_uuid = vm_root_volume_inv.uuid
    image_option = test_util.ImageOption()
    image_option.set_root_volume_uuid(root_volume_uuid)
    image_option.set_name('image_base_on_%s_vm' % status)
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    image = img_ops.create_root_volume_template(image_option)
    test_util.test_logger('create image success')
    image_base_on_stopped_vm_uuid = test_lib.lib_get_image_by_name(
        "image_base_on_%s_vm" % status).uuid
    base_on_image_vm = test_stub.create_vm(
        image_uuid=image_base_on_stopped_vm_uuid)
    vm_ops.destroy_vm(base_on_image_vm.get_vm().uuid)
    vm_ops.expunge_vm(base_on_image_vm.get_vm().uuid)

    #volume operations
    volume = test_stub.create_volume()
    vol_uuid = volume.get_volume().uuid
    test_lib.lib_attach_volume(vol_uuid, vm_uuid)
    test_util.test_logger('attach volume success')
    vm_ops.set_vm_disk_qos(vol_uuid, '20480')
    test_util.test_logger('set volume qos success')
    vm_ops.del_vm_disk_qos(vol_uuid)
    test_util.test_logger('delete volume qos success')
    test_lib.lib_detach_volume(vol_uuid)
    test_util.test_logger('detach volume success')
    test_lib.lib_delete_volume(vol_uuid)
    test_util.test_logger('delete volume success')

    #network operations
    nic_uuid = vm.get_vm().vmNics[0].uuid
    l3_uuid = test_lib.lib_get_random_l3(zone_uuid=vm.get_vm().zoneUuid).uuid
    test_util.test_logger("l3_uuid:%s" % l3_uuid)
    net_ops.detach_l3(nic_uuid)
    test_util.test_logger("l3_uuid:%s" % l3_uuid)
    net_ops.attach_l3(l3_uuid, vm_uuid)

    vm_uuid = vm.get_vm().uuid
    #set/del console password
    console_ops.set_vm_console_password(vm_uuid, 'testpassword')
    console_ops.delete_vm_console_password(vm_uuid)

    #add/del sshkey
    sshkeyimage_uuid = test_lib.lib_get_image_by_name('sshkeyimage').uuid
    sshkey_vm = test_stub.create_vm(image_uuid=sshkeyimage_uuid)
    sshkey_vm_uuid = sshkey_vm.get_vm().uuid
    test_lib.lib_add_vm_sshkey(sshkey_vm_uuid, 'testsshkey')
    vm_ops.delete_vm_ssh_key(sshkey_vm_uuid)
    vm_ops.destroy_vm(sshkey_vm_uuid)
    vm_ops.expunge_vm(sshkey_vm_uuid)

    #change owner
    account_name = uuid.uuid1().get_hex()
    account_pass = uuid.uuid1().get_hex()
    #account_pass = hashlib.sha512(account_name).hexdigest()
    test_account = account_operations.create_normal_account(
        account_name, account_pass)
    test_account_uuid = test_account.uuid
    admin_uuid = res_ops.get_resource_owner([vm_uuid])
    res_ops.change_recource_owner(test_account_uuid, vm_uuid)
    res_ops.change_recource_owner(admin_uuid, vm_uuid)
    account_operations.delete_account(test_account_uuid)

    #create/delete user tag
    tag = tag_ops.create_user_tag('VmInstanceVO', vm_uuid, 'a simulator vm')
    tag_ops.delete_tag(tag.uuid)

    #set vm monitor number
    vm_ops.set_vm_monitor_number(vm_uuid, '2')

    #set vm usb redirect
    vm_ops.set_vm_usb_redirect(vm_uuid, 'true')
    vm_ops.set_vm_usb_redirect(vm_uuid, 'false')

    #set vm rdp
    vm_ops.set_vm_rdp(vm_uuid, 'true')
    vm_ops.set_vm_rdp(vm_uuid, 'false')
Exemplo n.º 5
0
 def operate_vm_parall(self, vm_uuid):
     try:
         res_ops.change_recource_owner(new_account.uuid,vm_uuid)
     except:
         self.exc_info.append(sys.exc_info())
Exemplo n.º 6
0
def test():
    global vm
    global schd_job
    global schd_trigger
    global new_account

    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_name('volume for snapshot scheduler testing')
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)

    volume.attach(vm)
    volume.detach()

    test_util.test_dsc('create snapshot scheduler')
    start_date = int(time.time())
    #sp_option = test_util.SnapshotOption()
    #sp_option.set_name('simple_schduler_snapshot')
    #sp_option.set_volume_uuid(volume.get_volume().uuid)
    schd_job = schd_ops.create_scheduler_job(
        'simple_create_snapshot_scheduler', 'simple_create_snapshot_scheduler',
        volume.get_volume().uuid, 'volumeSnapshot', None)
    schd_trigger = schd_ops.create_scheduler_trigger(
        'simple_create_snapshot_scheduler', start_date + 60, None, 120,
        'simple')
    schd_ops.add_scheduler_job_to_trigger(schd_trigger.uuid, schd_job.uuid)

    #schd = vol_ops.create_snapshot_scheduler(sp_option, 'simple', 'simple_create_snapshot_scheduler',  start_date+60, 120)

    check_scheduler_state(schd_job, 'Enabled')

    snapshot_num = 0
    for i in range(0, 3):
        test_util.test_logger('round %s' % (i))
        test_stub.sleep_util(start_date + 60 + 120 * i - 2)
        test_util.test_logger(
            'check volume snapshot number at %s, there should be %s' %
            (start_date + 60 + 120 * i - 2, snapshot_num))
        new_snapshot_num = query_snapshot_number(volume.get_volume().uuid)
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' %
                                (snapshot_num))
        snapshot_num += 1

        test_stub.sleep_util(start_date + 60 + 120 * i + 65)
        test_util.test_logger(
            'check volume snapshot number at %s, there should be %s' %
            (start_date + 60 + 120 * i + 65, snapshot_num + 1))
        new_snapshot_num = query_snapshot_number(volume.get_volume().uuid)
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' %
                                (snapshot_num))

    new_account = account_operations.create_account('new_account', 'password',
                                                    'Normal')

    res_ops.change_recource_owner(new_account.uuid, volume.get_volume().uuid)

    test_util.test_dsc(
        'check scheduler state after changing the owner of volume')
    check_scheduler_state(schd_job, 'Disabled')

    current_time = int(time.time())
    except_start_time = start_date + 120 * ((
        (current_time - start_date) % 120) + 1)

    for i in range(0, 3):
        test_util.test_logger('round %s' % (i))
        test_stub.sleep_util(except_start_time + 60 + 120 * i - 2)
        test_util.test_logger(
            'check volume snapshot number at %s, there should be %s' %
            (except_start_time + 60 + 120 * i - 2, snapshot_num))
        new_snapshot_num = query_snapshot_number(volume.get_volume().uuid)
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' %
                                (snapshot_num))

        test_stub.sleep_util(except_start_time + 60 + 120 * i + 60)
        test_util.test_logger(
            'check volume snapshot number at %s, there should be %s' %
            (except_start_time + 60 + 120 * i + 65, snapshot_num + 1))
        new_snapshot_num = query_snapshot_number(volume.get_volume().uuid)
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' %
                                (snapshot_num))

    schd_ops.del_scheduler_job(schd_job.uuid)
    schd_ops.del_scheduler_trigger(schd_trigger.uuid)
    vm.destroy()
    account_operations.delete_account(new_account.uuid)

    test_util.test_pass(
        'Check Scheduler State after Changing Volume Owner Success')
def test():
    global vm
    global schd
    global new_account

    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_name('volume for snapshot scheduler testing')
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)

    volume.attach(vm)
    volume.detach()

    test_util.test_dsc('create snapshot scheduler')
    start_date = int(time.time())
    sp_option = test_util.SnapshotOption()
    sp_option.set_name('simple_schduler_snapshot')
    sp_option.set_volume_uuid(volume.get_volume().uuid)

    schd = vol_ops.create_snapshot_scheduler(sp_option, 'simple', 'simple_create_snapshot_scheduler',  start_date+60, 120)

    check_scheduler_state(schd, 'Enabled')

    snapshot_num = 0
    for i in range(0, 3):
        test_util.test_logger('round %s' % (i))
        test_stub.sleep_util(start_date + 60 + 120*i - 2)
        test_util.test_logger('check volume snapshot number at %s, there should be %s' % (start_date + 60 + 120*i - 2, snapshot_num))
        new_snapshot_num = query_snapshot_number('simple_schduler_snapshot')
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num))
        snapshot_num += 1

        test_stub.sleep_util(start_date + 60 + 120*i + 60)
        test_util.test_logger('check volume snapshot number at %s, there should be %s' % (start_date + 60 + 120*i + 65, snapshot_num+1))
        new_snapshot_num = query_snapshot_number('simple_schduler_snapshot')
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num))

    new_account = account_operations.create_account('new_account', 'password', 'Normal')

    res_ops.change_recource_owner(new_account.uuid, volume.get_volume().uuid)

    test_util.test_dsc('check scheduler state after changing the owner of volume')
    check_scheduler_state(schd, 'Disabled')

    current_time = int(time.time())
    except_start_time =  start_date + 120 * (((current_time - start_date) % 120) + 1)

    for i in range(0, 3):
        test_util.test_logger('round %s' % (i))
        test_stub.sleep_util(except_start_time + 60 + 120*i - 2)
        test_util.test_logger('check volume snapshot number at %s, there should be %s' % (except_start_time + 60 + 120*i - 2, snapshot_num))
        new_snapshot_num = query_snapshot_number('simple_schduler_snapshot')
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num))

        test_stub.sleep_util(except_start_time + 60 + 120*i + 60)
        test_util.test_logger('check volume snapshot number at %s, there should be %s' % (except_start_time + 60 + 120*i + 65, snapshot_num+1))
        new_snapshot_num = query_snapshot_number('simple_schduler_snapshot')
        if snapshot_num != new_snapshot_num:
            test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num))

    schd_ops.delete_scheduler(schd.uuid)
    vm.destroy()
    account_operations.delete_account(new_account.uuid)

    test_util.test_pass('Check Scheduler State after Changing Volume Owner Success')
def test():
    test_util.test_dsc('Create test vm with EIP and check.')
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm)
    vm.check()

    l3_name = os.environ.get('l3VlanNetworkName1')
    vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid)
    temp_vm1 = None
    if not vrs:
        #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding
        temp_vm1 = test_stub.create_vlan_vm()
        test_obj_dict.add_vm(temp_vm1)
        vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0]
    else:
        vr1 = vrs[0]

    l3_name = os.environ.get('l3NoVlanNetworkName1')
    vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid)
    temp_vm2 = None
    if not vrs:
        #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding
        temp_vm2 = test_stub.create_user_vlan_vm()
        test_obj_dict.add_vm(temp_vm2)
        vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0]
    else:
        vr2 = vrs[0]

    #we do not need temp_vm1 and temp_vm2, since we just use their VRs.
    if temp_vm1:
        temp_vm1.destroy()
        test_obj_dict.rm_vm(temp_vm1)
    if temp_vm2:
        temp_vm2.destroy()
        test_obj_dict.rm_vm(temp_vm2)

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    pri_l3_uuid = vm_nic.l3NetworkUuid
    vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0]
    vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr)
    l3_uuid = vr_pub_nic.l3NetworkUuid
    vip = test_stub.create_vip('create_eip_test', l3_uuid)
    test_obj_dict.add_vip(vip)

    eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid)
    vip.attach_eip(eip)
    vip.check()

    test_account = account_operations.create_account('account-%s' % time.strftime('%m%d-%H%M%S', time.localtime()), 'password', 'Normal')
    res_ops.change_recource_owner(test_account.uuid, eip.eip.uuid)
    account_operations.delete_account(test_account.uuid)

    eip.attach(vm_nic_uuid, vm)
    vip.check()
    eip.detach()
    vip.check()

    vm.destroy()
    test_obj_dict.rm_vm(vm)
    eip.delete()
    vip.delete()
    test_obj_dict.rm_vip(vip)
    test_util.test_pass('Change EIP Owner Success')
def test():
    global vm, session_uuid
    global test_account_uuid, test_account_session
    
    test_util.test_dsc('Test normal account change the qos network and volume ')

    #create normal account
    test_util.test_dsc('create normal account')
    account_name = 'a'
    account_pass = hashlib.sha512(account_name).hexdigest()
    test_account = acc_ops.create_normal_account(account_name, account_pass)
    test_account_uuid = test_account.uuid
    test_account_session = acc_ops.login_by_account(account_name, account_pass)

    #create L3 flat network
    test_util.test_dsc('create L2_vlan network  names is L2_vlan')
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    cluster_uuid = res_ops.query_resource(res_ops.CLUSTER)[0].uuid
    
    l2_inv = sce_ops.create_l2_vlan(zstack_management_ip, 'L2_vlan', 'eth0', '2205', zone_uuid)
    l2_uuid = l2_inv.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(zstack_management_ip, l2_uuid, cluster_uuid)

    test_util.test_dsc('create L3_flat_network names is L3_flat_network')
    l3_inv = sce_ops.create_l3(zstack_management_ip, 'l3_flat_network', 'L3BasicNetwork', l2_uuid, 'local.com')
    l3_uuid = l3_inv.inventory.uuid

    l3_dns = '223.5.5.5'
    start_ip = '192.168.109.2'
    end_ip = '192.168.109.10'
    gateway = '192.168.109.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(zstack_management_ip, l3_uuid, l3_dns)
    sce_ops.add_ip_range(zstack_management_ip,'IP_range', l3_uuid, start_ip, end_ip, gateway, netmask)

    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(zstack_management_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(zstack_management_ip, l3_uuid, pro_uuid)
    
    l2_inv2 = sce_ops.create_l2_vlan(zstack_management_ip, 'L2_vlan_2206', 'eth0', '2206', zone_uuid)
    l2_uuid2 = l2_inv2.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(zstack_management_ip, l2_uuid2, cluster_uuid)

    test_util.test_dsc('create L3_flat_network names is L3_flat_network')
    l3_inv2 = sce_ops.create_l3(zstack_management_ip, 'l3_flat_2', 'L3BasicNetwork', l2_uuid2, 'local.com')
    l3_uuid2 = l3_inv2.inventory.uuid

    l3_dns2 = '223.5.5.5'
    start_ip2 = '192.168.110.2'
    end_ip2 = '192.168.110.10'
    gateway2 = '192.168.110.1'
    netmask2 = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(zstack_management_ip, l3_uuid2, l3_dns2)
    sce_ops.add_ip_range(zstack_management_ip,'IP_range2', l3_uuid2, start_ip2, end_ip2, gateway2, netmask2)

    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(zstack_management_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(zstack_management_ip, l3_uuid2, pro_uuid)
    
    #share admin resoure to normal account
    test_util.test_dsc('share admin resoure to normal account')
    cond = res_ops.gen_query_conditions('name', '=', 'l3_flat_network')
    flat_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid
    acc_ops.share_resources([test_account_uuid], [flat_uuid])

    instance_offerings = res_ops.get_resource(res_ops.INSTANCE_OFFERING)
    for instance_offering in instance_offerings:
        acc_ops.share_resources([test_account_uuid], [instance_offering.uuid])

    #acc_ops.share_resources([test_account_uuid], [instance_offering_uuid])
    cond = res_ops.gen_query_conditions('mediaType', '!=', 'ISO')
    images = res_ops.query_resource(res_ops.IMAGE, cond)
    for image in images:
        acc_ops.share_resources([test_account_uuid], [image.uuid])

    #create vm
    test_util.test_dsc('create vm by normal account a')
    vm = test_stub.create_vm(session_uuid = test_account_session)
    vm_inv = vm.get_vm()
    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid

    vip = test_stub.create_vip('vip', l3_uuid2)
    res_ops.change_recource_owner(test_account_uuid, vip.vip.uuid)
    eip = test_stub.create_eip('eip_a', vip_uuid=vip.vip.uuid, session_uuid = test_account_session)

    net_ops.attach_eip(eip.eip.uuid, vm_nic_uuid, session_uuid = test_account_session)
    net_ops.detach_eip(eip.eip.uuid, session_uuid = test_account_session)
    net_ops.delete_eip(eip.eip.uuid, session_uuid = test_account_session)
    
    vip.delete()
    vm.check()
    vm.destroy(test_account_session)
    net_ops.delete_l2(l2_uuid)
    net_ops.delete_l2(l2_uuid2)
    vm.check()
    acc_ops.delete_account(test_account_uuid)    
    test_util.test_pass('normal account create eip by admin shared vip Test Success')