]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Ensuring profile kickstart script
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 28 May 2020 15:09:00 +0000 (17:09 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 28 May 2020 15:09:00 +0000 (17:09 +0200)
lib/cr_vmware_tpl/cobbler.py

index e981810dc792dfe24552e5efdda25f4df29ede43..e46a6afd37e6b0e0d97a5ad3b43dfd9947589cec 100644 (file)
@@ -14,6 +14,8 @@ import re
 import datetime
 import pipes
 import json
+import hashlib
+import textwrap
 
 # Third party modules
 import paramiko
@@ -215,10 +217,42 @@ class Cobbler(BaseHandler):
             LOG.debug(_("Sorted list of found profiles:") + "\n{}".format(pp(profile_list)))
         return profile_list
 
+    # -------------------------------------------------------------------------
+    def ensure_profile_ks(self):
+
+        remote_ks = self.config.cobbler_profile_ks
+        local_ks = self.base_dir / 'kickstart' / (self.config.cobbler_profile + '.ks')
+
+        if not local_ks.exists() or not local_ks.is_file():
+            msg = _("Kickstart script {!r} either not exists or is not a regular file.").format(
+                str(local_ks))
+            raise ExpectedCobblerError(msg)
+        local_ks_content = local_ks.read_bytes()
+        digest = hashlib.sha256(m).hexdigest()
+        if self.verbose > 1:
+            LOG.debug(_('{typ} sum of {ks!a}r is: {dig}').format(
+                typ='SHA256', ks=str(local_ks), dig=digest))
+
+        cmd = textwrap.dedent("""\
+        if [ -f {ks!r} ] ; then
+            digest=$(sha256sum {ks!r} | awk '{print $1}')
+            if [ "${digest}" != {dig!r} ] ; then
+                echo "SHA256 sum does not match." >&2
+                exit 4
+            fi
+            exit 0
+        else
+            exit 3
+        fi
+        """).format(ks=str(remote_ks), dig=digest)
+
+        proc = self.exec_ssh(cmd)
+
     # -------------------------------------------------------------------------
     def ensure_profile(self):
         """Ensure the existence and the correctnes of the given profile."""
 
+        self.ensure_profile_ks()
         profile = self.config.cobbler_profile
 
         LOG.info(_("Ensuring profile {!r} ...").format(profile))