]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Verifying existence of repos of the given distro
authorFrank Brehm <frank@brehm-online.com>
Thu, 23 Jun 2022 11:33:07 +0000 (13:33 +0200)
committerFrank Brehm <frank@brehm-online.com>
Thu, 23 Jun 2022 11:33:07 +0000 (13:33 +0200)
lib/cr_vmware_tpl/cobbler.py
lib/cr_vmware_tpl/handler.py

index d3d7a163a6631df71345bf5220bfd4e8659b75ce..8e63cae503b43561af40614a5ab7dc196bd70b40 100644 (file)
@@ -42,7 +42,7 @@ from .config import CrTplConfiguration
 
 from .xlate import XLATOR
 
-__version__ = '0.8.1'
+__version__ = '0.8.2'
 
 LOG = logging.getLogger(__name__)
 
@@ -348,6 +348,42 @@ class Cobbler(BaseHandler):
             LOG.debug(_("Sorted list of found distros:") + "\n{}".format(pp(distro_list)))
         return distro_list
 
+    # -------------------------------------------------------------------------
+    def get_repo_list(self):
+        """Trying to get a list of all configured repositories."""
+
+        repo_list = []
+
+        proc = self.exec_cobbler(('repo', 'list'), no_simulate=True)
+        for line in proc.stdout.splitlines():
+            repo = line.strip()
+            if repo:
+                repo_list.append(repo)
+        repo_list.sort(key=str.lower)
+        if self.verbose > 1:
+            LOG.debug(_("Sorted list of found repositories:") + "\n{}".format(pp(repo_list)))
+        return repo_list
+
+    # -------------------------------------------------------------------------
+    def verify_distro_repos(self, distro):
+
+        repo_list = self.get_repo_list()
+
+        LOG.debug(_("Checking existence of repos for distro {!r}.").format(distro.name))
+
+        all_ok = True
+        for repo in distro.repos:
+            if repo not in repo_list:
+                msg = _("Repo {r!r} for distro {d!r} not found on cobbler server.").format(
+                    r=repo, d=distro.name)
+                LOG.warn(msg)
+                all_ok = False
+            elif self.verbose > 1:
+                msg = _("Found repo {r!r} for distro {d!r}.").format(r=repo, d=distro.name)
+                LOG.debug(msg)
+
+        return all_ok
+
     # -------------------------------------------------------------------------
     def get_profile_list(self):
         """Trying to get a list of all configured cobbler profiles."""
index 13e272cdafd124a57e55f708faa996057fd96956..7948442334af8681802ccafaed3158cacf2b6196 100644 (file)
@@ -49,7 +49,7 @@ from .cobbler import Cobbler
 
 from .xlate import XLATOR
 
-__version__ = '2.1.0'
+__version__ = '2.1.1'
 
 LOG = logging.getLogger(__name__)
 TZ = pytz.timezone('Europe/Berlin')
@@ -382,6 +382,11 @@ class CrTplHandler(BaseHandler):
                 self.cfg.cobbler_distro)
             LOG.debug(msg)
 
+        if not self.cobbler.verify_distro_repos(self.cfg.current_distro):
+            msg = _("Not all rpos for distro {!r} were found on Cobbler server.").format(
+                self.cfg.current_distro.name)
+            raise ExpectedHandlerError(msg)
+
     # -------------------------------------------------------------------------
     def check_for_temp_tpl_vm(self, no_error=False):