Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break ipaplatform / ipalib import cycle of hell #258

Closed
wants to merge 1 commit into from

Conversation

tiran
Copy link
Member

@tiran tiran commented Nov 18, 2016

Here is an attempt to break the import cycle of hell between ipaplatform
and ipalib. All services now pass an ipalib.api object to
services.service(). RedHatServices.init() still needs to do a local
import because it initializes its wellknown service dict with service
instances.

Signed-off-by: Christian Heimes cheimes@redhat.com

self.api = api
else:
import ipalib # FixMe: break import cycle
self.api = ipalib.api
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is for backwards compatibility with external code. It can be removed in a future version of FreeIPA.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe would be better to make this comment to code, I'm not sure if we should have else branch there. We never declared this as a public stable API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else block is required to keep b/w compatibility with scripts like copy-schema-to-ca.py.

services = dict()
for s in base_services.wellknownservices:
services[s] = self.service_class_factory(s)
services[s] = self.service_class_factory(s, ipalib.api)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not proud of this fix. Do we need a list of service instances at all? Or can we get rid of it and use services.service() everywhere?

Copy link
Member Author

@tiran tiran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

justification

@@ -104,7 +104,7 @@ def restart_pki_ds():
"""Restart the CA DS instance to pick up schema changes
"""
root_logger.info('Restarting CA DS')
services.service('dirsrv').restart(SERVERID)
services.service('dirsrv', api).restart(SERVERID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really special code, according docs, this code must be copied from RHEL7 to RHEL6 and then executed on RHEL6. S this change will break RHEL6. IMO this code should be set to stone as is :)

Here is an attempt to break the import cycle of hell between ipaplatform
and ipalib. All services now pass an ipalib.api object to
services.service(). RedHatServices.__init__() still needs to do a local
import because it initializes its wellknown service dict with service
instances.

Signed-off-by: Christian Heimes <cheimes@redhat.com>
@tiran
Copy link
Member Author

tiran commented Nov 21, 2016

thx @mbasti-rh . I took care of it.

@MartinBasti MartinBasti self-assigned this Nov 21, 2016
@MartinBasti
Copy link
Contributor

LGTM, except the inline comment I made, I'll test it tomorrow

@HonzaCholasta
Copy link
Contributor

The original code is broken by design IMO. The API object is used only to get the configured service startup timeout and to guess our DS instance name. None of this is platform specific, so I would prefer if we removed this from ipaplatform altogether instead of "just" fixing the import issue.

Anyway, given that the current plan is to make ipaclient not depend on ipaplatform, is this change still necessary?

@tiran
Copy link
Member Author

tiran commented Nov 22, 2016

It's no longer a priority, but I still like to fix the imports No matter what the cyclic imports and cross-package dependencies are a mess. A wrong order of imports can trigger an import error. Even with this PR, ipapython.dogtag triggers an import of ipalib.api.

In the long run neither ipaplatform nor ipapython should have an import dependency on ipalib or a global ipalib.api object. Instead the API object should be passed.

@MartinBasti
Copy link
Contributor

ACK from me if @jcholast is not against it

@HonzaCholasta
Copy link
Contributor

I'm OK with it.

@MartinBasti MartinBasti added the ack Pull Request approved, can be merged label Nov 24, 2016
@MartinBasti
Copy link
Contributor

@MartinBasti MartinBasti added the pushed Pull Request has already been pushed label Nov 24, 2016
@tiran tiran deleted the break_import_cycles branch November 25, 2016 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ack Pull Request approved, can be merged pushed Pull Request has already been pushed
Projects
None yet
3 participants