mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Break ipaplatform / ipalib import cycle of hell
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> Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
committed by
Martin Basti
parent
2cbaf15604
commit
6409abf1a6
@@ -27,10 +27,10 @@ import os
|
||||
import json
|
||||
import time
|
||||
import collections
|
||||
import warnings
|
||||
|
||||
import six
|
||||
|
||||
import ipalib
|
||||
from ipapython import ipautil
|
||||
from ipaplatform.paths import paths
|
||||
|
||||
@@ -63,7 +63,6 @@ class KnownServices(collections.Mapping):
|
||||
instances as its own attributes on first access (or instance creation)
|
||||
and cache them.
|
||||
"""
|
||||
|
||||
def __init__(self, d):
|
||||
self.__d = d
|
||||
|
||||
@@ -93,9 +92,17 @@ class PlatformService(object):
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, service_name, api=ipalib.api):
|
||||
def __init__(self, service_name, api=None):
|
||||
self.service_name = service_name
|
||||
self.api = api
|
||||
if api is not None:
|
||||
self.api = api
|
||||
else:
|
||||
import ipalib # FixMe: break import cycle
|
||||
self.api = ipalib.api
|
||||
warnings.warn(
|
||||
"{s.__class__.__name__}('{s.service_name}', api=None) "
|
||||
"is deprecated.".format(s=self),
|
||||
RuntimeWarning, stacklevel=2)
|
||||
|
||||
def start(self, instance_name="", capture_output=True, wait=True,
|
||||
update_service_list=True):
|
||||
@@ -185,10 +192,11 @@ class PlatformService(object):
|
||||
class SystemdService(PlatformService):
|
||||
SYSTEMD_SRV_TARGET = "%s.target.wants"
|
||||
|
||||
def __init__(self, service_name, systemd_name, **kwargs):
|
||||
super(SystemdService, self).__init__(service_name, **kwargs)
|
||||
def __init__(self, service_name, systemd_name, api=None):
|
||||
super(SystemdService, self).__init__(service_name, api=api)
|
||||
self.systemd_name = systemd_name
|
||||
self.lib_path = os.path.join(paths.LIB_SYSTEMD_SYSTEMD_DIR, self.systemd_name)
|
||||
self.lib_path = os.path.join(paths.LIB_SYSTEMD_SYSTEMD_DIR,
|
||||
self.systemd_name)
|
||||
self.lib_path_exists = None
|
||||
|
||||
def service_instance(self, instance_name, operation=None):
|
||||
|
||||
@@ -41,17 +41,17 @@ class FedoraService(redhat_services.RedHatService):
|
||||
# Function that constructs proper Fedora-specific server classes for services
|
||||
# of specified name
|
||||
|
||||
def fedora_service_class_factory(name):
|
||||
def fedora_service_class_factory(name, api=None):
|
||||
if name == 'domainname':
|
||||
return FedoraService(name)
|
||||
return redhat_services.redhat_service_class_factory(name)
|
||||
return FedoraService(name, api)
|
||||
return redhat_services.redhat_service_class_factory(name, api)
|
||||
|
||||
|
||||
# Magicdict containing FedoraService instances.
|
||||
|
||||
class FedoraServices(redhat_services.RedHatServices):
|
||||
def service_class_factory(self, name):
|
||||
return fedora_service_class_factory(name)
|
||||
def service_class_factory(self, name, api=None):
|
||||
return fedora_service_class_factory(name, api)
|
||||
|
||||
|
||||
# Objects below are expected to be exported by platform module
|
||||
|
||||
@@ -31,7 +31,6 @@ from ipaplatform.base import services as base_services
|
||||
|
||||
from ipapython import ipautil, dogtag
|
||||
from ipapython.ipa_log_manager import root_logger
|
||||
from ipalib import api
|
||||
from ipaplatform.paths import paths
|
||||
|
||||
# Mappings from service names as FreeIPA code references to these services
|
||||
@@ -76,7 +75,7 @@ redhat_system_units['ods_signerd'] = redhat_system_units['ods-signerd']
|
||||
class RedHatService(base_services.SystemdService):
|
||||
system_units = redhat_system_units
|
||||
|
||||
def __init__(self, service_name):
|
||||
def __init__(self, service_name, api=None):
|
||||
systemd_name = service_name
|
||||
if service_name in self.system_units:
|
||||
systemd_name = self.system_units[service_name]
|
||||
@@ -86,7 +85,7 @@ class RedHatService(base_services.SystemdService):
|
||||
# and not a foo.target. Thus, not correct service name for
|
||||
# systemd, default to foo.service style then
|
||||
systemd_name = "%s.service" % (service_name)
|
||||
super(RedHatService, self).__init__(service_name, systemd_name)
|
||||
super(RedHatService, self).__init__(service_name, systemd_name, api)
|
||||
|
||||
|
||||
class RedHatDirectoryService(RedHatService):
|
||||
@@ -195,12 +194,12 @@ class RedHatSSHService(RedHatService):
|
||||
class RedHatCAService(RedHatService):
|
||||
def wait_until_running(self):
|
||||
root_logger.debug('Waiting until the CA is running')
|
||||
timeout = float(api.env.startup_timeout)
|
||||
timeout = float(self.api.env.startup_timeout)
|
||||
op_timeout = time.time() + timeout
|
||||
while time.time() < op_timeout:
|
||||
try:
|
||||
# check status of CA instance on this host, not remote ca_host
|
||||
status = dogtag.ca_status(api.env.host)
|
||||
status = dogtag.ca_status(self.api.env.host)
|
||||
except Exception as e:
|
||||
status = 'check interrupted due to error: %s' % e
|
||||
root_logger.debug('The CA status is: %s' % status)
|
||||
@@ -244,31 +243,31 @@ class RedHatCAService(RedHatService):
|
||||
# Function that constructs proper Red Hat OS family-specific server classes for
|
||||
# services of specified name
|
||||
|
||||
def redhat_service_class_factory(name):
|
||||
def redhat_service_class_factory(name, api=None):
|
||||
if name == 'dirsrv':
|
||||
return RedHatDirectoryService(name)
|
||||
return RedHatDirectoryService(name, api)
|
||||
if name == 'ipa':
|
||||
return RedHatIPAService(name)
|
||||
return RedHatIPAService(name, api)
|
||||
if name == 'sshd':
|
||||
return RedHatSSHService(name)
|
||||
return RedHatSSHService(name, api)
|
||||
if name in ('pki-tomcatd', 'pki_tomcatd'):
|
||||
return RedHatCAService(name)
|
||||
return RedHatService(name)
|
||||
return RedHatCAService(name, api)
|
||||
return RedHatService(name, api)
|
||||
|
||||
|
||||
# Magicdict containing RedHatService instances.
|
||||
|
||||
class RedHatServices(base_services.KnownServices):
|
||||
def service_class_factory(self, name):
|
||||
return redhat_service_class_factory(name)
|
||||
|
||||
def __init__(self):
|
||||
import ipalib # FixMe: break import cycle
|
||||
services = dict()
|
||||
for s in base_services.wellknownservices:
|
||||
services[s] = self.service_class_factory(s)
|
||||
services[s] = self.service_class_factory(s, ipalib.api)
|
||||
# Call base class constructor. This will lock services to read-only
|
||||
super(RedHatServices, self).__init__(services)
|
||||
|
||||
def service_class_factory(self, name, api=None):
|
||||
return redhat_service_class_factory(name, api)
|
||||
|
||||
# Objects below are expected to be exported by platform module
|
||||
|
||||
|
||||
@@ -44,8 +44,6 @@ from ipapython.ipa_log_manager import root_logger, log_mgr
|
||||
from ipapython import ipautil
|
||||
import ipapython.errors
|
||||
|
||||
from ipalib import x509 # FIXME: do not import from ipalib
|
||||
|
||||
from ipaplatform.constants import constants
|
||||
from ipaplatform.paths import paths
|
||||
from ipaplatform.redhat.authconfig import RedHatAuthConfig
|
||||
@@ -220,6 +218,8 @@ class RedHatTaskNamespace(BaseTaskNamespace):
|
||||
return True
|
||||
|
||||
def insert_ca_certs_into_systemwide_ca_store(self, ca_certs):
|
||||
from ipalib import x509 # FixMe: break import cycle
|
||||
|
||||
new_cacert_path = paths.SYSTEMWIDE_IPA_CA_CRT
|
||||
|
||||
if os.path.exists(new_cacert_path):
|
||||
|
||||
@@ -41,17 +41,17 @@ class RHELService(redhat_services.RedHatService):
|
||||
# Function that constructs proper RHEL-specific server classes for services
|
||||
# of specified name
|
||||
|
||||
def rhel_service_class_factory(name):
|
||||
def rhel_service_class_factory(name, api=None):
|
||||
if name == 'domainname':
|
||||
return RHELService(name)
|
||||
return redhat_services.redhat_service_class_factory(name)
|
||||
return RHELService(name, api)
|
||||
return redhat_services.redhat_service_class_factory(name, api)
|
||||
|
||||
|
||||
# Magicdict containing RHELService instances.
|
||||
|
||||
class RHELServices(redhat_services.RedHatServices):
|
||||
def service_class_factory(self, name):
|
||||
return rhel_service_class_factory(name)
|
||||
def service_class_factory(self, name, api=None):
|
||||
return rhel_service_class_factory(name, api)
|
||||
|
||||
|
||||
# Objects below are expected to be exported by platform module
|
||||
|
||||
Reference in New Issue
Block a user