]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Make the linter flake8 happy
authorFrank Brehm <frank@brehm-online.com>
Mon, 4 Jul 2022 16:38:21 +0000 (18:38 +0200)
committerFrank Brehm <frank@brehm-online.com>
Mon, 4 Jul 2022 16:38:21 +0000 (18:38 +0200)
.gitlab-ci.yml
lib/cr_vmware_tpl/cobbler.py
lib/cr_vmware_tpl/config.py
lib/cr_vmware_tpl/handler.py
setup.cfg

index 2cb502e07f074393654929d71ced1f6b6cc9c2a4..9c629b7c4b99a4903d3af0a5e5e85b287e83e3c6 100644 (file)
@@ -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: ''
index ed52ac6bbdbd0075b5afec352b8c3ce635347d6a..be91bf7f824387004d64e36d8aac53f9744e4049 100644 (file)
@@ -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')
index 2ed2dc287d9b89bca9b6f097eb42668ed5f7a1de..c529786d4b8e8b1c597e08d056030fe3f53421a3 100644 (file)
@@ -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):
index 225c29479faa48f76cc39d110944a81273965449..c8194860750246630709966af1e7b20d339b3f8f 100644 (file)
@@ -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
 
 
index 6ca6dc4b0103be235acb58b9a855752ba8147501..1dbf06d4c7118ea392ffe1aefba036753b182c3f 100644 (file)
--- 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