def test():
    global test_obj_dict

    #enable vmware vmotion
    SI = vct_ops.connect_vcenter(os.environ['vcenter'])
    content = SI.RetrieveContent()
    hosts = vct_ops.get_host(content)
    for host in hosts:
        vct_ops.enable_vmotion(host)

    network_pattern = 'L3-%s'%os.environ['dportgroup']
    if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern):
        network_pattern = 'L3-%s'%os.environ['portgroup0']
    ova_image_name = os.environ['vcenterDefaultmplate']
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName'))

    #create vm 
    vm = test_stub.create_vm_in_vcenter(vm_name = 'migrate_vm', image_name = ova_image_name, l3_name = network_pattern)
    vm.check()
    test_obj_dict.add_vm(vm)
    #check whether vm migration candidate hosts exist
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm.vm.uuid).inventories
    if candidate_hosts == []:
        test_util.test_logger('Not find vm migration candidate hosts, skip test migrate vm')
    else:
        test_util.test_dsc('Migrate vm to the specified host')
        host_uuid = candidate_hosts[0].uuid
        vm_ops.migrate_vm(vm.vm.uuid, host_uuid)
        vm.update()
        vm.check()
        #check whether the specified host is effective
        assert candidate_hosts[0].name == test_lib.lib_find_host_by_vm(vm.vm).name
        #check the consistency of the migration in zstack and vmware
        assert candidate_hosts[0].name == vct_ops.find_host_by_vm(content, vm.vm.name)
        test_util.test_dsc('vm in suspended state does not allow migration')
        vm.suspend()
        candidate_host = vm_ops.get_vm_migration_candidate_hosts(vm.vm.uuid).inventories
        assert candidate_host == []
        
    #create vm with disk
    vm1 = test_stub.create_vm_in_vcenter(vm_name = 'migrate_vm_with_disk', image_name = ova_image_name, l3_name = network_pattern, disk_offering_uuids = [disk_offering.uuid])
    vm1.check()
    test_obj_dict.add_vm(vm1)
    #check whether vm migration candidate hosts exist
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm1.vm.uuid).inventories
    if candidate_hosts == []:
        test_util.test_logger('Not find vm migration candidate hosts, skip test migrate vm with disk')
    else:
        test_util.test_dsc('Migrate vm with disk to the specified host')
        host_uuid = candidate_hosts[0].uuid
        vm_ops.migrate_vm(vm1.vm.uuid, host_uuid)
        vm1.update()
        vm1.check()
        assert candidate_hosts[0].name == test_lib.lib_find_host_by_vm(vm1.vm).name
        assert candidate_hosts[0].name == vct_ops.find_host_by_vm(content, vm1.vm.name)
   
    #cleanup 
    test_lib.lib_error_cleanup(test_obj_dict)

    test_util.test_pass("Migrate vm test passed.")
def test():
    global vm
    vm = test_stub.create_vm()

    #1
    hostname='vm123.zstack.org'
    vm_ops.set_vm_hostname(vm.get_vm().uuid,'vm123.zstack.org')
    host=test_lib.lib_find_host_by_vm(vm.get_vm())
    host_ops.reconnect_host(host.uuid)

    hostname_inv=vm_ops.get_vm_hostname(vm.get_vm().uuid)
    if hostname_inv != hostname:
        test_util.test_fail('can not get the vm hostname after set vm hostname')

    vm_inv=res_ops.get_resource(res_ops.VM_INSTANCE,uuid=vm.get_vm().uuid)[0]
    if vm_inv.vmNics[0].ip !=vm.get_vm().vmNics[0].ip:
        test_util.test_fail('can not get the correct ip address after set vm hostname and reconnected host')

    #2
    hostname = 'vm1234.zstack.org'
    vm_ops.set_vm_hostname(vm.get_vm().uuid,hostname)
    host=test_lib.lib_find_host_by_vm(vm.get_vm())
    vm_ops.reboot_vm(vm.get_vm().uuid)

    hostname_inv=vm_ops.get_vm_hostname(vm.get_vm().uuid)
    if hostname_inv != hostname:
        test_util.test_fail('can not get the vm hostname after set vm hostname')

    vm_inv=res_ops.get_resource(res_ops.VM_INSTANCE,uuid=vm.get_vm().uuid)[0]
    if vm_inv.vmNics[0].ip !=vm.get_vm().vmNics[0].ip:
        test_util.test_fail('can not get the correct ip address after set vm hostname and reboot vm')

    #3
    hostname = 'vm12345.zstack.org'
    vm_ops.set_vm_hostname(vm.get_vm().uuid, hostname)
    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    host_ops.reconnect_host(host.uuid)
    vm_ops.reboot_vm(vm.get_vm().uuid)

    hostname_inv = vm_ops.get_vm_hostname(vm.get_vm().uuid)
    if hostname_inv != hostname:
        test_util.test_fail('can not get the vm hostname after set vm hostname')

    vm_inv = res_ops.get_resource(res_ops.VM_INSTANCE, uuid=vm.get_vm().uuid)[0]
    if vm_inv.vmNics[0].ip != vm.get_vm().vmNics[0].ip:
        test_util.test_fail('can not get the correct ip address after set vm hostname and reboot vm and reconnect host')

    test_util.test_pass('SetVMHostname and get vm\'s correct ip')
def compare(ps, vm, dvol, backup):
    test_util.test_logger("-----------------compare----------------")
    # find vm_host
    host = test_lib.lib_find_host_by_vm(vm.vm)
    bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0]

    cond = res_ops.gen_query_conditions("uuid", '=', dvol.volume.uuid)
    current_volume = res_ops.query_resource(res_ops.VOLUME, cond)[0]

    vol_path = current_volume.installPath
    if ps.type == "SharedBlock":
        vol_path = "/dev/" + current_volume.installPath.split("/")[2] + "/" + current_volume.installPath.split("/")[3]
    test_util.test_logger(vol_path)

    name = backup.backupStorageRefs[0].installPath.split("/")[2]
    id = backup.backupStorageRefs[0].installPath.split("/")[3]
    # compare vm_root_volume & image
    cmd = "mkdir /root/%s;" \
          "/usr/local/zstack/imagestore/bin/zstcli " \
          "-rootca=/var/lib/zstack/imagestorebackupstorage/package/certs/ca.pem " \
          "-url=%s:8000 " \
          "pull -installpath /root/%s/old.qcow2 %s:%s;" \
          "qemu-img compare %s /root/%s/old.qcow2;" % (id, bs.hostname, id, name, id, vol_path, id)
    # clean image
    result = test_lib.lib_execute_ssh_cmd(host.managementIp, "root", "password", cmd, timeout=300)
    if result != "Images are identical.\n":
        test_util.test_fail("compare vm_root_volume & image created by backup")
def test():
    global vm
    loop = 20
    count = 0
    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vm("test_libvirt_snapshot_vm", image_name, l3_name)
    test_obj_dict.add_vm(vm)
    vm.check()

    volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
     
    snapshots = test_obj_dict.get_volume_snapshot(volume_uuid)
    snapshots.set_utility_vm(vm)
    while count <= loop:
        sp_name = "create_snapshot" + str(count)
        snapshots.create_snapshot(sp_name)
        snapshots.check()
        count += 1

    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    result = test_lib.lib_execute_ssh_cmd(host.managementIp, 'root', 'password', 'service libvirtd restart')

    time.sleep(600)

    vm.check()
    snapshots.check()

    snapshots.delete()
    test_obj_dict.rm_volume_snapshot(snapshots)
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Libvirt restart with snapshot passed')
def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout

    allow_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE]
    test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)
    
    test_stub.skip_if_not_storage_network_separate(test_lib.all_scenario_config)

    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('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()

    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()

    vr_hosts = test_stub.get_host_has_vr()
    mn_hosts = test_stub.get_host_has_mn()
    nfs_hosts = test_stub.get_host_has_nfs()
    if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts):
        test_util.test_fail("Not find out a suitable host")

    #vm.check()
    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")

    #test_stub.down_host_network(host_ip, test_lib.all_scenario_config)
    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    t = test_stub.async_exec_ifconfig_nic_down_up(1200, host_ip, host_username, host_password, "zsn1")

    vm.destroy()

    test_util.test_pass('Test VM ha change to running within 300s Success')
def test():

    ps_env = test_stub.PSEnvChecker()
    
    mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
    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 = random.choice(res_ops.query_resource(res_ops.HOST, conditions))
    record['host_ip'] = host.managementIp
    record['host_port'] = host.sshPort
    record['host_uuid'] = host.uuid

    test_util.test_dsc("Create {0} vm each with {1} datavolume".format(VM_COUNT, DATA_VOLUME_NUMBER))
    if ps_env.is_sb_ceph_env:
        ps_list = res_ops.query_resource(res_ops.PRIMARY_STORAGE)
        ps = random.choice(ps_list)
        ps_uuid = ps.uuid
        vm_list = test_stub.create_multi_vms(name_prefix='test-', count=VM_COUNT,
                                             data_volume_number=DATA_VOLUME_NUMBER, host_uuid=host.uuid, ps_uuid=ps_uuid, timeout=1800000, bs_type="ImageStoreBackupStorage" if ps.type == "SharedBlock" else "Ceph")
    else:
        vm_list = test_stub.create_multi_vms(name_prefix='test-', count=VM_COUNT,
                                             data_volume_number=DATA_VOLUME_NUMBER, host_uuid=host.uuid, timeout=1800000)

    for vm in vm_list:
        test_obj_dict.add_vm(vm)

    test_util.test_logger("host %s is disconnecting" % host.managementIp)
    for vm in vm_list:
        ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")

    #l2_network_interface = os.environ.get('l2ManagementNetworkInterface')
    l2interface = test_lib.lib_get_l2s_by_vm(vm.get_vm())[0].physicalInterface
    l2_network_interface = test_stub.get_host_l2_nic_name(l2interface)
    cmd = "ifdown %s && sleep 180 && ifup %s" % (l2_network_interface, l2_network_interface)
    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    rsp = test_lib.lib_execute_ssh_cmd(host.managementIp, host_username, host_password, cmd, 240)
    if not rsp:
        test_util.test_logger("host is expected to shutdown after its network down for a while")

    test_util.test_logger("wait for 180 seconds")
    time.sleep(180)
    for vm in vm_list:
        vm.update()
        if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host.managementIp:
            test_util.test_fail("VM is expected to start running on another host")
        vm.set_state(vm_header.RUNNING)
        vm.check()

    cmd = 'PORT=%s bash -ex %s %s' % (host.sshPort, os.environ.get('hostRecoverScript'),host.managementIp)
    test_util.test_logger(cmd)
    os.system(cmd)
    host_ops.reconnect_host(host.uuid)

    test_util.test_pass('Multi PrimaryStorage Vm HA Test Pass')
def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout

    must_ps_list = ['MiniStorage']
    test_lib.skip_test_if_any_ps_not_deployed(must_ps_list)    

    test_stub.skip_if_not_storage_network_separate(test_lib.all_scenario_config)

    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("ttylinux").uuid
    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()

    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()

    #vm.check()
    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")

    test_stub.down_host_network(host_ip, test_lib.all_scenario_config, "managment_net")
    if test_stub.check_vm_running_on_host(vm.vm.uuid, host_ip):
        test_util.test_fail("VM is expected to start running on another host")

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

    test_stub.up_host_network(host_ip, test_lib.all_scenario_config, "managment_net")

    test_util.test_pass('Test Success')
def test():
    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \
            None, fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    image_option = test_util.ImageOption()
    image_option.set_name('test_image_cache_cleanup')
    image_option.set_format('qcow2')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_url(os.environ.get('imageUrl_s'))
    image_option.set_backup_storage_uuid_list([bss[0].uuid])

    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)

    new_image.add_root_volume_template()

    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid

    vm = test_stub.create_vm([l3_net_uuid], new_image.image.uuid, 'imagecache_vm', \
            default_l3_uuid = l3_net_uuid)
    test_obj_dict.add_vm(vm)
    vm.check()
    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())

    vm.destroy()
    if test_lib.lib_get_vm_delete_policy() != 'Direct':
        vm.expunge()

    new_image.delete()
    if test_lib.lib_get_image_delete_policy() != 'Direct':
        new_image.expunge()
    if ps.type == 'SharedMountPoint':
        test_util.test_skip('CleanUpImageCacheOnPrimaryStorage not supported on SMP storage, skip test.')
    elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
        test_util.test_skip('ceph is not directly using image cache, skip test.')

    ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid)
    if ps.type == inventory.LOCAL_STORAGE_TYPE:
        image_cache_path = "%s/imagecache/template/%s/%s.qcow2" % (ps.mountPath, new_image.image.uuid, new_image.image.uuid)
        if test_lib.lib_check_file_exist(host, image_cache_path):
            test_util.test_fail('image cache is expected to be deleted')
    elif ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE:
        image_cache_path = "%s/imagecache/template/%s/%s.qcow2" % (ps.mountPath, new_image.image.uuid, new_image.image.uuid)
        if test_lib.lib_check_file_exist(host, image_cache_path):
            test_util.test_fail('image cache is expected to be deleted')
#    elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
#    elif ps.type == 'SharedMountPoint':

    test_util.test_pass('imagecache cleanup Pass.')
def migrate_vm_to_differnt_cluster(vm):
    test_util.test_dsc("migrate vm to different cluster")
    if not test_lib.lib_check_vm_live_migration_cap(vm.vm):
        test_util.test_skip('skip migrate if live migrate not supported')

    current_host = test_lib.lib_find_host_by_vm(vm.vm)
    conditions = res_ops.gen_query_conditions('clusterUuid', '!=', current_host.clusterUuid)
    candidate_hosts = res_ops.query_resource(res_ops.HOST, conditions, None)
    if len(candidate_hosts) == 0:
        test_util.test_fail('Not find available Hosts to do migration')

    vm.migrate(candidate_hosts[0].uuid)
def test():
    test_util.test_dsc('Create test vm as utility vm')
    vm1 = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm1)
    #this test will rely on live snapshot capability supporting
    host_inv = test_lib.lib_find_host_by_vm(vm1.get_vm())

    if not test_lib.lib_check_live_snapshot_cap(host_inv):
        vm1.destroy()
        test_obj_dict.rm_vm(vm1)
        test_util.test_skip('Skip test, since [host:] %s does not support live snapshot.' % host_inv.uuid)

    live_snapshot = test_lib.lib_check_live_snapshot_cap(host_inv)
    if not live_snapshot:
        vm1.destroy()
        test_obj_dict.rm_vm(vm1)
        test_util.test_skip("Skip test, since [host:] %s doesn't support live snapshot " % host_inv.uuid)

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

    test_util.test_dsc('Create volume for snapshot testing')
    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 testing')
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume1 = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume1)
    volume2 = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume2)
    #make sure utility vm is starting and running
    vm.check()

    volume1.attach(vm1)
    volume2.attach(vm1)

    test_util.test_dsc('create snapshot for root')
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm1.get_vm())
    snapshots = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots.set_utility_vm(vm)
    snapshots.create_snapshot('create_root_volume_snapshot1')
    volume1.check()
    volume2.check()

    snapshots2 = test_obj_dict.get_volume_snapshot(volume1.get_volume().uuid)
    snapshots2.set_utility_vm(vm)
    snapshots2.create_snapshot('create_data_volume_snapshot1')
    snapshots.check()
    volume1.check()
    volume2.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create root Snapshot and test data volume status test Success')
def check_vm_internal_cpu_mem(vm):
    managerip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    vm_ip = vm.get_vm().vmNics[0].ip
    get_cpu_cmd = "cat /proc/cpuinfo| grep 'processor'| wc -l"
    get_mem_cmd = "free -m |grep Mem"
    res = test_lib.lib_ssh_vm_cmd_by_agent(managerip, vm_ip, 'root',
                'password', get_cpu_cmd)
    vm_cpu = int(res.result.strip())
    res = test_lib.lib_ssh_vm_cmd_by_agent(managerip, vm_ip, 'root',
                'password', get_mem_cmd)
    vm_mem = int(res.result.split()[1])
    return vm_cpu, vm_mem
def test():
    test_util.test_dsc('Create test vm as utility vm')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)
    #this test will rely on live snapshot capability supporting
    host_inv = test_lib.lib_find_host_by_vm(vm.get_vm())

    if not test_lib.lib_check_live_snapshot_cap(host_inv):
        vm.destroy()
        test_obj_dict.rm_vm(vm)
        test_util.test_skip('Skip test, since [host:] %s does not support live snapshot.')

    libvirt_ver = test_lib.lib_get_host_libvirt_tag(host_inv)
    if not libvirt_ver or LooseVersion(libvirt_ver) < LooseVersion('1.2.7'):
        vm.destroy()
        test_obj_dict.rm_vm(vm)
        test_util.test_skip("Skip test, since [host:] %s libvert version: %s is lower than 1.2.7, which doesn't support live merge, when doing snapshot deleting." % (host_inv.uuid, libvirt_ver))

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

    test_util.test_dsc('Create volume for snapshot testing')
    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 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)
    #make sure utility vm is starting and running
    vm.check()

    test_util.test_dsc('create snapshot and check')
    #snapshots = zstack_sp_header.ZstackVolumeSnapshot()
    #snapshots.set_target_volume(volume)
    #test_obj_dict.add_volume_snapshot(snapshots)
    snapshots = test_obj_dict.get_volume_snapshot(volume.get_volume().uuid)
    snapshots.set_utility_vm(vm)
    snapshots.create_snapshot('create_snapshot1')
    snapshots.create_snapshot('create_snapshot2')
    snapshots.create_snapshot('create_snapshot3')

    volume.attach(vm1)
    snapshots.delete()
    test_obj_dict.rm_volume_snapshot(snapshots)
    volume.check()
    vm.destroy()
    test_obj_dict.rm_vm(vm)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete Snapshot on running vm test Success')
Exemple #13
0
def migrate_vm_to_random_host(vm, timeout = None):
    test_util.test_dsc("migrate vm to random host")
    target_host = test_lib.lib_find_random_host(vm.vm)
    current_host = test_lib.lib_find_host_by_vm(vm.vm)
    vm.migrate(target_host.uuid, timeout)

    new_host = test_lib.lib_get_vm_host(vm.vm)
    if not new_host:
        test_util.test_fail('Not find available Hosts to do migration')

    if new_host.uuid != target_host.uuid:
        test_util.test_fail('[vm:] did not migrate from [host:] %s to target [host:] %s, but to [host:] %s' % (vm.vm.uuid, current_host.uuid, target_host.uuid, new_host.uuid))
    else:
        test_util.test_logger('[vm:] %s has been migrated from [host:] %s to [host:] %s' % (vm.vm.uuid, current_host.uuid, target_host.uuid))
def compare(ps, vm, backup):
    test_util.test_logger("-----------------compare----------------")
    # find vm_host
    host = test_lib.lib_find_host_by_vm(vm.vm)
    cond = res_ops.gen_query_conditions("type", '=', "ImageStoreBackupStorage")
    bs = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0]

    root_volume = test_lib.lib_get_root_volume(vm.get_vm())
    for i in test_lib.lib_get_data_volumes(vm.get_vm()):
        if i.name == "DATA-for-test_vm":
            data_volume = i

    vm_path = root_volume.installPath
    data_path = data_volume.installPath
    if ps.type == "SharedBlock":
        vm_path = "/dev/" + root_volume.installPath.split("/")[2] + "/" + root_volume.installPath.split("/")[3]
        data_path = "/dev/" + data_volume.installPath.split("/")[2] + "/" + data_volume.installPath.split("/")[3]
    test_util.test_logger(vm_path)
    test_util.test_logger(data_path)

    for i in backup:
        if i.type == "Root":
            name = i.backupStorageRefs[0].installPath.split("/")[2]
            id = i.backupStorageRefs[0].installPath.split("/")[3]
        if i.type == "Data" and "DATA-for-test_vm" in i.metadata:
            name1 = i.backupStorageRefs[0].installPath.split("/")[2]
            id1 = i.backupStorageRefs[0].installPath.split("/")[3]

    # compare vm_root_volume & image
    cmd = "mkdir /root/%s;" \
          "/usr/local/zstack/imagestore/bin/zstcli " \
          "-rootca=/var/lib/zstack/imagestorebackupstorage/package/certs/ca.pem " \
          "-url=%s:8000 " \
          "pull -installpath /root/%s/old.qcow2 %s:%s;" \
          "qemu-img compare %s /root/%s/old.qcow2;" % (id, bs.hostname, id, name, id, vm_path, id)
    cmd1 = "mkdir /root/%s;" \
          "/usr/local/zstack/imagestore/bin/zstcli " \
          "-rootca=/var/lib/zstack/imagestorebackupstorage/package/certs/ca.pem " \
          "-url=%s:8000 " \
          "pull -installpath /root/%s/old.qcow2 %s:%s;" \
          "qemu-img compare %s /root/%s/old.qcow2;" % (id1, bs.hostname, id1, name1, id1, data_path, id1)
    # clean image
    result = test_lib.lib_execute_ssh_cmd(host.managementIp, "root", "password", cmd, timeout=300)
    if result != "Images are identical.\n":
        test_util.test_fail("compare vm_root_volume & image created by backup")
    result = test_lib.lib_execute_ssh_cmd(host.managementIp, "root", "password", cmd1, timeout=300)
    if result != "Images are identical.\n":
        test_util.test_fail("compare vm_data_volume & image created by backup")
Exemple #15
0
def migrate_vm_to_random_host(vm):
    test_util.test_dsc("migrate vm to random host")
    if not test_lib.lib_check_vm_live_migration_cap(vm.vm):
        test_util.test_skip('skip migrate if live migrate not supported')
    target_host = test_lib.lib_find_random_host(vm.vm)
    current_host = test_lib.lib_find_host_by_vm(vm.vm)
    vm.migrate(target_host.uuid)

    new_host = test_lib.lib_get_vm_host(vm.vm)
    if not new_host:
        test_util.test_fail('Not find available Hosts to do migration')

    if new_host.uuid != target_host.uuid:
        test_util.test_fail('[vm:] did not migrate from [host:] %s to target [host:] %s, but to [host:] %s' % (vm.vm.uuid, current_host.uuid, target_host.uuid, new_host.uuid))
    else:
        test_util.test_logger('[vm:] %s has been migrated from [host:] %s to [host:] %s' % (vm.vm.uuid, current_host.uuid, target_host.uuid))
def check_vm_internal_cpu_mem(vm, shutdown, window):
    if window:
        return check_window_vm_internal_cpu_mem(vm)
    managerip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    vm_ip = vm.get_vm().vmNics[0].ip
    get_cpu_cmd = "cat /proc/cpuinfo| grep 'processor'| wc -l"
    if not shutdown:
        get_mem_cmd = "free -m |grep Mem"
    else:
        get_mem_cmd = "dmidecode -t 17 | grep 'Size:'"
    res = test_lib.lib_ssh_vm_cmd_by_agent(managerip, vm_ip, 'root',
                'password', get_cpu_cmd)
    vm_cpu = int(res.result.strip())
    res = test_lib.lib_ssh_vm_cmd_by_agent(managerip, vm_ip, 'root',
                'password', get_mem_cmd)
    vm_mem = int(res.result.split()[1])
    return vm_cpu, vm_mem
def test():

    mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
    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 = random.choice(res_ops.query_resource(res_ops.HOST, conditions))
    record['host_ip'] = host.managementIp
    record['host_port'] = host.sshPort
    record['host_uuid'] = host.uuid

    vm_list=list(test_stub.generate_local_shared_test_vms(test_obj_dict, vm_ha=True, host_uuid=host.uuid))
    (vm_root_local, vm_root_local_data_local,
     vm_root_local_data_shared, vm_root_local_data_mixed,
     vm_root_shared, vm_root_shared_data_local,
     vm_root_shared_data_shared, vm_root_shared_data_mixed) = vm_list

    l2interface = test_lib.lib_get_l2s_by_vm(vm_list[0].get_vm())[0].physicalInterface
    l2_network_interface = test_stub.get_host_l2_nic_name(l2interface)
    cmd = "ifdown %s && sleep 180 && ifup %s" % (l2_network_interface, l2_network_interface)
    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    rsp = test_lib.lib_execute_ssh_cmd(host.managementIp, host_username, host_password, cmd, 240)
    if not rsp:
        test_util.test_logger("host is expected to shutdown after its network down for a while")

    test_util.test_logger("wait for 180 seconds")
    time.sleep(180)
    for vm in vm_list:
        vm.update()

    for vm in (vm_root_shared,vm_root_shared_data_shared):
        if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host.managementIp:
            test_util.test_fail("VM is expected to start running on another host")
            vm.set_state(vm_header.RUNNING)
            vm.check()

    for vm in (vm_root_local, vm_root_local_data_local, vm_root_local_data_shared,
               vm_root_local_data_mixed, vm_root_shared_data_local, vm_root_shared_data_mixed):
        assert vm.get_vm().state == inventory.STOPPED

    cmd = 'PORT=%s bash -ex %s %s' % (host.sshPort, os.environ.get('hostRecoverScript'),host.managementIp)
    test_util.test_logger(cmd)
    os.system(cmd)
    host_ops.reconnect_host(host.uuid)
def test():
    global vm
    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    vm = test_stub.create_vm()
    vm.check()
    host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid
    host_ops.change_host_state(host_uuid, "disable")
    time.sleep(10)
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")
    vm.stop()
    time.sleep(60)
    vm.check()
    vm.destroy()
    vm.check()
    host_ops.change_host_state(host_uuid, "enable")
    test_util.test_pass('VM ha never stop Test Success')
def print_iptables(vm):
    host = test_lib.lib_find_host_by_vm(vm)
    try:
        if not host.managementIp:
            test_util.test_logger('did not find host for vm: %s ' % vm.uuid)
            return 
    except:
        test_util.test_logger('did not find host for vm: %s ' % vm.uuid)
        return 

    host_cmd = host_plugin.HostShellCmd()
    host_cmd.command = 'iptables-save'
    rspstr = http.json_dump_post(testagent.build_http_path(host.managementIp, host_plugin.HOST_SHELL_CMD_PATH), host_cmd)
    rsp = jsonobject.loads(rspstr)
    if rsp.return_code != 0:
        test_util.test_logger('can not dump iptables on host: %s; reason: %s' % (host.managementIp, rsp.stderr))
    else:
        test_util.test_logger('iptables-save result on %s: %s' % (host.managementIp, rsp.stdout))
def test():
    global vm
    vm = test_stub.create_spice_vm()
    vm.check()

    vm_inv=vm.get_vm()
    vm_uuid=vm_inv.uuid
    vm_state = vm.get_vm().state
    host_inv = test_lib.lib_find_host_by_vm(vm_inv)
    host_ip= host_inv.managementIp
    host_username=host_inv.username
    host_password=host_inv.password

    test_util.test_dsc('check the vm console protocol is spice via read xml')
    cmd='''virsh dumpxml %s |grep spice | grep -v spicevmc | grep -v com.redhat.spice.0 |awk  '{print $2}' |awk -F= '{print $2}' '''% (vm_uuid)
    result=test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180)
    if eval(result) == "spice" :
	print "Vm console protocol is spice, test success"
    else :
	print "Vm console protocol is %s " % eval(result)
	print "test is fail"
        test_util.test_fail('Create VM with spice Test Failed')

    test_util.test_dsc('check the spiceStreamingMode is off via read xml')
    cmd='''virsh dumpxml %s |grep streaming|awk -F/ '{print $1}' |awk -F= '{print $2}' '''% (vm_uuid)
    result=test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180)
    if eval(result) == "off" :
	print "Vm spiceStreamingMode is off, test success"
    else :
	print "Vm spiceStreamingModeis %s " % eval(result)
	print "test is fail"
        test_util.test_fail('Create VM with spice and spiceStreamingMode is off Test Failed')

    test_util.test_dsc('check the vm console protocol is spice via GetVmConsoleAddressAction')
    if test_stub.get_vm_console_protocol(vm.vm.uuid).protocol == "spice" :
	print "Vm console protocol is spice, test success"
    else :
	print "Vm console protocol is %s " % test_stub.get_vm_console_protocol(vm.vm.uuid).protocol
        print "test is fail"
        test_util.test_fail('Create VM with spice Test Failed')

    vm.destroy()
    vm.check()
    test_util.test_pass('Create VM with spice Test Success')
def test():
    vm = test_stub.create_vr_vm('vm_imagecache', 'imageName_net', 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm)
    vm.check()
    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    image = test_lib.lib_get_image_by_name(os.environ.get('imageName_net'))

    if ps.type == inventory.LOCAL_STORAGE_TYPE or ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE or ps.type == 'SharedMountPoint':
        image_cache_path = "%s/imagecache/template/%s/" % (ps.mountPath, image.uuid)
        imagecache_file_size = int(test_lib.lib_get_file_size(host, image_cache_path))
        image_actual_size = int(image.actualSize)
        if imagecache_file_size < image.actualSize*0.99 or imagecache_file_size > image.actualSize*1.01:
            test_util.test_fail('image cache size (%s) not match image actual size(%s)' % (imagecache_file_size, image_actual_size))
    else:
        test_util.test_skip("Skip test when primary storage is not local or NFS")
#    elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('imagecache cleanup Pass.')
    def update(self):
        '''
        If vm's status was changed by none vm operations, it needs to call
        vm.update() to update vm's infromation. 

        The none vm operations: host.maintain() host.delete(), zone.delete()
        cluster.delete()
        '''
        super(ZstackTestVm, self).update()
        if self.get_state != vm_header.EXPUNGED:
            updated_vm = test_lib.lib_get_vm_by_uuid(self.vm.uuid)
            if updated_vm:
                self.vm = updated_vm
                #vm state need to chenage to stopped, if host is deleted
                host = test_lib.lib_find_host_by_vm(updated_vm)
                if not host and self.vm.state != vm_header.STOPPED:
                    self.set_state(vm_header.STOPPED)
            else:
                self.set_state(vm_header.EXPUNGED)
            return self.vm
def test():
    global vm
    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
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    host_ip = os.environ.get('hostIp3')
    conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip)
    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()
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure")
    l2_network_interface = os.environ.get('l2ManagementNetworkInterface')
    cmd = "ifdown %s && sleep 120 && ifup %s" % (l2_network_interface, l2_network_interface)
    try:
        rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd)
	test_util.test_fail("host is expected to shutdown after its network down for a while")
    except:
        test_util.test_logger("host may have been shutdown")

    time.sleep(200)
    vm.update()
    if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip:
	test_util.test_fail("VM is expected to start running on another host")
    vm.set_state(vm_header.RUNNING)
    vm.check()
    vm.destroy()

    test_util.test_pass('Test VM ha on host failure Success')
    def _live_snapshot_cap_check(self):
        '''
        Deprecated. It is not recommended to be called in create_snapshot.
        '''
        volume_obj = self.get_target_volume()
        volume_vm = volume_obj.get_target_vm()
        if volume_vm and volume_vm.get_state() == vm_header.RUNNING:
            host = test_lib.lib_find_host_by_vm(volume_vm.get_vm())
            conditions = res_ops.gen_query_conditions('tag', '=', \
                    'capability:liveSnapshot')
            tag_info = test_lib.lib_find_host_tag(host, conditions)
            if tag_info:
                test_util.test_logger('host: %s support live snapshot' % \
                        host.uuid)
                return True
            else:
                test_util.test_fail('host: %s does not support live snapshot' \
                        % host.uuid)
                return False

        return True
def test():
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    test_util.test_dsc("create vpc vrouter and attach vpc l3 to vpc")
    vr = test_stub.create_vpc_vrouter()
    test_stub.attach_l3_to_vpc_vr(vr)

    test_util.test_dsc("create two vm, vm1 in l3 {}, vm2 in l3 {}".format(flavor['vm1l3'], flavor['vm2l3']))

    vm1, vm2 = [test_stub.create_vm_with_random_offering(vm_name='vpc_vm_{}'.format(name), l3_name=name) for name in (flavor['vm1l3'], flavor['vm2l3'])]

    [test_obj_dict.add_vm(vm) for vm in (vm1,vm2)]
    [vm.check() for vm in (vm1,vm2)]

    if flavor['ops'] is VM_MIGRATE:
        test_stub.migrate_vm_to_random_host(vm2)
    elif flavor['ops'] is VM_REBOOT:
        vm1.reboot()
    elif flavor['ops'] is VR_REBOOT:
        vr.reboot()
        time.sleep(10)
    elif flavor['ops'] is VR_RECONNECT:
        vr.reconnect()
    elif flavor['ops'] is VR_MIGRATE:
        vr.migrate_to_random_host()
    elif flavor['ops'] is HOST_RECONNECT:
        host = test_lib.lib_find_host_by_vm(random.choice([vm1,vm2]).get_vm())
        host_ops.reconnect_host(host.uuid)

    if flavor['ops'] is not None:
        for vm in (vm1, vm2):
            vm.check()

    test_util.test_dsc("test two vm connectivity")
    [test_stub.run_command_in_vm(vm.get_vm(), 'iptables -F') for vm in (vm1,vm2)]

    test_stub.check_icmp_between_vms(vm1, vm2, expected_result='PASS')
    test_stub.check_tcp_between_vms(vm1, vm2, ["22"], [])

    test_lib.lib_error_cleanup(test_obj_dict)
    test_stub.remove_all_vpc_vrouter()
def test():
    global vm
    global default_mode
    global default_mode1
    default_mode = conf_ops.change_global_config('mevoco', 'vm.consoleMode', 'spice')
    default_mode1 = conf_ops.change_global_config('vm', 'spiceStreamingMode', 'all')
    vm = test_stub.create_spice_vm()
    vm.check()

    vm_inv=vm.get_vm()
    vm_uuid=vm_inv.uuid
    vm_state = vm.get_vm().state
    host_inv = test_lib.lib_find_host_by_vm(vm_inv)
    host_ip= host_inv.managementIp
    host_username=host_inv.username
    host_password=host_inv.password

    test_util.test_dsc('check the vm console protocol is spice via read xml')
    cmd='''virsh dumpxml %s |grep spice | grep -v spicevmc | grep -v com.redhat.spice.0 |awk  '{print $2}' |awk -F= '{print $2}' '''% (vm_uuid)
    result=test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180)
    if eval(result) == "spice" :
	print "Vm console protocol is spice, test success"
    else :
	print "Vm console protocol is %s " % eval(result)
	print "test is fail"
        test_util.test_fail('Create VM with spice Test Failed')

    test_util.test_dsc('check the spiceStreamingMode is all via read xml')
    cmd='''virsh dumpxml %s |grep streaming|awk -F/ '{print $1}' |awk -F= '{print $2}' '''% (vm_uuid)
    result=test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180)
    if eval(result) == "all" :
	print "Vm spiceStreamingMode is all, test success"
    else :
	print "Vm spiceStreamingModeis %s " % eval(result)
	print "test is fail"
        test_util.test_fail('Create VM with spice and spiceStreamingMode is all Test Failed')

    vm.destroy()
    vm.check()
    test_util.test_pass('Create VM with spice and spiceStreamingMode is all Test Success')
def test():
    vm1 = test_stub.create_vr_vm('vm_imagecache', 'imageName_net', 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm1)
    vm1.check()
    vm1.stop()
    image_creation_option = test_util.ImageOption()
    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm1.get_vm())
    image_creation_option.set_backup_storage_uuid_list([backup_storage_list[0].uuid])
    image_creation_option.set_root_volume_uuid(vm1.get_vm().rootVolumeUuid)
    image_creation_option.set_name('test_create_image_template_imagecache')

    image = test_image.ZstackTestImage()
    image.set_creation_option(image_creation_option)
    image.create()
    test_obj_dict.add_image(image)
    image.check()
    vm2 = test_stub.create_vm('vm_imagecache2', 'test_create_image_template_imagecache', os.environ.get('l3VlanNetwork3'))
    test_obj_dict.add_vm(vm2)

    host = test_lib.lib_find_host_by_vm(vm2.get_vm())
    ps = test_lib.lib_get_primary_storage_by_vm(vm2.get_vm())
    image = test_lib.lib_get_image_by_name('test_create_image_template_imagecache')
    img_ops.sync_image_size(image.uuid)
    image = test_lib.lib_get_image_by_name('test_create_image_template_imagecache')
    img_ops.delete_image(image.uuid)

    if ps.type == inventory.LOCAL_STORAGE_TYPE or ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE or ps.type == 'SharedMountPoint':
        image_cache_path = "%s/imagecache/template/%s/" % (ps.mountPath, image.uuid)
        imagecache_file_size = int(test_lib.lib_get_file_size(host, image_cache_path))
        image_actual_size = int(image.actualSize)
        if imagecache_file_size < image.actualSize*0.99 or imagecache_file_size > image.actualSize*1.01:
            test_util.test_fail('image cache size (%s) not match image actual size(%s)' % (imagecache_file_size, image_actual_size))
    else:
        test_util.test_skip("Skip test when primary storage is not local or NFS")
#    elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('imagecache cleanup Pass.')
def test():
    global vm
    global default_mode
    default_mode = conf_ops.change_global_config('mevoco', 'vm.consoleMode', 'spice')
    vm = test_stub.create_vnc_vm()
    vm.check()

    vm_inv=vm.get_vm()
    vm_uuid=vm_inv.uuid
    vm_state = vm.get_vm().state
    host_inv = test_lib.lib_find_host_by_vm(vm_inv)
    host_ip= host_inv.managementIp
    host_username=host_inv.username
    host_password=host_inv.password

    test_util.test_dsc('check the vm console protocol is vnc via read xml')
    cmd='''virsh dumpxml %s |grep vnc|awk  '{print $2}' |awk -F= '{print $2}' '''% (vm_uuid)
    result=test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180)
    if eval(result) == "vnc" :
	print "Vm console protocol is vnc, test success"
    else :
	print "Vm console protocol is %s " % eval(result)
	print "test is fail"
        test_util.test_fail('Create VM with vnc Test Failed')

    test_util.test_dsc('check the vm console protocol is vnc via GetVmConsoleAddressAction')
    if test_stub.get_vm_console_protocol(vm.vm.uuid).protocol == "vnc" :
	print "Vm console protocol is vnc, test success"
    else :
	print "Vm console protocol is %s " % test_stub.get_vm_console_protocol(vm.vm.uuid).protocol
        print "test is fail"
        test_util.test_fail('Create VM with vnc Test Failed')

    vm.destroy()
    vm.check()
    test_util.test_pass('Create VM with vnc Test Success')
Exemple #29
0
def test():
    global ssh_timeout
    data_volume_size = 10737418240
    disk_offering_option = test_util.DiskOfferingOption()
    disk_offering_option.set_name('root-disk-iso')
    disk_offering_option.set_diskSize(data_volume_size)
    data_volume_offering = vol_ops.create_volume_offering(disk_offering_option)
    test_obj_dict.add_disk_offering(data_volume_offering)

    cpuNum = 1
    memorySize = 536870912
    name = 'vm-offering-iso'
    new_offering_option = test_util.InstanceOfferingOption()
    new_offering_option.set_cpuNum(cpuNum)
    new_offering_option.set_memorySize(memorySize)
    new_offering_option.set_name(name)
    new_offering = vm_ops.create_instance_offering(new_offering_option)
    test_obj_dict.add_instance_offering(new_offering)

    img_option = test_util.ImageOption()
    img_option.set_name('image-iso')
    bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid
    img_option.set_backup_storage_uuid_list([bs_uuid])
    img_option.set_url('http://172.20.1.15:7480/iso/iso_for_install_vm_test.iso')
    image_inv = img_ops.add_iso_template(img_option)
    image_uuid = image_inv.uuid
    image = test_image.ZstackTestImage()
    image.set_image(image_inv)
    image.set_creation_option(img_option)
    test_obj_dict.add_image(image)

    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    root_disk_uuid = data_volume_offering.uuid
    vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'vm-iso', root_disk_uuid, new_offering.uuid)
    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    test_obj_dict.add_vm(vm)
    
    test_util.test_dsc('wait for iso installation')    
    vm_inv = vm.get_vm()
    vm_ip = vm_inv.vmNics[0].ip

    #test_lib.lib_wait_target_up(vm_ip, '22', 2400)
    #vm.check()

    #cmd ='[ -e /root ] && echo yes || echo no' 
    cmd ='[ -e /root ]'
    #ssh_num = 0
    #ssh_ok = 0
    #while ssh_num <= 5 and ssh_ok == 0 :
    #    rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180)
    #    if rsp == False:
    #        time.sleep(30)
    #    else:
    #        ssh_ok = 1
    #        break  
    #    ssh_num = ssh_num + 1

    #if ssh_ok == 0:
    #    test_util.test_fail('fail to ssh to VM')
    ssh_timeout = test_lib.SSH_TIMEOUT
    test_lib.SSH_TIMEOUT = 3600
    test_lib.lib_set_vm_host_l2_ip(vm_inv)
    if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd):
        test_lib.SSH_TIMEOUT = ssh_timeout
        test_util.test_fail("iso has not been failed to installed.")

    test_lib.SSH_TIMEOUT = ssh_timeout
    vm.destroy()
    test_obj_dict.rm_vm(vm)

    image.delete()
    test_obj_dict.rm_image(image)

    vol_ops.delete_disk_offering(root_disk_uuid)
    test_obj_dict.rm_disk_offering(data_volume_offering)

    vm_ops.delete_instance_offering(new_offering.uuid)
    test_obj_dict.rm_instance_offering(new_offering)

    test_util.test_pass('Create VM with ISO Installation Test Success')
def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout

    must_ps_list = [inventory.LOCAL_STORAGE_TYPE, 'SharedMountPoint']
    test_lib.skip_test_if_any_ps_not_deployed(must_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('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()
    #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('ls_vm_none_status')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()

    vr_hosts = test_stub.get_host_has_vr()
    mn_hosts = test_stub.get_host_has_mn()
    nfs_hosts = test_stub.get_host_has_nfs()
    if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts):
        test_util.test_fail("Not find out a suitable host")

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

    test_stub.down_host_network(host_ip, test_lib.all_scenario_config)

    cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_none_status')
    cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond)

    for i in range(0, 180):
        vm_stop_time = i
        if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown":
            test_stub.up_host_network(host_ip, test_lib.all_scenario_config)
            time.sleep(1)
            test_stub.recover_smp_nfs_server(host_ip)
            conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip)
            kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
            host_ops.reconnect_host(kvm_host_uuid)
            break
        time.sleep(1)

    if vm_stop_time is None:
        vm_stop_time = 180

    for i in range(vm_stop_time, 180):
        if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running":
            break
        time.sleep(1)
    else:
        test_util.test_fail("vm has not been changed to running as expected within 180s.")

    vm.destroy()

    test_util.test_pass('Test VM none change to Stopped within 180s Success')
Exemple #31
0
def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout
  
    test_lib.lib_skip_if_ps_num_is_not_eq_number(1)
    allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint', 'AliyunNAS', inventory.FUSIONSTOR_PRIMARY_STORAGE_TYPE]
    test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)

    test_lib.lib_cur_env_is_not_scenario()

    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('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()

    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()
    vm.check()

    test_stub.ensure_host_has_no_vr(host_uuid)

    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    host_port = test_lib.lib_get_host_port(host_ip)
    test_util.test_logger("host %s is disconnecting" %(host_ip))
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")

    test_stub.stop_ha_vm(vm.get_vm().uuid)

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

    #vm ha natural feature:
    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 or hasattr(host, 'managementIp_') and host.managementIp_ == 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)

    #test_util.test_logger("wait for 60 seconds")
    #time.sleep(60)

    test_stub.start_host(test_host, test_lib.all_scenario_config)
    test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config)

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

    vm.update()
    if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp != host_ip:
        test_util.test_fail("VM is not expected to start running on another host")

    vm.destroy()

    test_util.test_pass('Test checking vm status after graceful stop and start success')
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")

    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
    test_lib.clean_up_all_vr()
    #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid)
    mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
    #vr_host_ips = []
    #for vr in vrs:
    #    vr_ip = test_lib.lib_find_host_by_vr(vr).managementIp
    #    #ensure mn host has no vr
    #    if vr_ip == mn_ip:
    #        conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip)
    #        host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
    #        vm_ops.migrate_vm(vr.uuid, host_uuid)
    #    vr_host_ips.append(vr_ip)
    #    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', '=', 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()
    vm.check()

    test_stub.ensure_host_has_no_vr(host_uuid)

    if not test_lib.lib_check_vm_live_migration_cap(vm.vm):
        vm.destroy()
        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:
        vm.destroy()
        test_util.test_skip('Skip test on localstorage')

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

    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.down_host_network(host_ip, test_lib.all_scenario_config)
    test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold')

    time.sleep(30)

    #test_stub.up_host_network(host_ip, test_lib.all_scenario_config)
    test_stub.start_host(test_host, test_lib.all_scenario_config)
    test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config,
                                test_lib.deploy_config)

    time.sleep(120)
    cmd = "nohup zstack-ctl start &"
    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    if not test_lib.lib_execute_ssh_cmd(
            mn_ip, host_username, host_password, cmd, timeout=300):
        test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip))

    #test_util.test_logger("wait for 480 seconds")
    #time.sleep(480)

    time.sleep(120)
    cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid)
    if not res_ops.query_resource(res_ops.VM_INSTANCE,
                                  cond)[0].state == "Stopped":
        test_util.test_fail("vm is not stopped as expected.")

    vm.destroy()

    #this is used to design to check mn works normally
    time.sleep(20)
    vm.create()
    vm.check()
    vm.destroy()

    #host_ops.reconnect_host(host_uuid)
    test_util.test_pass(
        'Test checking vm status after force stop and start success')
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', 'AliyunNAS'
    ]
    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
    test_lib.clean_up_all_vr()
    #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()

    vr_hosts = test_stub.get_host_has_vr()
    mn_hosts = test_stub.get_host_has_mn()
    nfs_hosts = test_stub.get_host_has_nfs()
    test_util.test_logger('vr_hosts = %s' % vr_hosts)
    test_util.test_logger('mn_hosts = %s' % mn_hosts)
    test_util.test_logger('nfs_hosts = %s' % nfs_hosts)
    #test_stub.test_skip('debug')
    if not test_stub.ensure_vm_not_on(vm.get_vm().uuid,
                                      vm.get_vm().hostUuid,
                                      vr_hosts + mn_hosts + nfs_hosts):
        test_util.test_fail("Not find out a suitable host")

    vm.update()
    #vm.check()
    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    host_port = test_lib.lib_get_host_port(host_ip)
    test_util.test_logger("host %s is disconnecting" % (host_ip))
    host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")
    test_util.test_logger("force stop host: %s" % (host_ip))
    os.system('bash -ex %s %s' %
              (os.environ.get('hostForceStopScript'), host_ip))
    test_util.test_logger("host is expected to shutdown for a while")

    #     test_util.test_logger("wait for 360 seconds")
    #     time.sleep(360)
    test_util.test_logger("wait for 600 seconds")
    time.sleep(600)
    vm.update()
    if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip:
        test_util.test_fail("VM is expected to start running on another host")
    vm.set_state(vm_header.RUNNING)
    vm.check()

    if test_lib.lib_get_vm_last_host(vm.get_vm()).managementIp != host_ip:
        test_util.test_fail(
            "Migrated VM's last host is expected to be the last host[ip:%s]" %
            (host_ip))


#     vm.destroy()

    os.system('bash -ex %s %s' %
              (os.environ.get('hostRecoverScript'), host_ip))
    host_ops.reconnect_host(host_uuid)
    test_util.test_pass('Test VM ha on host failure Success')
def test():
    global test_obj_dict

    #enable vmware vmotion
    SI = vct_ops.connect_vcenter(os.environ['vcenter'])
    content = SI.RetrieveContent()
    hosts = vct_ops.get_host(content)
    for host in hosts:
        vct_ops.enable_vmotion(host)

    network_pattern = 'L3-%s' % os.environ['dportgroup']
    if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern):
        network_pattern = 'L3-%s' % os.environ['portgroup0']
    ova_image_name = os.environ['vcenterDefaultmplate']
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('largeDiskOfferingName'))

    #create vm
    vm = test_stub.create_vm_in_vcenter(vm_name='migrate_vm',
                                        image_name=ova_image_name,
                                        l3_name=network_pattern)
    vm.check()
    test_obj_dict.add_vm(vm)
    #check whether vm migration candidate hosts exist
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(
        vm.vm.uuid).inventories
    if candidate_hosts == []:
        test_util.test_logger(
            'Not find vm migration candidate hosts, skip test migrate vm')
    else:
        test_util.test_dsc('Migrate vm to the specified host')
        host_uuid = candidate_hosts[0].uuid
        vm_ops.migrate_vm(vm.vm.uuid, host_uuid)
        vm.update()
        vm.check()
        #check whether the specified host is effective
        assert candidate_hosts[0].name == test_lib.lib_find_host_by_vm(
            vm.vm).name
        #check the consistency of the migration in zstack and vmware
        assert candidate_hosts[0].name == vct_ops.find_host_by_vm(
            content, vm.vm.name)
        test_util.test_dsc('vm in suspended state does not allow migration')
        vm.suspend()
        candidate_host = vm_ops.get_vm_migration_candidate_hosts(
            vm.vm.uuid).inventories
        assert candidate_host == []

    #create vm with disk
    vm1 = test_stub.create_vm_in_vcenter(
        vm_name='migrate_vm_with_disk',
        image_name=ova_image_name,
        l3_name=network_pattern,
        disk_offering_uuids=[disk_offering.uuid])
    vm1.check()
    test_obj_dict.add_vm(vm1)
    #check whether vm migration candidate hosts exist
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(
        vm1.vm.uuid).inventories
    if candidate_hosts == []:
        test_util.test_logger(
            'Not find vm migration candidate hosts, skip test migrate vm with disk'
        )
    else:
        test_util.test_dsc('Migrate vm with disk to the specified host')
        host_uuid = candidate_hosts[0].uuid
        vm_ops.migrate_vm(vm1.vm.uuid, host_uuid)
        vm1.update()
        vm1.check()
        assert candidate_hosts[0].name == test_lib.lib_find_host_by_vm(
            vm1.vm).name
        assert candidate_hosts[0].name == vct_ops.find_host_by_vm(
            content, vm1.vm.name)

    #cleanup
    test_lib.lib_error_cleanup(test_obj_dict)

    test_util.test_pass("Migrate vm test passed.")
def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout

    must_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE]
    test_lib.skip_test_if_any_ps_not_deployed(must_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
    test_lib.clean_up_all_vr()
    #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()

    vm_creation_option.set_name('multihost_basic_vm2')
    vm2 = test_vm_header.ZstackTestVm()
    vm2.set_creation_option(vm_creation_option)
    vm2.create()

    vm_creation_option.set_name('multihost_basic_vm3')
    vm3 = test_vm_header.ZstackTestVm()
    vm3.set_creation_option(vm_creation_option)
    vm3.create()

    vr_hosts = test_stub.get_host_has_vr()
    mn_hosts = test_stub.get_host_has_mn()
    nfs_hosts = test_stub.get_host_has_nfs()
    if not test_stub.ensure_vm_not_on(vm.get_vm().uuid,
                                      vm.get_vm().hostUuid,
                                      vr_hosts + mn_hosts + nfs_hosts):
        test_util.test_fail("Not find out a suitable host")
    host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid
    test_stub.ensure_all_vrs_on_host(host_uuid)
    #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid)
    #target_host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid
    #for vr in vrs:
    #    if test_lib.lib_find_host_by_vr(vr).managementIp != test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp:
    #        vm_ops.migrate_vm(vr.uuid, target_host_uuid)

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

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

    test_stub.down_host_network(host_ip, test_lib.all_scenario_config)

    #Here we wait for 180 seconds for all vms have been killed, but test result show:
    #no need to wait, the reaction of killing the vm is very quickly.
    test_util.test_logger("wait for 30 seconds")
    time.sleep(30)

    if test_stub.check_vm_running_on_host(vm.vm.uuid, host_ip):
        test_util.test_fail("VM1 is expected to start running on another host")
    if test_stub.check_vm_running_on_host(vm2.vm.uuid, host_ip):
        test_util.test_fail("VM2 is expected to start running on another host")
    if test_stub.check_vm_running_on_host(vm3.vm.uuid, host_ip):
        test_util.test_fail("VM3 is expected to start running on another host")

    test_stub.up_host_network(host_ip, test_lib.all_scenario_config)
    conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip)
    kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
    host_ops.reconnect_host(kvm_host_uuid)

    vm.set_state(vm_header.RUNNING)
    vm2.set_state(vm_header.RUNNING)
    vm3.set_state(vm_header.RUNNING)
    time.sleep(60)
    vm.check()
    vm2.check()
    vm3.check()
    vm.destroy()
    vm2.destroy()
    vm3.destroy()

    test_util.test_pass('Test VM ha on host failure Success')
def test():
    global vm
    global host_uuid
    global test_host
    global host_ip
    global max_attempts
    global storagechecker_timeout

    must_ps_list = [inventory.LOCAL_STORAGE_TYPE, 'SharedMountPoint']
    test_lib.skip_test_if_any_ps_not_deployed(must_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('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()

    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_ps_uuid(
        res_ops.get_resource(res_ops.PRIMARY_STORAGE,
                             type="SharedMountPoint")[0].uuid)
    vm_creation_option.set_name('vm-smp')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    vm.check()

    vr_hosts = test_stub.get_host_has_vr()
    mn_hosts = test_stub.get_host_has_mn()
    nfs_hosts = test_stub.get_host_has_nfs()
    if not test_stub.ensure_vm_not_on(vm.get_vm().uuid,
                                      vm.get_vm().hostUuid,
                                      vr_hosts + mn_hosts + nfs_hosts):
        test_util.test_fail("Not find out a suitable host")

    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')

    vm.update()
    if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip:
        test_util.test_fail("VM is expected to start running on another host")

    cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid)
    for i in range(0, 300):
        if res_ops.query_resource(res_ops.VM_INSTANCE,
                                  cond)[0].state == "Running":
            break
        time.sleep(1)
    else:
        test_util.test_fail(
            "vm has not been changed to running as expected within 300s.")

    vm.set_state(vm_header.RUNNING)
    vm.check()

    vm.destroy()

    test_util.test_pass(
        'Test checking vm status after graceful stop and start success')
def test():
    global ssh_timeout
    data_volume_size = 10737418240
    disk_offering_option = test_util.DiskOfferingOption()
    disk_offering_option.set_name('root-disk-iso')
    disk_offering_option.set_diskSize(data_volume_size)
    data_volume_offering = vol_ops.create_volume_offering(disk_offering_option)
    test_obj_dict.add_disk_offering(data_volume_offering)

    cpuNum = 1
    memorySize = 536870912
    name = 'vm-offering-iso'
    new_offering_option = test_util.InstanceOfferingOption()
    new_offering_option.set_cpuNum(cpuNum)
    new_offering_option.set_memorySize(memorySize)
    new_offering_option.set_name(name)
    new_offering = vm_ops.create_instance_offering(new_offering_option)
    test_obj_dict.add_instance_offering(new_offering)

    cond = res_ops.gen_query_conditions('name', '=', 'image-iso')
    iso_image = res_ops.query_resource(res_ops.IMAGE, cond)
    if not iso_image:
        img_option = test_util.ImageOption()
        img_option.set_name('image-iso')
        bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid
        img_option.set_backup_storage_uuid_list([bs_uuid])
        img_option.set_url(os.environ.get('imageServer')+'/iso/iso_for_install_vm_test.iso')
        image_inv = img_ops.add_iso_template(img_option)
        image_uuid = image_inv.uuid
        image = test_image.ZstackTestImage()
        image.set_image(image_inv)
        image.set_creation_option(img_option)
        test_obj_dict.add_image(image)
    else:
        image_uuid = iso_image[0].uuid

    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    root_disk_uuid = data_volume_offering.uuid
    vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'vm-iso', root_disk_uuid, new_offering.uuid, system_tags=["cdroms::%s::Empty::Empty" % (image_uuid)])
    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    test_obj_dict.add_vm(vm)
    
    test_util.test_dsc('wait for iso installation')    
    vm_inv = vm.get_vm()
    vm_ip = vm_inv.vmNics[0].ip

    #test_lib.lib_wait_target_up(vm_ip, '22', 2400)
    #vm.check()

    #cmd ='[ -e /root ] && echo yes || echo no' 
    cmd ='[ -e /root ]'
    #ssh_num = 0
    #ssh_ok = 0
    #while ssh_num <= 5 and ssh_ok == 0 :
    #    rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180)
    #    if rsp == False:
    #        time.sleep(30)
    #    else:
    #        ssh_ok = 1
    #        break  
    #    ssh_num = ssh_num + 1

    #if ssh_ok == 0:
    #    test_util.test_fail('fail to ssh to VM')
    ssh_timeout = test_lib.SSH_TIMEOUT
    test_lib.SSH_TIMEOUT = 3600
    test_lib.lib_set_vm_host_l2_ip(vm_inv)
    if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd):
        test_lib.SSH_TIMEOUT = ssh_timeout
        test_util.test_fail("iso has not been failed to installed.")

    cmd_cdrom = 'ls /dev/ | grep sr | wc -l'
    cdroms = test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd_cdrom)
    assert str(cdroms).strip() == '3'

    test_lib.SSH_TIMEOUT = ssh_timeout
    vm.destroy()
    test_obj_dict.rm_vm(vm)

#     image.delete()
#     test_obj_dict.rm_image(image)

    vol_ops.delete_disk_offering(root_disk_uuid)
    test_obj_dict.rm_disk_offering(data_volume_offering)

    vm_ops.delete_instance_offering(new_offering.uuid)
    test_obj_dict.rm_instance_offering(new_offering)

    test_util.test_pass('Create VM with ISO Installation Test Success')
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")

    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')

    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    cmd = "ifconfig %s down && sleep 180 && ifconfig %s up" % (
        l2_network_interface, l2_network_interface)
    rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password,
                                       cmd, 180)
    if rsp:
        test_util.test_fail(
            "host is expected to shutdown after its network down for a while")
    else:
        test_util.test_logger("host may have been shutdown")

    cmd = "date"
    rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password,
                                       cmd)
    if rsp:
        test_util.test_fail(
            "host is expected to shutdown after its network down for a while")
    else:
        test_util.test_logger("host have been shutdown")

    try:
        vm.destroy()
    except:
        test_util.test_logger("destroy vm may time out since host is down")

    test_lib.lib_set_ha_selffencer_maxattempts(max_attempts)
    test_lib.lib_set_ha_selffencer_storagechecker_timeout(
        storagechecker_timeout)
    os.system('bash -ex %s %s' %
              (os.environ.get('hostRecoverScript'), host_ip))
    host_ops.reconnect_host(host_uuid)

    test_util.test_pass('Test Host Self fence Success')
Exemple #39
0
def test():
    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \
            None, fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    image_option = test_util.ImageOption()
    image_option.set_name('test_image_cache_cleanup')
    image_option.set_format('qcow2')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_url(os.environ.get('imageUrl_s'))
    image_option.set_backup_storage_uuid_list([bss[0].uuid])

    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)

    new_image.add_root_volume_template()

    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid

    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)
    host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
    vm_creation_option = test_util.VmOption()
    vm_creation_option.set_host_uuid(host_uuid)
    vm_creation_option.set_l3_uuids([l3_net_uuid])
    vm_creation_option.set_image_uuid(new_image.image.uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('test_image_cache_cleanup_vm1')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()

    test_obj_dict.add_vm(vm)
    vm.check()
    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())

    vm.destroy()
    vm.expunge()

    conditions = res_ops.gen_query_conditions('state', '=', 'Enabled')
    conditions = res_ops.gen_query_conditions('status', '=', 'Connected',
                                              conditions)
    conditions = res_ops.gen_query_conditions('uuid', '!=', host.uuid,
                                              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_name('test_image_cache_cleanup_vm2')
    vm2 = test_vm_header.ZstackTestVm()
    vm2.set_creation_option(vm_creation_option)
    vm2.create()
    host2 = test_lib.lib_find_host_by_vm(vm2.get_vm())
    test_obj_dict.add_vm(vm2)
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume1 = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume1)
    volume1.attach(vm2)

    if ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
        test_util.test_skip(
            'ceph is not directly using image cache, skip test.')

    image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath,
                                                      new_image.image.uuid)
    if not test_lib.lib_check_file_exist(host, image_cache_path):
        test_util.test_fail('image cache is expected to exist')
    if bss[0].type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
        image_cache_path = "%s/zstore-cache/%s" % (ps.mountPath,
                                                   new_image.image.uuid)
        if not test_lib.lib_check_file_exist(host, image_cache_path):
            test_util.test_fail('image cache is expected to exist')

    new_image.delete()
    new_image.expunge()

    ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid)
    if ps.type == inventory.LOCAL_STORAGE_TYPE:
        count = 0
        while True:
            image_cache_path = "%s/imagecache/template/%s/%s.qcow2" % (
                ps.mountPath, new_image.image.uuid, new_image.image.uuid)
            if not test_lib.lib_check_file_exist(host, image_cache_path):
                break
            elif count > 5:
                test_util.test_fail('image cache is expected to be deleted')
            test_util.test_logger('check %s times: image cache still exist' %
                                  (count))
            time.sleep(5)
            count += 1

    vm2.destroy()
    vm2.expunge()
    ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid)

    count = 0
    while True:
        image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath,
                                                          new_image.image.uuid)
        if not test_lib.lib_check_file_exist(host, image_cache_path):
            break
        elif count > 5:
            test_util.test_fail('image cache is expected to be deleted')
        test_util.test_logger('check %s times: image cache still exist' %
                              (count))
        time.sleep(5)
        count += 1

    count = 0
    while True:
        image_cache_path = "%s/zstore-cache/%s" % (ps.mountPath,
                                                   new_image.image.uuid)
        if not test_lib.lib_check_file_exist(host, image_cache_path):
            break
        elif count > 5:
            test_util.test_fail('image cache is expected to be deleted')
        test_util.test_logger('check %s times: image cache still exist' %
                              (count))
        time.sleep(5)
        count += 1

    test_util.test_pass('imagecache cleanup Pass.')
Exemple #40
0
def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout

    must_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE]
    test_lib.skip_test_if_any_ps_not_deployed(must_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
    test_lib.clean_up_all_vr()
    #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)
    #    break
    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()

    vr_hosts = test_stub.get_host_has_vr()
    mn_hosts = test_stub.get_host_has_mn()
    nfs_hosts = test_stub.get_host_has_nfs()
    if not test_stub.ensure_vm_not_on(vm.get_vm().uuid,
                                      vm.get_vm().hostUuid,
                                      vr_hosts + mn_hosts + nfs_hosts):
        test_util.test_fail("Not find out a suitable host")
    host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid
    test_stub.ensure_all_vrs_on_host(host_uuid)
    #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid)
    #target_host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid
    #for vr in vrs:
    #    if test_lib.lib_find_host_by_vr(vr).managementIp != test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp:
    #        vm_ops.migrate_vm(vr.uuid, target_host_uuid)

    #vm.check()
    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    host_port = test_lib.lib_get_host_port(host_ip)
    test_util.test_logger("host %s is disconnecting" % (host_ip))
    host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")
    #    l2_network_interface = os.environ.get('l2ManagementNetworkInterface')
    #l2interface = test_lib.lib_get_l2s_by_vm(vm.get_vm())[0].physicalInterface
    l2_network_interface = test_stub.get_host_l2_nic_name("br_eth0")
    cmd = "ifconfig %s down && sleep 360 && ifconfig %s up" % (
        l2_network_interface, l2_network_interface)
    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password,
                                       cmd, 360)
    if not rsp:
        test_util.test_logger(
            "host is expected to shutdown after its network down for a while")

    #test_util.test_logger("wait for 600 seconds")
    test_util.test_logger("wait for 180 seconds")
    time.sleep(180)
    vm.update()
    if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip:
        test_util.test_fail("VM is expected to start running on another host")
    vm.set_state(vm_header.RUNNING)
    vm.check()
    vm.destroy()

    cmd = 'PORT=%s bash -ex %s %s' % (
        host_port, os.environ.get('hostRecoverScript'), host_ip)
    test_util.test_logger(cmd)
    os.system(cmd)
    host_ops.reconnect_host(host_uuid)
    test_util.test_pass('Test VM ha on host failure Success')
def test():
    global default_snapshot_depth

    vm1 = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm1)
    
    #this test will rely on live snapshot capability supporting
    host_inv = test_lib.lib_find_host_by_vm(vm1.get_vm())

    if not test_lib.lib_check_live_snapshot_cap(host_inv):
        vm1.destroy()
        test_obj_dict.rm_vm(vm1)
        test_util.test_skip('Skip test, since [host:] %s does not support live snapshot.')

    test_util.test_dsc('Create test vm as utility vm')
    default_snapshot_depth = conf_ops.change_global_config('volumeSnapshot', \
            'incrementalSnapshot.maxNum', test_depth)

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

    test_util.test_dsc('Create volume for snapshot testing')
    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 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)
    vm.check()

    #volume doesn't need to be attached. It is because when create snapshot, 
    # the volume will be attached to utiltiy vm, who will add the volume.
    #snapshots = zstack_sp_header.ZstackVolumeSnapshot()
    #snapshots.set_target_volume(volume)
    #test_obj_dict.add_volume_snapshot(snapshots)
    snapshots = test_obj_dict.get_volume_snapshot(volume.get_volume().uuid)
    snapshots.set_utility_vm(vm)

    test_util.test_dsc('1. create 5 snapshots and check')
    num = 1
    while num < 6:
        snapshots.create_snapshot('sp %s' % str(num))
        num += 1

    snapshots.check()
    snapshot1 = snapshots.get_snapshot_head()
    snapshots.use_snapshot(snapshot1)

    test_util.test_dsc('1. create 5 new snapshots and check')
    num = 1
    while num < 6:
        snapshots.create_snapshot('sp 1.%s' % str(num))
        num += 1

    snapshots.check()
    snapshot1_3 = snapshots.get_current_snapshot().get_parent().get_parent()
    snapshot1_1 = snapshot1_3.get_parent().get_parent()

    snapshots.use_snapshot(snapshot1_3)
    test_util.test_dsc('1. create 5 new snapshots and check')
    num = 1
    while num < 6:
        snapshots.create_snapshot('sp 1.3.%s' % str(num))
        num += 1

    snapshots.check()
    snapshot1_3_2 = snapshots.get_current_snapshot().get_parent().get_parent().get_parent()

    snapshots.use_snapshot(snapshot1_3_2)
    test_util.test_dsc('1. create 5 new snapshots and check')
    num = 1
    while num < 6:
        snapshots.create_snapshot('sp 1.3.2.%s' % str(num))
        num += 1

    snapshots.check()
    snapshot1_3_2_1 = snapshots.get_current_snapshot().get_parent().get_parent().get_parent().get_parent()

    snapshots.use_snapshot(snapshot1_3_2_1)
    test_util.test_dsc('1. create 5 new snapshots and check')
    num = 1
    while num < 6:
        snapshots.create_snapshot('sp 1.3.2.1.%s' % str(num))
        num += 1

    snapshots.check()

    snapshots.use_snapshot(snapshot1_1)
    snapshots.create_snapshot('sp 1.1.1')
    snapshot1_1_1 = snapshots.get_current_snapshot()
    num = 2
    while num < 6:
        snapshots.create_snapshot('sp 1.1.%s' % str(num))
        num += 1

    snapshots.check()

    snapshots.use_snapshot(snapshot1_1_1)
    snapshots.create_snapshot('sp 1.1.1.1')
    snapshot1_1_1_1 = snapshots.get_current_snapshot()
    num = 2
    while num < 6:
        snapshots.create_snapshot('sp 1.1.1.%s' % str(num))
        num += 1

    snapshots.check()

    snapshots.use_snapshot(snapshot1_1_1_1)
    snapshots.create_snapshot('sp 1.1.1.1.1')
    snapshot1_1_1_1_1 = snapshots.get_current_snapshot()
    num = 2
    while num < 6:
        snapshots.create_snapshot('sp 1.1.1.1.%s' % str(num))
        num += 1

    snapshots.check()

    snapshots.delete()
    test_obj_dict.rm_volume_snapshot(snapshots)
    volume.check()
    volume.delete()

    test_obj_dict.rm_volume(volume)
    vm.destroy()
    conf_ops.change_global_config('volumeSnapshot', \
            'incrementalSnapshot.maxNum', default_snapshot_depth)
    test_util.test_pass('Create Snapshots with change max sp depth test Success')
def test():
    global image
    global test_obj_dict
    allow_bs_list = [
        inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE,
        inventory.CEPH_BACKUP_STORAGE_TYPE
    ]
    test_lib.skip_test_when_bs_type_not_in_list(allow_bs_list)

    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)

    #run condition
    hosts = res_ops.query_resource(res_ops.HOST)
    if len(hosts) <= 1:
        test_util.test_skip(
            "skip for host_num is not satisfy condition host_num>1")

    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])

    #create disk offering
    data_volume_size = 10737418240
    disk_offering_option = test_util.DiskOfferingOption()
    disk_offering_option.set_name('root-disk-iso')
    disk_offering_option.set_diskSize(data_volume_size)
    data_volume_offering = vol_ops.create_volume_offering(disk_offering_option)
    test_obj_dict.add_disk_offering(data_volume_offering)

    #create instance offering
    cpuNum = 2
    memorySize = 1024 * 1024 * 1024
    name = 'iso-vm-offering'
    new_offering_option = test_util.InstanceOfferingOption()
    new_offering_option.set_cpuNum(cpuNum)
    new_offering_option.set_memorySize(memorySize)
    new_offering_option.set_name(name)
    new_offering = vm_ops.create_instance_offering(new_offering_option)
    test_obj_dict.add_instance_offering(new_offering)

    #add iso
    img_option = test_util.ImageOption()
    img_option.set_name('iso1')
    bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [],
                                            None)[0].uuid
    img_option.set_backup_storage_uuid_list([bs_uuid])
    img_option.set_url(os.environ.get('isoForVmUrl'))
    image_inv = img_ops.add_iso_template(img_option)
    image_uuid = image_inv.uuid
    image = test_image.ZstackTestImage()
    image.set_image(image_inv)
    image.set_creation_option(img_option)
    test_obj_dict.add_image(image)

    #create vm by iso
    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    root_disk_uuid = data_volume_offering.uuid
    vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'iso-vm',
                                      root_disk_uuid, new_offering.uuid)
    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    test_obj_dict.add_vm(vm)

    #check vm
    vm_inv = vm.get_vm()
    vm_ip = vm_inv.vmNics[0].ip

    #cmd ='[ -e /root ]'
    #ssh_timeout = test_lib.SSH_TIMEOUT
    #test_lib.SSH_TIMEOUT = 3600
    test_lib.lib_set_vm_host_l2_ip(vm_inv)
    test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800)
    #if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd):
    #    test_lib.SSH_TIMEOUT = ssh_timeout
    #    test_util.test_fail("iso has been failed to installed.")

    #test_lib.SSH_TIMEOUT = ssh_timeout

    #clone vm
    cloned_vm_name = ['cloned_vm_name']
    cloned_vm_obj = vm.clone(cloned_vm_name)[0]
    test_obj_dict.add_vm(cloned_vm_obj)

    #delete iso
    image.delete()
    test_obj_dict.rm_image(image)

    #vm ops test
    test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ALL")

    #expunge iso
    image.expunge()

    #detach iso
    img_ops.detach_iso(vm.vm.uuid)

    #vm ops test
    test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ALL")

    #create image by vm root volume
    cloned_vm_img_name = "cloned_vm_image1"
    img_option2 = test_util.ImageOption()
    img_option2.set_backup_storage_uuid_list([bs_uuid])
    img_option2.set_root_volume_uuid(cloned_vm_obj.vm.rootVolumeUuid)
    img_option2.set_name(cloned_vm_img_name)
    image1 = test_image.ZstackTestImage()
    image1.set_creation_option(img_option2)
    image1.create()
    image1.check()
    test_obj_dict.add_image(image1)

    bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE)
    if inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE == bs_list[0] and len(
            bs_list) == 1:
        #export image
        image1.export()

    #create vm
    vm2 = test_stub.create_vm('image-vm', cloned_vm_img_name, l3_name)

    #delete image
    image1.delete()
    test_obj_dict.rm_image(image1)

    #vm ops test
    test_stub.vm_ops_test(vm2, "VM_TEST_ALL")

    #expunge image
    image1.expunge()

    #vm ops test
    test_stub.vm_ops_test(vm2, "VM_TEST_ALL")

    vm.destroy()
    vm2.destroy()
    cloned_vm_obj.destroy()

    vol_ops.delete_disk_offering(root_disk_uuid)
    vm_ops.delete_instance_offering(new_offering.uuid)
    test_obj_dict.rm_vm(vm)
    test_obj_dict.rm_disk_offering(data_volume_offering)
    test_obj_dict.rm_instance_offering(new_offering)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create VM Image in Image Store Success')
Exemple #43
0
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('3')
    storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout(
    )
    test_lib.lib_set_ha_selffencer_storagechecker_timeout('5')

    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()
    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')

    #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, "NeverStop")
    l2_network_interface = os.environ.get('l2ManagementNetworkInterface')
    cmd = "ifdown %s && sleep 180 && ifup %s" % (l2_network_interface,
                                                 l2_network_interface)
    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password,
                                       cmd, 180)
    if not rsp:
        test_util.test_logger(
            "host is expected to shutdown after its network down for a while")

    test_util.test_logger("wait for 600 seconds")
    time.sleep(600)
    vm.update()
    if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip:
        test_util.test_fail("VM is expected to start running on another host")
    vm.set_state(vm_header.RUNNING)
    vm.check()
    vm.destroy()
    test_lib.lib_set_ha_selffencer_maxattempts(max_attempts)
    test_lib.lib_set_ha_selffencer_storagechecker_timeout(
        storagechecker_timeout)

    os.system('bash -ex %s %s' %
              (os.environ.get('hostRecoverScript'), host_ip))
    host_ops.reconnect_host(host_uuid)
    test_util.test_pass('Test VM ha on host failure Success')
Exemple #44
0
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)
    test_lib.clean_up_all_vr()
    mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
    #vr_host_ips = []
    #for vr in vrs:
    #    vr_ip = test_lib.lib_find_host_by_vr(vr).managementIp
    #    #ensure mn host has no vr
    #    if vr_ip == mn_ip:
    #        conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip)
    #        host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
    #        vm_ops.migrate_vm(vr.uuid, host_uuid)
    #    vr_host_ips.append(vr_ip)
    #    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', '=', 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_status_runnning')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    vm.check()

    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_port = test_lib.lib_get_host_port(host_ip)
    test_util.test_logger("host %s is disconnecting" % (host_ip))

    test_stub.down_host_network(host_ip, test_lib.all_scenario_config)
    test_util.test_logger("wait for 30 seconds")
    time.sleep(30)
    test_stub.up_host_network(host_ip, test_lib.all_scenario_config)

    time.sleep(120)

    cmd = "nohup zstack-ctl start &"
    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    if not test_lib.lib_execute_ssh_cmd(
            mn_ip, host_username, host_password, cmd, timeout=300):
        test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip))

    time.sleep(120)
    cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid)
    if not res_ops.query_resource(res_ops.VM_INSTANCE,
                                  cond)[0].state == "Running":
        test_util.test_fail("vm is not stopped as expected.")

    vm.destroy()

    #check mn service works normally
    time.sleep(20)
    vm.create()
    vm.check()
    vm.destroy()

    test_util.test_pass(
        'Test vm checking status after network disconnect and connect success')
def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout

    allow_ps_list = [inventory.LOCAL_STORAGE_TYPE]
    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('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()
    #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('ls_vm_ha_self_start')
    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
    test_util.test_logger("host %s is disconnecting" %(host_ip))

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

    test_stub.down_host_network(host_ip, test_lib.all_scenario_config)

    #test_util.test_logger("wait for 300 seconds")
    #time.sleep(300)
    vm_stop_time = None
    cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_ha_self_start')
    cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond)
    for i in range(0, 300):
        vm_stop_time = i
        if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown":
            test_stub.up_host_network(host_ip, test_lib.all_scenario_config)
            break
        time.sleep(1)
    if vm_stop_time is None:
        vm_stop_time = 300 
    for i in range(vm_stop_time, 300):
        if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running":
            break
        time.sleep(1)
    else:
        test_util.test_fail("vm has not been changed to running as expected within 300s.")

    vm.destroy()

    test_util.test_pass('Test checking VM ha self-start after host is disconnect and recover Success')
def test():
    global vm
    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \
            None, fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    image_option = test_util.ImageOption()
    image_option.set_name('test_image_cache_cleanup')
    image_option.set_format('qcow2')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_url(os.environ.get('imageUrl_s'))
    image_option.set_backup_storage_uuid_list([bss[0].uuid])

    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)

    new_image.add_root_volume_template()

    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid

    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)
    host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
    vm_creation_option = test_util.VmOption()
    vm_creation_option.set_host_uuid(host_uuid)
    vm_creation_option.set_l3_uuids([l3_net_uuid])
    vm_creation_option.set_image_uuid(new_image.image.uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('test_image_cache_cleanup_vm1')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    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 non-localstorage')

    test_obj_dict.add_vm(vm)
    vm.check()
    host = test_lib.lib_find_host_by_vm(vm.get_vm())
    target_host = test_lib.lib_find_random_host(vm.vm)
    vm.stop()
    vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid)
    vm.check()
    vm.start()
    vm.check()

    new_image.delete()
    new_image.expunge()
    ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid)
    if ps.type == inventory.LOCAL_STORAGE_TYPE:
        image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath,
                                                          new_image.image.uuid)
        if test_lib.lib_check_file_exist(host, image_cache_path):
            test_util.test_fail('image cache is expected to be deleted')
#    elif ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE:
#    elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
#    elif ps.type == 'SharedMountPoint':

    vm.destroy()
    test_util.test_pass('Migrate VM Test Success')
def test():
    global vm
    global host_uuid
    global test_host
    global host_ip
    global max_attempts
    global storagechecker_timeout

    allow_ps_list = [inventory.LOCAL_STORAGE_TYPE]
    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
    l3_name2 = os.environ.get('l3VlanNetwork2')
    l3_net_uuid2 = test_lib.lib_get_l3_by_name(l3_name2).uuid
    test_lib.clean_up_all_vr()
    #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, l3_net_uuid2])
    vm_creation_option.set_default_l3_uuid(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_port = test_lib.lib_get_host_port(host_ip)
    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))

    cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid)
    vm_inv = res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0]

    test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold')
    test_util.test_logger("wait for 120 seconds")
    time.sleep(120)
    test_stub.start_host(test_host, test_lib.all_scenario_config)
    test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config)

    for i in range(0, 120):
        if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running":
            break
        time.sleep(1)
    else:
        test_util.test_fail("vm has not been changed to running as expected within %s s." %(240))

    vm.destroy()

    test_util.test_pass('Test VM ha with multiple networks disconnect host Success')
Exemple #48
0
def test():
    global vm
    global host_uuid
    global test_host
    global host_ip
    global max_attempts
    global storagechecker_timeout

    allow_ps_list = [inventory.LOCAL_STORAGE_TYPE]
    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('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()
    #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('ls_vm_none_status')
    vm2 = test_vm_header.ZstackTestVm()
    vm2.set_creation_option(vm_creation_option)
    vm2.create()

    test_stub.ensure_host_has_no_vr(host_uuid)

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

    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')

    cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_none_status')
    cond = res_ops.gen_query_conditions('uuid', '=', vm2.vm.uuid, cond)

    vm_stop_time = None
    for i in range(0, 180):
        if res_ops.query_resource(res_ops.VM_INSTANCE,
                                  cond)[0].state == "Unknown":
            vm_stop_time = i
            test_stub.start_host(test_host, test_lib.all_scenario_config)
            test_stub.recover_host_vlan(test_host,
                                        test_lib.all_scenario_config,
                                        test_lib.deploy_config)
            break
        time.sleep(1)

    if not vm_stop_time:
        vm_stop_time = 180

    for i in range(vm_stop_time, 180):
        if res_ops.query_resource(res_ops.VM_INSTANCE,
                                  cond)[0].state == "Stopped":
            break
        time.sleep(1)
    else:
        test_util.test_fail(
            "vm none is not change to Stopped as expected within 180s.")

    test_util.test_pass(
        'Test checking vm none status when host has been force stop Success.')
def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout

    allow_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE]
    test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)

    test_stub.skip_if_not_storage_network_separate(test_lib.all_scenario_config)

    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('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()

    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()
    vm.check()

    vr_hosts = test_stub.get_host_has_vr()
    mn_hosts = test_stub.get_host_has_mn()
    nfs_hosts = test_stub.get_host_has_nfs()
    if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts):
        test_util.test_fail("Not find out a suitable host")
    host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid
    test_stub.ensure_all_vrs_on_host(host_uuid)


    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    host_port = test_lib.lib_get_host_port(host_ip)
    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)
    test_stub.check_if_vm_starting_incorrectly_on_original_host(vm.get_vm().uuid, host_uuid, max_count=180)

    test_stub.start_host(test_host, test_lib.all_scenario_config)
    test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config)
    conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip)
    kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
    host_ops.reconnect_host(kvm_host_uuid)

    vm.set_state(vm_header.RUNNING)
    vm.check()

    vm.update()
    if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip:
        test_util.test_fail("VM is expected to start running on another host")

    vm.destroy()

    test_util.test_pass('Test checking vm status after graceful stop and start success')
def test():
    global vm
    global host_uuid
    global test_host
    global host_ip
    global max_attempts
    global storagechecker_timeout

    must_ps_list = [inventory.LOCAL_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE]
    test_lib.skip_test_if_any_ps_not_deployed(must_ps_list)

    test_lib.lib_cur_env_is_not_scenario()

    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('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()

    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('ls_vm_ha_self_start')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()

    vr_hosts = test_stub.get_host_has_vr()
    mn_hosts = test_stub.get_host_has_mn()
    nfs_hosts = test_stub.get_host_has_nfs()
    if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts):
        test_util.test_fail("Not find out a suitable host")

    #vm.check()
    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")

    test_stub.stop_ha_vm(vm.get_vm().uuid)
    vm.set_state(vm_header.STOPPED)
    vm.check()
    vm.start()
    vm.check()

    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 or host.managementIp_ == 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')

    vm_stop_time = None
    cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_ha_self_start')
    cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond)
    for i in range(0, 300):
        vm_stop_time = i
        if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped":
            test_stub.start_host(test_host, test_lib.all_scenario_config)
            test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config)
            conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip)
            kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
            host_ops.reconnect_host(kvm_host_uuid)
            break
        time.sleep(1)
    if vm_stop_time is None:
        vm_stop_time = 300
    for i in range(vm_stop_time, 300):
        if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Starting":
            break
        time.sleep(1)
    else:
        test_util.test_fail("vm has not been changed to running as expected within 300s.")


    vm.destroy()

    test_util.test_pass('Test checking VM ha and none status when force stop vm Success.')
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
    test_lib.clean_up_all_vr()
    #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_status_runnning')
    vm = test_vm_header.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    vm.check()

    vm_creation_option.set_name('multihost_basic_vm_status_stopped')
    vm2 = test_vm_header.ZstackTestVm()
    vm2.set_creation_option(vm_creation_option)
    vm2.create()
    vm2.stop()
    vm2.check()

    test_stub.ensure_host_has_no_vr(host_uuid)

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

    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 60 seconds")
    time.sleep(60)

    test_stub.start_host(test_host, test_lib.all_scenario_config)
    test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config)

    vm.set_state(vm_header.STOPPED)
    vm2.set_state(vm_header.STOPPED)
    vm.check()
    vm2.check()
    vm.destroy()
    vm2.destroy()

    #host_ops.reconnect_host(host_uuid)
    test_util.test_pass('Test checking vm status after force stop and start success')
def test():
    test_util.test_dsc('Create test vm as utility vm')
    vm1 = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm1)
    #this test will rely on live snapshot capability supporting
    host_inv = test_lib.lib_find_host_by_vm(vm1.get_vm())

    if not test_lib.lib_check_live_snapshot_cap(host_inv):
        vm1.destroy()
        test_obj_dict.rm_vm(vm1)
        test_util.test_skip('Skip test, since [host:] %s does not support live snapshot.' % host_inv.uuid)

    libvirt_ver = test_lib.lib_get_host_libvirt_tag(host_inv)
    if not libvirt_ver or StrictVersion(libvirt_ver) < StrictVersion('1.2.7'):
        vm1.destroy()
        test_obj_dict.rm_vm(vm1)
        test_util.test_skip("Skip test, since [host:] %s libvert version: %s is lower than 1.2.7, which doesn't support live merge, when doing snapshot deleting." % (host_inv.uuid, libvirt_ver))

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

    test_util.test_dsc('Create volume for snapshot testing')
    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 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)
    #make sure utility vm is starting and running
    vm.check()

    volume.attach(vm1)

    test_util.test_dsc('create snapshot and check')
    #snapshots = zstack_sp_header.ZstackVolumeSnapshot()
    #snapshots.set_target_volume(volume)
    #test_obj_dict.add_volume_snapshot(snapshots)
    snapshots = test_obj_dict.get_volume_snapshot(volume.get_volume().uuid)
    snapshots.set_utility_vm(vm)
    snapshots.create_snapshot('create_snapshot1')
    snapshots.check()

    snapshot1 = snapshots.get_current_snapshot()
    snapshots.create_snapshot('create_snapshot2')
    snapshots.check()
    snapshots.create_snapshot('create_snapshot3')
    snapshots.check()
    snapshot3 = snapshots.get_current_snapshot()

    #even with live snapshot function, the revert need stop vm.
    vm1.stop()    
    snapshots.use_snapshot(snapshot1)
    vm1.start()
    snapshots.create_snapshot('create_snapshot1.1.1')
    snapshots.check()
    snapshots.create_snapshot('create_snapshot1.1.2')
    snapshots.check()

    vm1.stop()
    snapshots.use_snapshot(snapshot1)
    vm1.start()
    snapshots.create_snapshot('create_snapshot1.2.1')
    snapshots.check()
    snapshot1_2_1 = snapshots.get_current_snapshot()
    snapshots.create_snapshot('create_snapshot1.2.2')
    snapshots.check()

    vm1.stop()
    snapshots.use_snapshot(snapshot3)
    snapshots.check()
    snapshots.create_snapshot('create_snapshot4')
    snapshots.check()
    #delay start vm
    vm1.start()

    test_util.test_dsc('Delete snapshot, volume and check')
    snapshots.delete_snapshot(snapshot3)
    snapshots.check()

    snapshots.delete_snapshot(snapshot1_2_1)
    snapshots.check()

    snapshots.delete()
    test_obj_dict.rm_volume_snapshot(snapshots)
    volume.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create Snapshot test Success')
Exemple #53
0
def test():
    global image
    global test_obj_dict

    #run condition
    hosts = res_ops.query_resource(res_ops.HOST)
    if len(hosts) <= 1:
        test_util.test_skip("skip for host_num is not satisfy condition host_num>1")

    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])

    #create disk offering
    data_volume_size = 10737418240
    disk_offering_option = test_util.DiskOfferingOption()
    disk_offering_option.set_name('root-disk-iso')
    disk_offering_option.set_diskSize(data_volume_size)
    data_volume_offering = vol_ops.create_volume_offering(disk_offering_option)
    test_obj_dict.add_disk_offering(data_volume_offering)

    #create instance offering
    cpuNum = 2
    memorySize = 2147483648
    name = 'iso-vm-offering'
    new_offering_option = test_util.InstanceOfferingOption()
    new_offering_option.set_cpuNum(cpuNum)
    new_offering_option.set_memorySize(memorySize)
    new_offering_option.set_name(name)
    new_offering = vm_ops.create_instance_offering(new_offering_option)
    test_obj_dict.add_instance_offering(new_offering)

    #add iso
    img_option = test_util.ImageOption()
    img_option.set_name('iso1')
    bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid
    img_option.set_backup_storage_uuid_list([bs_uuid])
    img_option.set_url('http://172.20.1.15:7480/iso/CentOS-x86_64-7.2-Minimal.iso')
    image_inv = img_ops.add_iso_template(img_option)
    image_uuid = image_inv.uuid
    image = test_image.ZstackTestImage()
    image.set_image(image_inv)
    image.set_creation_option(img_option)
    test_obj_dict.add_image(image)

    #create vm by iso
    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    root_disk_uuid = data_volume_offering.uuid
    vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'iso-vm', root_disk_uuid, new_offering.uuid)
    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    test_obj_dict.add_vm(vm)
    
    #check vm
    vm_inv = vm.get_vm()
    vm_ip = vm_inv.vmNics[0].ip

    #cmd ='[ -e /root ]'
    #ssh_timeout = test_lib.SSH_TIMEOUT
    #test_lib.SSH_TIMEOUT = 3600
    test_lib.lib_set_vm_host_l2_ip(vm_inv)
    test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800)
    #if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd):
    #    test_lib.SSH_TIMEOUT = ssh_timeout
    #    test_util.test_fail("iso has been failed to installed.")

    #test_lib.SSH_TIMEOUT = ssh_timeout

    #delete iso
    image.delete()
    test_obj_dict.rm_image(image)

    #expunge iso
    image.expunge()

    #detach iso
    img_ops.detach_iso(vm.vm.uuid)

    #vm ops test
    test_stub.vm_ops_test(vm, "VM_TEST_ATTACH")

    vm.destroy()
    vol_ops.delete_disk_offering(root_disk_uuid)
    vm_ops.delete_instance_offering(new_offering.uuid)
    test_obj_dict.rm_vm(vm)
    test_obj_dict.rm_disk_offering(data_volume_offering)
    test_obj_dict.rm_instance_offering(new_offering)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create VM Image in Image Store Success')
def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout

    allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE]
    test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)

    test_stub.skip_if_not_storage_network_separate(
        test_lib.all_scenario_config)

    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('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()

    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()

    vr_hosts = test_stub.get_host_has_vr()
    mn_hosts = test_stub.get_host_has_mn()
    if not test_stub.ensure_vm_not_on(vm.get_vm().uuid,
                                      vm.get_vm().hostUuid,
                                      vr_hosts + mn_hosts):
        test_util.test_fail("Not find out a suitable host")

    #vm.check()
    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")

    #test_stub.down_host_network(host_ip, test_lib.all_scenario_config)
    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    t = test_stub.async_exec_ifconfig_nic_down_up(180, host_ip, host_username,
                                                  host_password, "zsn1")

    time.sleep(180)

    vm.update()
    if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip:
        test_util.test_fail("VM is expected to start running on another host")
    vm.set_state(vm_header.RUNNING)
    vm.check()

    if test_lib.lib_get_vm_last_host(vm.get_vm()).managementIp != host_ip:
        test_util.test_fail(
            "Migrated VM's last host is expected to be the last host[ip:%s]" %
            (host_ip))

    vm.destroy()

    t.join()

    test_util.test_pass('Test VM ha change to running within 180s Success')
def test():
    global vm
    global host_uuid
    global host_ip
    global max_attempts
    global storagechecker_timeout
  
    test_lib.lib_skip_if_ps_num_is_not_eq_number(1)
    allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint', 'AliyunNAS', inventory.FUSIONSTOR_PRIMARY_STORAGE_TYPE]
    test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)

    test_lib.lib_cur_env_is_not_scenario()

    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('l3VlanNetworkName1')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    test_lib.clean_up_all_vr()

    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()
    vm.check()

    test_stub.ensure_host_has_no_vr(host_uuid)

    host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
    host_port = test_lib.lib_get_host_port(host_ip)
    test_util.test_logger("host %s is disconnecting" %(host_ip))
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")

    for i in range(10):
        test_stub.stop_ha_vm(vm.get_vm().uuid)
        vm.set_state(vm_header.STOPPED)
        vm.check()
        vm.start()
        vm.check()

    #vm ha natural feature:
    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 or hasattr(host, 'managementIp_') and host.managementIp_ == 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)

    #test_util.test_logger("wait for 60 seconds")
    #time.sleep(60)

    test_stub.start_host(test_host, test_lib.all_scenario_config)
    test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config)

    vm.set_state(vm_header.RUNNING)
    vm.check()

    vm.update()
    if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip:
        test_util.test_fail("VM is expected to start running on another host")

    vm.destroy()

    test_util.test_pass('Test checking vm status after graceful stop and start success')
Exemple #56
0
 def migrate_to_random_host(self, timeout = None, session_uuid = None):
     host_uuid = random.choice([host.uuid for host in res_ops.get_resource(res_ops.HOST)
                                                   if host.uuid != test_lib.lib_find_host_by_vm(self.inv).uuid])
     self.inv = vm_ops.migrate_vm(self.inv.uuid, host_uuid, timeout, session_uuid)
     super(ZstackTestVR, self).migrate(host_uuid)