Beispiel #1
0
def test_del_suffix_backend(topo):
    """Adding a database entry fails if the same database was deleted after an import

    :id: ac702c35-74b6-434e-8e30-316433f3e91a
    :feature: Import
    :setup: Standalone instance
    :steps: 1. Create a test suffix and add entries
            2. Stop the server and do online import using ldif2db
            3. Delete the suffix backend
            4. Add a new suffix with the same database name
            5. Restart the server and check the status
    :expectedresults: Adding database with the same name should be successful and the server should not hang
    """

    log.info('Adding suffix:{} and backend: {}'.format(TEST_SUFFIX2,
                                                       TEST_BACKEND2))
    backends = Backends(topo.standalone)
    backend = backends.create(properties={
        'nsslapd-suffix': TEST_SUFFIX2,
        'name': TEST_BACKEND2
    })

    log.info('Create LDIF file and import it')
    ldif_dir = topo.standalone.get_ldif_dir()
    ldif_file = os.path.join(ldif_dir, 'suffix_del2.ldif')

    dbgen(topo.standalone, 10, ldif_file, TEST_SUFFIX2)

    topo.standalone.tasks.importLDIF(suffix=TEST_SUFFIX2,
                                     input_file=ldif_file,
                                     args={TASK_WAIT: True})

    log.info('Deleting suffix-{}'.format(TEST_SUFFIX2))
    backend.delete()

    log.info(
        'Adding the same database-{} after deleting it'.format(TEST_BACKEND2))
    backends.create(properties={
        'nsslapd-suffix': TEST_SUFFIX2,
        'name': TEST_BACKEND2
    })
    log.info(
        'Checking if server can be restarted after re-adding the same database'
    )
    topo.standalone.restart()
    assert not topo.standalone.detectDisorderlyShutdown()
Beispiel #2
0
def test_del_suffix_import(topo):
    """Adding a database entry fails if the same database was deleted after an import

    :id: 652421ef-738b-47ed-80ec-2ceece6b5d77
    :feature: Import
    :setup: Standalone instance
    :steps: 1. Create a test suffix and add few entries
            2. Stop the server and do offline import using ldif2db
            3. Delete the suffix backend
            4. Add a new suffix with the same database name
            5. Check if adding the same database name is a success
    :expectedresults: Adding database with the same name should be successful
    """

    log.info('Adding suffix:{} and backend: {}'.format(TEST_SUFFIX1,
                                                       TEST_BACKEND1))
    backends = Backends(topo.standalone)
    backend = backends.create(properties={
        'nsslapd-suffix': TEST_SUFFIX1,
        'name': TEST_BACKEND1
    })

    log.info('Create LDIF file and import it')
    ldif_dir = topo.standalone.get_ldif_dir()
    ldif_file = os.path.join(ldif_dir, 'suffix_del1.ldif')

    dbgen(topo.standalone, 10, ldif_file, TEST_SUFFIX1)

    log.info('Stopping the server and running offline import')
    topo.standalone.stop()
    assert topo.standalone.ldif2db(TEST_BACKEND1, TEST_SUFFIX1, None, None,
                                   ldif_file)
    topo.standalone.start()

    log.info('Deleting suffix-{}'.format(TEST_SUFFIX2))
    backend.delete()

    log.info(
        'Adding the same database-{} after deleting it'.format(TEST_BACKEND1))
    backends.create(properties={
        'nsslapd-suffix': TEST_SUFFIX1,
        'name': TEST_BACKEND1
    })
Beispiel #3
0
def test_import_be_default(topo):
    """ Create a backend using the name "default". previously this name was
    used int

    :id: 8e507beb-e917-4330-8cac-1ff0eee10508
    :feature: Import
    :setup: Standalone instance
    :steps:
        1. Create a test suffix using the be name of "default"
        2. Create an ldif for the "default" backend
        3. Import ldif
        4. Verify all entries were imported
    :expectedresults:
        1. Success
        2. Success
        3. Success
        4. Success
    """
    log.info('Adding suffix:{} and backend: {}...'.format(
        TEST_DEFAULT_SUFFIX, TEST_DEFAULT_NAME))
    backends = Backends(topo.standalone)
    backends.create(properties={
        'nsslapd-suffix': TEST_DEFAULT_SUFFIX,
        'name': TEST_DEFAULT_NAME
    })

    log.info('Create LDIF file and import it...')
    ldif_dir = topo.standalone.get_ldif_dir()
    ldif_file = os.path.join(ldif_dir, 'default.ldif')
    dbgen(topo.standalone, 5, ldif_file, TEST_DEFAULT_SUFFIX)

    log.info('Stopping the server and running offline import...')
    topo.standalone.stop()
    assert topo.standalone.ldif2db(TEST_DEFAULT_NAME, None, None, None,
                                   ldif_file)
    topo.standalone.start()

    log.info('Verifying entry count after import...')
    entries = topo.standalone.search_s(TEST_DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE,
                                       "(objectclass=*)")
    assert len(entries) > 1

    log.info('Test PASSED')
Beispiel #4
0
def test_sss_mr(topo):
    """Test matching rule/server side sort does not crash DS

    :id: 48c73d76-1694-420f-ab55-187135f2d260
    :setup: Standalone Instance
    :steps:
        1. Add sample entries to the database
        2. Perform search using server side control (uid:2.5.13.3)
    :expectedresults:
        1. Success
        2. Success
    """

    log.info("Creating LDIF...")
    ldif_dir = topo.standalone.get_ldif_dir()
    ldif_file = os.path.join(ldif_dir, 'mr-crash.ldif')
    dbgen(topo.standalone, 5, ldif_file, DEFAULT_SUFFIX)

    log.info("Importing LDIF...")
    topo.standalone.stop()
    assert topo.standalone.ldif2db(DEFAULT_BENAME, None, None, None, ldif_file)
    topo.standalone.start()

    log.info(
        'Search using server side sorting using undefined mr in the attr...')
    sort_ctrl = SSSRequestControl(True, ['uid:2.5.13.3'])
    controls = [sort_ctrl]
    msg_id = topo.standalone.search_ext(DEFAULT_SUFFIX,
                                        ldap.SCOPE_SUBTREE,
                                        "objectclass=*",
                                        serverctrls=controls)
    try:
        rtype, rdata, rmsgid, response_ctrl = topo.standalone.result3(msg_id)
    except ldap.OPERATIONS_ERROR:
        pass

    log.info("Test PASSED")
Beispiel #5
0
def test_basic_import_export(topology_st, import_example_ldif):
    """Test online and offline LDIF import & export

    :id: 3ceeea11-9235-4e20-b80e-7203b2c6e149

    :setup: Standalone instance

    :steps:
         1. Generate a test ldif (50k entries)
         2. Import test ldif file using Online import.
         3. Import test ldif file using Offline import (ldif2db).
         4. Export test ldif file using Online export.
         5. Export test ldif file using Offline export (db2ldif).
         6. Cleanup - Import the Example LDIF for the other tests in this suite

    :expectedresults:
         1. Test ldif file creation should PASS.
         2. Online import should PASS.
         3. Offline import should PASS.
         4. Online export should PASS.
         5. Offline export should PASS.
         6. Cleanup should PASS.
    """

    log.info('Running test_basic_import_export...')

    tmp_dir = '/tmp'

    #
    # Test online/offline LDIF imports
    #
    topology_st.standalone.start()

    # Generate a test ldif (50k entries)
    ldif_dir = topology_st.standalone.get_ldif_dir()
    import_ldif = ldif_dir + '/basic_import.ldif'
    dbgen(topology_st.standalone, 50000, import_ldif, DEFAULT_SUFFIX)

    # Online
    try:
        topology_st.standalone.tasks.importLDIF(suffix=DEFAULT_SUFFIX,
                                                input_file=import_ldif,
                                                args={TASK_WAIT: True})
    except ValueError:
        log.fatal('test_basic_import_export: Online import failed')
        assert False

    # Offline
    topology_st.standalone.stop()
    if not topology_st.standalone.ldif2db(DEFAULT_BENAME, None, None, None, import_ldif):
        log.fatal('test_basic_import_export: Offline import failed')
        assert False
    topology_st.standalone.start()

    #
    # Test online and offline LDIF export
    #

    # Online export
    export_ldif = ldif_dir + '/export.ldif'
    exportTask = Tasks(topology_st.standalone)
    try:
        args = {TASK_WAIT: True}
        exportTask.exportLDIF(DEFAULT_SUFFIX, None, export_ldif, args)
    except ValueError:
        log.fatal('test_basic_import_export: Online export failed')
        assert False

    # Offline export
    topology_st.standalone.stop()
    if not topology_st.standalone.db2ldif(DEFAULT_BENAME, (DEFAULT_SUFFIX,),
                                          None, None, None, export_ldif):
        log.fatal('test_basic_import_export: Failed to run offline db2ldif')
        assert False

    topology_st.standalone.start()

    #
    # Cleanup - Import the Example LDIF for the other tests in this suite
    #
    ldif = '%s/dirsrv/data/Example.ldif' % topology_st.standalone.get_data_dir()
    import_ldif = topology_st.standalone.get_ldif_dir() + "/Example.ldif"
    shutil.copyfile(ldif, import_ldif)
    try:
        topology_st.standalone.tasks.importLDIF(suffix=DEFAULT_SUFFIX,
                                                input_file=import_ldif,
                                                args={TASK_WAIT: True})
    except ValueError:
        log.fatal('test_basic_import_export: Online import failed')
        assert False

    log.info('test_basic_import_export: PASSED')