From nobody Sun Feb 8 17:37:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550084614775979.3708651432748; Wed, 13 Feb 2019 11:03:34 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C87A689AE1; Wed, 13 Feb 2019 19:03:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9D1095D9C6; Wed, 13 Feb 2019 19:03:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 517C6181A13B; Wed, 13 Feb 2019 19:03:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1DJ3LbT009185 for ; Wed, 13 Feb 2019 14:03:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 83185608A6; Wed, 13 Feb 2019 19:03:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 789ED60856; Wed, 13 Feb 2019 19:03:20 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 13 Feb 2019 19:03:00 +0000 Message-Id: <20190213190305.10926-6-berrange@redhat.com> In-Reply-To: <20190213190305.10926-1-berrange@redhat.com> References: <20190213190305.10926-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH v3 05/10] lcitool: include root cause when reporting errors X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 13 Feb 2019 19:03:33 +0000 (UTC) The root cause exception contains the useful information about what really failed during loading of some resource, or running of a command. Signed-off-by: Daniel P. Berrang=C3=A9 --- guests/lcitool | 54 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/guests/lcitool b/guests/lcitool index 759eff6..bd32d1f 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -95,10 +95,10 @@ class Config: if not os.path.exists(config_dir): try: os.mkdir(config_dir) - except Exception: + except Exception as ex: raise Error( - "Can't create configuration directory ({})".format( - config_dir, + "Can't create configuration directory ({}): {}".format( + config_dir, ex, ) ) =20 @@ -117,10 +117,10 @@ class Config: try: with open(flavor_file, "w") as infile: infile.write("{}\n".format(flavor)) - except Exception: + except Exception as ex: raise Error( - "Can't write flavor file ({})".format( - flavor_file, + "Can't write flavor file ({}): {}".format( + flavor_file, ex ) ) =20 @@ -141,10 +141,10 @@ class Config: with open(vault_pass_file, "r") as infile: if not infile.readline().strip(): raise ValueError - except Exception: + except Exception as ex: raise Error( - "Missing or invalid vault password file ({})".format( - vault_pass_file, + "Missing or invalid vault password file ({}): {}".form= at( + vault_pass_file, ex ) ) =20 @@ -157,10 +157,10 @@ class Config: with open(root_pass_file, "r") as infile: if not infile.readline().strip(): raise ValueError - except Exception: + except Exception as ex: raise Error( - "Missing or invalid root password file ({})".format( - root_pass_file, + "Missing or invalid root password file ({}): {}".format( + root_pass_file, ex ) ) =20 @@ -177,8 +177,8 @@ class Inventory: parser =3D configparser.SafeConfigParser() parser.read(ansible_cfg_path) inventory_path =3D parser.get("defaults", "inventory") - except Exception: - raise Error("Can't find inventory location in ansible.cfg") + except Exception as ex: + raise Error("Can't read inventory location in ansible.cfg: {}"= .format(ex)) =20 inventory_path =3D os.path.join(base, inventory_path) =20 @@ -191,10 +191,10 @@ class Inventory: for line in infile: host =3D line.strip() self._facts[host] =3D {} - except Exception: + except Exception as ex: raise Error( - "Missing or invalid inventory ({})".format( - inventory_path, + "Missing or invalid inventory ({}): {}".format( + inventory_path, ex ) ) =20 @@ -202,8 +202,8 @@ class Inventory: try: self._facts[host] =3D self._read_all_facts(host) self._facts[host]["inventory_hostname"] =3D host - except Exception: - raise Error("Can't load facts for '{}'".format(host)) + except Exception as ex: + raise Error("Can't load facts for '{}': {}".format(host, e= x)) =20 @staticmethod def _add_facts_from_file(facts, yaml_path): @@ -254,8 +254,8 @@ class Projects: with open(mappings_path, "r") as infile: mappings =3D yaml.load(infile) self._mappings =3D mappings["mappings"] - except Exception: - raise Error("Can't load mappings") + except Exception as ex: + raise Error("Can't load mappings: {}".format(ex)) =20 source =3D os.path.join(base, "vars", "projects") =20 @@ -273,8 +273,8 @@ class Projects: with open(yaml_path, "r") as infile: packages =3D yaml.load(infile) self._packages[project] =3D packages["packages"] - except Exception: - raise Error("Can't load packages for '{}'".format(project)) + except Exception as ex: + raise Error("Can't load packages for '{}': {}".format(proj= ect, ex)) =20 def expand_pattern(self, pattern): projects =3D Util.expand_pattern(pattern, self._packages, "project= ") @@ -398,8 +398,8 @@ class Application: =20 try: subprocess.check_call(cmd) - except Exception: - raise Error("Failed to run {} on '{}'".format(playbook, hosts)) + except Exception as ex: + raise Error("Failed to run {} on '{}': {}".format(playbook, ho= sts), ex) =20 def _action_hosts(self, _hosts, _projects, _revision): for host in self._inventory.expand_pattern("all"): @@ -478,8 +478,8 @@ class Application: =20 try: subprocess.check_call(cmd) - except Exception: - raise Error("Failed to install '{}'".format(host)) + except Exception as ex: + raise Error("Failed to install '{}': {}".format(host, ex)) =20 def _action_update(self, hosts, projects, git_revision): self._execute_playbook("update", hosts, projects, git_revision) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list