From nobody Wed Feb 11 04:22:13 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1508427410990733.3875311677983; Thu, 19 Oct 2017 08:36:50 -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 E43764ACAC; Thu, 19 Oct 2017 15:36:49 +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 A8882EEF5B; Thu, 19 Oct 2017 15:36:49 +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 6D71B260; Thu, 19 Oct 2017 15:36:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9JFajAj013786 for ; Thu, 19 Oct 2017 11:36:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 68B65BA216; Thu, 19 Oct 2017 15:36:45 +0000 (UTC) Received: from inaba.usersys.redhat.com (ovpn-204-95.brq.redhat.com [10.40.204.95]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC119BA224 for ; Thu, 19 Oct 2017 15:36:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E43764ACAC Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Andrea Bolognani To: libvir-list@redhat.com Date: Thu, 19 Oct 2017 17:36:28 +0200 Message-Id: <20171019153632.15016-3-abologna@redhat.com> In-Reply-To: <20171019153632.15016-1-abologna@redhat.com> References: <20171019153632.15016-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-jenkins-ci PATCH 2/6] guests: Move configuration handling to load_config() 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: , MIME-Version: 1.0 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.38]); Thu, 19 Oct 2017 15:36:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Just a code move. We'll be adding more logic soon, and it'll be nice not to pollute the do_prepare() function too much because of it. Rename the existing load_config() function to load_install_config() accordingly. Signed-off-by: Andrea Bolognani --- guests/lcitool | 54 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/guests/lcitool b/guests/lcitool index 4578327..883e0eb 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -34,12 +34,12 @@ yaml_var() { grep "^$2:\\s*" "$1" 2>/dev/null | tail -1 | sed "s/$2:\\s*//g" } =20 -# load_config FILE +# load_install_config FILE # # Read all known configuration variables from $FILE and set them in the # environment. Configuration variables that have already been set in # the environment will not be updated. -load_config() { +load_install_config() { INSTALL_URL=3D${INSTALL_URL:-$(yaml_var "$1" install_url)} INSTALL_CONFIG=3D${INSTALL_CONFIG:-$(yaml_var "$1" install_config)} INSTALL_VIRT_TYPE=3D${INSTALL_VIRT_TYPE:-$(yaml_var "$1" install_virt_= type)} @@ -53,6 +53,32 @@ load_config() { INSTALL_NETWORK=3D${INSTALL_NETWORK:-$(yaml_var "$1" install_network)} } =20 +# load_config +# +# Read tool configuration and perform the necessary validation. +load_config() { + CONFIG_DIR=3D"$HOME/.config/$PROGRAM_NAME" + + VAULT_PASS_FILE=3D"$CONFIG_DIR/vault-password" + ROOT_PASS_FILE=3D"$CONFIG_DIR/root-password" + + # Make sure required passwords exist and are not invalid (empty) + test -f "$VAULT_PASS_FILE" && test "$(cat "$VAULT_PASS_FILE")" || { + die "$PROGRAM_NAME: $VAULT_PASS_FILE: Missing or invalid password" + } + test -f "$ROOT_PASS_FILE" && test "$(cat "$ROOT_PASS_FILE")" || { + die "$PROGRAM_NAME: $ROOT_PASS_FILE: Missing or invalid password" + } + + ROOT_HASH_FILE=3D"$CONFIG_DIR/.root-password.hash" + + # Regenerate root password hash. Ansible expects passwords as hashes b= ut + # doesn't provide a built-in facility to generate one from plain text + hash_file "$ROOT_PASS_FILE" >"$ROOT_HASH_FILE" || { + die "$PROGRAM_NAME: Failure while hashing root password" + } +} + # ---------------------- # User-visible actions # ---------------------- @@ -92,8 +118,8 @@ do_install() # Load configuration files. Values don't get overwritten after being # set the first time, so loading the host-specific configuration before # the group configuration ensures overrides work as expected - load_config "host_vars/$GUEST/install.yml" - load_config "group_vars/all/install.yml" + load_install_config "host_vars/$GUEST/install.yml" + load_install_config "group_vars/all/install.yml" =20 # Both memory size and disk size use GiB as unit, but virt-install wan= ts # disk size in GiB and memory size in *MiB*, so perform conversion here @@ -136,24 +162,7 @@ do_prepare() { die "$PROGRAM_NAME: $GUEST: Unknown guest" } =20 - VAULT_PASS_FILE=3D"$CONFIG_DIR/vault-password" - ROOT_PASS_FILE=3D"$CONFIG_DIR/root-password" - - # Make sure required passwords exist and are not invalid (empty) - test -f "$VAULT_PASS_FILE" && test "$(cat "$VAULT_PASS_FILE")" || { - die "$PROGRAM_NAME: $VAULT_PASS_FILE: Missing or invalid password" - } - test -f "$ROOT_PASS_FILE" && test "$(cat "$ROOT_PASS_FILE")" || { - die "$PROGRAM_NAME: $ROOT_PASS_FILE: Missing or invalid password" - } - - ROOT_HASH_FILE=3D"$CONFIG_DIR/.root-password.hash" - - # Regenerate root password hash. Ansible expects passwords as hashes b= ut - # doesn't provide a built-in facility to generate one from plain text - hash_file "$ROOT_PASS_FILE" >"$ROOT_HASH_FILE" || { - die "$PROGRAM_NAME: Failure while hashing root password" - } + load_config =20 ansible-playbook \ --vault-password-file "$VAULT_PASS_FILE" \ @@ -167,7 +176,6 @@ do_prepare() { =20 CALL_NAME=3D"$0" PROGRAM_NAME=3D"${0##*/}" -CONFIG_DIR=3D"$HOME/.config/$PROGRAM_NAME" =20 test -f "$PROGRAM_NAME" || { die "$PROGRAM_NAME: Must be run from the source directory" --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list