From: Frank Brehm Date: Mon, 4 Jul 2022 16:38:21 +0000 (+0200) Subject: Make the linter flake8 happy X-Git-Tag: 2.6.2~1^2~8^2~12 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=f9305acc4765645093d2d6c7148cdde03ae82149;p=pixelpark%2Fcreate-vmware-tpl.git Make the linter flake8 happy --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2cb502e..9c629b7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ stages: variables: OS_ID: centos7 FLAKE8_MAX_LINE_LENGTH: 99 - FLAKE8_MAX_COMPLEXITY: 20 + FLAKE8_MAX_COMPLEXITY: 22 FLAKE8_IGNORE_ERRORS: 'E226,E302,E41,E402' GIT_SUBMODULE_STRATEGY: 'recursive' VSPHERE_HOST: '' diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index ed52ac6..be91bf7 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -13,15 +13,12 @@ import logging import re import datetime import pipes -import json import hashlib import textwrap import ipaddress import tempfile import os -from json import JSONDecodeError - from pathlib import Path # Third party modules @@ -48,7 +45,7 @@ from .config import CrTplConfiguration from .xlate import XLATOR -__version__ = '0.9.0' +__version__ = '0.9.1' LOG = logging.getLogger(__name__) @@ -564,7 +561,6 @@ class Cobbler(BaseHandler): self.local_ks_file.write_text(ks_content) - # local_ks = self.base_dir / 'kickstart' / ('profile.' + self.cfg.cobbler_profile + '.ks') remote_ks = self.cfg.cobbler_profile_ks LOG.info(_("Ensuring currentness of profile kickstart script {!r}.").format( str(remote_ks))) @@ -738,7 +734,6 @@ class Cobbler(BaseHandler): LOG.info(_("Creating new profile {!r} ...").format(profile)) - os_id = self.cfg.os_id distro_info = self.cfg.current_distro comment = "Profile for creating a {} VM.".format(distro_info.description) @@ -956,7 +951,6 @@ class Cobbler(BaseHandler): ks_meta = ' '.join(ks_meta_list) args = ['system', 'add'] - # args.append('--clobber') args.append('--name') args.append(name) args.append('--profile') @@ -971,8 +965,6 @@ class Cobbler(BaseHandler): else: args.append('--ksmeta') args.append(ks_meta) - # args.append('--kickstart') - # args.append(str(self.cfg.system_ks)) args.append('--power-type') args.append('apc') args.append('--hostname') diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index 2ed2dc2..c529786 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -31,7 +31,7 @@ from . import DEFAULT_CONFIG_DIR, DEFAULT_DISTRO_ARCH, MAX_PORT_NUMBER from .xlate import XLATOR -__version__ = '2.0.1' +__version__ = '2.1.1' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -387,7 +387,7 @@ class CobblerDistroInfo(FbGenericBaseObject): if repos: if is_sequence(repos): for repo in repos: - self.repos.add(snippet) + self.repos.add(repo) else: msg = _("The given parameter {p!r} must be sequential type (given: {v!r}).") raise TypeError(msg.format(p='repos', v=repos)) @@ -532,7 +532,6 @@ class CobblerDistroInfo(FbGenericBaseObject): out += ", ".join(fields) + ")>" - return out # ------------------------------------------------------------------------- @@ -569,7 +568,7 @@ class CobblerDistroInfo(FbGenericBaseObject): def __copy__(self): new = self.__class__( - self.name, shortname=self.shortname, distro=self.distro, arch=arch, + self.name, shortname=self.shortname, distro=self.distro, arch=self.arch, ks_repo_url=self.ks_repo_url, description=self.description) for package in self.packages: @@ -613,36 +612,15 @@ class CobblerDistroInfo(FbGenericBaseObject): continue if key.lower() == 'repos': - if is_sequence(value): - for repo in value: - repo = repo.strip() - if repo != '': - new.repos.add(repo) - elif value.strip() != '': - new.repos.add(value.strip()) - + cls._update_repos(new, value) continue if key.lower() == 'packages': - if is_sequence(value): - for pkg in value: - pkg = pkg.strip() - if pkg != '' and pkg not in new.packages: - new.packages.append(pkg) - elif value.strip() != '': - new.packages.add(value.strip()) - + cls._update_packages(new, value) continue if key.lower() == 'snippets': - if is_sequence(value): - for snippet in value: - snippet = snippet.strip() - if snippet != '': - new.snippets.add(snippet) - elif value.strip() != '': - new.snippets.add(value.strip()) - + cls._update_snippets(new, value) continue if verbose: @@ -656,6 +634,42 @@ class CobblerDistroInfo(FbGenericBaseObject): return new + # ------------------------------------------------------------------------- + @classmethod + def _update_repos(cls, new, value): + + if is_sequence(value): + for repo in value: + repo = repo.strip() + if repo != '': + new.repos.add(repo) + elif value.strip() != '': + new.repos.add(value.strip()) + + # ------------------------------------------------------------------------- + @classmethod + def _update_packages(cls, new, value): + + if is_sequence(value): + for pkg in value: + pkg = pkg.strip() + if pkg != '' and pkg not in new.packages: + new.packages.add(pkg) + elif value.strip() != '': + new.packages.add(value.strip()) + + # ------------------------------------------------------------------------- + @classmethod + def _update_snippets(cls, new, value): + + if is_sequence(value): + for snippet in value: + snippet = snippet.strip() + if snippet != '': + new.snippets.add(snippet) + elif value.strip() != '': + new.snippets.add(value.strip()) + # ============================================================================= class LdapConnectionDict(dict, FbGenericBaseObject): @@ -1011,7 +1025,6 @@ class CrTplConfiguration(BaseMultiConfig): for distro in self.cobbler_distros.keys(): res['cobbler_distros'][distro] = self.cobbler_distros[distro].as_dict(short=short) - res['root_password'] = None if self.root_password: if self.verbose > 4: @@ -1070,7 +1083,7 @@ class CrTplConfiguration(BaseMultiConfig): if not distro.ks_repo_url: msg = _( "Did not found the base install repo URL of configured Cobbler " - "distro {!r}.").format( distro_id) + "distro {!r}.").format(distro_id) raise CrTplConfigError(msg) if not len(distro.repos): diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index 225c294..c819486 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -29,8 +29,6 @@ import paramiko from pyVmomi import vim import ldap3 -from ldap3.core.exceptions import LDAPInvalidDnError, LDAPInvalidValueError -from ldap3.core.exceptions import LDAPException, LDAPBindError # Own modules @@ -56,7 +54,7 @@ from .cobbler import Cobbler from .xlate import XLATOR -__version__ = '2.3.0' +__version__ = '2.3.1' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -791,7 +789,8 @@ class CrTplHandler(BaseHandler): msg += '\n' + pp(ai) LOG.debug(msg) if not ai: - raise HandlerError(_("Did not get address infos for {h!r}, IPv4 TCP port {p}.").format( + raise HandlerError(_( + "Did not get address infos for {h!r}, IPv4 TCP port {p}.").format( h=ip, p=22)) addr_info = random.choice(ai) @@ -1318,15 +1317,10 @@ class CrTplHandler(BaseHandler): try: self.connect_ldap() - line = ('#' * 60) + '\n' + line = ('#' * 60) + '\n' auth_keys = line admins = self.get_ldap_admins() - if not admins: - msg = _("Did not found any admins below base DN {!r} with filter:") - msg = msg.format(self.cfg.ldap_connection['default'].base_dn) - msg += '\n' + fltr - raise HandlerError(msg) for uid in sorted(admins.keys(), key=str.lower): @@ -1431,6 +1425,12 @@ class CrTplHandler(BaseHandler): admins[uid] = admin + if not admins: + msg = _("Did not found any admins below base DN {!r} with filter:") + msg = msg.format(self.cfg.ldap_connection['default'].base_dn) + msg += '\n' + fltr + raise HandlerError(msg) + return admins diff --git a/setup.cfg b/setup.cfg index 6ca6dc4..1dbf06d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -58,7 +58,7 @@ max-line-length = 99 [flake8] max-line-length = 99 -max-complexity = 20 +max-complexity = 22 ignore = E226,E302,E41,E402 # vim: filetype=dosini