#72 ./lib389/tests/instance/setup_test.py breaks CI on older versions of DS
Opened by vashirov. Modified

With 1.3.5, that doesn't have template-dse-minimal.ldif, I see the following:

lib389/tests/instance/setup_test.py::test_setup_ds_minimal FAILED
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
topology = <lib389.tests.instance.setup_test.TopologyInstance object at 0x7fcf286cec50>
    def test_setup_ds_minimal(topology):
        # Create the setupDs
        lc = LogCapture()
        # Give it the right types.
        sds = SetupDs(verbose=DEBUGGING, dryrun=False, log=lc.log)
        # Get the dicts from Type2Base, as though they were from _validate_ds_2_config
        # IE get the defaults back just from Slapd2Base.collect
        # Override instance name, root password, port and secure port.
        general_options = General2Base(lc.log)
        general_options.verify()
        general = general_options.collect()
        slapd_options = Slapd2Base(lc.log)
        slapd_options.set('instance_name', INSTANCE_SERVERID)
        slapd_options.set('port', INSTANCE_PORT)
        slapd_options.set('root_password', PW_DM)
        slapd_options.verify()
        slapd = slapd_options.collect()
>       sds.create_from_args(general, slapd, {}, None)
lib389/tests/instance/setup_test.py:99: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
lib389/instance/setup.py:300: in create_from_args
    self._install_ds(general, slapd, backends)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <lib389.instance.setup.SetupDs object at 0x7fcf286ce350>
general = {'config_version': 2, 'defaults': '999999999', 'full_machine_name': 'qeos-246.lab.eng.rdu2.redhat.com', 'selinux': True, ...}
slapd = {'backup_dir': '/var/lib/dirsrv/slapd-standalone/bak', 'bin_dir': '/usr/bin', 'cert_dir': '/etc/dirsrv/slapd-standalone', 'config_dir': '/etc/dirsrv/slapd-standalone', ...}
backends = {}
    def _install_ds(self, general, slapd, backends):
        """
            Actually install the Ds from the dicts provided.
            You should never call this directly, as it bypasses assertions.
            """
        # register the instance to /etc/sysconfig
        # We do this first so that we can trick remove-ds.pl if needed.
        # There may be a way to create this from template like the dse.ldif ...
        initconfig = ""
        with open("%s/dirsrv/config/template-initconfig" % slapd['sysconf_dir']) as template_init:
            for line in template_init.readlines():
                initconfig += line.replace('{{', '{', 1).replace('}}', '}', 1).replace('-', '_')
        with open("%s/sysconfig/dirsrv-%s" % (slapd['sysconf_dir'], slapd['instance_name']), 'w') as f:
            f.write(initconfig.format(
                SERVER_DIR=slapd['lib_dir'],
                SERVERBIN_DIR=slapd['sbin_dir'],
                CONFIG_DIR=slapd['config_dir'],
                INST_DIR=slapd['inst_dir'],
                RUN_DIR=slapd['run_dir'],
                DS_ROOT='',
                PRODUCT_NAME='slapd',
            ))
        # Create all the needed paths
        # we should only need to make bak_dir, cert_dir, config_dir, db_dir, ldif_dir, lock_dir, log_dir, run_dir? schema_dir,
        for path in ('backup_dir', 'cert_dir', 'config_dir', 'db_dir', 'ldif_dir', 'lock_dir', 'log_dir', 'run_dir'):
            if self.verbose:
                self.log.info("ACTION: creating %s" % slapd[path])
            try:
                os.makedirs(slapd[path], mode=0o775)
            except OSError:
                pass
            os.chown(slapd[path], slapd['user_uid'], slapd['group_gid'])
        ### Warning! We need to down the directory under db too for .restore to work.
        # See dblayer.c for more!
        db_parent = os.path.join(slapd['db_dir'], '..')
        os.chown(db_parent, slapd['user_uid'], slapd['group_gid'])
        # Copy correct data to the paths.
        # Copy in the schema
        #  This is a little fragile, make it better.
        # It won't matter when we move schema to usr anyway ...
        _ds_shutil_copytree(os.path.join(slapd['sysconf_dir'], 'dirsrv/schema'), slapd['schema_dir'])
        os.chown(slapd['schema_dir'], slapd['user_uid'], slapd['group_gid'])
        # Copy in the collation
        srcfile = os.path.join(slapd['sysconf_dir'], 'dirsrv/config/slapd-collations.conf')
        dstfile = os.path.join(slapd['config_dir'], 'slapd-collations.conf')
        shutil.copy2(srcfile, dstfile)
        os.chown(slapd['schema_dir'], slapd['user_uid'], slapd['group_gid'])
        # If we are on the correct platform settings, systemd
        if general['systemd'] and not self.containerised:
            # Should create the symlink we need, but without starting it.
            subprocess.check_call(["/usr/bin/systemctl",
                                    "enable",
                                    "dirsrv@%s" % slapd['instance_name']])
        # Else we need to detect other init scripts?
        # Bind sockets to our type?
        # Create certdb in sysconfidir
        if self.verbose:
            self.log.info("ACTION: Creating certificate database is %s" % slapd['cert_dir'])
        # Create dse.ldif with a temporary root password.
        # The template is in slapd['data_dir']/dirsrv/data/template-dse.ldif
        # Variables are done with %KEY%.
        # You could cheat and read it in, do a replace of % to { and } then use format?
        if self.verbose:
            self.log.info("ACTION: Creating dse.ldif")
        dse = ""
>       with open(os.path.join(slapd['data_dir'], 'dirsrv', 'data', 'template-dse-minimal.ldif')) as template_dse:
E       IOError: [Errno 2] No such file or directory: '/usr/share/dirsrv/data/template-dse-minimal.ldif'
lib389/instance/setup.py:379: IOError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /root/lib389/lib389/instance/setup.py(379)_install_ds()
-> with open(os.path.join(slapd['data_dir'], 'dirsrv', 'data', 'template-dse-minimal.ldif')) as template_dse:
(Pdb) where
  /usr/lib/python2.7/site-packages/_pytest/runner.py(157)__init__()
-> self.result = func()
  /usr/lib/python2.7/site-packages/_pytest/runner.py(145)<lambda>()
-> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(745)__call__()
-> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(339)_hookexec()
-> return self._inner_hookexec(hook, methods, kwargs)
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(334)<lambda>()
-> _MultiCall(methods, kwargs, hook.spec_opts).execute()
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(613)execute()
-> return _wrapped_call(hook_impl.function(*args), self.execute)
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(254)_wrapped_call()
-> return call_outcome.get_result()
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(280)get_result()
-> _reraise(*ex)  # noqa
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(265)__init__()
-> self.result = func()
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(614)execute()
-> res = hook_impl.function(*args)
  /usr/lib/python2.7/site-packages/_pytest/runner.py(98)pytest_runtest_call()
-> item.runtest()
  /usr/lib/python2.7/site-packages/_pytest/python.py(1593)runtest()
-> self.ihook.pytest_pyfunc_call(pyfuncitem=self)
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(745)__call__()
-> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(339)_hookexec()
-> return self._inner_hookexec(hook, methods, kwargs)
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(334)<lambda>()
-> _MultiCall(methods, kwargs, hook.spec_opts).execute()
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(613)execute()
-> return _wrapped_call(hook_impl.function(*args), self.execute)
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(254)_wrapped_call()
-> return call_outcome.get_result()
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(280)get_result()
-> _reraise(*ex)  # noqa
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(265)__init__()
-> self.result = func()
  /usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py(614)execute()
-> res = hook_impl.function(*args)
  /usr/lib/python2.7/site-packages/_pytest/python.py(142)pytest_pyfunc_call()
-> testfunction(**testargs)
  /root/lib389/lib389/tests/instance/setup_test.py(99)test_setup_ds_minimal()
-> sds.create_from_args(general, slapd, {}, None)
  /root/lib389/lib389/instance/setup.py(300)create_from_args()
-> self._install_ds(general, slapd, backends)
> /root/lib389/lib389/instance/setup.py(379)_install_ds()
-> with open(os.path.join(slapd['data_dir'], 'dirsrv', 'data', 'template-dse-minimal.ldif')) as template_dse:
(Pdb) q
The following errors occurred during removal:
Could not open the DSE config file '/etc/dirsrv/slapd-standalone/dse.ldif'. Error: No such file or directory
Error: could not remove directory server standalone
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

It shouldn't blindly assume the presence of template-dse-minimal.ldif, but instead try for template-dse.ldif and exit gracefully if no files are not found. Moreover, it shouldn't hose up the system. In my case I need to manually clear the partly installed instance.


You should be able to remove the instance with remove-ds.pl - I was really careful to make sure the first thing the installer does is touch the file to make surce you can remove it cleanly.

I think that this is otherwise easy to resolve.

I'm not able to do that, even if I touch dse.ldif:

[root@qeos-72 lib389]# ls /etc/dirsrv/
config  schema  slapd-standalone
[root@qeos-72 lib389]# ls /etc/dirsrv/slapd-standalone/
schema  slapd-collations.conf
[root@qeos-72 lib389]# cat /etc/sysconfig/dirsrv-standalone 
# This file is sourced by dirsrv upon startup to set
# the default environment for a single specific  directory
# server instances.  To set defaults for all instances, edit
# the file in the same directory called dirsrv.
# These settings are used by the start_dirsrv and
# start_slapd scripts (as well as their associates stop
# and restart scripts).  Do not edit them unless you know
# what you are doing.
# This file is in systemd EnvironmentFile format _ see man systemd.exec
SERVER_DIR=/usr/lib64
SERVERBIN_DIR=/usr/sbin
CONFIG_DIR=/etc/dirsrv/slapd-standalone
INST_DIR=/usr/lib64/dirsrv
RUN_DIR=/var/run/dirsrv
DS_ROOT=
PRODUCT_NAME=slapd
# Put custom instance specific settings below here.
# if using systemd, omit the "; export VARNAME" at the end
[root@qeos-72 lib389]# ls /var/lib/dirsrv/slapd-standalone/ -R
/var/lib/dirsrv/slapd-standalone/:
bak  db  ldif
/var/lib/dirsrv/slapd-standalone/bak:
/var/lib/dirsrv/slapd-standalone/db:
/var/lib/dirsrv/slapd-standalone/ldif:
[root@qeos-72 lib389]# remove-ds.pl -i slapd-standalone
The following errors occurred during removal:
Could not open the DSE config file '/etc/dirsrv/slapd-standalone/dse.ldif'. Error: No such file or directory
Error: could not remove directory server standalone
[root@qeos-72 lib389]# touch /etc/dirsrv/slapd-standalone/dse.ldif
[root@qeos-72 lib389]# remove-ds.pl -i slapd-standalone
The following errors occurred during removal:
Error: could not find the config entry 'cn=config' in '/etc/dirsrv/slapd-standalone/dse.ldif'.  Error: No such object
Error: could not find the config entry 'cn=config,cn=ldbm database,cn=plugins,cn=config' in '/etc/dirsrv/slapd-standalone/dse.ldif'.  Error: No such object
Error: could not remove directory server standalone

Test fails at teardown as well for the same reason. And all next tests fail with Error, because they can't cleanup the instances.

Metadata