コード例 #1
0
def add_backup_storage(deployConfig, session_uuid):
    if xmlobject.has_element(deployConfig, 'backupStorages.sftpBackupStorage'):
        for bs in xmlobject.safe_list(deployConfig.backupStorages.sftpBackupStorage):
            action = api_actions.AddSftpBackupStorageAction()
            action.sessionUuid = session_uuid
            action.name = bs.name_
            action.description = bs.description__
            action.url = bs.url_
            action.username = bs.username_
            action.password = bs.password_
            action.hostname = bs.hostname_
            action.timeout = AddKVMHostTimeOut #for some platform slowly salt execution
            action.type = inventory.SFTP_BACKUP_STORAGE_TYPE
            if bs.uuid__:
                action.resourceUuid = bs.uuid__
            thread = threading.Thread(target = _thread_for_action, args = (action, ))
            wait_for_thread_queue()
            thread.start()

    if xmlobject.has_element(deployConfig, 'backupStorages.simulatorBackupStorage'):
        for bs in xmlobject.safe_list(deployConfig.backupStorages.simulatorBackupStorage):
            action = api_actions.AddSimulatorBackupStorageAction()
            action.sessionUuid = session_uuid
            action.name = bs.name_
            action.description = bs.description__
            action.url = bs.url_
            action.type = inventory.SIMULATOR_BACKUP_STORAGE_TYPE
            action.totalCapacity = sizeunit.get_size(bs.totalCapacity_)
            action.availableCapacity = sizeunit.get_size(bs.availableCapacity_)
            thread = threading.Thread(target = _thread_for_action, args = (action, ))
            wait_for_thread_queue()
            thread.start()

    wait_for_thread_done()
コード例 #2
0
def add_virtual_router(deployConfig, session_uuid, l3_name = None, \
        zone_name = None):

    if not xmlobject.has_element(deployConfig, 'instanceOfferings.virtualRouterOffering'):
        return

    for i in xmlobject.safe_list(deployConfig.instanceOfferings.virtualRouterOffering):
        if l3_name and l3_name != i.managementL3NetworkRef.text_:
            continue 

        if zone_name and zone_name != i.zoneRef.text_:
            continue 

        print "continue l3_name: %s; zone_name: %s" % (l3_name, zone_name)
        action = api_actions.CreateVirtualRouterOfferingAction()
        action.sessionUuid = session_uuid
        action.name = i.name_
        action.description = i.description__
        action.cpuNum = i.cpuNum_
        action.cpuSpeed = i.cpuSpeed_
        if i.memorySize__:
            action.memorySize = sizeunit.get_size(i.memorySize_)
        elif i.memoryCapacity_:
            action.memorySize = sizeunit.get_size(i.memoryCapacity_)

        action.isDefault = i.isDefault__
        action.type = 'VirtualRouter'

        zinvs = res_ops.get_resource(res_ops.ZONE, session_uuid, name=i.zoneRef.text_)
        zinv = get_first_item_from_list(zinvs, 'zone', i.zoneRef.text_, 'virtual router offering')
        action.zoneUuid = zinv.uuid
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zinv.uuid)
        cond1 = res_ops.gen_query_conditions('name', '=', \
                i.managementL3NetworkRef.text_, cond)
        minvs = res_ops.query_resource(res_ops.L3_NETWORK, cond1, \
                session_uuid)

        minv = get_first_item_from_list(minvs, 'Management L3 Network', i.managementL3NetworkRef.text_, 'virtualRouterOffering')

        action.managementNetworkUuid = minv.uuid
        if xmlobject.has_element(i, 'publicL3NetworkRef'):
            cond1 = res_ops.gen_query_conditions('name', '=', \
                    i.publicL3NetworkRef.text_, cond)
            pinvs = res_ops.query_resource(res_ops.L3_NETWORK, cond1, \
                    session_uuid)
            pinv = get_first_item_from_list(pinvs, 'Public L3 Network', i.publicL3NetworkRef.text_, 'virtualRouterOffering')

            action.publicNetworkUuid = pinv.uuid

        iinvs = res_ops.get_resource(res_ops.IMAGE, session_uuid, \
                name=i.imageRef.text_)
        iinv = get_first_item_from_list(iinvs, 'Image', i.imageRef.text_, 'virtualRouterOffering')

        action.imageUuid = iinv.uuid

        thread = threading.Thread(target = _thread_for_action, args = (action, ))
        wait_for_thread_queue()
        thread.start()

    wait_for_thread_done()
コード例 #3
0
    def _generate_sim_ps_action(zone, pr, zone_ref, cluster_ref):
        if zone_ref == 0:
            zone_name = zone.name_
        else:
            zone_name = generate_dup_name(zone.name_, zone_ref, 'z')

        zinvs = res_ops.get_resource(res_ops.ZONE,
                                     session_uuid,
                                     name=zone_name)
        zinv = get_first_item_from_list(zinvs, 'Zone', zone_name,
                                        'primary storage')

        action = api_actions.AddSimulatorPrimaryStorageAction()
        action.sessionUuid = session_uuid
        action.name = generate_dup_name(
            generate_dup_name(pr.name_, zone_ref, 'z'), cluster_ref, 'c')
        action.description = generate_dup_name(
            generate_dup_name(pr.description__, zone_ref, 'zone'), cluster_ref,
            'cluster')
        action.url = generate_dup_name(
            generate_dup_name(pr.url_, zone_ref, 'z'), cluster_ref, 'c')

        action.type = inventory.SIMULATOR_PRIMARY_STORAGE_TYPE
        action.zoneUuid = zinv.uuid
        action.totalCapacity = sizeunit.get_size(pr.totalCapacity_)
        action.availableCapacity = sizeunit.get_size(pr.availableCapacity_)
        if pr.uuid__:
            action.resourceUuid = pr.uuid__
        return action
コード例 #4
0
    def _deploy_host(cluster, zone_ref, cluster_ref):
        if not xmlobject.has_element(cluster, "hosts.host"):
            return

        if zone_ref == 0 and cluster_ref == 0:
            cluster_name = cluster.name_
        else:
            cluster_name = generate_dup_name(generate_dup_name(cluster.name_, zone_ref, 'z'), cluster_ref, 'c')

        cinvs = res_ops.get_resource(res_ops.CLUSTER, session_uuid, name=cluster_name)
        cinv = get_first_item_from_list(cinvs, 'Cluster', cluster_name, 'L3 network')
        for host in xmlobject.safe_list(cluster.hosts.host):
            if host_ip and host_ip != host.managementIp_:
                continue

            if host.duplication__ == None:
                host_duplication = 1
            else:
                host_duplication = int(host.duplication__)

            for i in range(host_duplication):
                if cluster.hypervisorType_ == inventory.KVM_HYPERVISOR_TYPE:
                    action = api_actions.AddKVMHostAction()
                    action.username = host.username_
                    action.password = host.password_
                    action.timeout = AddKVMHostTimeOut
                    if hasattr(host, 'sshPort_'):
                        action.port = host.sshPort_
                elif cluster.hypervisorType_ == inventory.SIMULATOR_HYPERVISOR_TYPE:
                    action = api_actions.AddSimulatorHostAction()
                    if host.cpuCapacity__:
                        action.cpuCapacity = host.cpuCapacity_
                    else:
                        action.cpuCapacity = 416000
                    if host.memoryCapacity__:
                        action.memoryCapacity = sizeunit.get_size(host.memoryCapacity_)
                    else:
                        action.memoryCapacity = sizeunit.get_size('1024G')

                action.sessionUuid = session_uuid
                action.clusterUuid = cinv.uuid
                action.hostTags = host.hostTags__
                if zone_ref == 0 and cluster_ref == 0 and i == 0:
                    action.name = host.name_
                    action.description = host.description__
                    action.managementIp = host.managementIp_
                    if host.uuid__:
                        action.resourceUuid = host.uuid__
                else:
                    action.name = generate_dup_name(
                        generate_dup_name(generate_dup_name(host.name_, zone_ref, 'z'), cluster_ref, 'c'), i, 'h')
                    action.description = generate_dup_name(
                        generate_dup_name(generate_dup_name(host.description__, zone_ref, 'z'), cluster_ref, 'c'), i,
                        'h')
                    action.managementIp = generate_dup_host_ip(host.managementIp_, zone_ref, cluster_ref, i)

                thread = threading.Thread(target=_thread_for_action, args=(action,))
                wait_for_thread_queue()
                thread.start()
コード例 #5
0
ファイル: cephagent.py プロジェクト: tsunli/zstack-utility
    def _get_file_actual_size(self, path):
        ret = bash.bash_r("rbd info %s | grep -q fast-diff" % path)

        # if no fast-diff supported and not xsky ceph skip actual size check
        if ret != 0 and not ceph.is_xsky():
            return None

        # use json format result first
        r, jstr = bash.bash_ro("rbd du %s --format json" % path)
        if r == 0 and bool(jstr):
            total_size = 0
            result = jsonobject.loads(jstr)
            if result.images is not None:
                for item in result.images:
                    total_size += int(item.used_size)
                return total_size

        r, size = bash.bash_ro(
            "rbd du %s | awk 'END {if(NF==3) {print $3} else {print $4,$5} }' | sed s/[[:space:]]//g"
            % path,
            pipe_fail=True)
        if r != 0:
            return None

        size = size.strip()
        if not size:
            return None

        return sizeunit.get_size(size)
コード例 #6
0
    def _add_io(instance_offering_xml_obj, session_uuid):
        action = api_actions.CreateInstanceOfferingAction()
        action.sessionUuid = session_uuid
        action.name = instance_offering_xml_obj.name_
        action.description = instance_offering_xml_obj.description__
        action.cpuNum = instance_offering_xml_obj.cpuNum_
        action.cpuSpeed = instance_offering_xml_obj.cpuSpeed_
        if instance_offering_xml_obj.memorySize__:
            action.memorySize = sizeunit.get_size(instance_offering_xml_obj.memorySize_)
        elif instance_offering_xml_obj.memoryCapacity_:
            action.memorySize = sizeunit.get_size(instance_offering_xml_obj.memoryCapacity_)

        try:
            evt = action.run()
            test_util.test_logger(jsonobject.dumps(evt))
        except:
            exc_info.append(sys.exc_info())
コード例 #7
0
 def _add_disk_offering(disk_offering_xml_obj, session_uuid):
     action = api_actions.CreateDiskOfferingAction()
     action.sessionUuid = session_uuid
     action.name = disk_offering_xml_obj.name_
     action.description = disk_offering_xml_obj.description_
     action.diskSize = sizeunit.get_size(disk_offering_xml_obj.diskSize_)
     if disk_offering_xml_obj.uuid__:
         action.resourceUuid = disk_offering_xml_obj.uuid__
     evt = action.run()
     dinv = evt.inventory
     deploy_logger(jsonobject.dumps(evt))
コード例 #8
0
 def _add_disk_offering(disk_offering_xml_obj, session_uuid):
     action = api_actions.CreateDiskOfferingAction()
     action.sessionUuid = session_uuid
     action.name = disk_offering_xml_obj.name_
     action.description = disk_offering_xml_obj.description_
     action.diskSize = sizeunit.get_size(disk_offering_xml_obj.diskSize_)
     try:
         evt = action.run()
         test_util.test_logger(jsonobject.dumps(evt))
     except:
         exc_info.append(sys.exc_info())
コード例 #9
0
    def _generate_sim_ps_action(zone, pr, zone_ref, cluster_ref):
        if zone_ref == 0:
            zone_name = zone.name_
        else:
            zone_name = generate_dup_name(zone.name_, zone_ref, 'z')

        zinvs = res_ops.get_resource(res_ops.ZONE, session_uuid, name=zone_name)
        zinv = get_first_item_from_list(zinvs, 'Zone', zone_name, 'primary storage')

        action = api_actions.AddSimulatorPrimaryStorageAction()
        action.sessionUuid = session_uuid
        action.name = generate_dup_name(generate_dup_name(pr.name_, zone_ref, 'z'), cluster_ref, 'c') 
        action.description = generate_dup_name(generate_dup_name(pr.description__, zone_ref, 'zone'), cluster_ref, 'cluster')
        action.url = generate_dup_name(generate_dup_name(pr.url_, zone_ref, 'z'), cluster_ref, 'c')

        action.type = inventory.SIMULATOR_PRIMARY_STORAGE_TYPE
        action.zoneUuid = zinv.uuid
        action.totalCapacity = sizeunit.get_size(pr.totalCapacity_)
        action.availableCapacity = sizeunit.get_size(pr.availableCapacity_)
        return action
コード例 #10
0
 def _add_io(instance_offering_xml_obj, session_uuid):
     action = api_actions.CreateInstanceOfferingAction()
     action.sessionUuid = session_uuid
     action.name = instance_offering_xml_obj.name_
     action.description = instance_offering_xml_obj.description__
     action.cpuNum = instance_offering_xml_obj.cpuNum_
     action.cpuSpeed = instance_offering_xml_obj.cpuSpeed_
     action.memorySize = sizeunit.get_size(instance_offering_xml_obj.memorySize_)
     if instance_offering_xml_obj.uuid__:
         action.resourceUuid = instance_offering_xml_obj.uuid__
     evt = action.run()
     deploy_logger(jsonobject.dumps(evt))
コード例 #11
0
ファイル: cephagent.py プロジェクト: zstackorg/zstack-utility
    def _get_file_actual_size(self, path):
        ret = bash.bash_r("rbd info %s | grep -q fast-diff" % path)

        # if no fast-diff supported and not xsky ceph skip actual size check
        if ret != 0 and not isXsky():
            return None

        r, size = bash.bash_ro("rbd du %s | tail -1 | awk '{ print $3 }'" % path)

        if r != 0:
            return None

        size = size.strip('\t\n ')
        return sizeunit.get_size(size)
コード例 #12
0
ファイル: cephagent.py プロジェクト: ilibx/zstack-utility
    def _get_file_actual_size(self, path):
        ret = bash.bash_r("rbd info %s | grep -q fast-diff" % path)

        # if no fast-diff supported and not xsky ceph skip actual size check
        if ret != 0 and not ceph.is_xsky():
            return None

        r, size = bash.bash_ro("rbd du %s | tail -1 | awk '{ print $3 }'" %
                               path)

        if r != 0:
            return None

        if not size:
            return None

        size = size.strip('\t\n ')
        return sizeunit.get_size(size)
コード例 #13
0
def add_backup_storage(deployConfig, session_uuid):
    if xmlobject.has_element(deployConfig, 'backupStorages.sftpBackupStorage'):
        for bs in xmlobject.safe_list(deployConfig.backupStorages.sftpBackupStorage):
            action = api_actions.AddSftpBackupStorageAction()
            action.sessionUuid = session_uuid
            action.name = bs.name_
            action.description = bs.description__
            action.url = bs.url_
            action.username = bs.username_
            action.password = bs.password_
            action.hostname = bs.hostname_
	    if hasattr(bs, 'port_'):
                action.port = bs.port_
                action.sshport = bs.port_
                action.sshPort = bs.port_
            action.timeout = AddKVMHostTimeOut #for some platform slowly salt execution
            action.type = inventory.SFTP_BACKUP_STORAGE_TYPE
            thread = threading.Thread(target = _thread_for_action, args = (action, ))
            wait_for_thread_queue()
            thread.start()

    if xmlobject.has_element(deployConfig, 'backupStorages.imageStoreBackupStorage'):
        for bs in xmlobject.safe_list(deployConfig.backupStorages.imageStoreBackupStorage):
            action = api_actions.AddImageStoreBackupStorageAction()
            action.sessionUuid = session_uuid
            action.name = bs.name_
            action.description = bs.description__
            action.url = bs.url_
            action.username = bs.username_
            action.password = bs.password_
            action.hostname = bs.hostname_
	    if hasattr(bs, 'port_'):
                action.port = bs.port_
                action.sshport = bs.port_
                action.sshPort = bs.port_
            action.timeout = AddKVMHostTimeOut #for some platform slowly salt execution
            action.type = inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE
            thread = threading.Thread(target = _thread_for_action, args = (action, ))
            wait_for_thread_queue()
            thread.start()

    if xmlobject.has_element(deployConfig, 'backupStorages.cephBackupStorage'):
        for bs in xmlobject.safe_list(deployConfig.backupStorages.cephBackupStorage):
            action = api_actions.AddCephBackupStorageAction()
            action.sessionUuid = session_uuid
            action.name = bs.name_
            action.description = bs.description__
            action.monUrls = bs.monUrls_.split(';')
            if bs.poolName__:
                action.poolName = bs.poolName_
            action.timeout = AddKVMHostTimeOut #for some platform slowly salt execution
            action.type = inventory.CEPH_BACKUP_STORAGE_TYPE
            thread = threading.Thread(target = _thread_for_action, args = (action, ))
            wait_for_thread_queue()
            thread.start()

    if xmlobject.has_element(deployConfig, 'backupStorages.simulatorBackupStorage'):
        for bs in xmlobject.safe_list(deployConfig.backupStorages.simulatorBackupStorage):
            action = api_actions.AddSimulatorBackupStorageAction()
            action.sessionUuid = session_uuid
            action.name = bs.name_
            action.description = bs.description__
            action.url = bs.url_
            action.type = inventory.SIMULATOR_BACKUP_STORAGE_TYPE
            action.totalCapacity = sizeunit.get_size(bs.totalCapacity_)
            action.availableCapacity = sizeunit.get_size(bs.availableCapacity_)
            thread = threading.Thread(target = _thread_for_action, args = (action, ))
            wait_for_thread_queue()
            thread.start()

    wait_for_thread_done()
コード例 #14
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')
コード例 #15
0
def test():
    global res
    global original_rate
    test_util.test_dsc('Test storage over provision method')
    test_lib.lib_skip_if_ps_num_is_not_eq_number(1)
    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

    ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1)
    if not ps:
        test_util.test_skip('No Enabled/Connected primary storage was found, skip test.' )
        return True

    host = host[0]
    ps = ps[0]
    ps_type = ps.type
    #TODO: Fix ceph testing
    if ps_type == 'Ceph' or ps_type == 'SharedMountPoint':
        test_util.test_skip('skip test for ceph and smp.')

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

    avail_cap = get_storage_capacity(ps_type, host.uuid, ps.uuid)
    if avail_cap < kept_disk_size:
        test_util.test_skip('available disk capacity:%d is too small, skip test.' % avail_cap)
        return True
    res = sizeunit.get_size(test_lib.lib_get_reserved_primary_storage())
    original_rate = test_lib.lib_set_provision_storage_rate(over_provision_rate)
    #data_volume_size = int(over_provision_rate * (avail_cap - kept_disk_size) / target_volume_num)   
    data_volume_size = int(over_provision_rate * (avail_cap - res )/ target_volume_num)
    #will change the rate back to check if available capacity is same with original one. This was a bug, that only happened when system create 1 vm.
    test_lib.lib_set_provision_storage_rate(original_rate)
    avail_cap_tmp = get_storage_capacity(ps_type, host.uuid, ps.uuid)
    if avail_cap != avail_cap_tmp:
        test_util.test_fail('disk size is not same, between 2 times provision. Before change over rate, 1st cap: %d; 2nd cap: %d' % (avail_cap, avail_cap_tmp))

    test_lib.lib_set_provision_storage_rate(over_provision_rate)
    test_util.test_logger('Will create a serial of volume. Each of them will have %d size.' % data_volume_size)
    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)
    
    times = 1
    while (times <= target_volume_num):
        try:
            volume_creation_option.set_name('volume-%d' % times)
            volume = test_stub.create_volume(volume_creation_option)
            test_obj_dict.add_volume(volume)
            test_util.test_logger('Current available storage size: %d' % get_storage_capacity(ps_type, host.uuid, ps.uuid))
            volume.attach(vm)
        except Exception as e:
            test_util.test_logger("Unexpected volume Creation Failure in storage over provision test. ")
            raise e

        times += 1

    time.sleep(2)
    avail_cap2 = (get_storage_capacity(ps_type, host.uuid, ps.uuid)-res)
    if avail_cap2 > data_volume_size:
        test_util.test_fail('Available disk size: %d is still bigger than offering disk size: %d , after creating %d volumes.' % (avail_cap2, data_volume_size, target_volume_num))
    
    try:
        volume_creation_option.set_name('volume-%d' % (times + 1))
        volume = test_stub.create_volume(volume_creation_option)
        test_obj_dict.add_volume(volume)
        volume.attach(vm)
    except:
        test_util.test_logger("Expected Volume Creation Failure in storage over provision test. ")
    else:
        test_util.test_fail("The %dth Volume is still attachable, which is wrong"% (target_volume_num + 1))

    test_lib.lib_set_provision_storage_rate(original_rate)
    test_lib.lib_robot_cleanup(test_obj_dict)

    test_util.test_pass('Memory Over Provision Test Pass')
コード例 #16
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')