From nobody Fri Apr 26 01:25:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589537199; cv=none; d=zohomail.com; s=zohoarc; b=VTkI47nZXq6hcokIeO/Y/qQzBwlWPkjq9UL49MBfRD/Qmp58DRL79Klvx8OM9v2QCnLOo4w71CEq0EUKLkmpNFue67C0sfhiZbkE2YtlvcZUmHpPz49GHDbaSPoKrVVqCZ32kpN0pvj6skdmY/9l1UasXwvcJLjXbSoGFSoN2HQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589537199; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=fnhlCU8+V4b9/XGChjANuV6qKl7cvmWcvaoapPlckRc=; b=OjbwNmTtVrZSNgVnVXV0RczLDzpeLWH3C/Vtf39eaa+HyYn0v3rqpEsBplhIgieAcqKNwoN4P652luyjTlsXQfEYUm6j7TgVd5JY3iVJhq5lxxhu6lyFeqsd1fnLyICJi8LWX51eNfhi+9pI+ZuEopM5609ZTr7tU2EOg6uXd9Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1589537199376674.7143552150004; Fri, 15 May 2020 03:06:39 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-262-b4zJ28ptMrKW_5EWhhUXVg-1; Fri, 15 May 2020 06:06:34 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C991F1899528; Fri, 15 May 2020 10:06:28 +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 0BED05D9D7; Fri, 15 May 2020 10:06:28 +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 3ED381809547; Fri, 15 May 2020 10:06:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04FA6OrO013042 for ; Fri, 15 May 2020 06:06:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 60DFC2E029; Fri, 15 May 2020 10:06:24 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6499346; Fri, 15 May 2020 10:06:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589537197; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fnhlCU8+V4b9/XGChjANuV6qKl7cvmWcvaoapPlckRc=; b=QJt3Os0lYrFY8Tph+PamcIFQArFB7sJy0aR0NmuRt9S2v2dVn7IFzhdDjuA7XGrIAqp9Nh vIAncnNR5DIpW2r5PC2FhXCmJ/N0HlOqV3QSVyjCAOsSz38wdAruMApaEj2S2zKh9tralL Q5YPNl+BgOve4FqVKU6Ul7V3CQ5rpdg= X-MC-Unique: b4zJ28ptMrKW_5EWhhUXVg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt-ci PATCH] guests: don't force user to create a config.yaml file Date: Fri, 15 May 2020 11:06:10 +0100 Message-Id: <20200515100610.1307279-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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: , 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Only the "install" command requires a per-user config.yaml with a password set. We should not require this for the other commands to be run. Signed-off-by: Daniel P. Berrang=C3=A9 --- guests/lcitool | 51 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/guests/lcitool b/guests/lcitool index 27aee7b..1f093d0 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -138,11 +138,15 @@ class Config: with open(os.path.join(base, "config.yaml"), "r") as fp: self.values =3D yaml.safe_load(fp) =20 + user_config_path =3D self._get_config_file("config.yaml") + if not os.path.exists(user_config_path): + return + try: - with open(self._get_config_file("config.yaml"), "r") as fp: + with open(user_config_path, "r") as fp: user_config =3D yaml.safe_load(fp) except Exception as e: - raise Exception("Missing or invalid config.yaml file: {}".form= at(e)) + raise Exception("Invalid config.yaml file: {}".format(e)) =20 if user_config is None: raise Exception("Missing or invalid config.yaml file") @@ -181,20 +185,13 @@ class Config: if k not in known_keys: del _dict[k] =20 - def _validate_section(self, config, section, mandatory_keys): + def _validate_section(self, config, section): # remove keys we don't recognize self._remove_unknown_keys(config[section], self.values[section].ke= ys()) =20 - # check that the mandatory keys are present and non-empty - for key in mandatory_keys: - if config.get(section).get(key) is None: - raise Exception(("Missing or empty value for mandatory key" - "'{}.{}'").format(section, key)) - # check that all keys have values assigned and of the right type for key in config[section].keys(): =20 - # mandatory keys were already checked, so this covers optional= keys if config[section][key] is None: raise Exception( "Missing value for '{}.{}'".format(section, key) @@ -209,22 +206,6 @@ class Config: # delete sections we don't recognize self._remove_unknown_keys(config, self.values.keys()) =20 - if "install" not in config: - raise Exception("Missing mandatory section 'install'") - - self._validate_section(config, "install", ["root_password"]) - - # we only need this for the gitlab check below, if 'flavor' is mis= sing - # that's okay, we'll provide a default later - flavor =3D config["install"].get("flavor") - if flavor is not None and flavor not in ["test", "jenkins", "gitla= b"]: - raise Exception( - "Invalid value '{}' for 'install.flavor'".format(flavor) - ) - - if flavor =3D=3D "gitlab": - self._validate_section(config, "gitlab", ["runner_secret"]) - def _update(self, values): self.values["install"].update(values["install"]) =20 @@ -561,10 +542,28 @@ class Application: for project in self._projects.expand_pattern("all"): print(project) =20 + def _validate_install_config(self, config): + if config.values["install"].get("root_password") is None: + raise Exception("Missing mandatory install.root_password confi= g.yaml parameter") + + # we only need this for the gitlab check below, if 'flavor' is mis= sing + # that's okay, we'll provide a default later + flavor =3D config.values["install"].get("flavor") + if flavor is not None and flavor not in ["test", "jenkins", "gitla= b"]: + raise Exception( + "Invalid value '{}' for 'install.flavor'".format(flavor) + ) + + if flavor =3D=3D "gitlab": + if config.values["gitlab"].get("runner_secret") is None: + raise Exception("Missing mandatory gitlab.runner_secret co= nfig.yaml parameter") + def _action_install(self, args): base =3D Util.get_base() config =3D self._config =20 + self._validate_install_config(config) + for host in self._inventory.expand_pattern(args.hosts): facts =3D self._inventory.get_facts(host) =20 --=20 2.26.2