コード例 #1
0
def test():
    global new_offering_uuid
    test_util.test_dsc('Test memory status after change VM offering')

    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.' )
        return True

    host_uuid = host[0].uuid
    zone_uuid = host[0].zoneUuid
    host_avail_mem1 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).availableMemory
    zone_avail_mem1 = test_lib.lib_get_cpu_memory_capacity(zone_uuids = [zone_uuid]).availableMemory
    #unit is KB
    new_offering1 = test_lib.lib_create_instance_offering(cpuNum = 1, \
            memorySize = 536870912, name = 'new_instance1')

    test_obj_dict.add_instance_offering(new_offering1)
    new_offering_uuid = new_offering1.uuid

    vm = test_stub.create_vm(vm_name = 'test_avail_memory', \
            host_uuid = host_uuid, \
            instance_offering_uuid = new_offering1.uuid)
    test_obj_dict.add_vm(vm)

    vm.stop()

    new_offering2 = test_lib.lib_create_instance_offering(cpuNum = 1, \
            memorySize = 1073741824, name = 'new_instance2')

    test_obj_dict.add_instance_offering(new_offering2)
    new_offering_uuid = new_offering2.uuid
    vm_inv = vm.get_vm()
    vm.change_instance_offering(new_offering_uuid)
    vm.start()
    host_avail_mem2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).availableMemory
    host_mem_diff = host_avail_mem1 - host_avail_mem2
    if host_avail_mem2 >= host_avail_mem1 :
        test_util.test_fail('Host available memory is not correct after change vm template. Previous value: %s , Current value: %s' % (host_avail_mem1, host_avail_mem2))
    else:
        test_util.test_logger('Host available memory before change template: %s , after change template: %s , the difference: %s' % (host_avail_mem1, host_avail_mem2, host_mem_diff))

    zone_avail_mem2 = test_lib.lib_get_cpu_memory_capacity(zone_uuids = [zone_uuid]).availableMemory
    zone_mem_diff = zone_avail_mem1 - zone_avail_mem2
    if zone_avail_mem2 >= zone_avail_mem1 :
        test_util.test_fail('Zone available memory is not correct after change vm template. Previous value: %s , Current value: %s' % (zone_avail_mem1, zone_avail_mem2))
    else:
        test_util.test_logger('Zone available memory before change template: %s , after change template: %s , the difference: %s' % (zone_avail_mem1, zone_avail_mem2, zone_mem_diff))

    if zone_mem_diff != host_mem_diff:
        test_util.test_fail('available memory change is not correct after change vm template. zone changed value: %s , host changed value: %s' % ((zone_avail_mem1 - zone_avail_mem2), (host_avail_mem1 - host_avail_mem2)))

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Test available memory when changing instance offering Pass')
コード例 #2
0
def get_vm_num_based_cpu_available_on_host(host_uuid, each_vm_cpu_consume):
    """
    This function is used to compute available cpu num based on host current have
    """
    host_total_cpu = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).totalCpu
    host_avail_cpu = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).availableCpu
    #host_total_mem = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).totalMemory
    #host_avail_mem = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).availableMemory

    print "total: %s; avail: %s" %(host_total_cpu, host_avail_cpu)
    return host_avail_cpu / each_vm_cpu_consume
def get_vm_num_based_cpu_available_on_host(host_uuid, each_vm_cpu_consume):
    """
    This function is used to compute available cpu num based on host current have
    """
    host_total_cpu = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).totalCpu
    host_avail_cpu = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).availableCpu
    #host_total_mem = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).totalMemory
    #host_avail_mem = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).availableMemory

    print "total: %s; avail: %s" %(host_total_cpu, host_avail_cpu)
    return host_avail_cpu / each_vm_cpu_consume
コード例 #4
0
def test():
    test_util.test_dsc('Test Host Reconnect function and check if the available CPU and memory number are aligned between before and after reconnect action')
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm)

    zone_uuid = vm.get_vm().zoneUuid
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid

    tot_res1 = test_lib.lib_get_cpu_memory_capacity([zone_uuid])
    
    host_ops.reconnect_host(host_uuid)
    time.sleep(5)

    tot_res2 = test_lib.lib_get_cpu_memory_capacity([zone_uuid])

    if compare_capacity( tot_res1, tot_res2):
        test_util.test_logger("the resource consumption are same after reconnect host")
    else:
        test_util.test_fail("the resource consumption are different after reconnect host: %s " % host_uuid)

    vm_offering_uuid = vm.get_vm().instanceOfferingUuid
    cond = res_ops.gen_query_conditions('uuid', '=', vm_offering_uuid)
    vm_offering = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0]
    vm_cpu = vm_offering.cpuNum
    vm_memory = vm_offering.memorySize
    
    vm.destroy()
    test_obj_dict.rm_vm(vm)

    tot_res3 = test_lib.lib_get_cpu_memory_capacity([zone_uuid])
    if compare_capacity(tot_res1, tot_res3, vm_cpu, vm_memory):
        test_util.test_logger("the resource consumption are aligned after destroy a vm")
    else:
        test_util.test_fail("the resource consumption are not aligned after destroy vm: %s on host: %s" % (vm.get_vm().uuid, host_uuid))

    test_stub.ensure_hosts_connected(120)
    test_stub.ensure_pss_connected()    
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm)

    tot_res4 = test_lib.lib_get_cpu_memory_capacity([zone_uuid])

    if compare_capacity(tot_res1, tot_res4):
        test_util.test_logger("the resource consumption are aligned after create a new vm")
    else:
        test_util.test_fail("the resource consumption are not aligned after create a new vm: %s " % vm.get_vm().uuid)

    vm.destroy()

    test_util.test_pass('Reconnect Host and Test CPU/Memory Capacity Pass')
コード例 #5
0
def test():
    test_util.test_dsc('Test Host Reconnect function and check if the available CPU and memory number are aligned between before and after reconnect action')
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm)

    zone_uuid = vm.get_vm().zoneUuid
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid

    tot_res1 = test_lib.lib_get_cpu_memory_capacity([zone_uuid])
    
    host_ops.reconnect_host(host_uuid)

    tot_res2 = test_lib.lib_get_cpu_memory_capacity([zone_uuid])

    if compare_capacity( tot_res1, tot_res2):
        test_util.test_logger("the resource consumption are same after reconnect host")
    else:
        test_util.test_fail("the resource consumption are different after reconnect host: %s " % host_uuid)

    vm_offering_uuid = vm.get_vm().instanceOfferingUuid
    cond = res_ops.gen_query_conditions('uuid', '=', vm_offering_uuid)
    vm_offering = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0]
    vm_cpu = vm_offering.cpuNum * vm_offering.cpuSpeed
    vm_memory = vm_offering.memorySize
    
    vm.destroy()
    test_obj_dict.rm_vm(vm)

    tot_res3 = test_lib.lib_get_cpu_memory_capacity([zone_uuid])
    if compare_capacity(tot_res1, tot_res3, vm_cpu, vm_memory):
        test_util.test_logger("the resource consumption are aligned after destroy a vm")
    else:
        test_util.test_fail("the resource consumption are not aligned after destroy vm: %s on host: %s" % (vm.get_vm().uuid, host_uuid))

    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm)

    tot_res4 = test_lib.lib_get_cpu_memory_capacity([zone_uuid])

    if compare_capacity(tot_res1, tot_res4):
        test_util.test_logger("the resource consumption are aligned after create a new vm")
    else:
        test_util.test_fail("the resource consumption are not aligned after create a new vm: %s " % vm.get_vm().uuid)

    vm.destroy()

    test_util.test_pass('Reconnect Host and Test CPU/Memory Capacity Pass')
コード例 #6
0
def test():
    global original_rate
    test_util.test_dsc('Change Test memory over provision method')
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit=1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.')
        return True

    host = host[0]
    over_provision_rate1 = 2
    over_provision_rate2 = 1.5

    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid])
    avail_mem = host_res.availableMemory
    if avail_mem <= 1024 * 1024 * 1024:
        test_util.test_skip('Available memory is less than 512MB, skip test.')
        return True

    original_rate = test_lib.lib_set_provision_memory_rate(
        over_provision_rate1)

    vm = test_stub.create_vm(vm_name='mem_over_prs_vm_1')
    test_obj_dict.add_vm(vm)

    test_lib.lib_set_provision_memory_rate(over_provision_rate2)
    vm.destroy()

    vm = test_stub.create_vm(vm_name='mem_over_prs_vm_2')
    test_obj_dict.add_vm(vm)

    test_lib.lib_set_provision_memory_rate(original_rate)
    vm.destroy()

    host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid])
    avail_mem2 = host_res2.availableMemory
    if avail_mem2 != avail_mem:
        test_util.test_fail(
            'Available memory: %d is different with original available memory: %d'
            % (avail_mem2, avail_mem))
    else:
        test_util.test_logger(
            'Available memory: %d is same with original available memory.' %
            avail_mem2)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Change Memory Over Provision Test Pass')
コード例 #7
0
def test():
    global original_rate
    test_util.test_dsc('Change Test memory over provision method')
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.' )
        return True

    host = host[0]
    over_provision_rate1 = 2
    over_provision_rate2 = 1.5

    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    avail_mem = host_res.availableMemory
    if avail_mem <= 1024*1024*1024:
        test_util.test_skip('Available memory is less than 512MB, skip test.')
        return True

    original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate1)

    vm = test_stub.create_vm(vm_name = 'mem_over_prs_vm_1')
    test_obj_dict.add_vm(vm)

    test_lib.lib_set_provision_memory_rate(over_provision_rate2)
    vm.destroy()

    vm = test_stub.create_vm(vm_name = 'mem_over_prs_vm_2')
    test_obj_dict.add_vm(vm)

    test_lib.lib_set_provision_memory_rate(original_rate)
    vm.destroy()

    host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    avail_mem2 = host_res2.availableMemory
    if avail_mem2 != avail_mem:
        test_util.test_fail('Available memory: %d is different with original available memory: %d' % (avail_mem2, avail_mem))
    else:
        test_util.test_logger('Available memory: %d is same with original available memory.' % avail_mem2)
    
    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Change Memory Over Provision Test Pass')
def test():
    global original_rate
    global new_offering_uuid
    test_util.test_dsc('Test memory allocation and reclaiming.')
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.' )
        return True

    host = host[0]
    over_provision_rate = 1
    target_vm_num = 5

    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    #avail_mem = host_res.availableMemory * over_provision_rate
    avail_mem = host_res.availableMemory
    if avail_mem <= 1024*1024*1024:
        test_util.test_skip('Available memory is less than 1024MB, skip test.')
        return True

    original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate)
    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    avail_mem = host_res.availableMemory

    test_mem = avail_mem / target_vm_num
    new_offering_mem = test_mem
    new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem)

    new_offering_uuid = new_offering.uuid

    rounds = 0
    while (rounds < 3):
        times = 1
        while (times <= (target_vm_num)):
            thread = threading.Thread(target = parallelly_create_vm, \
                    args = ('parallel_vm_creating_%d' % times, \
                        host.uuid, \
                        new_offering.uuid, ))
            thread.start()

            times += 1

        times = 1
        print 'Running VM: %s ' % len(test_obj_dict.get_vm_list())
        while threading.active_count() > 1:
            check_thread_exception()
            time.sleep(1)
            if times > 5:
                test_util.test_fail('creating vm time exceed 5s')
            times += 1

        check_thread_exception()

        for vm in test_obj_dict.get_all_vm_list():
            try:
                vm.destroy()
                test_obj_dict.rm_vm(vm)
            except Exception as e:
                test_util.test_logger("VM Destroying Failure in memory reclaiming test. :%s " % e)
                raise e

        host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
        avail_mem2 = host_res2.availableMemory
        if avail_mem2 != avail_mem:
            test_util.test_fail('Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds))

        rounds += 1
    
    test_lib.lib_set_provision_memory_rate(original_rate)
    vm_ops.delete_instance_offering(new_offering_uuid)
    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('Parallel vm creation Test Pass')
コード例 #9
0
def test():
    global original_rate
    test_util.test_dsc('Test change storage over provision rate method')
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.' )
        return True

    host = host[0]
    over_provision_rate1 = 2.5
    over_provision_rate2 = 1.5
    target_volume_num = 12
    kept_disk_size = 10 * 1024 * 1024

    vm = test_stub.create_vm(vm_name = 'storage_over_prs_vm_1', \
                    host_uuid = host.uuid)
    test_obj_dict.add_vm(vm)

    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    ps_res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid])
    avail_cap = ps_res.availableCapacity
    if avail_cap < kept_disk_size:
        test_util.test_skip('available disk capacity:%d is too small, skip test.' % avail_cap)
        return True

    original_rate = test_lib.lib_set_provision_storage_rate(over_provision_rate1)
    data_volume_size = int(over_provision_rate1 * (avail_cap - kept_disk_size) / target_volume_num)
    disk_offering_option = test_util.DiskOfferingOption()
    disk_offering_option.set_name('storage-over-ps-test')
    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)

    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(data_volume_offering.uuid)
    
    volume_creation_option.set_name('volume-1')
    volume1 = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume1)
    #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid])
    #test_util.test_logger('Current available storage size: %d' % res.availableCapacity)
    volume1.attach(vm)

    test_lib.lib_set_provision_storage_rate(over_provision_rate2)
    volume_creation_option.set_name('volume-2')
    volume2 = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume2)
    #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid])
    #test_util.test_logger('Current available storage size: %d' % res.availableCapacity)
    volume2.attach(vm)
    volume1.delete()

    test_lib.lib_set_provision_storage_rate(over_provision_rate1)
    volume2.delete()

    test_lib.lib_set_provision_storage_rate(original_rate)
    ps_res2 = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid])
    avail_cap2 = ps_res2.availableCapacity
    if avail_cap2 != avail_cap:
        test_util.test_fail('Available disk size: %d is different with original size: %d, after creating volume under different over rate.' % (avail_cap2, avail_cap))
    
    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Memory Over Provision Test Pass')
コード例 #10
0
def test():
    global original_rate
    test_util.test_dsc('Test change storage over provision rate method')
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit=1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.')
        return True

    host = host[0]
    over_provision_rate1 = 2.5
    over_provision_rate2 = 1.5
    target_volume_num = 12
    kept_disk_size = 10 * 1024 * 1024

    vm = test_stub.create_vm(vm_name = 'storage_over_prs_vm_1', \
                    host_uuid = host.uuid)
    test_obj_dict.add_vm(vm)

    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid])
    ps_res = test_lib.lib_get_storage_capacity(zone_uuids=[zone_uuid])
    avail_cap = ps_res.availableCapacity
    if avail_cap < kept_disk_size:
        test_util.test_skip(
            'available disk capacity:%d is too small, skip test.' % avail_cap)
        return True

    original_rate = test_lib.lib_set_provision_storage_rate(
        over_provision_rate1)
    data_volume_size = int(over_provision_rate1 *
                           (avail_cap - kept_disk_size) / target_volume_num)
    disk_offering_option = test_util.DiskOfferingOption()
    disk_offering_option.set_name('storage-over-ps-test')
    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)

    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(data_volume_offering.uuid)

    volume_creation_option.set_name('volume-1')
    volume1 = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume1)
    #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid])
    #test_util.test_logger('Current available storage size: %d' % res.availableCapacity)
    volume1.attach(vm)

    test_lib.lib_set_provision_storage_rate(over_provision_rate2)
    volume_creation_option.set_name('volume-2')
    volume2 = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume2)
    #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid])
    #test_util.test_logger('Current available storage size: %d' % res.availableCapacity)
    volume2.attach(vm)
    volume1.delete()

    test_lib.lib_set_provision_storage_rate(over_provision_rate1)
    volume2.delete()

    test_lib.lib_set_provision_storage_rate(original_rate)
    ps_res2 = test_lib.lib_get_storage_capacity(zone_uuids=[zone_uuid])
    avail_cap2 = ps_res2.availableCapacity
    if avail_cap2 != avail_cap:
        test_util.test_fail(
            'Available disk size: %d is different with original size: %d, after creating volume under different over rate.'
            % (avail_cap2, avail_cap))

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Memory Over Provision Test Pass')
コード例 #11
0
def test():
    global new_offering_uuid
    test_util.test_dsc('Test memory status after change VM offering')

    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit=1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.')
        return True

    host_uuid = host[0].uuid
    zone_uuid = host[0].zoneUuid
    host_avail_mem1 = test_lib.lib_get_cpu_memory_capacity(
        host_uuids=[host_uuid]).availableMemory
    zone_avail_mem1 = test_lib.lib_get_cpu_memory_capacity(
        zone_uuids=[zone_uuid]).availableMemory
    #unit is KB
    new_offering1 = test_lib.lib_create_instance_offering(cpuNum = 1, \
            memorySize = 536870912, name = 'new_instance1')

    test_obj_dict.add_instance_offering(new_offering1)
    new_offering_uuid = new_offering1.uuid

    vm = test_stub.create_vm(vm_name = 'test_avail_memory', \
            host_uuid = host_uuid, \
            instance_offering_uuid = new_offering1.uuid)
    test_obj_dict.add_vm(vm)

    vm.stop()

    new_offering2 = test_lib.lib_create_instance_offering(cpuNum = 1, \
            memorySize = 1073741824, name = 'new_instance2')

    test_obj_dict.add_instance_offering(new_offering2)
    new_offering_uuid = new_offering2.uuid
    vm_inv = vm.get_vm()
    vm.change_instance_offering(new_offering_uuid)
    vm.start()
    host_avail_mem2 = test_lib.lib_get_cpu_memory_capacity(
        host_uuids=[host_uuid]).availableMemory
    host_mem_diff = host_avail_mem1 - host_avail_mem2
    if host_avail_mem2 >= host_avail_mem1:
        test_util.test_fail(
            'Host available memory is not correct after change vm template. Previous value: %s , Current value: %s'
            % (host_avail_mem1, host_avail_mem2))
    else:
        test_util.test_logger(
            'Host available memory before change template: %s , after change template: %s , the difference: %s'
            % (host_avail_mem1, host_avail_mem2, host_mem_diff))

    zone_avail_mem2 = test_lib.lib_get_cpu_memory_capacity(
        zone_uuids=[zone_uuid]).availableMemory
    zone_mem_diff = zone_avail_mem1 - zone_avail_mem2
    if zone_avail_mem2 >= zone_avail_mem1:
        test_util.test_fail(
            'Zone available memory is not correct after change vm template. Previous value: %s , Current value: %s'
            % (zone_avail_mem1, zone_avail_mem2))
    else:
        test_util.test_logger(
            'Zone available memory before change template: %s , after change template: %s , the difference: %s'
            % (zone_avail_mem1, zone_avail_mem2, zone_mem_diff))

    if zone_mem_diff != host_mem_diff:
        test_util.test_fail(
            'available memory change is not correct after change vm template. zone changed value: %s , host changed value: %s'
            % ((zone_avail_mem1 - zone_avail_mem2),
               (host_avail_mem1 - host_avail_mem2)))

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass(
        'Test available memory when changing instance offering Pass')
コード例 #12
0
def test():
    global original_rate
    global new_offering_uuid
    test_util.test_dsc('Test memory allocation and reclaiming.')
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.' )
        return True

    host = host[0]
    over_provision_rate = 1
    target_vm_num = 5

    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    #avail_mem = host_res.availableMemory * over_provision_rate
    avail_mem = host_res.availableMemory
    if avail_mem <= 1024*1024*1024:
        test_util.test_skip('Available memory is less than 1024MB, skip test.')
        return True

    original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate)
    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    avail_mem = host_res.availableMemory

    test_mem = avail_mem / target_vm_num
    new_offering_mem = test_mem
    new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem)

    new_offering_uuid = new_offering.uuid

    rounds = 0
    while (rounds < 3):
        times = 1
        while (times <= (target_vm_num+3)):
            try:
                vm = test_stub.create_vm(vm_name = 'mem_reclaim_vm_%d' % times, \
                        host_uuid = host.uuid, \
                        instance_offering_uuid = new_offering.uuid)
                test_obj_dict.add_vm(vm)
            except Exception as e:
                test_util.test_logger("VM Creation Failure in memory reclaiming test. :%s " % e)
                pass

            times += 1

        for vm in test_obj_dict.get_all_vm_list():
            try:
                vm.destroy()
                test_obj_dict.rm_vm(vm)
            except Exception as e:
                test_util.test_logger("VM Destroying Failure in memory reclaiming test. :%s " % e)
                pass

        host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
        avail_mem2 = host_res2.availableMemory
        if avail_mem2 != avail_mem:
            test_util.test_fail('Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds))

        rounds += 1
    
    test_lib.lib_set_provision_memory_rate(original_rate)
    vm_ops.delete_instance_offering(new_offering_uuid)
    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('Memory Over Provision Test Pass')
コード例 #13
0
def test():
    global vm
    ova_image_name = 'centos-dhcp'
    network_pattern1 = os.environ['vcenterDefaultNetwork']
    cpuNum = 2
    memorySize = 2*1024*1024*1024

    cond = res_ops.gen_query_conditions('type', '!=', 'Vcenter')
    ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)
    for i in ps:
        if (i.type == 'Ceph') or (i.type == 'Sharedblock'):
            break
    else:
        test_util.test_skip('Skip test on non ceph or sharedblock PS')
    ps_uuid = ps[0].uuid
    cond = res_ops.gen_query_conditions('primaryStorage.uuid', '=', ps_uuid)
    cluster_uuid = res_ops.query_resource(res_ops.CLUSTER, cond)[0].uuid
    cond = res_ops.gen_query_conditions('clusterUuid', '=', cluster_uuid)    
    host = res_ops.query_resource(res_ops.HOST, cond)[0]  

    new_offering = test_lib.lib_create_instance_offering(cpuNum = cpuNum, memorySize = memorySize)
    vm = test_stub.create_vm_in_vcenter(vm_name = 'v2v-test', image_name = ova_image_name, l3_name = network_pattern1, instance_offering_uuid = new_offering.uuid)
    vm.check()
    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)
    volume_creation_option.set_name('vcenter_volume')
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume.attach(vm)

    l3_name = os.environ.get('l3VlanNetworkName1')
    l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
    v2v_conversion_host = test_stub.add_v2v_conversion_host('v2v_host', host.uuid, '/tmp/zstack', 'VMWARE')
    tag_ops.create_system_tag("V2VConversionHostVO", v2v_conversion_host.uuid, "networkInboundBandwidth::167772160")
    url = 'vmware://%s' % vm.vm.uuid
    avail_mem = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableMemory
    avail_cpu = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableCpu
    avail_cap = test_lib.lib_get_storage_capacity(ps_uuids = [ps_uuid]).availableCapacity
    migrate_task = test_stub.convert_vm_from_foreign_hypervisor('test', url, cpuNum, memorySize, ps_uuid, [l3_uuid], cluster_uuid, v2v_conversion_host.uuid)

    for i in range(30):
        cond = res_ops.gen_query_conditions('uuid', '=', migrate_task.uuid)
        long_job = res_ops.query_resource(res_ops.LONGJOB, cond)[0]
        if long_job.state == 'Failed':
            test_util.test_fail('v2v long job failed.')
        elif long_job.state == 'Running':
            time.sleep(60)
        elif long_job.state == 'Succeeded':
            test_util.test_logger('v2v long job has been finished.')
            break
    avail_mem2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableMemory
    avail_cpu2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableCpu
    avail_cap2 = test_lib.lib_get_storage_capacity(ps_uuids = [ps_uuid]).availableCapacity

    if (avail_mem - memorySize) != avail_mem2:
        test_util.test_fail('Available memory: %d is different with expected available memory: %d' % (avail_mem2, avail_mem - memorySize))
    if (avail_cpu - cpuNum) != avail_cpu2:
        test_util.test_fail('Available cpuNum: %d is different with expected available cpuNum: %d' % (avail_cpu2, avail_cpu1 - memorySize))
    cond = res_ops.gen_query_conditions('type', '=', 'root')
    cond = res_ops.gen_query_conditions('primaryStorageUuid', '=', ps_uuid, cond)
    vm_root_volume_size = res_ops.query_resource(res_ops.VOLUME, cond)[0].size
    if (avail_cap - vm_root_volume_size - disk_offering.diskSize) != avail_cap2:
        test_util.test_fail('Available storage: %d is different with expected available storage: %d' % (avail_cap2, avail_cap - vm_root_volume_size - disk_offering.diskSize))
    actual_qos = (vm_root_volume_size + disk_offering.diskSize) / long_job.executeTime

    if actual_qos > 167772160:
        test_util.test_fail('Fail to set qos for converting vm, expect qos:167772160 < actual_qos:%s.' % actual_qos)

    #cleanup
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass("Migrate vcenter vm to zstack successfully.")
コード例 #14
0
def check_available_cpu_mem(zone_uuid):
    available_cpu = test_lib.lib_get_cpu_memory_capacity([zone_uuid]).availableCpu
    available_memory = test_lib.lib_get_cpu_memory_capacity([zone_uuid]).availableMemory
    return available_cpu, available_memory
コード例 #15
0
def test():
    global original_rate
    global new_offering_uuid
    test_util.test_dsc('Test memory over provision method')
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.' )
        return True

    host = host[0]
    over_provision_rate = 2
    target_vm_num = 4

    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    real_availableMemory = host_res.availableMemory
    avail_mem = real_availableMemory * over_provision_rate
    if avail_mem <= 1024*1024*1024:
        test_util.test_skip('Available memory is less than 512MB, skip test.')
        return True

    test_util.test_logger('host available memory is: %s' % host_res.availableMemory)

    original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate)

    new_offering_mem = int((avail_mem - 1) / target_vm_num)
    if (new_offering_mem % 2) != 0 :
        new_offering_mem = new_offering_mem - 1 
    new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem)

    new_offering_uuid = new_offering.uuid

    times = 1
    while (times <= target_vm_num):
        try:
            vm_name = 'mem_over_prs_vm_%d' % times
            vm = test_stub.create_vm(vm_name = vm_name, \
                    host_uuid = host.uuid, \
                    instance_offering_uuid = new_offering.uuid)
            test_obj_dict.add_vm(vm)
            host_res_new = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
            test_util.test_logger('After create vm: %s, host available memory is: %s' % (vm_name, host_res_new.availableMemory))
        except Exception as e:
            test_util.test_logger("Unexpected VM Creation Failure in memory over provision test. Previous available memory is %s" % host_res_new.availableMemory)
            raise e

        times += 1

    host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    avail_mem2 = host_res2.availableMemory
    if avail_mem2 > new_offering_mem:
        test_util.test_fail('Available memory: %d is still bigger than offering memory: %d , after creating 4 vms.' % (avail_mem2, new_offering_mem))
    
    try:
        vm = test_stub.create_vm(vm_name = 'mem_over_prs_vm_bad', \
                host_uuid = host.uuid, \
                instance_offering_uuid = new_offering.uuid)
        test_obj_dict.add_vm(vm)
    except:
        test_util.test_logger("Expected VM Creation Failure in memory over provision test. ")
    else:
        test_util.test_fail("The 5th VM is still created up, which is wrong")

    test_lib.lib_set_provision_memory_rate(original_rate)
    vm_ops.delete_instance_offering(new_offering_uuid)
    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('Memory Over Provision Test Pass')
コード例 #16
0
def check_available_cpu_mem(zone_uuid):
    available_cpu = test_lib.lib_get_cpu_memory_capacity([zone_uuid
                                                          ]).availableCpu
    available_memory = test_lib.lib_get_cpu_memory_capacity([zone_uuid
                                                             ]).availableMemory
    return available_cpu, available_memory
コード例 #17
0
def test():
    global original_rate
    global new_offering_uuid
    test_util.test_dsc('Test memory over provision method')
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit=1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.')
        return True

    host = host[0]
    over_provision_rate = 2
    target_vm_num = 4

    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid])
    real_availableMemory = host_res.availableMemory - \
            sizeunit.get_size(test_lib.lib_get_reserved_memory())
    avail_mem = real_availableMemory * over_provision_rate
    if avail_mem <= 1024 * 1024 * 1024:
        test_util.test_skip('Available memory is less than 512MB, skip test.')
        return True

    test_util.test_logger('host available memory is: %s' %
                          host_res.availableMemory)

    original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate)

    new_offering_mem = avail_mem / target_vm_num
    new_offering = test_lib.lib_create_instance_offering(
        memorySize=new_offering_mem)

    new_offering_uuid = new_offering.uuid

    times = 1
    while (times <= target_vm_num):
        try:
            vm_name = 'mem_over_prs_vm_%d' % times
            vm = test_stub.create_vm(vm_name = vm_name, \
                    host_uuid = host.uuid, \
                    instance_offering_uuid = new_offering.uuid)
            test_obj_dict.add_vm(vm)
            host_res_new = test_lib.lib_get_cpu_memory_capacity(
                host_uuids=[host.uuid])
            test_util.test_logger(
                'After create vm: %s, host available memory is: %s' %
                (vm_name, host_res_new.availableMemory))
        except Exception as e:
            test_util.test_logger(
                "Unexpected VM Creation Failure in memory over provision test. Previous available memory is %s"
                % host_res_new.availableMemory)
            raise e

        times += 1

    host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid])
    avail_mem2 = host_res2.availableMemory
    if avail_mem2 > new_offering_mem:
        test_util.test_fail(
            'Available memory: %d is still bigger than offering memory: %d , after creating 4 vms.'
            % (avail_mem2, new_offering_mem))

    try:
        vm = test_stub.create_vm(vm_name = 'mem_over_prs_vm_bad', \
                host_uuid = host.uuid, \
                instance_offering_uuid = new_offering.uuid)
        test_obj_dict.add_vm(vm)
    except:
        test_util.test_logger(
            "Expected VM Creation Failure in memory over provision test. ")
    else:
        test_util.test_fail("The 5th VM is still created up, which is wrong")

    test_lib.lib_set_provision_memory_rate(original_rate)
    vm_ops.delete_instance_offering(new_offering_uuid)
    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('Memory Over Provision Test Pass')
コード例 #18
0
def test():
    global original_rate
    global new_offering_uuid
    test_util.test_dsc('Test memory allocation and reclaiming.')
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.' )
        return True

    host = host[0]
    over_provision_rate = 1
    target_vm_num = 5

    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    #avail_mem = host_res.availableMemory * over_provision_rate
    avail_mem = host_res.availableMemory
    if avail_mem <= 1024*1024*1024:
        test_util.test_skip('Available memory is less than 1024MB, skip test.')
        return True

    original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate)
    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
    avail_mem = host_res.availableMemory

    test_mem = avail_mem / target_vm_num
    new_offering_mem = test_mem
    new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem)

    new_offering_uuid = new_offering.uuid

    rounds = 0
    while (rounds < 3):
        times = 1
        while (times <= (target_vm_num)):
            thread = threading.Thread(target = parallelly_create_vm, \
                    args = ('parallel_vm_creating_%d' % times, \
                        host.uuid, \
                        new_offering.uuid, ))
            thread.start()

            times += 1

        times = 1
        print 'Running VM: %s ' % len(test_obj_dict.get_vm_list())
        while threading.active_count() > 1:
            check_thread_exception()
            time.sleep(1)
            if times > 30:
                test_util.test_fail('creating vm time exceed 30s')
            times += 1

        check_thread_exception()

        for vm in test_obj_dict.get_all_vm_list():
            try:
                vm.destroy()
                test_obj_dict.rm_vm(vm)
            except Exception as e:
                test_util.test_logger("VM Destroying Failure in memory reclaiming test. :%s " % e)
                raise e

        host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid])
        avail_mem2 = host_res2.availableMemory
        if avail_mem2 != avail_mem:
            test_util.test_fail('Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds))

        rounds += 1
    
    test_lib.lib_set_provision_memory_rate(original_rate)
    vm_ops.delete_instance_offering(new_offering_uuid)
    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('Parallel vm creation Test Pass')
コード例 #19
0
def test():
    global original_rate
    global new_offering_uuid
    test_util.test_dsc('Test memory allocation and reclaiming.')
    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit=1)
    if not host:
        test_util.test_skip('No Enabled/Connected host was found, skip test.')
        return True

    host = host[0]
    over_provision_rate = 1
    target_vm_num = 5

    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid])
    #avail_mem = host_res.availableMemory * over_provision_rate
    avail_mem = host_res.availableMemory
    if avail_mem <= 1024 * 1024 * 1024:
        test_util.test_skip('Available memory is less than 1024MB, skip test.')
        return True

    original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate)
    host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid])
    avail_mem = host_res.availableMemory

    test_mem = avail_mem / target_vm_num
    new_offering_mem = test_mem
    new_offering = test_lib.lib_create_instance_offering(
        memorySize=new_offering_mem)

    new_offering_uuid = new_offering.uuid

    rounds = 0
    while (rounds < 3):
        times = 1
        while (times <= (target_vm_num + 3)):
            try:
                vm = test_stub.create_vm(vm_name = 'mem_reclaim_vm_%d' % times, \
                        host_uuid = host.uuid, \
                        instance_offering_uuid = new_offering.uuid)
                test_obj_dict.add_vm(vm)
            except Exception as e:
                test_util.test_logger(
                    "VM Creation Failure in memory reclaiming test. :%s " % e)
                pass

            times += 1

        for vm in test_obj_dict.get_all_vm_list():
            try:
                vm.destroy()
                test_obj_dict.rm_vm(vm)
            except Exception as e:
                test_util.test_logger(
                    "VM Destroying Failure in memory reclaiming test. :%s " %
                    e)
                pass

        host_res2 = test_lib.lib_get_cpu_memory_capacity(
            host_uuids=[host.uuid])
        avail_mem2 = host_res2.availableMemory
        if avail_mem2 != avail_mem:
            test_util.test_fail(
                'Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d'
                % (avail_mem2, avail_mem, target_vm_num, rounds))

        rounds += 1

    test_lib.lib_set_provision_memory_rate(original_rate)
    vm_ops.delete_instance_offering(new_offering_uuid)
    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('Memory Over Provision Test Pass')