import datetime
import pipes
import json
+import hashlib
+import textwrap
# Third party modules
import paramiko
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))