def migrate(vm_obj):
    ps = test_lib.lib_get_primary_storage_by_vm(vm_obj.get_vm())
    if vm_obj.vm.state == "Running" and ps.type in [inventory.CEPH_PRIMARY_STORAGE_TYPE, 'SharedMountPoint', inventory.NFS_PRIMARY_STORAGE_TYPE,
                   'SharedBlock', inventory.LOCAL_STORAGE_TYPE]:
        target_host = test_lib.lib_find_random_host(vm_obj.vm)
        vm_obj.migrate(target_host.uuid)
    elif ps.type in [inventory.LOCAL_STORAGE_TYPE]:
        vm_obj.check()
        target_host = test_lib.lib_find_random_host(vm_obj.vm)
        vol_ops.migrate_volume(vm_obj.get_vm().allVolumes[0].uuid, target_host.uuid)
        vm_obj.start()
        test_lib.lib_wait_target_up(vm_obj.get_vm().vmNics[0].ip, 22, 300)
    else:
        test_util.test_fail("FOUND NEW STORAGTE TYPE. FAILED")
Exemplo n.º 2
0
def test():
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    global agent_url
    global vm
    imagestore = test_lib.lib_get_image_store_backup_storage()
    if imagestore == None:
        test_util.test_skip('Required imagestore to test')
    image_uuid = test_stub.get_image_by_bs(imagestore.uuid)
    cond = res_ops.gen_query_conditions('type', '=', 'LocalStorage')
    local_pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)
    if len(local_pss) == 0:
        test_util.test_skip('Required ceph ps to test')
    ps_uuid = local_pss[0].uuid
    vm = test_stub.create_vm(image_uuid=image_uuid, ps_uuid=ps_uuid)
    vm.stop()
    target_host = test_lib.lib_find_random_host(vm.vm)

    agent_url = flavor['agent_url']
    agent_action = flavor['agent_action']
    if agent_action == 1:
        agent_time = (24 * 60 * 60 - 60) * 1000
    elif agent_action == 2:
        agent_time = 360 * 1000

    rsp = dep_ops.json_post(
        "http://127.0.0.1:8888/test/api/v1.0/store/create",
        simplejson.dumps({
            "key": vm.get_vm().rootVolumeUuid,
            "value": '{"%s":%s}' % (agent_url, agent_action)
        }))
    start = time.time()
    vol_ops.migrate_volume(vm.get_vm().rootVolumeUuid, target_host.uuid)
    end = time.time()
    if end - start < agent_time / 2 / 1000:
        test_util.test_fail('execution time too short %s' % (end - start))
def test():
    global test_obj_dict
    volume_creation_option = test_util.VolumeOption()
    ps_uuid = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [])[0].uuid
    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume_creation_option.set_primary_storage_uuid(ps_uuid)
    if res_ops.query_resource(res_ops.PRIMARY_STORAGE, [])[0].type == "LocalStorage":
        host = test_lib.lib_find_random_host()
        volume_creation_option.set_system_tags(["localStorage::hostUuid::%s" % host.uuid])
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume_uuid = volume.volume.uuid
    vol_size = volume.volume.size

    set_size = 1024*1024*1024*5
    vol_ops.resize_data_volume(volume_uuid, set_size)
    cond = res_ops.gen_query_conditions('type', '=', "Data")
    cond = res_ops.gen_query_conditions('status', '=', "Ready", cond)
    vol_size_after  = res_ops.query_resource(res_ops.VOLUME, cond)[0].size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after)
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Resize Data Volume Test Success')
Exemplo n.º 4
0
def test():
    global test_obj_dict

    pss = res_ops.get_resource(res_ops.PRIMARY_STORAGE)
    if pss[0].type != "LocalStorage":
        test_util.test_skip(
            "this test is designed to run on localstorage, skip on other ps type."
        )

    vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm)
    vm.check()

    vm_nic_uuid = vm.vm.vmNics[0].uuid
    net_ops.detach_l3(vm_nic_uuid)

    vm.stop()
    vm.check()

    #test_stub.migrate_vm_to_random_host(vm)
    target_host = test_lib.lib_find_random_host(vm.vm)
    vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid)

    l3_name = os.environ.get('l3VlanNetwork3')
    l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid

    net_ops.attach_l3(l3_uuid, vm.vm.uuid)

    vm.start()
    vm.check()

    test_util.test_pass('test detach l3, migrate and attaching passed.')
def test():
    global vm
    vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s',
                                'l3VlanNetwork2')
    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')
    target_host = test_lib.lib_find_random_host(vm.vm)
    vm.stop()
    thread = threading.Thread(target=migrate_volume,
                              args=(
                                  vm.get_vm().allVolumes[0].uuid,
                                  target_host.uuid,
                              ))
    thread.start()
    time.sleep(5)
    progress = res_ops.get_task_progress(vm.get_vm().allVolumes[0].uuid)

    if int(progress.progress) < 0 or int(progress.progress) > 100:
        test_util.test_fail(
            "Progress of task should be between 0 and 100, while it actually is %s"
            % (progress.progress))
    thread.join()

    vm.destroy()
    test_util.test_pass('Migrate Stopped VM Test Success')
def test():
    global test_obj_dict
    volume_creation_option = test_util.VolumeOption()
    ps_uuid = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [])[0].uuid
    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume_creation_option.set_primary_storage_uuid(ps_uuid)
    if res_ops.query_resource(res_ops.PRIMARY_STORAGE,
                              [])[0].type == "LocalStorage":
        host = test_lib.lib_find_random_host()
        volume_creation_option.set_system_tags(
            ["localStorage::hostUuid::%s" % host.uuid])
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume_uuid = volume.volume.uuid
    vol_size = volume.volume.size

    set_size = 1024 * 1024 * 1024 * 5
    vol_ops.resize_data_volume(volume_uuid, set_size)
    cond = res_ops.gen_query_conditions('type', '=', "Data")
    cond = res_ops.gen_query_conditions('status', '=', "Ready", cond)
    vol_size_after = res_ops.query_resource(res_ops.VOLUME, cond)[0].size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Data Volume failed, size = %s' %
                            vol_size_after)
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Resize Data Volume Test Success')
def test():
    global vm
    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_resize_vm", image_name, l3_name)
    vm.check()

    vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size
    volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
    set_size = 1024*1024*1024*5
    vol_ops.resize_volume(volume_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after)

    test_stub.migrate_vm_to_random_host(vm)
    vm.check()
    
    target_host = test_lib.lib_find_random_host(vm.get_vm())
    vol_ops.migrate_volume(volume_uuid, target_host.uuid)
    vm.update()
    vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after)

    vm.destroy()
    test_util.test_pass('Resize VM and Migrate Test Success')
def migrate_volume(index):
    target_host = test_lib.lib_find_random_host(vms[index].get_vm())
    vms[index].stop()
    migrate_jobs[index] = str(uuid.uuid4()).replace('-', '')
    threads_result[index] = "Start"
    vol_ops.migrate_volume_apiid(vms[index].get_vm().allVolumes[0].uuid, target_host.uuid, migrate_jobs[index])
    threads_result[index] = "Done"
def test():
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    global agent_url
    global vm
    imagestore = test_lib.lib_get_image_store_backup_storage()
    if imagestore == None:
        test_util.test_skip('Required imagestore to test')
    image_uuid = test_stub.get_image_by_bs(imagestore.uuid)
    cond = res_ops.gen_query_conditions('type', '=', 'LocalStorage')
    local_pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)
    if len(local_pss) == 0:
        test_util.test_skip('Required ceph ps to test')
    ps_uuid = local_pss[0].uuid
    vm = test_stub.create_vm(image_uuid=image_uuid, ps_uuid=ps_uuid)
    vm.stop()
    target_host = test_lib.lib_find_random_host(vm.vm)

    agent_url = flavor['agent_url']
    agent_action = flavor['agent_action']
    if agent_action == 1:
        agent_time = (24*60*60-60)*1000
    elif agent_action == 2:
        agent_time = 360 * 1000

    rsp = dep_ops.json_post("http://127.0.0.1:8888/test/api/v1.0/store/create", simplejson.dumps({"key": vm.get_vm().rootVolumeUuid, "value": '{"%s":%s}' % (agent_url, agent_action)}))
    start = time.time()
    vol_ops.migrate_volume(vm.get_vm().rootVolumeUuid, target_host.uuid)
    end = time.time()
    if end - start < agent_time / 2 / 1000:
        test_util.test_fail('execution time too short %s' % (end - start))
def test():
    global vm, kvm_host

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)
    for i in ps:
        if i.type == inventory.LOCAL_STORAGE_TYPE:
            break
    else:
        test_util.test_skip('Skip test on non-localstoreate PS')

    #ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]
    #if ps.type != inventory.LOCAL_STORAGE_TYPE:
    #    test_util.test_skip('Skip test on non-localstorage')
    #if "test-config-local-ps.xml" != os.path.basename(os.environ.get('WOODPECKER_TEST_CONFIG_FILE')).strip():
# test_util.test_skip('Skip test on non-localstoreage')
#query all hosts and change password
    conditions = res_ops.gen_query_conditions('state', '=', 'Enabled')
    if res_ops.query_resource(res_ops.HOST, conditions):
        kvm_host = res_ops.query_resource(res_ops.HOST, conditions)
        for i in kvm_host:
            host_ops.update_kvm_host(i.uuid, 'password', 'password*()')
            cmd = 'echo "password*()"| passwd --stdin root'
            test_lib.lib_execute_ssh_cmd(i.managementIp, "root", "password",
                                         cmd)
            host_ops.reconnect_host(i.uuid)
    else:
        test_util.test_skip("There is no host. Skip test")

    test_util.test_dsc('Test KVM Host Infomation: password')

    #create vm and stop and migrate
    vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s',
                                'l3VlanNetwork2')
    vm.check()
    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()
    vm.destroy()
    vm.expunge()
    ################################# recover KVM HOST Password #################################
    conditions = res_ops.gen_query_conditions('state', '=', 'Enabled')
    if res_ops.query_resource(res_ops.HOST, conditions):
        kvm_host = res_ops.query_resource(res_ops.HOST, conditions)
        for i in kvm_host:
            host_ops.update_kvm_host(i.uuid, 'password', 'password')
            cmd = 'echo "password"| passwd --stdin root'
            test_lib.lib_execute_ssh_cmd(i.managementIp, "root", "password*()",
                                         cmd)
            host_ops.reconnect_host(i.uuid)
    else:
        test_util.test_skip("There is no host. Skip test")

    test_util.test_dsc('Test KVM Host Infomation: password')

    test_util.test_pass(
        'Migrate Stopped VM with special_password Test Success')
Exemplo n.º 11
0
def migrate_volume(index):
    target_host = test_lib.lib_find_random_host(vms[index].get_vm())
    vms[index].stop()
    migrate_jobs[index] = str(uuid.uuid4()).replace('-', '')
    threads_result[index] = "Start"
    vol_ops.migrate_volume_apiid(vms[index].get_vm().allVolumes[0].uuid,
                                 target_host.uuid, migrate_jobs[index])
    threads_result[index] = "Done"
def test():
    global vm
    vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2')
    test_obj_dict.add_vm(vm)
    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')
 
    vm_inv = vm.get_vm()
    vm_uuid = vm_inv.uuid

    test_util.test_dsc('Add ISO Image')
    cond = res_ops.gen_query_conditions('name', '=', 'sftp') 
    bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid    

    img_option = test_util.ImageOption()
    img_option.set_name('iso')
    img_option.set_backup_storage_uuid_list([bs_uuid])
    mn = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0]
    cmd = "echo fake iso for test only >  %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso" % (os.environ.get('zstackInstallPath'))
    if os.system("ip r | grep %s" % (mn.hostName)) == 0:
        os.system(cmd)
    else:
        for host in test_lib.lib_get_all_hosts_from_plan():
            test_util.test_logger("host.managementIp_: %s" %(host.managementIp_))
            test_util.test_logger("mn.hostName: %s" %(mn.hostName))
            test_util.test_logger("anotherIp: %s" %(test_stub.get_another_ip_of_host(host.managementIp_, host.username_, host.password_)))
            if host.managementIp_ == mn.hostName or test_stub.get_another_ip_of_host(host.managementIp_, host.username_, host.password_) == mn.hostName:
                out = test_lib.lib_execute_ssh_cmd(host.managementIp_, host.username_, host.password_, cmd, timeout=30)

    img_option.set_url('http://%s:8080/zstack/static/zstack-repo/7/x86_64/os/test.iso' % (mn.hostName))
    image_inv = img_ops.add_iso_template(img_option)
    image = test_image.ZstackTestImage()
    image.set_image(image_inv)
    image.set_creation_option(img_option)

    test_obj_dict.add_image(image)

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

    test_util.test_dsc('Migrate VM')
    vm.check()
    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()

    img_ops.detach_iso(vm_uuid)
    image.delete()
    image.expunge()
    test_obj_dict.rm_image(image)
    vm.destroy()
    test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
Exemplo n.º 13
0
def migrate(vm_obj):
    ps = test_lib.lib_get_primary_storage_by_vm(vm_obj.get_vm())
    if vm_obj.vm.state == "Running" and ps.type in [
            inventory.CEPH_PRIMARY_STORAGE_TYPE, 'SharedMountPoint',
            inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedBlock',
            inventory.LOCAL_STORAGE_TYPE
    ]:
        target_host = test_lib.lib_find_random_host(vm_obj.vm)
        vm_obj.migrate(target_host.uuid)
    elif ps.type in [inventory.LOCAL_STORAGE_TYPE]:
        vm_obj.check()
        target_host = test_lib.lib_find_random_host(vm_obj.vm)
        vol_ops.migrate_volume(vm_obj.get_vm().allVolumes[0].uuid,
                               target_host.uuid)
        vm_obj.start()
        test_lib.lib_wait_target_up(vm_obj.get_vm().vmNics[0].ip, 22, 300)
    else:
        test_util.test_fail("FOUND NEW STORAGTE TYPE. FAILED")
def test():
    ps_env = test_stub.PSEnvChecker()

    local_nfs_env = ps_env.is_local_nfs_env
    local_smp_env = ps_env.is_local_smp_env

    local_ps, another_ps = ps_env.get_two_ps()

    vm = test_stub.create_multi_vms(name_prefix='test-', count=1)[0]
    test_obj_dict.add_vm(vm)

    volume_in_local = []
    if not local_nfs_env:
        volume_in_local = test_stub.create_multi_volumes(count=VOLUME_NUMBER, ps=local_ps,
                                                         host_uuid=test_lib.lib_get_vm_host(vm.get_vm()).uuid)

    volume_in_another = test_stub.create_multi_volumes(count=VOLUME_NUMBER, ps=another_ps,
                                                       host_uuid=None if local_nfs_env else test_lib.lib_get_vm_host(vm.get_vm()).uuid)

    for volume in volume_in_local + volume_in_another:
        test_obj_dict.add_volume(volume)

    for volume in volume_in_local + volume_in_another:
        volume.attach(vm)
        volume.check()
    vm.check()

    for volume in volume_in_local + volume_in_another:
        volume.detach()
        volume.check()
    vm.check()

    target_host = test_lib.lib_find_random_host(vm.get_vm())

    vm.stop()
    vm.check()
    vol_ops.migrate_volume(test_lib.lib_get_root_volume(vm.get_vm()).uuid, target_host.uuid)

    for volume in volume_in_local:
        vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid)

    if not (local_nfs_env or local_smp_env):
        for volume in volume_in_another:
            vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid)

    for volume in volume_in_local + volume_in_another:
        volume.attach(vm)
        volume.check()

    vm.start()
    vm.check()

    for volume in volume_in_local + volume_in_another:
        assert volume.get_volume().vmInstanceUuid == vm.get_vm().uuid

    test_util.test_pass('Multi PrimaryStorage Test Pass')
def test():
    global vm, kvm_host 

    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)
    for i in ps:
        if i.type == inventory.LOCAL_STORAGE_TYPE:
 	    break
    else:
        test_util.test_skip('Skip test on non-localstoreate PS')

    #ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0]
    #if ps.type != inventory.LOCAL_STORAGE_TYPE:
    #    test_util.test_skip('Skip test on non-localstorage')
    #if "test-config-local-ps.xml" != os.path.basename(os.environ.get('WOODPECKER_TEST_CONFIG_FILE')).strip():
	# test_util.test_skip('Skip test on non-localstoreage')
#query all hosts and change password
    conditions = res_ops.gen_query_conditions('state', '=', 'Enabled')
    if res_ops.query_resource(res_ops.HOST, conditions):
        kvm_host = res_ops.query_resource(res_ops.HOST, conditions)
        for i in kvm_host:
        	host_ops.update_kvm_host(i.uuid, 'password', 'password*()')
 		cmd = 'echo "password*()"| passwd --stdin root'
    		test_lib.lib_execute_ssh_cmd(i.managementIp,"root","password",cmd)
    		host_ops.reconnect_host(i.uuid)
    else:
        test_util.test_skip("There is no host. Skip test")

    test_util.test_dsc('Test KVM Host Infomation: password')

#create vm and stop and migrate
    vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2')
    vm.check()
    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()
    vm.destroy()
    vm.expunge()
################################# recover KVM HOST Password #################################
    conditions = res_ops.gen_query_conditions('state', '=', 'Enabled')
    if res_ops.query_resource(res_ops.HOST, conditions):
        kvm_host = res_ops.query_resource(res_ops.HOST, conditions)
        for i in kvm_host:
                host_ops.update_kvm_host(i.uuid, 'password', 'password')
                cmd = 'echo "password"| passwd --stdin root'
                test_lib.lib_execute_ssh_cmd(i.managementIp,"root","password*()",cmd)
                host_ops.reconnect_host(i.uuid)
    else:
        test_util.test_skip("There is no host. Skip test")

    test_util.test_dsc('Test KVM Host Infomation: password')

    test_util.test_pass('Migrate Stopped VM with special_password Test Success')
def test():
    global image1

    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)

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

    image_name1 = 'image1_a'
    image_option = test_util.ImageOption()
    image_option.set_format('qcow2')
    image_option.set_name(image_name1)
    #image_option.set_system_tags('qemuga')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_url(os.environ.get('imageUrl_s'))
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    image_option.set_timeout(3600 * 1000)

    image1 = zstack_image_header.ZstackTestImage()
    image1.set_creation_option(image_option)
    image1.add_root_volume_template()
    image1.check()

    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm1 = test_stub.create_vm(image_name1, image_name, l3_name)
    test_obj_dict.add_vm(vm1)

    image1.delete()
    image1.expunge()

    target_host = test_lib.lib_find_random_host(vm1.vm)
    vm1.migrate(target_host.uuid)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create VM Image in Image Store Success')
def migrate_volume(index):
    target_host = test_lib.lib_find_random_host(vms[index].get_vm())
    vms[index].stop()
    sp_option = test_util.SnapshotOption()
    sp_option.set_volume_uuid(vms[index].get_vm().allVolumes[0].uuid)
    for i in range(0, 50):
        sp_option.set_name("snapshot_for_migrate_progress_%s" % (i))
        sp = vol_ops.create_snapshot(sp_option)

    vol_ops.migrate_volume(vms[index].get_vm().allVolumes[0].uuid, target_host.uuid)
    threads_result[index] = "Done"
Exemplo n.º 18
0
def migrate_volume(index):
    target_host = test_lib.lib_find_random_host(vms[index].get_vm())
    vms[index].stop()
    sp_option = test_util.SnapshotOption()
    sp_option.set_volume_uuid(vms[index].get_vm().allVolumes[0].uuid)
    for i in range(0, 50):
        sp_option.set_name("snapshot_for_migrate_progress_%s" % (i))
        sp = vol_ops.create_snapshot(sp_option)

    vol_ops.migrate_volume(vms[index].get_vm().allVolumes[0].uuid,
                           target_host.uuid)
    threads_result[index] = "Done"
def test():
    global vm
    vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s',
                                'l3VlanNetwork2')
    test_obj_dict.add_vm(vm)
    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')

    vm_inv = vm.get_vm()
    vm_uuid = vm_inv.uuid

    test_util.test_dsc('Add ISO Image')
    cond = res_ops.gen_query_conditions('name', '=', 'sftp')
    bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid

    img_option = test_util.ImageOption()
    img_option.set_name('iso')
    img_option.set_backup_storage_uuid_list([bs_uuid])
    os.system(
        "echo fake iso for test only >  %s/apache-tomcat/webapps/zstack/static/test.iso"
        % (os.environ.get('zstackInstallPath')))
    img_option.set_url('http://%s:8080/zstack/static/test.iso' %
                       (os.environ.get('node1Ip')))
    image_inv = img_ops.add_iso_template(img_option)
    image = test_image.ZstackTestImage()
    image.set_image(image_inv)
    image.set_creation_option(img_option)

    test_obj_dict.add_image(image)

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

    test_util.test_dsc('Migrate VM')
    vm.check()
    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()

    img_ops.detach_iso(vm_uuid)
    image.delete()
    image.expunge()
    test_obj_dict.rm_image(image)
    vm.destroy()
    test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
def migrate_vm_to_random_host(vm):
    test_util.test_dsc("migrate pf_vm to random host")
    target_host = test_lib.lib_find_random_host(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))
Exemplo n.º 21
0
def migrate_volume(index):
    target_host = test_lib.lib_find_random_host(vms[index].get_vm())
    vms[index].stop()
    sp_option = test_util.SnapshotOption()
    sp_option.set_volume_uuid(vms[index].get_vm().allVolumes[0].uuid)
    for i in range(0, 50):
        sp_option.set_name("snapshot_for_migrate_progress_%s" % (i))
        sp = vol_ops.create_snapshot(sp_option)

    migrate_jobs[index] = str(uuid.uuid4()).replace('-', '')
    print 'shuang %s' % (migrate_jobs[index])
    threads_result[index] = "Start"
    vol_ops.migrate_volume_apiid(vms[index].get_vm().allVolumes[0].uuid, target_host.uuid, migrate_jobs[index])
    threads_result[index] = "Done"
Exemplo n.º 22
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))
Exemplo n.º 23
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 test():
    global vm
    vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2')
    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')
    vm.check()
    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()

    vm.destroy()
    test_util.test_pass('Migrate Stopped VM Test Success')
Exemplo n.º 25
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 test():
    global test_obj_dict
    volume_creation_option = test_util.VolumeOption()
    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume_uuid = volume.volume.uuid
    vol_size = volume.volume.size
    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vm("test_resize_vm", image_name, l3_name)
    vm.check()
    test_obj_dict.add_vm(vm)
    volume.attach(vm)
    vm.stop()
    vm.check()

    set_size = 1024 * 1024 * 1024 * 5
    vol_ops.resize_data_volume(volume_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_data_volumes(vm.get_vm())[0].size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Data Volume failed, size = %s' %
                            vol_size_after)

    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    image_option = test_util.ImageOption()
    image_option.set_data_volume_uuid(volume_uuid)
    image_option.set_name('data_resize_template')
    image_option.set_backup_storage_uuid_list([bs_list[0].uuid])
    data_image = img_ops.create_data_volume_template(image_option)
    target_host = test_lib.lib_find_random_host(vm.get_vm())

    new_data = vol_ops.create_volume_from_template(
        data_image.uuid,
        volume.volume.primaryStorageUuid,
        host_uuid=target_host.uuid)
    if set_size != new_data.size:
        test_util.test_fail('Resize Data Volume failed, size = %s' %
                            new_data.size)

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Resize Data Volume Test Success')
def test():
    global vm
    vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2')
    test_obj_dict.add_vm(vm)
    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')
 
    vm_inv = vm.get_vm()
    vm_uuid = vm_inv.uuid

    test_util.test_dsc('Add ISO Image')
    cond = res_ops.gen_query_conditions('name', '=', 'sftp') 
    bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid    

    img_option = test_util.ImageOption()
    img_option.set_name('iso')
    img_option.set_backup_storage_uuid_list([bs_uuid])
    os.system("echo fake iso for test only >  %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath')))
    img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip')))
    image_inv = img_ops.add_iso_template(img_option)
    image = test_image.ZstackTestImage()
    image.set_image(image_inv)
    image.set_creation_option(img_option)

    test_obj_dict.add_image(image)

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

    test_util.test_dsc('Migrate VM')
    vm.check()
    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()

    img_ops.detach_iso(vm_uuid)
    image.delete()
    image.expunge()
    test_obj_dict.rm_image(image)
    vm.destroy()
    test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
Exemplo n.º 28
0
def test():
    global vm
    vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s',
                                'l3VlanNetwork2')
    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')
    vm.check()
    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()

    vm.destroy()
    test_util.test_pass('Migrate Stopped VM Test Success')
def test():
    global image1

    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)

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

    image_name1 = 'image1_a'
    image_option = test_util.ImageOption()
    image_option.set_format('qcow2')
    image_option.set_name(image_name1)
    #image_option.set_system_tags('qemuga')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_url(os.environ.get('imageUrl_s'))
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    image_option.set_timeout(3600*1000)

    image1 = zstack_image_header.ZstackTestImage()
    image1.set_creation_option(image_option)
    image1.add_root_volume_template()
    image1.check()

    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm1 = test_stub.create_vm(image_name1, image_name, l3_name)
    test_obj_dict.add_vm(vm1)

    image1.delete()
    image1.expunge()

    target_host = test_lib.lib_find_random_host(vm1.vm)
    vm1.migrate(target_host.uuid)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create VM Image in Image Store Success')
def test():
    global vm
    vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2')
    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')
    target_host = test_lib.lib_find_random_host(vm.vm)
    vm.stop()
    thread = threading.Thread(target=migrate_volume, args=(vm.get_vm().allVolumes[0].uuid, target_host.uuid, ))
    thread.start()
    time.sleep(5)
    progress = res_ops.get_task_progress(vm.get_vm().allVolumes[0].uuid)

    if int(progress.progress) < 0 or int(progress.progress) > 100:
        test_util.test_fail("Progress of task should be between 0 and 100, while it actually is %s" % (progress.progress))
    thread.join()

    vm.destroy()
    test_util.test_pass('Migrate Stopped VM Test Success')
def test():
    global test_obj_dict
    volume_creation_option = test_util.VolumeOption()
    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume_uuid = volume.volume.uuid
    vol_size = volume.volume.size
    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vm("test_resize_vm", image_name, l3_name)
    vm.check()
    test_obj_dict.add_vm(vm)
    volume.attach(vm)
    vm.stop()
    vm.check()

    set_size = 1024 * 1024 * 1024 * 5
    vol_ops.resize_data_volume(volume_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_data_volumes(vm.get_vm())[0].size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Data Volume failed, size = %s' %
                            vol_size_after)

    volume.detach()
    vm.update()
    target_host = test_lib.lib_find_random_host(vm.get_vm())
    vol_ops.migrate_volume(volume_uuid, target_host.uuid)

    cond = res_ops.gen_query_conditions('uuid', '=', volume_uuid)
    data_volume = res_ops.query_resource(res_ops.VOLUME, cond)
    vol_size_after = data_volume[0].size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Data Volume failed, size = %s' %
                            vol_size_after)

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Resize Data Volume Test Success')
def test():
    global test_obj_dict
    volume_creation_option = test_util.VolumeOption()
    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume_uuid = volume.volume.uuid
    vol_size = volume.volume.size
    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vm("test_resize_vm", image_name, l3_name)
    vm.check()
    test_obj_dict.add_vm(vm)
    volume.attach(vm)
    vm.stop()
    vm.check()

    set_size = 1024*1024*1024*5
    vol_ops.resize_data_volume(volume_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_data_volumes(vm.get_vm())[0].size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after)

    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    image_option = test_util.ImageOption()
    image_option.set_data_volume_uuid(volume_uuid)
    image_option.set_name('data_resize_template')
    image_option.set_backup_storage_uuid_list([bs_list[0].uuid])
    data_image = img_ops.create_data_volume_template(image_option)
    target_host = test_lib.lib_find_random_host(vm.get_vm())

    new_data = vol_ops.create_volume_from_template(data_image.uuid, volume.volume.primaryStorageUuid, host_uuid = target_host.uuid)
    if set_size != new_data.size:
        test_util.test_fail('Resize Data Volume failed, size = %s' % new_data.size)

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Resize Data Volume Test Success')
def test():
    global test_obj_dict
    volume_creation_option = test_util.VolumeOption()
    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume_uuid = volume.volume.uuid
    vol_size = volume.volume.size
    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vm("test_resize_vm", image_name, l3_name)
    vm.check()
    test_obj_dict.add_vm(vm)
    volume.attach(vm)
    vm.stop()
    vm.check()

    set_size = 1024*1024*1024*5
    vol_ops.resize_data_volume(volume_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_data_volumes(vm.get_vm())[0].size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after)

    volume.detach()
    vm.update()
    target_host = test_lib.lib_find_random_host(vm.get_vm())
    vol_ops.migrate_volume(volume_uuid, target_host.uuid)

    cond = res_ops.gen_query_conditions('uuid', '=', volume_uuid)
    data_volume = res_ops.query_resource(res_ops.VOLUME, cond)
    vol_size_after = data_volume[0].size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after)

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Resize Data Volume Test Success')
def test():
    global test_obj_dict

    pss = res_ops.get_resource(res_ops.PRIMARY_STORAGE)
    if pss[0].type != "LocalStorage":
        test_util.test_skip("this test is designed to run on localstorage, skip on other ps type.")    

    l3_name = os.environ.get('l3VlanNetwork3')
    l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    l2_net_uuid = test_lib.lib_get_l3_by_name(l3_name).l2NetworkUuid
    l2_net_type = res_ops.get_resource(res_ops.L2_NETWORK, uuid=l2_net_uuid)[0].type

    test_util.test_logger("l2_network.type@@:%s" %(l2_net_type))
    if l2_net_type == "VxlanNetwork":
        test_util.test_skip("Vxlan network not support detach l2 network, therefore, skip the test")


    vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm)
    vm.check()

    vm_nic_uuid = vm.vm.vmNics[0].uuid
    net_ops.detach_l3(vm_nic_uuid)

    vm.stop()
    vm.check()

    #test_stub.migrate_vm_to_random_host(vm)
    target_host = test_lib.lib_find_random_host(vm.vm)
    vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid)

    l3_name = os.environ.get('l3VlanNetwork3')
    l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid

    net_ops.attach_l3(l3_uuid, vm.vm.uuid)

    vm.start()
    vm.check()

    test_util.test_pass('test detach l3, migrate and attaching passed.')
def test():
    global vm
    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_resize_vm", image_name, l3_name)
    vm.check()
    vm.stop()
    vm.check()

    vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size
    volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
    set_size = 1024*1024*1024*5
    vol_ops.resize_volume(volume_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after)
    vm.start()
    vm.check()

    test_stub.migrate_vm_to_random_host(vm)
    vm.check()
    vm.stop()
    vm.check()
    
    target_host = test_lib.lib_find_random_host(vm.get_vm())
    vol_ops.migrate_volume(volume_uuid, target_host.uuid)
    vm.start()
    vm.update()
    vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after)

    vm.destroy()
    test_util.test_pass('Resize VM and Migrate Test 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
    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)
    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


    vm.destroy()
    test_util.test_pass('Migrate VM Test Success')
def migrate_volume(index):
    target_host = test_lib.lib_find_random_host(vms[index].get_vm())
    vms[index].stop()
    vol_ops.migrate_volume(vms[index].get_vm().allVolumes[0].uuid, target_host.uuid)
    threads_result[index] = "Done"
Exemplo n.º 39
0
def test():
    ps_env = test_stub.PSEnvChecker()

    local_nfs_env = ps_env.is_local_nfs_env
    local_smp_env = ps_env.is_local_smp_env

    local_ps, another_ps = ps_env.get_two_ps()

    vm = test_stub.create_multi_vms(name_prefix='test-', count=1)[0]
    test_obj_dict.add_vm(vm)

    volume_in_local = []
    if not local_nfs_env:
        volume_in_local = test_stub.create_multi_volumes(
            count=VOLUME_NUMBER,
            ps=local_ps,
            host_uuid=test_lib.lib_get_vm_host(vm.get_vm()).uuid)

    volume_in_another = test_stub.create_multi_volumes(
        count=VOLUME_NUMBER,
        ps=another_ps,
        host_uuid=None
        if local_nfs_env else test_lib.lib_get_vm_host(vm.get_vm()).uuid)

    for volume in volume_in_local + volume_in_another:
        test_obj_dict.add_volume(volume)

    for volume in volume_in_local + volume_in_another:
        volume.attach(vm)
        volume.check()
    vm.check()

    for volume in volume_in_local + volume_in_another:
        volume.detach()
        volume.check()
    vm.check()

    target_host = test_lib.lib_find_random_host(vm.get_vm())

    vm.stop()
    vm.check()
    vol_ops.migrate_volume(
        test_lib.lib_get_root_volume(vm.get_vm()).uuid, target_host.uuid)

    for volume in volume_in_local:
        vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid)

    if not (local_nfs_env or local_smp_env):
        for volume in volume_in_another:
            vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid)

    for volume in volume_in_local + volume_in_another:
        volume.attach(vm)
        volume.check()

    vm.start()
    vm.check()

    for volume in volume_in_local + volume_in_another:
        assert volume.get_volume().vmInstanceUuid == vm.get_vm().uuid

    test_util.test_pass('Multi PrimaryStorage Test Pass')
def test():
    global vm
    vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s',
                                'l3VlanNetwork2')
    test_obj_dict.add_vm(vm)
    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')

    vm_inv = vm.get_vm()
    vm_uuid = vm_inv.uuid

    test_util.test_dsc('Add ISO Image')
    cond = res_ops.gen_query_conditions('name', '=', 'sftp')
    bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid

    img_option = test_util.ImageOption()
    img_option.set_name('iso')
    img_option.set_backup_storage_uuid_list([bs_uuid])
    mn = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0]
    cmd = "echo fake iso for test only >  %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso" % (
        os.environ.get('zstackInstallPath'))
    if os.system("ip r | grep %s" % (mn.hostName)) == 0:
        os.system(cmd)
    else:
        for host in test_lib.lib_get_all_hosts_from_plan():
            test_util.test_logger("host.managementIp_: %s" %
                                  (host.managementIp_))
            test_util.test_logger("mn.hostName: %s" % (mn.hostName))
            test_util.test_logger(
                "anotherIp: %s" % (test_stub.get_another_ip_of_host(
                    host.managementIp_, host.username_, host.password_)))
            if host.managementIp_ == mn.hostName or test_stub.get_another_ip_of_host(
                    host.managementIp_, host.username_,
                    host.password_) == mn.hostName:
                out = test_lib.lib_execute_ssh_cmd(host.managementIp_,
                                                   host.username_,
                                                   host.password_,
                                                   cmd,
                                                   timeout=30)

    img_option.set_url(
        'http://%s:8080/zstack/static/zstack-repo/7/x86_64/os/test.iso' %
        (mn.hostName))
    image_inv = img_ops.add_iso_template(img_option)
    image = test_image.ZstackTestImage()
    image.set_image(image_inv)
    image.set_creation_option(img_option)

    test_obj_dict.add_image(image)

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

    test_util.test_dsc('Migrate VM')
    vm.check()
    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()

    img_ops.detach_iso(vm_uuid)
    image.delete()
    image.expunge()
    test_obj_dict.rm_image(image)
    vm.destroy()
    test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
Exemplo n.º 41
0
def test():
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    ps_env = test_stub.PSEnvChecker()
    local_ps, shared_ps = ps_env.get_two_ps()

    test_util.test_dsc("Create VM: {}".format(os.environ.get('CASE_FLAVOR')))

    vm = test_stub.create_vm_with_random_offering(vm_name='test_vm',
                                                  ps_uuid=local_ps.uuid if flavor["root_vol"] is LOCAL else shared_ps.uuid,
                                                  l3_name='l3VlanNetworkName1',
                                                  image_name='imageName_net')

    test_obj_dict.add_vm(vm)

    if flavor['data_vol'] in (LOCAL, MIXED):
        local_vol = test_stub.create_multi_volumes(count=1,host_uuid=vm.get_vm().hostUuid, ps=local_ps)[0]
        test_obj_dict.add_volume(local_vol)
        local_vol.attach(vm)
    else:
        local_vol = None

    if flavor['data_vol'] in (SHARED, MIXED):
        shared_vol = test_stub.create_multi_volumes(count=1, ps=shared_ps)[0]
        test_obj_dict.add_volume(shared_vol)
        shared_vol.attach(vm)
    else:
        shared_vol = None

    vm.check()

    test_util.test_dsc("Try to perform live migration")
    if flavor['root_vol'] is SHARED and flavor['data_vol'] in (None, SHARED):
        test_stub.migrate_vm_to_random_host(vm)
    elif flavor['root_vol'] is LOCAL and flavor['data_vol'] is None:
        test_util.test_dsc("Try to perform local vm live migration")
        test_stub.migrate_vm_to_random_host(vm)
    else:
        with test_lib.expected_failure("live migration will fail if have local volumes", Exception):
            test_stub.migrate_vm_to_random_host(vm)
    vm.check()

    test_util.test_dsc("Try to perform cold migration")
    if local_vol:
        local_vol.detach()
    if shared_vol:
        shared_vol.detach()
    vm.stop()
    vm.check()

    if flavor['root_vol'] is LOCAL:
        target_host = test_lib.lib_find_random_host(vm.get_vm())
        vol_ops.migrate_volume(test_lib.lib_get_root_volume(vm.get_vm()).uuid, target_host.uuid)
        if local_vol:
            vol_ops.migrate_volume(local_vol.get_volume().uuid, target_host.uuid)
        if shared_vol:
            with test_lib.expected_failure('cold migrate volume in shared ps', Exception):
                vol_ops.migrate_volume(shared_vol.get_volume().uuid, target_host.uuid)

    if local_vol:
        local_vol.attach(vm)
    if shared_vol:
        shared_vol.attach(vm)
    vm.start()
    vm.check()

    test_util.test_dsc("Try to perform detached VM hot migration")
    if flavor['root_vol'] is SHARED and flavor['data_vol'] in (LOCAL, MIXED):
        if local_vol:
            local_vol.detach()
        if shared_vol:
            shared_vol.detach()

        test_stub.migrate_vm_to_random_host(vm)

        if local_vol:
            vol_ops.migrate_volume(local_vol.get_volume().uuid, vm.get_vm().hostUuid)

        if local_vol:
            local_vol.attach(vm)
        if shared_vol:
            shared_vol.attach(vm)
        vm.check()

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Multi PrimaryStorage Test Pass')
def stopped_vm_operations(vm, bss):

    vm_uuid = vm.get_vm().uuid
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    vm_ops.stop_vm(vm_uuid)
    #Change vm's instanceoffering
    vm_ops.update_vm(vm_uuid, 2, 2048 * 1024 * 1024)

    #Change vm's status
    ha_ops.set_vm_instance_ha_level(vm_uuid, 'neverstop')
    vm_ops.stop_vm(vm_uuid)
    ha_ops.del_vm_instance_ha_level(vm_uuid)
    vm_ops.stop_vm(vm_uuid)
    if ps.type != 'LocalStorage':
        target_host_uuid = test_lib.lib_find_random_host(vm.get_vm()).uuid
        if target_host_uuid != None:
            vm_ops.start_vm_with_target_host(vm_uuid, target_host_uuid)
    #vm_ops.stop_vm(vm_uuid)
    vm_ops.destroy_vm(vm_uuid)
    vm_ops.recover_vm(vm_uuid)
    vm_ops.reinit_vm(vm_uuid)

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

    #migrate
    vm_ops.start_vm(vm_uuid)
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
    vm_ops.stop_vm(vm_uuid)
    migrate_host_uuids = []
    if candidate_hosts != None:
        for host in candidate_hosts.inventories:
            migrate_host_uuids.append(host.uuid)
        if ps.type == 'LocalStorage':
            vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
            #vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])
            vol_ops.migrate_volume(vol_uuid, migrate_host_uuids[0])
            test_util.test_logger('migrate vm success')

    #resize root volume
    vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size
    vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
    set_size = 1024 * 1024 * 1024 * 5
    vol_ops.resize_volume(vol_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' %
                            vol_size_after)
    test_util.test_logger('resize vm success')

    #storage migrate

    #change vm image
    image_list = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid)
    image_uuids = []
    for image in image_list.inventories:
        image_uuids.append(image.uuid)
    vm_ops.change_vm_image(vm_uuid, image_uuids[0])
    vm.update()

    #update vm nic mac
    nic_uuid = vm.get_vm().vmNics[0].uuid
    mac = 'fa:4c:ee:9a:76:00'
    vm_ops.update_vm_nic_mac(nic_uuid, mac)

    #set/del static ip
    l3network_uuid = test_lib.lib_get_l3_uuid_by_nic(nic_uuid)
    vm_ops.change_vm_static_ip(vm_uuid, l3network_uuid,
                               vm.get_vm().vmNics[0].ip)
    vm_ops.delete_vm_static_ip(vm_uuid, l3network_uuid)

    #snapshot operations
    sp_option = test_util.SnapshotOption()
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    root_volume_uuid = vm_root_volume_inv.uuid
    sp_option.set_volume_uuid(root_volume_uuid)
    sp = vol_ops.create_snapshot(sp_option)
    vol_ops.use_snapshot(sp.uuid)
    vol_ops.delete_snapshot(sp.uuid)

    common_operations(vm, bss, 'stopped')
    vm.destroy()
    vm.expunge()
def test():
    test_util.test_dsc('test vm life cycle on specified ceph pool')
    try:
        ps = res_ops.query_resource(res_ops.CEPH_PRIMARY_STORAGE)[0]
    except Exception as e:
        test_util.test_dsc(str(e))
        test_util.test_skip('Skip for not finding ceph ps')
    ps_uuid = ps.uuid

    aliasName = 'test_aliasName_new_vm_life'
    poolName = 'for_test_vm_life_cycle_sas_pool'
    description = 'test_description'
    isCreate = 'true'
    test_util.test_dsc('add new pool by zstack')
    ps_ops.add_ceph_primary_storage_pool(ps_uuid, poolName, aliasName, isCreate, poolType="Root")
    cond = res_ops.gen_query_conditions('aliasName', '=', aliasName)
    pool = res_ops.query_resource(res_ops.CEPH_PRIMARY_STORAGE_POOL, cond)[0]
    print pool
    test_util.test_dsc("poolName: " + str(pool.poolName))
    if pool.poolName != poolName:
        test_util.test_fail('Find wrong pool should find: ' + str(poolName) + 'But find: ' + str(pool.poolName))

    #create vm on sas pool
    instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(
       os.environ.get('instanceOfferingName_s')).uuid
    cond = res_ops.gen_query_conditions('mediaType', '!=', 'ISO')
    cond = res_ops.gen_query_conditions('platform', '=', 'Linux', cond)
    image_uuid = test_lib.lib_get_image_by_name(
        os.environ.get('imageName_s')).uuid
    l3net_uuid = test_lib.lib_get_l3_by_name(
        os.environ.get('l3PublicNetworkName')).uuid

    vm_creation_option = test_util.VmOption()
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_l3_uuids([l3net_uuid])
    vm_creation_option.set_rootVolume_systemTags(["ceph::rootPoolName::for_test_vm_life_cycle_sas_pool"])
    vm = test_vm.ZstackTestVm()
    vm.set_creation_option(vm_creation_option)
    vm.create()
    test_util.test_dsc('Create sas VM Test Success')

    #stop vm
    vm.stop()
    #vm.check()

    #start vm
    vm.start()
    vm.clone(["clone_vm"])
    target_host = test_lib.lib_find_random_host(vm.vm)
    vm.migrate(target_host.uuid)
    current_host = test_lib.lib_find_host_by_vm(vm.vm)
    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))

    test_util.test_pass('Test vm life cycle Success')
def stopped_vm_operations(vm,bss):
   
   vm_uuid = vm.get_vm().uuid
   ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
   vm_ops.stop_vm(vm_uuid)
   #Change vm's instanceoffering
   vm_ops.update_vm(vm_uuid,2,2048*1024*1024)
   
   #Change vm's status
   ha_ops.set_vm_instance_ha_level(vm_uuid,'neverstop')
   vm_ops.stop_vm(vm_uuid)
   ha_ops.del_vm_instance_ha_level(vm_uuid)
   vm_ops.stop_vm(vm_uuid)
   if ps.type != 'LocalStorage':
      target_host_uuid = test_lib.lib_find_random_host(vm.get_vm()).uuid
      if target_host_uuid != None:
         vm_ops.start_vm_with_target_host(vm_uuid,target_host_uuid)
   #vm_ops.stop_vm(vm_uuid)
   vm_ops.destroy_vm(vm_uuid)
   vm_ops.recover_vm(vm_uuid)
   vm_ops.reinit_vm(vm_uuid)

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

   #migrate
   vm_ops.start_vm(vm_uuid)
   candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
   vm_ops.stop_vm(vm_uuid)
   migrate_host_uuids = []
   if candidate_hosts != None:
      for host in candidate_hosts.inventories:
         migrate_host_uuids.append(host.uuid)
      if ps.type == 'LocalStorage':
         vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
         #vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])		
         vol_ops.migrate_volume(vol_uuid, migrate_host_uuids[0])
         test_util.test_logger('migrate vm success')
   
   #resize root volume
   vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size
   vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
   set_size = 1024*1024*1024*5
   vol_ops.resize_volume(vol_uuid, set_size)
   vm.update()
   vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
   if set_size != vol_size_after:
      test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after)
   test_util.test_logger('resize vm success')
   
   #storage migrate
         
   #change vm image
   image_list = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid)
   image_uuids = []
   for image in image_list.inventories:
      image_uuids.append(image.uuid)
   vm_ops.change_vm_image(vm_uuid,image_uuids[0])
   vm.update()
   
   #update vm nic mac
   nic_uuid = vm.get_vm().vmNics[0].uuid
   mac = 'fa:4c:ee:9a:76:00'
   vm_ops.update_vm_nic_mac(nic_uuid,mac)

   #set/del static ip
   l3network_uuid = test_lib.lib_get_l3_uuid_by_nic(nic_uuid)
   vm_ops.change_vm_static_ip(vm_uuid, l3network_uuid, vm.get_vm().vmNics[0].ip)
   vm_ops.delete_vm_static_ip(vm_uuid, l3network_uuid)
  
   #snapshot operations
   sp_option = test_util.SnapshotOption()
   vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
   root_volume_uuid = vm_root_volume_inv.uuid
   sp_option.set_volume_uuid(root_volume_uuid)
   sp = vol_ops.create_snapshot(sp_option)
   vol_ops.use_snapshot(sp.uuid)
   vol_ops.delete_snapshot(sp.uuid)

   common_operations(vm,bss,'stopped')
   vm.destroy()
   vm.expunge()
def test():
    ps_env = test_stub.PSEnvChecker()

    local_nfs_env = ps_env.is_local_nfs_env

    local_ps, another_ps = ps_env.get_two_ps()

    vm = test_stub.create_multi_vms(name_prefix='test-', count=1)[0]
    test_obj_dict.add_vm(vm)
    vm.check()

    volume_in_local = test_stub.create_multi_volumes(
        count=VOLUME_NUMBER,
        ps=local_ps,
        host_uuid=test_lib.lib_get_vm_host(vm.get_vm()).uuid)

    volume_in_another = test_stub.create_multi_volumes(
        count=VOLUME_NUMBER,
        ps=another_ps,
        host_uuid=None
        if local_nfs_env else test_lib.lib_get_vm_host(vm.get_vm()).uuid)

    for volume in volume_in_local + volume_in_another:
        test_obj_dict.add_volume(volume)

    for volume in volume_in_local + volume_in_another:
        volume.attach(vm)
        volume.check()
    vm.check()
    vm.update()

    snapshots_list = []
    for volume in vm.get_vm().allVolumes:
        snapshots = test_obj_dict.get_volume_snapshot(volume.uuid)
        snapshots.set_utility_vm(vm)
        snapshots.create_snapshot('create_volume_snapshot')
        snapshots_list.append(snapshots)

    for volume in volume_in_local + volume_in_another:
        volume.detach()
        volume.check()
    vm.check()

    target_host = test_lib.lib_find_random_host(vm.get_vm())

    vm.stop()
    vm.check()
    vol_ops.migrate_volume(
        test_lib.lib_get_root_volume(vm.get_vm()).uuid, target_host.uuid)

    for volume in volume_in_local:
        vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid)

    if not local_nfs_env:
        for volume in volume_in_another:
            vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid)

    for volume in volume_in_local + volume_in_another:
        volume.attach(vm)
        volume.check()

    for snapshots in snapshots_list:
        snapshot = snapshots.get_current_snapshot()
        snapshots.use_snapshot(snapshot)

    vm.start()
    vm.check()

    for volume in volume_in_local + volume_in_another:
        assert volume.get_volume().vmInstanceUuid == vm.get_vm().uuid

    test_util.test_pass('Multi PrimaryStorage Test Pass')