]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Better exception handling
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 29 May 2020 10:26:14 +0000 (12:26 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 29 May 2020 10:26:14 +0000 (12:26 +0200)
etc/create-vmware-template.ini.default
lib/cr_vmware_tpl/cobbler.py

index b56ca18d5fcd576d76d0f5f1b45af3f7bb9d8182..f08e18b924f4657f1c7a84de1d206f6a760e4f44 100644 (file)
@@ -16,6 +16,8 @@
 
 [Template]
 
+;vm_id = centos8
+
 ;vm = template.pixelpark.com
 
 ;vmware_cfg_version = vmx-14
 ;max_wait_for_finish_install = 3600
 
 
+[Cobbler]
+
+# distro = CentOS-8.1-x86_64
+
+# host = cobbler.pixelpark.com
+
+# ssh_port = 22
+
+# ssh_user = root
+
+# ssh_timeout = 30
+
+# root_dir = /var/lib/cobbler
+
+# profile = 
+
+# profile_repos = pp-centos8-baseos
+
+# nameservers = 93.188.109.11, 93.188.109.12, 93.188.109.13
+
+# dns_search = pixelpark.net, pixelpark.com, pixelpark.de
+
+
 ; vim: filetype=dosini
index 357b8eca98f22baff7f792ea7f7725130bb29fc3..1130864bf0a237005466d0a77899c7e7078b2557 100644 (file)
@@ -19,6 +19,7 @@ import textwrap
 
 # Third party modules
 import paramiko
+from paramiko.ssh_exception import SSHException
 
 # Own modules
 
@@ -34,7 +35,7 @@ from .config import CrTplConfiguration
 
 from .xlate import XLATOR
 
-__version__ = '0.3.7'
+__version__ = '0.3.8'
 
 LOG = logging.getLogger(__name__)
 
@@ -163,6 +164,11 @@ class Cobbler(BaseHandler):
 
             proc = CompletedProcess(cmd, retcode, output, err, start_dt=start_dt, end_dt=end_dt)
 
+        except SSHException as e:
+            msg = _("Could not connect via {w} to {user}@{host}: {e}").format(
+                w='SSH', user=self.ssh_user, host=self.host, e=e)
+            raise ExpectedCobblerError(msg)
+
         finally:
             if ssh:
                 if self.verbose > 2:
@@ -205,6 +211,11 @@ class Cobbler(BaseHandler):
                     local=str(local_file), host=self.host, remote=str(remote_file)))
             sftp.put(str(local_file), str(remote_file))
 
+        except SSHException as e:
+            msg = _("Could not connect via {w} to {user}@{host}: {e}").format(
+                w='SCP', user=self.ssh_user, host=self.host, e=e)
+            raise ExpectedCobblerError(msg)
+
         finally:
             sftp = None
             if ssh:
@@ -218,10 +229,38 @@ class Cobbler(BaseHandler):
 
         proc = self.exec_cobbler('version', no_simulate=True)
 
+        if proc.returncode != 0:
+            err = _('No error message')
+            if proc.stderr:
+                err = proc.stderr
+            elif proc.stdout:
+                err = proc.stdout
+            msg = _("Could not get version of cobbler: {}").format(err)
+            raise ExpectedCobblerError(msg)
+
         first_line = proc.stdout.splitlines()[0]
         cobbler_version = re.sub(r'^\s*cobbler\s+', '', first_line, flags=re.IGNORECASE).strip()
         LOG.info(_("Version of {} is:").format("Cobbler") + " {!r}".format(cobbler_version))
 
+        rdir = self.config.cobbler_rootdir
+        if self.verbose > 1:
+            msg = _("Checking existence of remote directory {!r} ...").format(str(rdir))
+            LOG.debug(msg)
+
+        cmd = textwrap.dedent("""\
+        if [ -d {rdir!r} ] ; then
+            exit 0
+        fi
+        exit 7
+        """).format(rdir=str(rdir))
+
+        proc = self.exec_ssh(cmd)
+        if proc.returncode != 0:
+            msg = _(
+                "Cobbler root directory {rdir!r} on host {host!r} does not "
+                "exists or is not a directory.").format(rdir=str(rdir), host=self.host)
+            raise ExpectedCobblerError(msg)
+
         return cobbler_version
 
     # -------------------------------------------------------------------------