Ejemplo n.º 1
0
def destroy_initial_database():
    zoneinvs = res_ops.query_resource_fields(res_ops.ZONE, [], None, ['uuid'])
    for zoneinv in zoneinvs:
        zone_operations.delete_zone(zoneinv.uuid)
    backstorageinvs = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None, ['uuid'])
    for backstorageinv in backstorageinvs:
        bs_operations.delete_backup_storage(backstorageinv.uuid)
    iam2_ops.clean_iam2_enviroment()
def error_cleanup():
    global disaster_bs_uuid
    global data_volume_uuid
    global image_uuid
    vol_ops.delete_volume(data_volume_uuid)
    img_ops.delete_image(image_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
Ejemplo n.º 3
0
def error_cleanup():
    global disaster_bs_uuid
    global data_volume_uuid
    global image_uuid
    vol_ops.delete_volume(data_volume_uuid)
    img_ops.delete_image(image_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
def error_cleanup():
    global disaster_bs_uuid
    global image_uuid
    global vm
    vm_ops.destroy_vm(vm.uuid)
    img_ops.delete_image(image_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
def error_cleanup():
    global image_uuid, backup_storage_inventory_uuid
    if not image_uuid:
        img_ops.delete_image(image_uuid)
        img_ops.expunge_image(image_uuid)
    if not backup_storage_inventory_uuid:
        bs_ops.delete_backup_storage(backup_storage_inventory_uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
def error_cleanup():
    global image_uuid, backup_storage_inventory_uuid
    if not image_uuid:
        img_ops.delete_image(image_uuid)
        img_ops.expunge_image(image_uuid)
    if not backup_storage_inventory_uuid: 
        bs_ops.delete_backup_storage(backup_storage_inventory_uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
Ejemplo n.º 7
0
def destroy_initial_database():
    zoneinvs = res_ops.query_resource_fields(res_ops.ZONE, [], None, ['uuid'])
    for zoneinv in zoneinvs:
        zone_operations.delete_zone(zoneinv.uuid)
    backstorageinvs = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [],
                                                    None, ['uuid'])
    for backstorageinv in backstorageinvs:
        bs_operations.delete_backup_storage(backstorageinv.uuid)
def error_cleanup():
    global disaster_bs_uuid
    global image_uuid
    global vm
    vm_ops.destroy_vm(vm.uuid)
    img_ops.delete_image(image_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
def test():
    test_util.test_dsc('create image check timeout test')
    if res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE):
        bs = res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE)[0]
    else:
        test_util.test_skip("No sftp backupstorage for test. Skip test")
    cond = res_ops.gen_query_conditions('backupStorageRef.backupStorage.uuid',
                                        '=', bs.uuid)
    images = res_ops.query_resource(res_ops.IMAGE, cond)

    #create backup storage on previous vm
    backup_storage_option = test_util.SftpBackupStorageOption()
    backup_storage_option.name = bs.name
    backup_storage_option.username = bs.username
    backup_storage_option.hostname = bs.hostname
    backup_storage_option.password = test_lib.lib_get_backup_storage_host(
        bs.uuid).password
    backup_storage_option.sshPort = bs.sshPort
    backup_storage_option.importImages = "true"
    backup_storage_option.url = bs.url

    bs_ops.delete_backup_storage(bs.uuid)
    backup_storage_inventory = bs_ops.create_backup_storage(
        backup_storage_option)
    time.sleep(5)
    cond = res_ops.gen_query_conditions('backupStorageRef.backupStorage.uuid',
                                        '=', backup_storage_inventory.uuid)
    images_imported = res_ops.query_resource(res_ops.IMAGE, cond)
    if len(images_imported) != len(images):
        test_util.test_fail(
            "imported images has different number(%s) than original images(%s)"
            % (len(images_imported), len(images)))
    for image in images:
        image_match = False
        for ii in images_imported:
            if compare_image(image, ii):
                image_match = True
        if not image_match:
            test_util.test_fail("images(%s) not imported correctly" %
                                (image.uuid))

    test_lib.lib_error_cleanup(test_obj_dict)
def test():
    test_util.test_dsc('create image check timeout test')
    if res_ops.query_resource(res_ops.CEPH_BACKUP_STORAGE):
        bs = res_ops.query_resource(res_ops.CEPH_BACKUP_STORAGE)[0]
    else:
        test_util.test_skip("No ceph backupstorage for test. Skip test")
    cond = res_ops.gen_query_conditions('backupStorageRef.backupStorage.uuid',
                                        '=', bs.uuid)
    images = res_ops.query_resource(res_ops.IMAGE, cond)

    #create backup storage on previous vm
    backup_storage_option = test_util.CephBackupStorageOption()
    backup_storage_option.name = bs.name
    backup_storage_option.monUrls = os.environ.get(
        'cephBackupStorageMonUrls').split(';')
    backup_storage_option.importImages = "true"
    backup_storage_option.poolName = bs.poolName

    bs_ops.delete_backup_storage(bs.uuid)
    backup_storage_inventory = bs_ops.create_backup_storage(
        backup_storage_option)
    time.sleep(5)
    cond = res_ops.gen_query_conditions('backupStorageRef.backupStorage.uuid',
                                        '=', backup_storage_inventory.uuid)
    images_imported = res_ops.query_resource(res_ops.IMAGE, cond)
    if len(images_imported) != len(images):
        test_util.test_fail(
            "imported images has different number(%s) than original images(%s)"
            % (len(images_imported), len(images)))
    for image in images:
        image_match = False
        for ii in images_imported:
            if compare_image(image, ii):
                image_match = True
        if not image_match:
            test_util.test_fail("images(%s) not imported correctly" %
                                (image.uuid))

    test_lib.lib_error_cleanup(test_obj_dict)
def test():
    bs_list = res_ops.query_resource(res_ops.IMAGE_STORE_BACKUP_STORAGE)
    images = res_ops.query_resource(res_ops.IMAGE)
    image_name_list = [img.name for img in images]
    for _bs in bs_list:
        bs_ops.delete_backup_storage(_bs.uuid)

    time.sleep(10)

    for bs in bs_list:
        bs_option = test_util.ImageStoreBackupStorageOption()
        bs_option.set_name(bs.name)
        bs_option.set_url(bs.url)
        bs_option.set_hostname(bs.hostname)
        bs_option.set_password('password')
        bs_option.set_sshPort(bs.sshPort)
        bs_option.set_username(bs.username)
        bs_option.set_import_images('true')
        bs_inv = bs_ops.create_image_store_backup_storage(bs_option)

        for zone_uuid in bs.attachedZoneUuids:
            bs_ops.attach_backup_storage(bs_inv.uuid, zone_uuid)

    time.sleep(10)

    _bs_list = res_ops.query_resource(res_ops.IMAGE_STORE_BACKUP_STORAGE)
    _images = res_ops.query_resource(res_ops.IMAGE)
    _image_name_list = [_img.name for _img in _images]

    if set([bs.name for bs in bs_list]) != set([_bs.name for _bs in _bs_list]):
        test_util.test_fail("Add ImageStore backupstorage failed")

    if set(image_name_list) != set(_image_name_list):
        test_util.test_fail("Import image failed when add ImageStore backupstorage")

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Add ImageStore backupstorage with image importing test Pass')
def test():
    test_util.test_dsc('create image check timeout test')
    if res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE):
        bs = res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE)[0]
    else:
        test_util.test_skip("No sftp backupstorage for test. Skip test")
    cond = res_ops.gen_query_conditions('backupStorageRef.backupStorage.uuid', '=', bs.uuid)
    images =  res_ops.query_resource(res_ops.IMAGE, cond)

    #create backup storage on previous vm
    backup_storage_option = test_util.SftpBackupStorageOption()
    backup_storage_option.name = bs.name
    backup_storage_option.username = bs.username
    backup_storage_option.hostname = bs.hostname
    backup_storage_option.password = test_lib.lib_get_backup_storage_host(bs.uuid).password
    backup_storage_option.sshPort = bs.sshPort
    backup_storage_option.importImages = "true"
    backup_storage_option.url = bs.url

    bs_ops.delete_backup_storage(bs.uuid)
    backup_storage_inventory = bs_ops.create_backup_storage(backup_storage_option)
    time.sleep(5)
    cond = res_ops.gen_query_conditions('backupStorageRef.backupStorage.uuid', '=', backup_storage_inventory.uuid)
    images_imported =  res_ops.query_resource(res_ops.IMAGE, cond)
    if len(images_imported) != len(images):
        test_util.test_fail("imported images has different number(%s) than original images(%s)" % (len(images_imported), len(images)))
    for image in images:
        image_match = False
        for ii in images_imported:
	    if compare_image(image, ii):
                image_match = True
        if not image_match:
            test_util.test_fail("images(%s) not imported correctly" % (image.uuid))


    test_lib.lib_error_cleanup(test_obj_dict)
def env_recover():
    global disaster_bs_uuid
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
    image_option = test_util.ImageOption()
    image_option.set_name('add_image_to_data_protect_bs')
    image_option.set_format(image.format)
    image_option.set_platform(image.platform)
    image_option.set_url(image.url)
    image_option.set_mediaType(image.mediaType)
    image_option.set_backup_storage_uuid_list([disaster_bs_uuid])
    #Try to add image to disaster bs directly
    try:
        new_img = img_ops.add_image(image_option)
    except Exception,e:
        if unicode(e).encode("utf-8").find('禁止') != -1:
            test_util.test_pass('AddImage is forbidden in Disaster BS, Here is the expect error info: %s' %unicode(e).encode("utf-8"))

    finally:
        bs_ops.delete_backup_storage(disaster_bs_uuid)

    test_util.test_fail('The Image is add to Disaster BS unexpectly')

#Will be called only if exception happens in test().
def error_cleanup():
    global disaster_bs_uuid
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)

#recover envrionment wehether the test pass or not
def env_recover():
    global disaster_bs_uuid
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
def error_cleanup():
    global disaster_bs_uuid
    global root_volume_uuid
    vol_ops.delete_volume(root_volume_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
Ejemplo n.º 16
0
def error_cleanup():
    global disaster_bs_uuid
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
Ejemplo n.º 17
0
    image_option.set_format(image.format)
    image_option.set_platform(image.platform)
    image_option.set_url(image.url)
    image_option.set_mediaType(image.mediaType)
    image_option.set_backup_storage_uuid_list([disaster_bs_uuid])
    #Try to add image to disaster bs directly
    try:
        new_img = img_ops.add_image(image_option)
    except Exception, e:
        if str(e).find('forbidden') != -1:
            test_util.test_pass(
                'AddImage is forbidden in Disaster BS, Here is the expect error info: %s'
                % str(e))

    finally:
        bs_ops.delete_backup_storage(disaster_bs_uuid)

    test_util.test_fail('The Image is add to Disaster BS unexpectly')


#Will be called only if exception happens in test().
def error_cleanup():
    global disaster_bs_uuid
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)


#recover envrionment wehether the test pass or not
def env_recover():
    global disaster_bs_uuid
    if disaster_bs_uuid != None:
def error_cleanup():
    global disaster_bs_uuid
    global root_volume_uuid
    vol_ops.delete_volume(root_volume_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
Ejemplo n.º 19
0
def test():
    test_util.test_dsc('Create Scheduler Trigger and Scheduler Job')
    cond = res_ops.gen_query_conditions('type', '=', 'ImageStoreBackupStorage')
    bs = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)
    if not bs :
        test_util.test_skip('Not find image store type backup storage.')
    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3PublicNetworkName')
    remote_bs_vm = test_stub.create_vm('remote_bs_vm', image_name, l3_name)
    test_obj_dict.add_vm(remote_bs_vm)
    image_name = os.environ.get('imageName_s')
    l3_name = os.environ.get('l3VlanNetworkName1')
    test_vm = test_stub.create_vm('test-vm', image_name, l3_name)
    test_obj_dict.add_vm(test_vm)
    add_local_bs_tag = tag_ops.create_system_tag('ImageStoreBackupStorageVO', bs[0].uuid,'allowbackup')
    #wait for vm start up 
    test_lib.lib_wait_target_up(remote_bs_vm.vm.vmNics[0].ip, '22', 90)
    remote_bs = test_stub.create_image_store_backup_storage('remote_bs', remote_bs_vm.vm.vmNics[0].ip, 'root', 'password', '/zstack_bs', '22')
    add_remote_bs = tag_ops.create_system_tag('ImageStoreBackupStorageVO', remote_bs.uuid,'remotebackup')
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    bs_ops.attach_backup_storage(remote_bs.uuid, zone_uuid)    
    parameters= {"retentionType":"Count","retentionValue":"1","backupStorageUuids":bs[0].uuid,"remoteBackupStorageUuid":""}
    schd_job = schd_ops.create_scheduler_job('backup_database_scheduler', 'backup_database_scheduler', '7ae6456c0b01324dae6d4bef358a5772', 'databaseBackup',parameters=parameters)
    schd_trigger = schd_ops.create_scheduler_trigger('backup_database_schedule',type='cron', cron='0 * * ? * *')
    schd_ops.add_scheduler_job_to_trigger(schd_trigger.uuid, schd_job.uuid)
    #wait for 60s *2
    time.sleep(120)
 
    db_backup1 = schd_ops.query_db_backup()
    if len(db_backup1) != 1:
        test_util.test_fail('there sholuld be 1 db backup,but now there are %s' % len(db_backup1))   
    db_backup2 = schd_ops.get_db_backup_from_imagestore(url = 'ssh://*****:*****@%s:22/zstack_bs' % bs[0].hostname)
    if len(db_backup2.backups) != 1:
        test_util.test_fail('there sholuld be 1 db backup,but now there are %s' % len(db_backup2.backups))

    db_url = schd_ops.export_db_backup_from_bs(bs[0].uuid, db_backup1[0].uuid) 
    test_util.test_dsc('export database backup successfully,url is %s' % db_url.databaseBackupUrl)
    schd_ops.sync_db_from_imagestore_bs(remote_bs.uuid, bs[0].uuid, db_backup1[0].uuid)
    test_vm.destroy()

    test_util.test_dsc('Recover db From BackupStorage')
    backupStorageUrl = 'ssh://*****:*****@%s:22/zstack_bs' % remote_bs_vm.vm.vmNics[0].ip
    recover_db = schd_ops.recover_db_from_backup(backupStorageUrl = backupStorageUrl, backupInstallPath = db_backup2.backups[0].installPath, mysqlRootPassword='******')
    #wait for db recover
    time.sleep(60)
    cond = res_ops.gen_query_conditions('name', '=', 'test-vm')
    vm = res_ops.query_resource(res_ops.VM_INSTANCE, cond)
    if not vm:
        test_util.test_fail('there sholuld be a vm after recovering db from remote backup bs')
    
    schd_ops.change_scheduler_state(schd_job.uuid, 'disable')
    db_backup3 = schd_ops.query_db_backup()
    zone = res_ops.query_resource(res_ops.ZONE)[0]
    zone_ops.delete_zone(zone.uuid)
    recover_db = schd_ops.recover_db_from_backup(uuid=db_backup3[0].uuid, mysqlRootPassword='******')
    #wait for db recover
    time.sleep(60)
    vm = res_ops.query_resource(res_ops.VM_INSTANCE, cond)
    if not vm:
        test_util.test_fail('there sholuld be a vm after recovering db from local backup bs')

    test_util.test_dsc('Clear env')
    schd_ops.del_scheduler_job(schd_job.uuid)
    schd_ops.del_scheduler_trigger(schd_trigger.uuid)
    tag_ops.delete_tag(add_local_bs_tag.uuid)
    bs_ops.delete_backup_storage(remote_bs.uuid)    
    bs_ops.reclaim_space_from_bs(bs[0].uuid)
    remote_bs_vm.destroy()
    test_vm.destroy()
Ejemplo n.º 20
0
def env_recover():
    global disaster_bs_uuid
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
def error_cleanup():
    global disaster_bs_uuid
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)