Remove some basic pystyle and pylint errors

Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
Stanislav Laznicka 2018-02-12 16:18:34 +01:00 committed by Christian Heimes
parent f7511edbfb
commit 8f9b0fc1de

View File

@ -118,6 +118,7 @@ def __remove_instance_legacy(serverid, force=False):
"Attempting to force removal", paths.REMOVE_DS_PL) "Attempting to force removal", paths.REMOVE_DS_PL)
remove_ds_instance(serverid, force=True) remove_ds_instance(serverid, force=True)
def __remove_instance_python(serverid): def __remove_instance_python(serverid):
"""Call the lib389 api to remove the instance. Because of the """Call the lib389 api to remove the instance. Because of the
design of the api, there is no "force" command. Provided a marker design of the api, there is no "force" command. Provided a marker
@ -129,24 +130,23 @@ def __remove_instance_python(serverid):
from lib389.instance.remove import remove_ds_instance from lib389.instance.remove import remove_ds_instance
from lib389 import DirSrv from lib389 import DirSrv
logger.debug("Attempting to remove instance %s" % serverid) logger.debug("Attempting to remove instance %s", serverid)
# Alloc the local instance by name (no creds needed!) # Alloc the local instance by name (no creds needed!)
inst = DirSrv(verbose=True, external_log=logger) ds = DirSrv(verbose=True, external_log=logger)
inst.local_simple_allocate(serverid) ds.local_simple_allocate(serverid)
# Remove it # Remove it
remove_ds_instance(instance) remove_ds_instance(ds)
logger.debug("Instance removed correctly.") logger.debug("Instance removed correctly.")
def remove_ds_instance(serverid, force=False): def remove_ds_instance(serverid, force=False):
if os.path.exists(paths.REMOVE_DS_PL): if os.path.exists(paths.REMOVE_DS_PL):
# We still have legacy tools. Lets use them. # We still have legacy tools. Lets use them.
self.__remove_instance_legacy(serverid, force) __remove_instance_legacy(serverid, force)
else: else:
# Okay, 389 have removed their perl tools. Great! Use the api driven installer # 389 have removed their perl tools \o/. Use the api driven installer
self.__remove_instance_python(serverid) __remove_instance_python(serverid)
def get_ds_instances(): def get_ds_instances():
@ -558,26 +558,27 @@ class DsInstance(service.Service):
idrange_size = self.idmax - self.idstart + 1 idrange_size = self.idmax - self.idstart + 1
except TypeError: except TypeError:
idrange_size = None idrange_size = None
self.sub_dict = dict(FQDN=self.fqdn, SERVERID=self.serverid, self.sub_dict = dict(
PASSWORD=self.dm_password, FQDN=self.fqdn, SERVERID=self.serverid,
RANDOM_PASSWORD=ipautil.ipa_generate_password(), PASSWORD=self.dm_password,
SUFFIX=self.suffix, RANDOM_PASSWORD=ipautil.ipa_generate_password(),
REALM=self.realm, USER=DS_USER, SUFFIX=self.suffix,
SERVER_ROOT=server_root, DOMAIN=self.domain, REALM=self.realm, USER=DS_USER,
TIME=int(time.time()), IDSTART=self.idstart, SERVER_ROOT=server_root, DOMAIN=self.domain,
IDMAX=self.idmax, HOST=self.fqdn, TIME=int(time.time()), IDSTART=self.idstart,
ESCAPED_SUFFIX=str(self.suffix), IDMAX=self.idmax, HOST=self.fqdn,
GROUP=DS_GROUP, ESCAPED_SUFFIX=str(self.suffix),
IDRANGE_SIZE=idrange_size, GROUP=DS_GROUP,
DOMAIN_LEVEL=self.domainlevel, IDRANGE_SIZE=idrange_size,
MAX_DOMAIN_LEVEL=constants.MAX_DOMAIN_LEVEL, DOMAIN_LEVEL=self.domainlevel,
MIN_DOMAIN_LEVEL=constants.MIN_DOMAIN_LEVEL, MAX_DOMAIN_LEVEL=constants.MAX_DOMAIN_LEVEL,
STRIP_ATTRS=" ".join(replication.STRIP_ATTRS), MIN_DOMAIN_LEVEL=constants.MIN_DOMAIN_LEVEL,
EXCLUDES='(objectclass=*) $ EXCLUDE ' + STRIP_ATTRS=" ".join(replication.STRIP_ATTRS),
' '.join(replication.EXCLUDES), EXCLUDES='(objectclass=*) $ EXCLUDE ' +
TOTAL_EXCLUDES='(objectclass=*) $ EXCLUDE ' + ' '.join(replication.EXCLUDES),
' '.join(replication.TOTAL_EXCLUDES), TOTAL_EXCLUDES='(objectclass=*) $ EXCLUDE ' +
) ' '.join(replication.TOTAL_EXCLUDES),
)
def __create_instance_legacy(self): def __create_instance_legacy(self):
pent = pwd.getpwnam(DS_USER) pent = pwd.getpwnam(DS_USER)
@ -622,7 +623,7 @@ class DsInstance(service.Service):
os.remove(paths.DIRSRV_BOOT_LDIF) os.remove(paths.DIRSRV_BOOT_LDIF)
def __create_instance_python(self): def __create_instance_python(self):
# We only import lib389 now, because we can't always guarantee it's presence # We only import lib389 now, we can't always guarantee its presence
# yet. After f28, this can be made a dependency proper. # yet. After f28, this can be made a dependency proper.
from lib389.instance.setup import SetupDs from lib389.instance.setup import SetupDs
from lib389.instance.options import General2Base, Slapd2Base from lib389.instance.options import General2Base, Slapd2Base
@ -655,7 +656,7 @@ class DsInstance(service.Service):
'nsslapd-suffix': self.suffix.ldap_text() 'nsslapd-suffix': self.suffix.ldap_text()
} }
backends = [userroot,] backends = [userroot, ]
sds.create_from_args(general, slapd, backends, None) sds.create_from_args(general, slapd, backends, None)
@ -663,13 +664,15 @@ class DsInstance(service.Service):
# Get the instance .... # Get the instance ....
inst = DirSrv(verbose=True, external_log=logger) inst = DirSrv(verbose=True, external_log=logger)
inst.remote_simple_allocate(ldapuri=ipaldap.get_ldap_uri(self.fqdn), password=self.dm_password) inst.remote_simple_allocate(
ldapuri=ipaldap.get_ldap_uri(self.fqdn),
password=self.dm_password)
# This actually opens the conn and binds. # This actually opens the conn and binds.
inst.open() inst.open()
ipadomain = IpaDomain(inst, dn=self.suffix.ldap_text()) ipadomain = IpaDomain(inst, dn=self.suffix.ldap_text())
ipadomain.create(properties={ ipadomain.create(properties={
'dc' : self.realm.split('.')[0].lower(), 'dc': self.realm.split('.')[0].lower(),
'info': 'IPA V2.0', 'info': 'IPA V2.0',
}) })
# Done! # Done!
@ -680,7 +683,7 @@ class DsInstance(service.Service):
# We still have legacy tools. Lets use them. # We still have legacy tools. Lets use them.
self.__create_instance_legacy() self.__create_instance_legacy()
else: else:
# Okay, 389 have removed their perl tools. Great! Use the api driven installer # 389 have removed its perl tools \o/. Use the api driven installer
self.__create_instance_python() self.__create_instance_python()
def __update_dse_ldif(self): def __update_dse_ldif(self):
@ -1147,12 +1150,12 @@ class DsInstance(service.Service):
try: try:
self.fstore.restore_file(paths.LIMITS_CONF) self.fstore.restore_file(paths.LIMITS_CONF)
except ValueError as error: except ValueError as error:
logger.debug("%s: %s" % (paths.LIMITS_CONF , error)) logger.debug("%s: %s", paths.LIMITS_CONF, error)
try: try:
self.fstore.restore_file(paths.SYSCONFIG_DIRSRV) self.fstore.restore_file(paths.SYSCONFIG_DIRSRV)
except ValueError as error: except ValueError as error:
logger.debug("%s: %s" % (paths.SYSCONFIG_DIRSRV , error)) logger.debug("%s: %s", paths.SYSCONFIG_DIRSRV, error)
# disabled during IPA installation # disabled during IPA installation
if enabled: if enabled: