• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python vm_operations.start_vm函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中zstackwoodpecker.operations.vm_operations.start_vm函数的典型用法代码示例。如果您正苦于以下问题:Python start_vm函数的具体用法?Python start_vm怎么用?Python start_vm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了start_vm函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test

def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid
    test_util.test_dsc('Create test vm and check')
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
    #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    #vr_uuid = vr.uuid
    
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    ps_uuid = ps.uuid
    ps_ops.change_primary_storage_state(ps_uuid, 'maintain')
    if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail('VM is expected to stop when PS change to maintain state')

    vm.set_state(vm_header.STOPPED)
    vm.check()
    ps_ops.change_primary_storage_state(ps_uuid, 'enable')
    host_ops.reconnect_host(host_uuid)
    #vm_ops.reconnect_vr(vr_uuid)
    vrs = test_lib.lib_get_all_vrs()
    for vr in vrs:
        vm_ops.start_vm(vr.uuid)  

    vm.start()
    vm.check()
    vm.destroy()
    test_util.test_pass('PS maintain mode Test Success')
开发者ID:mrwangxc,项目名称:zstack-woodpecker,代码行数:35,代码来源:test_maintain_ps.py


示例2: test

def test():
   test_util.test_dsc('Test Change VM Image In Multihosts Env')
   global vm
   image = test_lib.lib_get_image_by_name("centos")
   vm = test_stub.create_vm(image_uuid=image.uuid)
   last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   last_host_uuid = test_lib.lib_get_vm_last_host(vm.get_vm()).uuid
   image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
   vm_uuid = vm.get_vm().uuid
   host_ops.change_host_state(host_uuid = last_host_uuid, state = 'disable')
   vm_ops.stop_vm(vm_uuid)
   ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
   #Disable vm's host.If ps is shared storage,the vm will be started on another host that meets the conditions and the operation of changing vm image will success.
   if ps.type != 'LocalStorage':
      vm_ops.change_vm_image(vm_uuid,image_uuid)
      vm_ops.start_vm(vm_uuid)
      #check whether the network config has changed
      l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
      if l3network_uuid_after != last_l3network_uuid:
         test_util.test_fail('Change VM Image Failed.The Network config has changed.')
      #check whether primarystorage has changed
      primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
      if primarystorage_uuid_after != last_primarystorage_uuid:
         test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')
      vm.destroy()
      test_util.test_pass('Change Vm Image Test Success In Multihosts Env Success')
   #Disable vm's host.If ps is local storage,the operation of changing vm image will fail.  
   else:
      try:
         vm_ops.change_vm_image(vm_uuid, image_uuid)
      except:
         test_util.test_pass('Change Vm Image Test Success In Multihosts Env Success')
   test_util.test_fail('Test Change VM Image In Multihosts Env Success Failed')
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:34,代码来源:test_change_vm_image_in_multihosts_env.py


示例3: test

def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid
    test_util.test_dsc('Create test vm and check')
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
    #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    #vr_uuid = vr.uuid
    
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc('Add ISO Image')
    cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid
    img_option = test_util.ImageOption()
    img_option.set_name('iso')
    img_option.set_backup_storage_uuid_list([bs_uuid])
    os.system("echo fake iso for test only >  %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath')))
    img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip')))
    image_inv = img_ops.add_iso_template(img_option)
    image = test_image.ZstackTestImage()
    image.set_image(image_inv)
    image.set_creation_option(img_option)
    test_obj_dict.add_image(image)


    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    ps_uuid = ps.uuid
    ps_ops.change_primary_storage_state(ps_uuid, 'maintain')
    if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail('VM is expected to stop when PS change to maintain state')
    vm.set_state(vm_header.STOPPED)
    vm.check()

    test_util.test_dsc('Attach ISO to VM')
    cond = res_ops.gen_query_conditions('name', '=', 'iso')
    iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid
    img_ops.attach_iso(iso_uuid, vm.vm.uuid)


    ps_ops.change_primary_storage_state(ps_uuid, 'enable')
    host_ops.reconnect_host(host_uuid)
    #vm_ops.reconnect_vr(vr_uuid)
    vrs = test_lib.lib_get_all_vrs()
    for vr in vrs:
        vm_ops.start_vm(vr.uuid)  

    vm.start()
    vm.check()
    vm.destroy()
    vm.check()
    #vm.expunge()
    #vm.check()
    test_util.test_pass('PS maintain mode Test Success')
开发者ID:mrwangxc,项目名称:zstack-woodpecker,代码行数:60,代码来源:test_maintain_ps_attach_iso.py


示例4: test

def test():
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)

    #create VRs.
    vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)
    if not vrs:
        vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
        vm.destroy()
        vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    else:
        vr1 = vrs[0]

    vm_ops.stop_vm(vr1.uuid)
    if test_lib.lib_get_ha_enable() != 'true' or vr1.applianceVmType != "vrouter":
        vm_ops.start_vm(vr1.uuid)

    vr1_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr1)
    if not test_lib.lib_wait_target_up(vr1_mgmt_ip, '7272', 120):
        test_util.test_fail('vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr1.uuid)

    timeout = time.time() + 60
    while time.time() < timeout:
        cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid) 
        vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond)
        if vms[0].status == 'Connected':
            test_util.test_pass('Test Reconnect VR VM start VRs success')
        time.sleep(1)

    test_util.test_fail('VR VM: %s is not connected within 60 seconds' % vr1.uuid)
开发者ID:mrwangxc,项目名称:zstack-woodpecker,代码行数:32,代码来源:test_stop_start_vr.py


示例5: test

def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid
    test_util.test_dsc('Create test vm and check')
    test_lib.lib_set_delete_policy('vm', 'Delay')
    test_lib.lib_set_delete_policy('volume', 'Delay')
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
    #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    #vr_uuid = vr.uuid
    
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()

    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi'])
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume.delete()
    volume.check()

    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    ps_uuid = ps.uuid
    ps_ops.change_primary_storage_state(ps_uuid, 'maintain')
    if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail('VM is expected to stop when PS change to maintain state')

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

    ps_ops.change_primary_storage_state(ps_uuid, 'enable')
    host_ops.reconnect_host(host_uuid)
    #vm_ops.reconnect_vr(vr_uuid)
    vrs = test_lib.lib_get_all_vrs()
    for vr in vrs:
        vm_ops.start_vm(vr.uuid)  

    vm.start()
    vm.check()

    volume.delete()
    #volume.expunge()
    volume.check()

    vm.destroy()
    test_lib.lib_set_delete_policy('vm', 'Direct')
    test_lib.lib_set_delete_policy('volume', 'Direct')
    test_util.test_pass('Delete volume under PS maintain mode Test Success')
开发者ID:mrwangxc,项目名称:zstack-woodpecker,代码行数:58,代码来源:test_maintain_ps_recover_share_vol.py


示例6: env_recover

def env_recover():
    local_ps, shared_ps = test_stub.PSEnvChecker().get_two_ps()
    if local_ps.state in ('Disabled', "Maintenance"):
        ps_ops.change_primary_storage_state(local_ps.uuid, state='enable')
    if shared_ps.state in ('Disabled', "Maintenance"):
        ps_ops.change_primary_storage_state(shared_ps.uuid, state='enable')
    for vr in res_ops.get_resource(res_ops.APPLIANCE_VM):
        if vr.state != inventory.RUNNING:
            vm_ops.start_vm(vr.uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:10,代码来源:test_local_shared_ps_ops.py


示例7: check_resource

def check_resource():

    hosts = res_ops.query_resource(res_ops.HOST, [], None)
    for host in hosts:
        if host.status != "Connected":
            host_ops.reconnect_host(host.uuid) 
            return False

    pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [], None)
    for ps in pss:
        if ps.status != "Connected":
            ps_ops.reconnect_primary_storage(ps.uuid)
            return False

    bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, [], None)
    for bs in bss:
        if bs.status != "Connected":
            bs_ops.reconnect_backup_storage(bs.uuid)
            return False

    if os.environ.get('WOODPECKER_PARALLEL') != None and os.environ.get('WOODPECKER_PARALLEL') == '0':
        vms = res_ops.query_resource(res_ops.VM_INSTANCE, [], None)
        for vm in vms:
            if vm.type == 'UserVm':
                try:
                    vm_ops.destroy_vm(vm.uuid)
                except:
                    test_util.test_logger('ignore exception try to destroy vm')
                try:
                    vm_ops.expunge_vm(vm.uuid)
                except:
                    test_util.test_logger('ignore exception try to expunge vm')

    vrs = res_ops.query_resource(res_ops.APPLIANCE_VM, [], None)
    for vr in vrs:
        if vr.status != "Connected" or vr.state != "Running":
            if vr.applianceVmType != "vrouter":
		try:
                    vm_ops.stop_vm(vr.uuid, force='cold')
                    vm_ops.start_vm(vr.uuid)
                except:
                    test_util.test_logger('Exception when reboot vr vm')
            else:
                try:
                    vm_ops.stop_vm(vr.uuid, force='cold')
                except:
                    test_util.test_logger('Exception when reboot vr vm')
            return False

    return True
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:50,代码来源:case_setup.py


示例8: error_cleanup

def error_cleanup():
    global ps_uuid
    if ps_uuid != None:
        ps_ops.change_primary_storage_state(ps_uuid, 'enable')
    global host_uuid
    if host_uuid != None:
        host_ops.reconnect_host(host_uuid)
    vrs = test_lib.lib_get_all_vrs()
    for vr in vrs:
        vm_ops.start_vm(vr.uuid)  
    #global vr_uuid
    #if vr_uuid != None:
    #    vm_ops.reconnect_vr(vr_uuid)
    global test_obj_dict
    test_lib.lib_error_cleanup(test_obj_dict)
开发者ID:mrwangxc,项目名称:zstack-woodpecker,代码行数:15,代码来源:test_maintain_ps_attach_iso.py


示例9: test

def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid
    test_util.test_dsc('Create test vm and check')
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
    #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    #vr_uuid = vr.uuid
    
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()
    #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    #ps_uuid = ps.uuid
    #ps_ops.change_primary_storage_state(ps_uuid, 'maintain')
    test_stub.maintain_all_pss()
    if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail('VM is expected to stop when PS change to maintain state')

    vm.set_state(vm_header.STOPPED)
    vm.check()
    #ps_ops.change_primary_storage_state(ps_uuid, 'enable')
    test_stub.enable_all_pss()
    host_ops.reconnect_host(host_uuid)
    #vm_ops.reconnect_vr(vr_uuid)
    test_stub.ensure_pss_connected()
    vrs = test_lib.lib_get_all_vrs()
    for vr in vrs:
        vr_cond = res_ops.gen_query_conditions('uuid', '=', vr.uuid)
        vr_inv = res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0]
        if vr_inv.state == 'Stopped':
            vm_ops.start_vm(vr.uuid)
        else:
            test_lib.lib_wait_target_up(vr_inv.vmNics[0].ip, '22', 360)
            for _ in xrange(100):
                if res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0].state != 'Running':
                    time.sleep(3)
                else:
                    break

    vm.start()
    vm.check()
    vm.destroy()
    test_util.test_pass('PS maintain mode Test Success')
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:48,代码来源:test_maintain_ps.py


示例10: test

def test():
    global vcenter_uuid, vm_uuid

    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    #ova_image_name = os.environ['vcenter2_template_exist']
    vm_name = os.environ['vcenter2_no_nic_vm']
    network_pattern1 = os.environ['vcenter2_network_pattern1']

    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid = inv.uuid

    if vcenter_uuid == None:
        test_util.test_fail("vcenter_uuid is None")

    #vm = test_stub.create_vm_in_vcenter(vm_name = 'vm-start-stop-test', image_name = ova_image_name, l3_name = network_pattern1)
    vm_cond = res_ops.gen_query_conditions("name", '=', vm_name)
    vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0]
    vm_uuid = vm_inv.uuid
    vm_state = vm_inv.state.strip().lower()
    if not vm_uuid:
        test_util.test_fail("remote woodpecker vm uuid is null")
    elif vm_uuid and vm_state != "running":
        print "#%s#" % vm_state
        vm_ops.start_vm(vm_uuid)
        if not test_lib.lib_wait_target_up(vm_inv.vmNics[0].ip, '22', 90):
            test_util.test_fail('VM is expected to running')
        vm.stop()
        if not test_lib.lib_wait_target_down(vm_inv.vmNics[0].ip, '22', 90):
            test_util.test_fail('VM is expected to stopped')
    elif vm_uuid and vm_state == "running":
        print "#%s#" % vm_state
        vm.stop()
        if not test_lib.lib_wait_target_down(vm_inv.vmNics[0].ip, '22', 90):
            test_util.test_fail('VM is expected to stopped')
        vm_ops.start_vm(vm_uuid)
        if not test_lib.lib_wait_target_up(vm_inv.vmNics[0].ip, '22', 90):
            test_util.test_fail('VM is expected to running')

    vm_ops.destroy_vm(vm_uuid)
    vm_ops.expunge_vm(vm_uuid)

    vct_ops.delete_vcenter(vcenter_uuid)
    test_util.test_pass("vm start and stop of vcenter test passed.")
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:47,代码来源:test_vcenter_vm_no_nic_start_stop.py


示例11: test

def test():
   session_uuid = acc_ops.login_as_admin()
   acc_ops.logout(session_uuid)
   
   image_name = os.environ.get('imageName3')
   image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
   try:
       vm = test_stub.create_vm(image_uuid = image_uuid, session_uuid=session_uuid)
       test_util.test_fail('Expect exception after logout while there is none')
   except:
       pass

   vm = test_stub.create_vm(image_uuid = image_uuid)
   vm_ops.stop_vm(vm.get_vm().uuid)
   vm_ops.start_vm(vm.get_vm().uuid)
   try:
       vm_ops.stop_vm(vm.get_vm().uuid, session_uuid=session_uuid)
       test_util.test_fail('Expect exception after logout while there is none')
   except:
       pass
   vm.destroy()
   vm.expunge()
   test_util.test_pass('Test operations after session logout passed')
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:23,代码来源:test_session_logout.py


示例12: ensure_vr_is_running_connected

def ensure_vr_is_running_connected(l3_uuid):
    vr_list = test_lib.lib_find_vr_by_l3_uuid(l3_uuid)
    if not vr_list: return

    if vr_list[0].applianceVmType == "VirtualRouter":

        if vr_list[0].state == "Stopped":
            vm_ops.start_vm(vr_list[0].uuid)

    elif vr_list[0].applianceVmType == "vrouter":
        pass
    else:
        test_util.test_fail("current vr type not support in ensure_vr_is_connected.")

    cond = res_ops.gen_query_conditions('uuid', '=', vr_list[0].uuid)
    for i in range(600):
        time.sleep(1)
        vr1 = res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0]
        if vr1.state == "Running" and vr1.status == "Connected":
            test_util.test_logger("vr has successfully changed to Running and Connected")
            break
    else:
        test_util.test_fail("vr has not been successfully changed to Running and Connected within 300s: state=%s:status=%s" %(vr1.state, vr1.status))
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:23,代码来源:test_stub.py


示例13: test

def test():
    new_offering = test_lib.lib_create_instance_offering(cpuNum = 1,\
            memorySize = 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(new_offering)
    vm = test_stub.create_vm(vm_name = 'ckvmoffering-c7-64', image_name = "imageName_i_c7", instance_offering_uuid=new_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

    (available_cpu_before, available_memory_before, vm_outer_cpu_before, vm_outer_mem_before,
     vm_interal_cpu_before, vm_interal_mem_before) = test_stub.check_cpu_mem(vm, shutdown=True)

    vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(vm.get_vm().instanceOfferingUuid)
    MEMchange = 126*1024*1024
    AlignedMemChange = 128*1024*1024
    vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum + 1, vm_instance_offering.memorySize + MEMchange)
    vm.update()
    time.sleep(10)
    vm.check()

    vm_ops.stop_vm(vm.get_vm().uuid)
    test_stub.wait_for_certain_vm_state(vm, 'stopped')

    vm_ops.start_vm(vm.get_vm().uuid)
    test_stub.wait_for_certain_vm_state(vm, 'running')
    vm.check()

    (available_cpu_after, available_memory_after, vm_outer_cpu_after, vm_outer_mem_after,
     vm_interal_cpu_after, vm_internal_mem_after) = test_stub.check_cpu_mem(vm, shutdown=True)

    assert available_cpu_before == available_cpu_after + 1
    assert available_memory_after + AlignedMemChange / int(test_lib.lib_get_provision_memory_rate()) in range(available_memory_before-1, available_memory_before+1)
    assert vm_outer_cpu_before == vm_outer_cpu_after - 1
    assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange
    assert vm_interal_cpu_before == vm_interal_cpu_after - 1
    assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange/1024/1024
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:37,代码来源:test_hotplugin_cpu_memory_shutdown.py


示例14: test

def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout

    allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint']
    test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)

    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    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
    #l3_name = os.environ.get('l3NoVlanNetworkName1')
    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid)
    for vr in vrs:
	if test_lib.lib_is_vm_running(vr) != True:
	    vm_ops.start_vm(vr.uuid)
    time.sleep(60)

    mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    conditions = res_ops.gen_query_conditions('state', '=', 'Enabled')
    conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions)
    conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip, conditions)
    host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
    vm_creation_option.set_host_uuid(host_uuid)
    vm_creation_option.set_l3_uuids([l3_net_uuid])
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multihost_basic_vm')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()

    test_stub.ensure_host_has_no_vr(host_uuid)

    #vm.check()
    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure")
    l2_network_interface = os.environ.get('l2ManagementNetworkInterface')

    cmd = "ifconfig %s down && sleep 30 && ifconfig %s up" % (l2_network_interface, l2_network_interface)
    try:
	rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd)
	test_util.test_logger("host is not expected to shutdown after its network down just for a little while")
    except:
        test_util.test_fail("host may have been shutdown, while it's not expected to shutdown")

    cmd = "date"
    try:
	rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd)
        test_util.test_logger("host is still alive")
    except:
	test_util.test_fail("host is not expected to shutdown after its network down just for a little while")

    test_stub.exercise_connection(100, 10)

    vm.destroy()

    time.sleep(60)
    test_util.test_pass('Test Host Self fence Success')
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:69,代码来源:test_vm_ha_self_fence_no_shutdown.py


示例15: test

def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout
    global test_host

    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_s')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid)
    vr_host_ips = []
    for vr in vrs:
        vr_host_ips.append(test_lib.lib_find_host_by_vr(vr).managementIp)
	if test_lib.lib_is_vm_running(vr) != True:
	    vm_ops.start_vm(vr.uuid)
    time.sleep(60)

    mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    conditions = res_ops.gen_query_conditions('state', '=', 'Enabled')
    conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions)
    conditions = res_ops.gen_query_conditions('managementIp', '=', mn_ip, conditions)
    #for vr_host_ip in vr_host_ips:
    #    conditions = res_ops.gen_query_conditions('managementIp', '!=', vr_host_ip, conditions)
    host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
    vm_creation_option.set_host_uuid(host_uuid)
    vm_creation_option.set_l3_uuids([l3_net_uuid])
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multihost_basic_vm')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()

    if not test_lib.lib_check_vm_live_migration_cap(vm.vm):
        test_util.test_skip('skip ha if live migrate not supported')

    ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid)
    if ps.type == inventory.LOCAL_STORAGE_TYPE:
        test_util.test_skip('Skip test on localstorage')

    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    test_util.test_logger("host %s is disconnecting" %(host_ip))

    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")

    host_list = test_stub.get_sce_hosts(test_lib.all_scenario_config, test_lib.scenario_file)
    for host in host_list:
        if host.ip_ == host_ip:
            test_host = host
            break
    if not test_host:
        test_util.test_fail('there is no host with ip %s in scenario file.' %(host_ip))

    test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold')

    test_util.test_logger("wait for 30 seconds to ensure vm disconnected, then just wait 90s for target up.")
    time.sleep(30)

    if test_lib.lib_wait_target_up(vm.vm.vmNics[0].ip, '22', 90):
        test_util.test_logger("%s can be connected within 120s" %(vm.vm.vmNics[0].ip))  

    test_stub.start_host(test_host, test_lib.all_scenario_config)

    vm.destroy()

    test_util.test_pass('Test VM ha change to running within 120s Success')
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:75,代码来源:test_mn_ha_vm_ha_force_stop_host_vm_running_lt_2min.py


示例16: test

def test():
    global vcenter_uuid1
    global vcenter_uuid2
    global mevoco1_ip
    global mevoco2_ip


    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    vm_name = os.environ['vcenter2_sync_vm_start_stop']



    mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP']
    mevoco2_ip = os.environ['serverIp2']    


    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid1 = inv.uuid
    if vcenter_uuid1 == None:
        test_util.test_fail("vcenter_uuid is None")


    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid2 = inv.uuid
    if vcenter_uuid2 == None:
        test_util.test_fail("vcenter_uuid is None")



    #start vm in remote and check
    test_util.test_logger("start vm for sync test")
    vm_cond = res_ops.gen_query_conditions("name", '=', vm_name)
    vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0]
    vm_uuid = vm_inv.uuid
    vm_state = vm_inv.state.strip().lower()
    if not vm_uuid:
        test_util.test_fail("remote woodpecker vm uuid is null")
    elif vm_uuid and vm_state != "running":
        print "#%s#" % vm_state
        vm_ops.start_vm(vm_uuid)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0]
    vm_uuid = vm_inv.uuid
    vm_state = vm_inv.state.strip().lower()
    if not vm_uuid:
        test_util.test_fail("local woodpecker vm uuid is null")
    elif vm_state != "running":
        test_util.test_fail("vcenter sync vm start failed.")



    #stop vm in remote and check
    test_util.test_logger("stop vm for sync test")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0]
    vm_uuid = vm_inv.uuid
    vm_state = vm_inv.state.strip().lower()
    if not vm_uuid:
        test_util.test_fail("remote woodpecker vm uuid is null")
    elif vm_uuid and vm_state != "stopped":
        vm_ops.stop_vm(vm_uuid)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0]
    vm_uuid = vm_inv.uuid
    vm_state = vm_inv.state.strip().lower()
    if not vm_uuid:
        test_util.test_fail("local woodpecker vm uuid is null")
    elif vm_state != "stopped":
        test_util.test_fail("vcenter sync vm stop failed.")



    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    if vcenter_uuid2:
        vct_ops.delete_vcenter(vcenter_uuid2)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    if vcenter_uuid1:
        vct_ops.delete_vcenter(vcenter_uuid1)

    test_util.test_pass("vcenter sync start and stop vm test passed.")
开发者ID:mrwangxc,项目名称:zstack-woodpecker,代码行数:90,代码来源:test_vcenter_sync_vm_start_stop.py


示例17: test

def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid
    allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, "SharedBlock"]
    test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)

    test_util.test_dsc('Create test vm and check')

    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \
            None)
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    l3_1_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
    #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    #vr_uuid = vr.uuid
    
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()

    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi'])

    #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    #ps_uuid = ps.uuid
    #ps_ops.change_primary_storage_state(ps_uuid, 'maintain')
    test_stub.maintain_all_pss()
    if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail('VM is expected to stop when PS change to maintain state')

    vm.set_state(vm_header.STOPPED)
    vm.check()
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()

    #ps_ops.change_primary_storage_state(ps_uuid, 'enable')
    test_stub.enable_all_pss()
    host_ops.reconnect_host(host_uuid)
    #vm_ops.reconnect_vr(vr_uuid)
    vrs = test_lib.lib_get_all_vrs()
    for vr in vrs:
        vm_ops.start_vm(vr.uuid)  

    vm.start()
    vm.check()

    volume.delete()
    #volume.expunge()
    volume.check()

    vm.destroy()
    test_util.test_pass('Delete volume under PS maintain mode Test Success')
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:62,代码来源:test_maintain_ps_crt_share_vol.py


示例18: running_vm_operations

def running_vm_operations(vm,bss):
      
   numa = config_ops.get_global_config_value('vm', 'numa')
   live_migration = config_ops.get_global_config_value('localStoragePrimaryStorage','liveMigrationWithStorage.allow')
   ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
   vm_uuid = vm.get_vm().uuid
   #change vm's instanceoffering
   if numa == 'false':
      try:
         vm_ops.update_vm(vm_uuic,2,2048*1024*1024)
         test_util.test_fail('Test Fail.Cannot change instanceoffering of running vm when NUMA is false')
      except:
         config_ops.change_global_config('vm','numa','true')
   
   vm_ops.reboot_vm(vm_uuid)
   vm_ops.update_vm(vm_uuid,2,2048*1024*1024)

   #Change vm's status;set ha level/stop/del ha level/reboot/pause/resume/force stop
   ha_ops.set_vm_instance_ha_level(vm_uuid,'NeverStop')
   vm_ops.stop_vm(vm_uuid)
   ha_ops.del_vm_instance_ha_level(vm_uuid)
   vm_ops.stop_vm(vm_uuid)
   vm_ops.start_vm(vm_uuid)
   vm_ops.reboot_vm(vm_uuid)
   vm_ops.suspend_vm(vm_uuid)
   vm_ops.resume_vm(vm_uuid)
   vm_ops.stop_vm(vm_uuid,'cold')
   vm_ops.start_vm(vm_uuid)

   #clone vms
   vm_ops.clone_vm(vm_uuid,['vm-1','vm-2','vm-3'],'InstantStart')

   #migrate
   candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
   migrate_host_uuids = []
   if candidate_hosts == None:
      pass
   else:
      for host in candidate_hosts.inventories:
         migrate_host_uuids.append(host.uuid)
      if ps.type == 'LocalStorage':
         if live_migration == 'false':
       	   try:
       	      vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])
       	      test_util.test_fail('Test Fail.Cannot migrate localstorage vm when liveMigrationWithStorage is false.' )
       	   except:
       	      config_ops.change_global_config('localStoragePrimaryStorage','liveMigrationWithStorage.allow','true')
       	 else:
       	    vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])
       	    test_util.test_logger('migrate vm success')
      else:
         vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])
         test_util.test_logger('migrate vm success')

   #change vm's password(qga)
   try:
      vm_ops.change_vm_password(vm_uuid,'root','testpassword')
      test_util.test_fail('Test Fail.Cannot change vm password when qga is disabled.')
   except:
      vm_ops.set_vm_qga_enable(vm_uuid)
     
   vm_ops.change_vm_password(vm_uuid,'root','testpassword')
   vm_ops.set_vm_qga_disable(vm_uuid)

   #snapshot operations
   sp_option = test_util.SnapshotOption()
   vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
   root_volume_uuid = vm_root_volume_inv.uuid
   test_util.test_logger('rootvolumerunning:%s' % root_volume_uuid)
   sp_option.set_volume_uuid(root_volume_uuid)
   sp = vol_ops.create_snapshot(sp_option)
   vm_ops.stop_vm(vm_uuid)
   vol_ops.use_snapshot(sp.uuid)
   vm_ops.start_vm(vm_uuid)
   vol_ops.delete_snapshot(sp.uuid)
   
   common_operations(vm,bss,'running')

   vm_ops.destroy_vm(vm_uuid)
   vm_ops.recover_vm(vm_uuid)
   vm_ops.start_vm(vm_uuid)
   vm.destroy()
   vm.expunge()
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:83,代码来源:test_vm_operation.py


示例19: test

def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout

    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    max_attempts = test_lib.lib_get_ha_selffencer_maxattempts()
    test_lib.lib_set_ha_selffencer_maxattempts('12')
    storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout()
    test_lib.lib_set_ha_selffencer_storagechecker_timeout('15')

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_s')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    #l3_name = os.environ.get('l3NoVlanNetworkName1')
    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid)
    for vr in vrs:
	if test_lib.lib_is_vm_running(vr) == True:
	    vm_ops.start_vm(vr.uuid)
    time.sleep(60)

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    conditions = res_ops.gen_query_conditions('state', '=', 'Enabled')
    conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions)
    conditions = res_ops.gen_query_conditions('managementIp', '!=', os.environ.get('hostIp'), conditions)
    host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
    vm_creation_option.set_host_uuid(host_uuid)
    vm_creation_option.set_l3_uuids([l3_net_uuid])
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multihost_basic_vm')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    #vm.check()
    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure")
    l2_network_interface = os.environ.get('l2ManagementNetworkInterface')

    cmd = "ifdown %s && sleep 30 && ifup %s" % (l2_network_interface, l2_network_interface)
    try:
	rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd)
	test_util.test_logger("host is not expected to shutdown after its network down just for a little while")
    except:
        test_util.test_fail("host may have been shutdown, while it's not expected to shutdown")

    cmd = "date"
    try:
	rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd)
        test_util.test_logger("host is still alive")
    except:
	test_util.test_fail("host is not expected to shutdown after its network down just for a little while")

    vm.destroy()

    test_lib.lib_set_ha_selffencer_maxattempts(max_attempts)
    test_lib.lib_set_ha_selffencer_storagechecker_timeout(storagechecker_timeout)

    time.sleep(60)
    test_util.test_pass('Test Host Self fence Success')
开发者ID:dennis-sun-chao,项目名称:zstack-woodpecker,代码行数:68,

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_lib.clean_up_all_vr函数代码示例发布时间:2022-05-26
下一篇:
Python vm_operations.reconnect_vr函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap