From: Frank Brehm Date: Thu, 28 May 2020 15:09:00 +0000 (+0200) Subject: Ensuring profile kickstart script X-Git-Tag: 2.1.2^2~9^2~31^2~94 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=e6135113f0a80626137c77636968ca05e4c87395;p=pixelpark%2Fcreate-vmware-tpl.git Ensuring profile kickstart script --- diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index e981810..e46a6af 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -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))