Пример #1
0
def test():
    new_offering = test_lib.lib_create_instance_offering(cpuNum = 1,\
            cpuSpeed = 111, memorySize = 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(new_offering)
    vm = test_stub.create_vm(vm_name='ckvmoffering-c6-64',
                             image_name="imageName_i_c6",
                             instance_offering_uuid=new_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

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

    vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(
        vm.get_vm().instanceOfferingUuid)
    vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum + 1, None)
    vm.update()
    time.sleep(10)
    vm.check()

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

    assert available_cpu_before == available_cpu_after + 1
    assert available_memory_before == available_memory_after
    assert vm_outer_cpu_before == vm_outer_cpu_after - 1
    assert vm_outer_mem_before == vm_outer_mem_after
    assert vm_interal_cpu_before == vm_interal_cpu_after - 1
    assert vm_interal_mem_before == vm_internal_mem_after
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():
    test_lib.lib_set_vm_numa('true')

    vm = test_stub.create_vr_vm('migrate_vm', 'imageName3', 'l3VlanNetwork2')
    test_obj_dict.add_vm(vm)
    vm.check()

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

    test_stub.migrate_vm_to_random_host(vm)
    vm.check()

    vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(vm.get_vm().instanceOfferingUuid)

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

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

    assert available_cpu_before == available_cpu_after + 1
    assert available_memory_after + AlignedMemChange / float(test_lib.lib_get_provision_memory_rate()) in range(available_memory_before-1, available_memory_before+1)
    assert vm_outer_cpu_before == vm_outer_cpu_after - 1
    assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange
    assert vm_interal_cpu_before == vm_interal_cpu_after - 1
    assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange/1024/1024
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering after migration Test Pass')
Пример #3
0
def test():
    test_util.test_dsc("STEP1: Ceate vm instance offering")
    vm_instanc_offering = test_lib.lib_create_instance_offering(cpuNum = 2,
                                                                memorySize = 2 * 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(vm_instanc_offering)

    test_util.test_dsc("STEP2: Ceate vm and wait until it up for testing")
    vm = test_stub.create_vm(vm_name = 'window-telnet', image_name = "imageName_windows",
                             instance_offering_uuid=vm_instanc_offering.uuid)
    test_obj_dict.add_vm(vm)
    time.sleep(10)

    test_util.test_dsc("STEP3: Hot Plugin CPU and Memory and check capacity")
    cpu_change = random.randint(1,5)
    mem_change = random.randint(1,500) * 1024 * 1024

    with test_stub.CapacityCheckerContext(vm, cpu_change, mem_change, window=True):
        vm_ops.update_vm(vm.get_vm().uuid, vm_instanc_offering.cpuNum+cpu_change,
                         vm_instanc_offering.memorySize+mem_change)
        vm.update()
        time.sleep(10)

    test_util.test_dsc("STEP4: Destroy test object")
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
Пример #4
0
def test():
    new_offering = test_lib.lib_create_instance_offering(cpuNum = 1,\
            cpuSpeed = 111, memorySize = 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(new_offering)
    vm = test_stub.create_vm(vm_name = 'ckvmoffering-c7-64', image_name = "imageName_i_c7", instance_offering_uuid=new_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

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

    vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(vm.get_vm().instanceOfferingUuid)
    MEMchange = 64*1024*1024
    vm_ops.update_vm(vm.get_vm().uuid, None, vm_instance_offering.memorySize + MEMchange)
    vm.update()
    time.sleep(10)
    test_stub.online_hotplug_cpu_memory(vm)

    (available_cpu_after, available_memory_after, vm_outer_cpu_after, vm_outer_mem_after,
     vm_interal_cpu_after, vm_internal_mem_after) = test_stub.check_cpu_mem(vm)
    AlignedMemChange = 128*1024*1024

    assert available_cpu_before == available_cpu_after
    #test_util.test_logger("%s %s %s" % (available_memory_before, available_memory_after, MEMchange))
    assert available_memory_after + AlignedMemChange / int(test_lib.lib_get_provision_memory_rate()) in range(available_memory_before-1, available_memory_before)
    assert vm_outer_cpu_before == vm_outer_cpu_after
    assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange
    assert vm_interal_cpu_before == vm_interal_cpu_after
    assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange/1024/1024
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():

    test_util.test_dsc("STEP1: Ceate vm instance offering")
    vm_instance_offering = test_lib.lib_create_instance_offering(cpuNum = 1,
                                                                memorySize = 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(vm_instance_offering)

    test_util.test_dsc("STEP2: Ceate vm and wait until it up for testing")
    vm = test_stub.create_vm(vm_name = 'ckvmoffering-c6-64', image_name = "imageName_i_c6",
                             instance_offering_uuid=vm_instance_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc("STEP3: Continuously Hot Plugin CPU and Memory and check capacity")
    last_cpu = vm_instance_offering.cpuNum
    last_mem = vm_instance_offering.memorySize
    cpu_change = 0
    mem_change_list = [random.randint(0, 500)*1024*1024 for _ in xrange(8)]

    for mem_change in mem_change_list:
        with test_stub.CapacityCheckerContext(vm, cpu_change, mem_change) as cc:
            vm_ops.update_vm(vm.get_vm().uuid, last_cpu + cpu_change, last_mem + mem_change)
            last_cpu += cpu_change
            last_mem += cc.mem_aligned_change
            vm.update()
            test_stub.online_hotplug_cpu_memory(vm)
            time.sleep(5)

    test_util.test_dsc("STEP4: Destroy test object")
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    test_util.test_dsc("STEP1: Ceate vm instance offering")
    vm_instance_offering = test_lib.lib_create_instance_offering(cpuNum=1, memorySize=1024*1024*1024)
    test_obj_dict.add_instance_offering(vm_instance_offering)

    test_util.test_dsc("STEP2: Ceate vm and wait until it up for testing image_name : {}".format(flavor['image']))
    vm = test_stub.create_vm(vm_name='test_vm', image_name=flavor['image'],
                             instance_offering_uuid=vm_instance_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

    cpu_change = random.randint(1, 5) if flavor['add_cpu'] else 0
    mem_change = random.randint(1, 500)*1024*1024 if flavor['add_memory'] else 0

    test_util.test_dsc("STEP3: Hot Plugin CPU: {} and Memory: {} and check capacity".format(cpu_change, mem_change))

    with test_stub.CapacityCheckerContext(vm, cpu_change, mem_change):
        vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum+cpu_change,
                         vm_instance_offering.memorySize+mem_change)
        vm.update()
        if flavor['need_online']:
            test_stub.online_hotplug_cpu_memory(vm)
        time.sleep(10)

    test_util.test_dsc("STEP4: Destroy test object")
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
Пример #7
0
    def testmethod():
        test_util.test_dsc("STEP1: Ceate vm instance offering")
        vm_instance_offering = test_lib.lib_create_instance_offering(
            cpuNum=1, memorySize=1024 * 1024 * 1024)
        tbj.add_instance_offering(vm_instance_offering)

        test_util.test_dsc("STEP2: Ceate vm and wait until it up for testing")
        vm = create_vm(vm_name='test_vm',
                       image_name=test_image_name,
                       instance_offering_uuid=vm_instance_offering.uuid)
        tbj.add_vm(vm)
        vm.check()

        cpu_change = random.randint(1, 5) if add_cpu else 0
        mem_change = random.randint(1, 500) * 1024 * 1024 if add_memory else 0

        test_util.test_dsc(
            "STEP3: Hot Plugin CPU: {} and Memory: {} and check capacity".
            format(cpu_change, mem_change))

        with CapacityCheckerContext(vm, cpu_change, mem_change):
            vm_ops.update_vm(vm.get_vm().uuid,
                             vm_instance_offering.cpuNum + cpu_change,
                             vm_instance_offering.memorySize + mem_change)
            vm.update()
            if need_online:
                online_hotplug_cpu_memory(vm)
            time.sleep(10)

        test_util.test_dsc("STEP4: Destroy test object")
        test_lib.lib_error_cleanup(tbj)
        test_util.test_pass('VM online change instance offering Test Pass')
Пример #8
0
    def testmethod():
        test_util.test_dsc("STEP1: Ceate vm instance offering")
        vm_instance_offering = test_lib.lib_create_instance_offering(cpuNum=1, memorySize=1024*1024*1024)
        tbj.add_instance_offering(vm_instance_offering)

        test_util.test_dsc("STEP2: Ceate vm and wait until it up for testing")
        vm = create_vm(vm_name='test_vm', image_name = test_image_name,
                       instance_offering_uuid=vm_instance_offering.uuid)
        tbj.add_vm(vm)
        vm.check()

        cpu_change = random.randint(1, 5) if add_cpu else 0
        mem_change = random.randint(1, 500)*1024*1024 if add_memory else 0

        test_util.test_dsc("STEP3: Hot Plugin CPU: {} and Memory: {} and check capacity".format(cpu_change, mem_change))

        with CapacityCheckerContext(vm, cpu_change, mem_change):
            vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum+cpu_change,
                             vm_instance_offering.memorySize+mem_change)
            vm.update()
            if need_online:
                online_hotplug_cpu_memory(vm)
            time.sleep(10)

        test_util.test_dsc("STEP4: Destroy test object")
        test_lib.lib_error_cleanup(tbj)
        test_util.test_pass('VM online change instance offering Test Pass')
def test():
    test_util.test_dsc("STEP1: Ceate vm instance offering")
    vm_instanc_offering = test_lib.lib_create_instance_offering(cpuNum = 2,
                                                                memorySize = 2 * 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(vm_instanc_offering)

    test_util.test_dsc("STEP2: Ceate vm and wait until it up for testing")
    vm = test_stub.create_vm(vm_name = 'window-telnet', image_name = "imageName_windows",
                             instance_offering_uuid=vm_instanc_offering.uuid)
    test_obj_dict.add_vm(vm)
    time.sleep(10)

    test_util.test_dsc("STEP3: Hot Plugin CPU and Memory and check capacity")
    cpu_change = random.randint(1,5)
    mem_change = random.randint(1,500) * 1024 * 1024

    with test_stub.CapacityCheckerContext(vm, cpu_change, mem_change, window=True):
        # wait for 90s to ensure all the windows services up
        time.sleep(90)
        vm_ops.update_vm(vm.get_vm().uuid, vm_instanc_offering.cpuNum+cpu_change,
                         vm_instanc_offering.memorySize+mem_change)
        vm.update()
        time.sleep(10)

    test_util.test_dsc("STEP4: Destroy test object")
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():
    test_util.test_dsc('Test update instance offering')

    vm = test_stub.create_basic_vm()
    vm.stop()
    instance_offering = test_lib.lib_get_instance_offering_by_uuid(vm.get_vm().instanceOfferingUuid)
    test_obj_dict.add_vm(vm)
    vm_ops.update_vm(vm.get_vm().uuid, instance_offering.cpuNum * 2, None)
    vm_ops.update_vm(vm.get_vm().uuid, None, instance_offering.memorySize * 2)

    vm.update()
    if (vm.get_vm().cpuNum != instance_offering.cpuNum * 2):
        test_util.test_fail("cpuNum change is expected to change")
    if (vm.get_vm().memorySize != instance_offering.memorySize * 2):
        test_util.test_fail("memorySize change is expected to change")

    vm.start()
    if (vm.get_vm().cpuNum != instance_offering.cpuNum * 2):
        test_util.test_fail("cpuNum change is expected to take effect after Vm restart")
    if (vm.get_vm().memorySize != instance_offering.memorySize * 2):
        test_util.test_fail("memorySize change is expected to take effect after Vm restart")

    vm.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Test update instance cpu memory Pass')
def update_cpu_mem(vm):
    vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(vm.get_vm().instanceOfferingUuid)
    vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum + CPUchange,
                     vm_instance_offering.memorySize + MEMchange)
    vm.update()
    test_stub.online_hotplug_cpu_memory(vm)
    vm.check()
def test():
    test_util.test_dsc("STEP1: Ceate vm instance offering")
    vm_instance_offering = test_lib.lib_create_instance_offering(
        cpuNum=1, memorySize=1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(vm_instance_offering)

    test_util.test_dsc("STEP2: Ceate vm and wait until it up for testing")
    vm = test_stub.create_vm(vm_name='ckvmoffering-c7-64',
                             image_name="imageName_i_c7",
                             instance_offering_uuid=vm_instance_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc(
        "STEP3: Continuously Hot Plugin CPU and Memory and check capacity")
    last_cpu = vm_instance_offering.cpuNum
    last_mem = vm_instance_offering.memorySize

    for _ in xrange(5):
        cpu_change = random.randint(1, 5)
        mem_change = random.randint(1, 500) * 1024 * 1024
        with test_stub.CapacityCheckerContext(vm, cpu_change,
                                              mem_change) as cc:
            vm_ops.update_vm(vm.get_vm().uuid, last_cpu + cpu_change,
                             last_mem + mem_change)
            last_cpu += cpu_change
            last_mem += cc.mem_aligned_change
            vm.update()
            test_stub.online_hotplug_cpu_memory(vm)
            time.sleep(5)

    test_util.test_dsc("STEP4: Destroy test object")
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
Пример #13
0
def test():
    test_util.test_dsc('Test update instance offering')

    vm = test_stub.create_basic_vm()
    instance_offering = test_lib.lib_get_instance_offering_by_uuid(vm.get_vm().instanceOfferingUuid)
    test_obj_dict.add_vm(vm)
    vm_ops.update_vm(vm.get_vm().uuid, instance_offering.cpuNum * 2, None)
    vm_ops.update_vm(vm.get_vm().uuid, None, instance_offering.memorySize * 2)

    vm.update()
    if (vm.get_vm().cpuNum != instance_offering.cpuNum * 2):
        test_util.test_fail("cpuNum is expected to change")
    if (vm.get_vm().memorySize != instance_offering.memorySize * 2):
        test_util.test_fail("memorySize is expected to change")

    vm.stop()
    vm.update()
    if (vm.get_vm().cpuNum != instance_offering.cpuNum * 2):
        test_util.test_fail("cpuNum is expected to change")
    if (vm.get_vm().memorySize != instance_offering.memorySize * 2):
        test_util.test_fail("memorySize is expected to change")

    vm.start()
    if (vm.get_vm().cpuNum != instance_offering.cpuNum * 2):
        test_util.test_fail("cpuNum change is expected to take effect after Vm restart")
    if (vm.get_vm().memorySize != instance_offering.memorySize * 2):
        test_util.test_fail("memorySize change is expected to take effect after Vm restart")

    vm.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Test update instance cpu memory Pass')
Пример #14
0
def update_cpu_mem(vm):
    vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(
        vm.get_vm().instanceOfferingUuid)
    vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum + CPUchange,
                     vm_instance_offering.memorySize + MEMchange)
    vm.update()
    test_stub.online_hotplug_cpu_memory(vm)
    vm.check()
Пример #15
0
def test():
    new_offering = test_lib.lib_create_instance_offering(cpuNum = 1,\
            cpuSpeed = 111, memorySize = 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(new_offering)
    vm = test_stub.create_vm(vm_name='ckvmoffering-c6-64',
                             image_name="imageName_i_c6",
                             instance_offering_uuid=new_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()
    mem_aligned_dict = {}
    mem_aligned_dict['126'] = 128 * 1024 * 1024
    mem_aligned_dict['1'] = 128 * 1024 * 1024
    mem_aligned_dict['63'] = 128 * 1024 * 1024
    mem_aligned_dict['129'] = 128 * 1024 * 1024
    mem_aligned_dict['191'] = 128 * 1024 * 1024
    mem_aligned_dict['192'] = 256 * 1024 * 1024
    mem_aligned_dict['300'] = 256 * 1024 * 1024
    last_mem = new_offering.memorySize

    for memory in mem_aligned_dict:
        (available_cpu_before, available_memory_before, vm_outer_cpu_before,
         vm_outer_mem_before, vm_interal_cpu_before,
         vm_interal_mem_before) = test_stub.check_cpu_mem(vm)

        vm_ops.update_vm(vm.get_vm().uuid, None,
                         last_mem + int(memory) * 1024 * 1024)
        vm.update()
        last_mem += mem_aligned_dict[memory] * 1024 * 1024

        (available_cpu_after, available_memory_after, vm_outer_cpu_after,
         vm_outer_mem_after, vm_interal_cpu_after,
         vm_internal_mem_after) = test_stub.check_cpu_mem(vm)
        AlignedMemChange = mem_aligned_dict[memory]

        assert available_cpu_before == available_cpu_after
        test_util.test_logger("%s %s %s" %
                              (available_memory_before, available_memory_after,
                               AlignedMemChange))
        assert available_memory_after + AlignedMemChange / int(
            test_lib.lib_get_provision_memory_rate()) in range(
                available_memory_before - 10, available_memory_before + 10)
        assert vm_outer_cpu_before == vm_outer_cpu_after
        assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange
        assert vm_interal_cpu_before == vm_interal_cpu_after
        #test_util.test_logger("%s %s %s" % (vm_interal_mem_before, vm_internal_mem_after, MEMchange))
        assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange / 1024 / 1024
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():

    test_util.test_dsc("STEP1: Ceate vm instance offering")
    vm_instance_offering = test_lib.lib_create_instance_offering(
        cpuNum=1, memorySize=1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(vm_instance_offering)

    test_util.test_dsc("STEP2: Ceate vm and wait until it up for testing")
    vm = test_stub.create_vm(vm_name='ckvmoffering-c7-64',
                             image_name="imageName_i_c7",
                             instance_offering_uuid=vm_instance_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc("STEP3: Ceate Snapshot of root volume")
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    snapshots = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots.set_utility_vm(vm)
    snapshots.create_snapshot('create_root_snapshot1')
    snapshot1 = snapshots.get_current_snapshot()

    test_util.test_dsc("STEP4: Hot Plugin CPU and Memory and check capacity")
    cpu_change = random.randint(1, 5)
    mem_change = random.randint(1, 500) * 1024 * 1024

    with test_stub.CapacityCheckerContext(vm, cpu_change, mem_change):
        vm_ops.update_vm(vm.get_vm().uuid,
                         vm_instance_offering.cpuNum + cpu_change,
                         vm_instance_offering.memorySize + mem_change)
        vm.update()
        test_stub.online_hotplug_cpu_memory(vm)
        time.sleep(10)

    test_util.test_dsc(
        "STEP5: Recover from snapshot make sure CPU memory no change")
    with test_stub.CapacityCheckerContext(vm, 0, 0) as cc:
        vm.stop()
        vm.check()
        snapshots.check()
        snapshots.use_snapshot(snapshot1)
        vm.start()
        vm.check()
        cc.disable_internal_check = True

    test_util.test_dsc("STEP6: Destroy test object")
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():
    new_offering = test_lib.lib_create_instance_offering(cpuNum = 1,\
            cpuSpeed = 111, memorySize = 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(new_offering)
    vm = test_stub.create_vm(vm_name='ckvmoffering-c7-64',
                             image_name="imageName_i_c7",
                             instance_offering_uuid=new_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

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

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

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

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

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

    assert available_cpu_before == available_cpu_after + 1
    assert available_memory_after + AlignedMemChange / int(
        test_lib.lib_get_provision_memory_rate()) in range(
            available_memory_before - 1, available_memory_before + 1)
    assert vm_outer_cpu_before == vm_outer_cpu_after - 1
    assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange
    assert vm_interal_cpu_before == vm_interal_cpu_after - 1
    assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange / 1024 / 1024
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():

    test_util.test_dsc("STEP1: Ceate vm instance offering")
    vm_instance_offering = test_lib.lib_create_instance_offering(cpuNum = 1,
                                                                memorySize = 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(vm_instance_offering)

    test_util.test_dsc("STEP2: Ceate vm and wait until it up for testing")
    vm = test_stub.create_vm(vm_name = 'ckvmoffering-c7-64', image_name = "imageName_i_c7",
                             instance_offering_uuid=vm_instance_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

    test_util.test_dsc("STEP3: Ceate Snapshot of root volume")
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    snapshots = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots.set_utility_vm(vm)
    snapshots.create_snapshot('create_root_snapshot1')
    snapshot1 = snapshots.get_current_snapshot()

    test_util.test_dsc("STEP4: Hot Plugin CPU and Memory and check capacity")
    cpu_change = random.randint(1,5)
    mem_change = random.randint(1,500)*1024*1024

    with test_stub.CapacityCheckerContext(vm, cpu_change, mem_change):
        vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum+cpu_change,
                         vm_instance_offering.memorySize+mem_change)
        vm.update()
        test_stub.online_hotplug_cpu_memory(vm)
        time.sleep(10)

    test_util.test_dsc("STEP5: Recover from snapshot make sure CPU memory no change")
    with test_stub.CapacityCheckerContext(vm, 0, 0) as cc:
        vm.stop()
        vm.check()
        snapshots.check()
        snapshots.use_snapshot(snapshot1)
        vm.start()
        vm.check()
        cc.disable_internal_check = True

    test_util.test_dsc("STEP6: Destroy test object")
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():
    vm = hot_plug_common.create_onlinechange_vm(test_stub, test_obj_dict)
    (available_cpu_before, available_memory_before, vm_outer_cpu_before, vm_outer_mem_before,
     vm_interal_cpu_before, vm_interal_mem_before) = hot_plug_common.check_cpu_mem(vm)

    vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(vm.get_vm().instanceOfferingUuid)
    vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum + 1, None)
    vm.update()
    time.sleep(10)

    (available_cpu_after, available_memory_after, vm_outer_cpu_after, vm_outer_mem_after,
     vm_interal_cpu_after, vm_internal_mem_after) = hot_plug_common.check_cpu_mem(vm)

    assert available_cpu_before == available_cpu_after + 1
    assert available_memory_before == available_memory_after
    assert vm_outer_cpu_before == vm_outer_cpu_after - 1
    assert vm_outer_mem_before == vm_outer_mem_after
    assert vm_interal_cpu_before == vm_interal_cpu_after - 1
    assert vm_interal_mem_before == vm_internal_mem_after
def test():
    new_offering = test_lib.lib_create_instance_offering(cpuNum = 1,\
            cpuSpeed = 111, memorySize = 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(new_offering)
    vm = test_stub.create_vm(vm_name='ckvmoffering-c7-64',
                             image_name="imageName_i_c7",
                             instance_offering_uuid=new_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()
    last_cpu = new_offering.cpuNum
    last_mem = new_offering.memorySize

    for x in xrange(5):
        (available_cpu_before, available_memory_before, vm_outer_cpu_before,
         vm_outer_mem_before, vm_interal_cpu_before,
         vm_interal_mem_before) = test_stub.check_cpu_mem(vm)

        MEMchange = 126 * 1024 * 1024
        AlignedMemChange = 128 * 1024 * 1024
        vm_ops.update_vm(vm.get_vm().uuid, last_cpu + 2, last_mem + MEMchange)
        last_cpu += 2
        last_mem += MEMchange
        vm.update()
        time.sleep(10)
        test_stub.online_hotplug_cpu_memory(vm)
        vm.check()

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

        assert available_cpu_before == available_cpu_after + 2
        assert available_memory_after + AlignedMemChange / int(
            test_lib.lib_get_provision_memory_rate()) in range(
                available_memory_before - 1, available_memory_before + 1)
        assert vm_outer_cpu_before == vm_outer_cpu_after - 2
        assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange
        assert vm_interal_cpu_before == vm_interal_cpu_after - 2
        assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange / 1024 / 1024
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():
    test_lib.lib_set_vm_numa('true')

    vm = test_stub.create_vr_vm('migrate_vm', 'imageName3', 'l3VlanNetwork2')
    test_obj_dict.add_vm(vm)
    vm.check()

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

    test_stub.migrate_vm_to_random_host(vm)
    vm.check()

    vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(
        vm.get_vm().instanceOfferingUuid)

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

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

    assert available_cpu_before == available_cpu_after + 1
    assert available_memory_after + AlignedMemChange / float(
        test_lib.lib_get_provision_memory_rate()) in range(
            available_memory_before - 1, available_memory_before + 1)
    assert vm_outer_cpu_before == vm_outer_cpu_after - 1
    assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange
    assert vm_interal_cpu_before == vm_interal_cpu_after - 1
    assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange / 1024 / 1024
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass(
        'VM online change instance offering after migration Test Pass')
def test():
    vm = hot_plug_common.create_onlinechange_vm(test_stub, test_obj_dict)
    (available_cpu_before, available_memory_before, vm_outer_cpu_before,
     vm_outer_mem_before, vm_interal_cpu_before,
     vm_interal_mem_before) = hot_plug_common.check_cpu_mem(vm)

    vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(
        vm.get_vm().instanceOfferingUuid)
    vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum + 1, None)
    vm.update()
    time.sleep(10)

    (available_cpu_after, available_memory_after, vm_outer_cpu_after,
     vm_outer_mem_after, vm_interal_cpu_after,
     vm_internal_mem_after) = hot_plug_common.check_cpu_mem(vm)

    assert available_cpu_before == available_cpu_after + 1
    assert available_memory_before == available_memory_after
    assert vm_outer_cpu_before == vm_outer_cpu_after - 1
    assert vm_outer_mem_before == vm_outer_mem_after
    assert vm_interal_cpu_before == vm_interal_cpu_after - 1
    assert vm_interal_mem_before == vm_internal_mem_after
def test():
    new_offering = test_lib.lib_create_instance_offering(cpuNum = 1,\
            memorySize = 1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(new_offering)
    vm = test_stub.create_vm(vm_name = 'ckvmoffering-c7-64', image_name = "imageName_i_c7", instance_offering_uuid=new_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

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

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

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

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

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

    assert available_cpu_before == available_cpu_after + 1
    assert available_memory_after + AlignedMemChange / int(test_lib.lib_get_provision_memory_rate()) in range(available_memory_before-1, available_memory_before+1)
    assert vm_outer_cpu_before == vm_outer_cpu_after - 1
    assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange
    assert vm_interal_cpu_before == vm_interal_cpu_after - 1
    assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange/1024/1024
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():
    new_offering = test_lib.lib_create_instance_offering(cpuNum=1,
                                                         cpuSpeed=111,
                                                         memorySize=1024 *
                                                         1024 * 1024)
    test_obj_dict.add_instance_offering(new_offering)
    vm = test_stub.create_vm(vm_name='ckvmoffering-u12-64',
                             image_name="imageName_i_u12",
                             instance_offering_uuid=new_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()
    last_cpu = new_offering.cpuNum

    for _ in xrange(5):
        (available_cpu_before, available_memory_before, vm_outer_cpu_before,
         vm_outer_mem_before, vm_interal_cpu_before,
         vm_interal_mem_before) = test_stub.check_cpu_mem(vm)
        vm_ops.update_vm(vm.get_vm().uuid, last_cpu + 1, None)
        last_cpu += 1
        vm.update()
        test_stub.online_hotplug_cpu_memory(vm)
        vm.check()

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

        assert available_cpu_before == available_cpu_after + 1
        assert available_memory_before == available_memory_after
        assert vm_outer_cpu_before == vm_outer_cpu_after - 1
        assert vm_outer_mem_before == vm_outer_mem_after
        assert vm_interal_cpu_before == vm_interal_cpu_after - 1
        assert vm_interal_mem_before == vm_internal_mem_after

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
def test():
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    test_util.test_dsc("STEP1: Ceate vm instance offering")
    vm_instance_offering = test_lib.lib_create_instance_offering(
        cpuNum=1, memorySize=1024 * 1024 * 1024)
    test_obj_dict.add_instance_offering(vm_instance_offering)

    test_util.test_dsc(
        "STEP2: Ceate vm and wait until it up for testing image_name : {}".
        format(flavor['image']))
    vm = test_stub.create_vm(vm_name='test_vm',
                             image_name=flavor['image'],
                             instance_offering_uuid=vm_instance_offering.uuid)
    test_obj_dict.add_vm(vm)
    vm.check()

    cpu_change = random.randint(1, 5) if flavor['add_cpu'] else 0
    mem_change = random.randint(
        1, 500) * 1024 * 1024 if flavor['add_memory'] else 0

    test_util.test_dsc(
        "STEP3: Hot Plugin CPU: {} and Memory: {} and check capacity".format(
            cpu_change, mem_change))

    with test_stub.CapacityCheckerContext(vm, cpu_change, mem_change):
        vm_ops.update_vm(vm.get_vm().uuid,
                         vm_instance_offering.cpuNum + cpu_change,
                         vm_instance_offering.memorySize + mem_change)
        vm.update()
        if flavor['need_online']:
            test_stub.online_hotplug_cpu_memory(vm)
        time.sleep(10)

    test_util.test_dsc("STEP4: Destroy test object")
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('VM online change instance offering Test Pass')
Пример #26
0
 def set_iso_first(self, iso_uuid, vm_uuid=None):
     if not vm_uuid:
         vm_uuid = self.vm1.vm.uuid
     system_tags = ['iso::%s::0' % iso_uuid]
     vm_ops.update_vm(vm_uuid, system_tags=system_tags)
def running_vm_operations(vm,bss):
      
   numa = config_ops.get_global_config_value('vm', 'numa')
   live_migration = config_ops.get_global_config_value('localStoragePrimaryStorage','liveMigrationWithStorage.allow')
   ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
   vm_uuid = vm.get_vm().uuid
   #change vm's instanceoffering
   if numa == 'false':
      try:
         vm_ops.update_vm(vm_uuic,2,2048*1024*1024)
         test_util.test_fail('Test Fail.Cannot change instanceoffering of running vm when NUMA is false')
      except:
         config_ops.change_global_config('vm','numa','true')
   
   vm_ops.reboot_vm(vm_uuid)
   vm_ops.update_vm(vm_uuid,2,2048*1024*1024)

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

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

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

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

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

   vm_ops.destroy_vm(vm_uuid)
   vm_ops.recover_vm(vm_uuid)
   vm_ops.start_vm(vm_uuid)
   vm.destroy()
   vm.expunge()
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 running_vm_operations(vm, bss):

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

    vm_ops.reboot_vm(vm_uuid)
    vm_ops.update_vm(vm_uuid, 2, 2048 * 1024 * 1024)

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

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

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

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

    vm_ops.change_vm_password(vm_uuid, 'root', 'testpassword')
    vm_ops.set_vm_qga_disable(vm_uuid)

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

    common_operations(vm, bss, 'running')

    vm_ops.destroy_vm(vm_uuid)
    vm_ops.recover_vm(vm_uuid)
    vm_ops.start_vm(vm_uuid)
    vm.destroy()
    vm.expunge()
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()