def __init__(self):
     super(ZstackTestVolume, self).__init__()
     self.volume_creation_option = test_util.VolumeOption()
     self.original_checking_points = []
     self.delete_policy = test_lib.lib_get_delete_policy('volume')
     self.delete_delay_time = test_lib.lib_get_expunge_time('volume')
     self.snapshot_tree = None
Exemplo n.º 2
0
 def __init__(self):
     super(ZstackTestVm, self).__init__()
     self.vm_creation_option = test_util.VmOption()
     self.changed_instance_offering_uuid = None
     self.delete_policy = test_lib.lib_get_delete_policy('vm')
     self.delete_delay_time = test_lib.lib_get_expunge_time('vm')
     self.test_volumes = []
Exemplo n.º 3
0
def test():
    global vm
    if test_lib.lib_get_ha_enable() != 'true':
        test_util.test_skip("vm ha not enabled. Skip test")

    delete_policy = test_lib.lib_get_delete_policy('vm')
    vm = test_stub.create_vm()
    vm.set_delete_policy('Delay')
    vm.check()
    vm.destroy()
    ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")
    vm.recover()
    time.sleep(60)
    vm.set_state(vm_header.RUNNING)
    vm.check()
    vm.destroy()
    vm.set_delete_policy(delete_policy)
    test_util.test_pass('VM ha never stop auto start with recover Test Success')
Exemplo n.º 4
0
 def __init__(self):
     super(ZstackTestVm, self).__init__()
     self.vm_creation_option = test_util.VmOption()
     self.changed_instance_offering_uuid = None
     self.delete_policy = test_lib.lib_get_delete_policy('vm')
     self.delete_delay_time = test_lib.lib_get_expunge_time('vm')
 def __init__(self):
     super(ZstackTestImage, self).__init__()
     self.image_creation_option = test_util.ImageOption()
     self.original_checking_points = []
     self.delete_policy = test_lib.lib_get_delete_policy('image')
     self.delete_delay_time = test_lib.lib_get_expunge_time('image')
Exemplo n.º 6
0
 def __init__(self):
     super(ZstackTestImage, self).__init__()
     self.image_creation_option = test_util.ImageOption()
     self.original_checking_points = []
     self.delete_policy = test_lib.lib_get_delete_policy('image')
     self.delete_delay_time = test_lib.lib_get_expunge_time('image')
def test():
    global vm
    global schd1
    global schd2

    delete_policy = test_lib.lib_get_delete_policy('vm')
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    vm.set_delete_policy('Delay')

    start_date = int(time.time())
    schd1 = vm_ops.stop_vm_scheduler(vm.get_vm().uuid, 'simple',
                                     'simple_stop_vm_scheduler',
                                     start_date + 10, 20)
    schd2 = vm_ops.start_vm_scheduler(vm.get_vm().uuid, 'simple',
                                      'simple_start_vm_scheduler',
                                      start_date + 20, 20)

    test_stub.sleep_util(start_date + 45)

    test_util.test_dsc('check scheduler state after create scheduler')
    check_scheduler_state(schd1, 'Enabled')
    check_scheduler_state(schd2, 'Enabled')
    if not check_scheduler_msg('run scheduler for job: StopVmInstanceJob',
                               start_date + 10):
        test_util.test_fail(
            'StopVmInstanceJob not executed at expected timestamp range')
    if not check_scheduler_msg('run scheduler for job: StartVmInstanceJob',
                               start_date + 20):
        test_util.test_fail(
            'StartVmInstanceJob not executed at expected timestamp range')

    vm.destroy()

    current_time = int(time.time())
    except_start_time = start_date + 20 * ((
        (current_time - start_date) % 20) + 1)
    test_stub.sleep_util(except_start_time + 45)

    test_util.test_dsc('check scheduler state after destroy vm')
    check_scheduler_state(schd1, 'Disabled')
    check_scheduler_state(schd2, 'Disabled')
    if check_scheduler_msg('run scheduler for job: StopVmInstanceJob',
                           except_start_time + 10):
        test_util.test_fail(
            'StopVmInstanceJob executed at unexpected timestamp range')
    if check_scheduler_msg('run scheduler for job: StartVmInstanceJob',
                           except_start_time + 20):
        test_util.test_fail(
            'StartVmInstanceJob executed at unexpected timestamp range')

    vm.recover()

    current_time = int(time.time())
    except_start_time = start_date + 20 * ((
        (current_time - start_date) % 20) + 1)
    test_stub.sleep_util(except_start_time + 45)

    test_util.test_dsc('check scheduler state after recover vm')
    check_scheduler_state(schd1, 'Enabled')
    check_scheduler_state(schd2, 'Enabled')
    if not check_scheduler_msg('run scheduler for job: StopVmInstanceJob',
                               except_start_time + 10):
        test_util.test_fail(
            'StopVmInstanceJob not executed at expected timestamp range')
    if not check_scheduler_msg('run scheduler for job: StartVmInstanceJob',
                               except_start_time + 20):
        test_util.test_fail(
            'StartVmInstanceJob not executed at expected timestamp range')

    schd_ops.delete_scheduler(schd1.uuid)
    schd_ops.delete_scheduler(schd2.uuid)
    vm.set_delete_policy(delete_policy)
    vm.destroy()

    conditions = res_ops.gen_query_conditions('uuid', '=', schd1.uuid)
    if len(res_ops.query_resource(res_ops.SCHEDULER, conditions)) > 0:
        test_util.test_fail(
            'check stop vm scheduler, it is expected to be destroied, but it still exists'
        )

    conditions = res_ops.gen_query_conditions('uuid', '=', schd2.uuid)
    if len(res_ops.query_resource(res_ops.SCHEDULER, conditions)) > 0:
        test_util.test_fail(
            'check start vm scheduler, it is expected to be destroied, but it still exists'
        )

    test_util.test_pass(
        'Check Scheduler State after Destroy and Recover VM Success')
Exemplo n.º 8
0
def test():
    test_util.test_dsc('Create original vm')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)
    vm.stop()
    vm1 = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm1)
    
    vm1.check()
    test_util.test_dsc('create snapshot for root volume')
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    snapshots_root = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots_root.set_utility_vm(vm1)
    test_obj_dict.add_volume_snapshot(snapshots_root)
    snapshots_root.create_snapshot('create_root_snapshot1')

    test_util.test_dsc('create image template from root volume')
    root_volume_uuid = vm_root_volume_inv.uuid
    root_image_uuid = vm_root_volume_inv.rootImageUuid
    vm_img_inv = test_lib.lib_get_image_by_uuid(root_image_uuid)
    image_option = test_util.ImageOption()
    image_option.set_name('creating_image_from_root_volume')
    image_option.set_guest_os_type(vm_img_inv.guestOsType)
    image_option.set_bits(vm_img_inv.bits)
    image_option.set_root_volume_uuid(root_volume_uuid)
    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm())
    bs_uuid_list = []
    for bs in backup_storage_list:
        bs_uuid_list.append(bs.uuid)
    image_option.set_backup_storage_uuid_list(bs_uuid_list)
    image = zstack_img_header.ZstackTestImage()
    image.set_creation_option(image_option)
    image.create()
    if test_lib.lib_get_delete_policy('image') != zstack_header.DELETE_DIRECT:
        test_obj_dict.add_image(image)
    image.delete()

    test_util.test_dsc('Construct volume obj.')
    r_volume = zstack_volume_header.ZstackTestVolume()
    r_volume.set_volume(test_lib.lib_get_root_volume(vm.get_vm()))
    r_volume.set_state(vol_header.ATTACHED)

    test_util.test_dsc('Create volume template')
    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm())
    vol_tmpt = r_volume.create_template([bs_list[0].uuid], 'new_data_template_by_root_volume')
    if test_lib.lib_get_delete_policy('image') != zstack_header.DELETE_DIRECT:
        test_obj_dict.add_image(vol_tmpt)

    #destroy vm
    host_uuid = test_lib.lib_get_vm_host(vm.get_vm()).uuid
    vm.destroy()

    test_util.test_dsc('Create volume from template')
    ps_uuid = vm.get_vm().allVolumes[0].primaryStorageUuid
    ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid)

    if ps.type == inventory.LOCAL_STORAGE_TYPE:
        volume = vol_tmpt.create_data_volume(ps_uuid, 'new_data_volume_from_template1', host_uuid)
    else:
        volume = vol_tmpt.create_data_volume(ps_uuid, 'new_data_volume_from_template1')

    test_obj_dict.add_volume(volume)
    vol_tmpt.delete()

    test_util.test_dsc('create snapshot')
    snapshots = zstack_sp_header.ZstackVolumeSnapshot()
    snapshots.set_target_volume(volume)
    snapshots.set_utility_vm(vm1)
    test_obj_dict.add_volume_snapshot(snapshots)
    snapshots.create_snapshot('create_snapshot1')

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

    test_util.test_dsc('delete snapshot3')
    snapshots.delete_snapshot(snapshot3)

    snapshots.check()
    test_obj_dict.rm_volume_snapshot(snapshots)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create snapshot from a volume, which is created from data volume template, which is create from a root volume Success')
def test():
    global vm
    global schd_job1
    global schd_job2
    global schd_trigger1
    global schd_trigger2

    delete_policy = test_lib.lib_get_delete_policy('vm')
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    vm.set_delete_policy('Delay')

    start_date = int(time.time())
    schd_job1 = schd_ops.create_scheduler_job('simple_stop_vm_scheduler', 'simple_stop_vm_scheduler', vm.get_vm().uuid, 'stopVm', None)
    schd_trigger1 = schd_ops.create_scheduler_trigger('simple_stop_vm_scheduler', start_date+10, None, 20, 'simple')
    schd_ops.add_scheduler_job_to_trigger(schd_trigger1.uuid, schd_job1.uuid)
    #schd1 = vm_ops.stop_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_stop_vm_scheduler', start_date+10, 20)

    schd_job2 = schd_ops.create_scheduler_job('simple_start_vm_scheduler', 'simple_start_vm_scheduler', vm.get_vm().uuid, 'startVm', None)
    schd_trigger2 = schd_ops.create_scheduler_trigger('simple_start_vm_scheduler', start_date+20, None, 20, 'simple')
    schd_ops.add_scheduler_job_to_trigger(schd_trigger2.uuid, schd_job2.uuid)
    #schd2 = vm_ops.start_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_start_vm_scheduler', start_date+20, 20)

    test_stub.sleep_util(start_date+45)

    test_util.test_dsc('check scheduler state after create scheduler')
    check_scheduler_state(schd_job1, 'Enabled')
    check_scheduler_state(schd_job2, 'Enabled')
    if not check_scheduler_msg('run scheduler for job: StopVmInstanceJob', start_date+10):
        test_util.test_fail('StopVmInstanceJob not executed at expected timestamp range')
    if not check_scheduler_msg('run scheduler for job: StartVmInstanceJob', start_date+20):
        test_util.test_fail('StartVmInstanceJob not executed at expected timestamp range')

    vm.destroy()

    current_time = int(time.time())
    except_start_time =  start_date + 20 * (((current_time - start_date) % 20) + 1)
    test_stub.sleep_util(except_start_time + 45)

    test_util.test_dsc('check scheduler state after destroy vm')
    check_scheduler_state(schd_job1, 'Disabled')
    check_scheduler_state(schd_job2, 'Disabled')
    if check_scheduler_msg('run scheduler for job: StopVmInstanceJob', except_start_time+10):
        test_util.test_fail('StopVmInstanceJob executed at unexpected timestamp range')
    if check_scheduler_msg('run scheduler for job: StartVmInstanceJob', except_start_time+20):
        test_util.test_fail('StartVmInstanceJob executed at unexpected timestamp range')

    vm.recover()

    current_time = int(time.time())
    except_start_time =  start_date + 20 * (((current_time - start_date) % 20) + 1)
    test_stub.sleep_util(except_start_time + 45)

    test_util.test_dsc('check scheduler state after recover vm')
    check_scheduler_state(schd_job1, 'Disabled')
    check_scheduler_state(schd_job2, 'Disabled')
#    if not check_scheduler_msg('run scheduler for job: StopVmInstanceJob', except_start_time+10):
#        test_util.test_fail('StopVmInstanceJob not executed at expected timestamp range')
#    if not check_scheduler_msg('run scheduler for job: StartVmInstanceJob', except_start_time+20):
#        test_util.test_fail('StartVmInstanceJob not executed at expected timestamp range' )

    schd_ops.del_scheduler_job(schd_job1.uuid)
    schd_ops.del_scheduler_trigger(schd_trigger1.uuid)
    schd_ops.del_scheduler_job(schd_job2.uuid)
    schd_ops.del_scheduler_trigger(schd_trigger2.uuid)

    vm.set_delete_policy(delete_policy)
    vm.destroy()

    conditions = res_ops.gen_query_conditions('uuid', '=', schd_job1.uuid)
    if len(res_ops.query_resource(res_ops.SCHEDULERJOB, conditions)) > 0:
        test_util.test_fail('check stop vm scheduler, it is expected to be destroied, but it still exists')
   
    conditions = res_ops.gen_query_conditions('uuid', '=', schd_job2.uuid)
    if len(res_ops.query_resource(res_ops.SCHEDULERJOB, conditions)) > 0:
        test_util.test_fail('check start vm scheduler, it is expected to be destroied, but it still exists')

    test_util.test_pass('Check Scheduler State after Destroy and Recover VM Success')