Exemple #1
0
def test_import_export(topology_st):
    BE_NAME = 'userRoot'
    EXCLUDE_SUFFIX = "ou=Groups,dc=example,dc=com"
    LDIF_NAME = "test_import_export.ldif"
    LDIF_PATH = os.path.join(topology_st.standalone.ds_paths.ldif_dir,
                             LDIF_NAME)
    topology_st.logcap = LogCapture()
    args = FakeArgs()

    # Export the backend
    args.be_names = [BE_NAME]
    args.ldif = LDIF_NAME
    args.use_id2entry = None
    args.encrypted = None
    args.min_base64 = None
    args.no_dump_uniq_id = None
    args.replication = None
    args.not_folded = None
    args.no_seq_num = None
    args.include_suffixes = None
    args.exclude_suffixes = [EXCLUDE_SUFFIX]
    backend_export(topology_st.standalone, None, topology_st.logcap.log, args)

    # Verify export worked
    assert os.path.exists(LDIF_PATH)
    with open(LDIF_PATH, 'r') as ldif:
        for line in ldif:
            assert not line.endswith("%s\n" % EXCLUDE_SUFFIX)

    # Import the backend
    args.be_name = BE_NAME
    args.ldifs = [LDIF_NAME]
    args.chunks_size = None
    args.encrypted = None
    args.gen_uniq_id = None
    args.only_core = None
    args.include_suffixes = None
    args.exclude_suffixes = None
    backend_import(topology_st.standalone, None, topology_st.logcap.log, args)
    os.remove(LDIF_PATH)
Exemple #2
0
def test_import_warning(topology_st):
    """Import ldif file with skipped entries to generate a warning message

    :id: 66f9275b-11b4-4718-b401-18fa6011b362
    :setup: Standalone Instance
    :steps:
        1. Create LDIF file with skipped entries
        2. Import the LDIF file with backend import
        3. Check the topology logs
        4. Check errors log
    :expectedresults:
        1. Success
        2. Success
        3. Result message should contain warning code
        4. Errors log should contain skipped entry message
    """

    standalone = topology_st.standalone
    message = 'The import task has finished successfully, with warning code 8, check the logs for more detail'

    args = FakeArgs()
    args.be_name = 'userRoot'
    args.ldifs = [create_example_ldif(topology_st)]
    args.chunks_size = None
    args.encrypted = False
    args.gen_uniq_id = None
    args.only_core = False
    args.include_suffixes = 'dc=example,dc=com'
    args.exclude_suffixes = None

    log.info('Import the LDIF file')
    backend_import(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)

    log.info('Check logs for a warning message')
    assert topology_st.logcap.contains(message)
    assert standalone.ds_error_log.match(
        '.*Skipping entry "uid=demo,ou=People,dc=example,dc=com" which has no parent.*'
    )