From nobody Fri Apr 26 05:28:00 2024 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 1552387779382547.121179252645; Tue, 12 Mar 2019 03:49:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8CF5F3092642; Tue, 12 Mar 2019 10:49:37 +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 5E7C927187; Tue, 12 Mar 2019 10:49:37 +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 99F43181A13B; Tue, 12 Mar 2019 10:49:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2CAnYUf002082 for ; Tue, 12 Mar 2019 06:49:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 673CA1001E6F; Tue, 12 Mar 2019 10:49:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-56.ams2.redhat.com [10.36.112.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39B4A1001E6A; Tue, 12 Mar 2019 10:49:33 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 12 Mar 2019 10:49:25 +0000 Message-Id: <20190312104927.6431-2-berrange@redhat.com> In-Reply-To: <20190312104927.6431-1-berrange@redhat.com> References: <20190312104927.6431-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 1/3] lcitool: remove Error class for exception handling 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 12 Mar 2019 10:49:38 +0000 (UTC) Since the program is self-contained and not exposing a library API there is no reason to subclass the Exception object. Removing ensures that the try/except block around the application execution will catch all exceptions and print a pretty message. Signed-off-by: Daniel P. Berrang=C3=A9 --- guests/lcitool | 58 ++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/guests/lcitool b/guests/lcitool index 1d17c04..487b67d 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -35,13 +35,6 @@ except ImportError: import ConfigParser as configparser =20 =20 -class Error(Exception): - - def __init__(self, message): - super(Error, self).__init__() - self.message =3D message - - class Util: =20 @staticmethod @@ -57,7 +50,7 @@ class Util: @staticmethod def expand_pattern(pattern, source, name): if pattern is None: - raise Error("Missing {} list".format(name)) + raise Exception("Missing {} list".format(name)) =20 if pattern =3D=3D "all": pattern =3D "*" @@ -74,7 +67,7 @@ class Util: partial_matches +=3D [item] =20 if not partial_matches: - raise Error("Invalid {} list '{}'".format(name, pattern)) + raise Exception("Invalid {} list '{}'".format(name, patter= n)) =20 matches +=3D partial_matches =20 @@ -142,7 +135,7 @@ class Config: try: os.mkdir(config_dir) except Exception as ex: - raise Error( + raise Exception( "Can't create configuration directory ({}): {}".format( config_dir, ex, ) @@ -164,14 +157,14 @@ class Config: with open(flavor_file, "w") as infile: infile.write("{}\n".format(flavor)) except Exception as ex: - raise Error( + raise Exception( "Can't write flavor file ({}): {}".format( flavor_file, ex ) ) =20 if flavor not in ["test", "jenkins"]: - raise Error("Invalid flavor '{}'".format(flavor)) + raise Exception("Invalid flavor '{}'".format(flavor)) =20 return flavor =20 @@ -188,7 +181,7 @@ class Config: if not infile.readline().strip(): raise ValueError except Exception as ex: - raise Error( + raise Exception( "Missing or invalid vault password file ({}): {}".form= at( vault_pass_file, ex ) @@ -204,7 +197,7 @@ class Config: if not infile.readline().strip(): raise ValueError except Exception as ex: - raise Error( + raise Exception( "Missing or invalid root password file ({}): {}".format( root_pass_file, ex ) @@ -224,7 +217,7 @@ class Inventory: parser.read(ansible_cfg_path) inventory_path =3D parser.get("defaults", "inventory") except Exception as ex: - raise Error( + raise Exception( "Can't read inventory location in ansible.cfg: {}".format(= ex)) =20 inventory_path =3D os.path.join(base, inventory_path) @@ -239,7 +232,7 @@ class Inventory: host =3D line.strip() self._facts[host] =3D {} except Exception as ex: - raise Error( + raise Exception( "Missing or invalid inventory ({}): {}".format( inventory_path, ex ) @@ -250,7 +243,8 @@ class Inventory: self._facts[host] =3D self._read_all_facts(host) self._facts[host]["inventory_hostname"] =3D host except Exception as ex: - raise Error("Can't load facts for '{}': {}".format(host, e= x)) + raise Exception("Can't load facts for '{}': {}".format( + host, ex)) =20 @staticmethod def _add_facts_from_file(facts, yaml_path): @@ -302,7 +296,7 @@ class Projects: mappings =3D yaml.load(infile) self._mappings =3D mappings["mappings"] except Exception as ex: - raise Error("Can't load mappings: {}".format(ex)) + raise Exception("Can't load mappings: {}".format(ex)) =20 source =3D os.path.join(base, "vars", "projects") =20 @@ -321,7 +315,7 @@ class Projects: packages =3D yaml.load(infile) self._packages[project] =3D packages["packages"] except Exception as ex: - raise Error( + raise Exception( "Can't load packages for '{}': {}".format(project, ex)) =20 def expand_pattern(self, pattern): @@ -434,7 +428,7 @@ class Application: if git_revision is not None: tokens =3D git_revision.split("/") if len(tokens) < 2: - raise Error( + raise Exception( "Missing or invalid git revision '{}'".format(git_revi= sion) ) git_remote =3D tokens[0] @@ -477,7 +471,7 @@ class Application: try: subprocess.check_call(cmd) except Exception as ex: - raise Error( + raise Exception( "Failed to run {} on '{}': {}".format(playbook, hosts, ex)) =20 def _action_hosts(self, args): @@ -519,7 +513,7 @@ class Application: elif facts["os_name"] in ["CentOS", "Fedora"]: install_config =3D "kickstart.cfg" else: - raise Error( + raise Exception( "Host {} doesn't support installation".format(host) ) initrd_inject =3D os.path.join(base, "configs", install_config) @@ -558,7 +552,7 @@ class Application: try: subprocess.check_call(cmd) except Exception as ex: - raise Error("Failed to install '{}': {}".format(host, ex)) + raise Exception("Failed to install '{}': {}".format(host, = ex)) =20 def _action_update(self, args): self._execute_playbook("update", args.hosts, args.projects, @@ -573,7 +567,7 @@ class Application: =20 hosts =3D self._inventory.expand_pattern(args.hosts) if len(hosts) > 1: - raise Error("Can't generate Dockerfile for multiple hosts") + raise Exception("Can't generate Dockerfile for multiple hosts") host =3D hosts[0] =20 facts =3D self._inventory.get_facts(host) @@ -583,18 +577,18 @@ class Application: os_full =3D os_name + os_version =20 if package_format not in ["deb", "rpm"]: - raise Error("Host {} doesn't support Dockerfiles".format(host)) + raise Exception("Host {} doesn't support Dockerfiles".format(h= ost)) if args.cross_arch: if os_name !=3D "Debian": - raise Error("Cannot cross compile on {}".format(os_name)) + raise Exception("Cannot cross compile on {}".format(os_nam= e)) if args.cross_arch =3D=3D self._native_arch: - raise Error("Cross arch {} should differ from native {}". + raise Exception("Cross arch {} should differ from native {= }". format(args.cross_arch, self._native_arch)) =20 projects =3D self._projects.expand_pattern(args.projects) for project in projects: if project not in facts["projects"]: - raise Error( + raise Exception( "Host {} doesn't support project {}".format( host, project, @@ -620,8 +614,8 @@ class Application: if key in mappings[package]: cross_policy =3D mappings[package][key] if cross_policy not in ["native", "foreign", "skip"]: - raise Error("Unexpected cross arch policy {} for {}", - cross_policy, package) + raise Exception("Unexpected cross arch policy {} for {= }", + cross_policy, package) =20 for key in keys: if key in mappings[package]: @@ -702,6 +696,6 @@ class Application: if __name__ =3D=3D "__main__": try: Application().run() - except Error as err: - sys.stderr.write("{}: {}\n".format(sys.argv[0], err.message)) + except Exception as err: + sys.stderr.write("{}: {}\n".format(sys.argv[0], err)) sys.exit(1) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 05:28:00 2024 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 155238778803032.64666156215185; Tue, 12 Mar 2019 03:49:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6033181F35; Tue, 12 Mar 2019 10:49:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C4E1648D1; Tue, 12 Mar 2019 10:49:46 +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 F385E3D388; Tue, 12 Mar 2019 10:49:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2CAnar8002097 for ; Tue, 12 Mar 2019 06:49:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 561CA1001E6F; Tue, 12 Mar 2019 10:49:36 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-56.ams2.redhat.com [10.36.112.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AA681001DD5; Tue, 12 Mar 2019 10:49:34 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 12 Mar 2019 10:49:26 +0000 Message-Id: <20190312104927.6431-3-berrange@redhat.com> In-Reply-To: <20190312104927.6431-1-berrange@redhat.com> References: <20190312104927.6431-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 2/3] lcitool: push exception catching down into run method 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 12 Mar 2019 10:49:46 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Andrea Bolognani --- guests/lcitool | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/guests/lcitool b/guests/lcitool index 487b67d..2c86d07 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -690,12 +690,12 @@ class Application: =20 def run(self): args =3D self._parser.parse_args() - args.func(args) + try: + args.func(args) + except Exception as err: + sys.stderr.write("{}: {}\n".format(sys.argv[0], err)) + sys.exit(1) =20 =20 if __name__ =3D=3D "__main__": - try: - Application().run() - except Exception as err: - sys.stderr.write("{}: {}\n".format(sys.argv[0], err)) - sys.exit(1) + Application().run() --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 05:28:00 2024 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 1552387788227651.1292348030486; Tue, 12 Mar 2019 03:49:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96508307E049; Tue, 12 Mar 2019 10:49:46 +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 66E2F60161; Tue, 12 Mar 2019 10:49:46 +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 26A5D181A13E; Tue, 12 Mar 2019 10:49:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2CAncbn002112 for ; Tue, 12 Mar 2019 06:49:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 55D971001DD5; Tue, 12 Mar 2019 10:49:38 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-56.ams2.redhat.com [10.36.112.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50A531001E6A; Tue, 12 Mar 2019 10:49:36 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 12 Mar 2019 10:49:27 +0000 Message-Id: <20190312104927.6431-4-berrange@redhat.com> In-Reply-To: <20190312104927.6431-1-berrange@redhat.com> References: <20190312104927.6431-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 3/3] lcitool: add support for --debug / -d argument 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 12 Mar 2019 10:49:47 +0000 (UTC) Introduce a --debug / -d argument that allows the display of information relevant to developers debugging problems. Initially this just displays the top level exception catch, so that full stack traces are shown. Signed-off-by: Daniel P. Berrang=C3=A9 --- guests/lcitool | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/guests/lcitool b/guests/lcitool index 2c86d07..d8a3aca 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -350,6 +350,9 @@ class Application: description=3D"libvirt CI guest management tool", ) =20 + self._parser.add_argument("--debug", "-d", action=3D"store_true", + help=3D"display debugging information") + subparsers =3D self._parser.add_subparsers(metavar=3D"ACTION") subparsers.required =3D True =20 @@ -690,11 +693,14 @@ class Application: =20 def run(self): args =3D self._parser.parse_args() - try: + if args.debug: args.func(args) - except Exception as err: - sys.stderr.write("{}: {}\n".format(sys.argv[0], err)) - sys.exit(1) + else: + try: + args.func(args) + except Exception as err: + sys.stderr.write("{}: {}\n".format(sys.argv[0], err)) + sys.exit(1) =20 =20 if __name__ =3D=3D "__main__": --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list