From nobody Sun May 19 06:30:30 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 1531324495015857.7479142243727; Wed, 11 Jul 2018 08:54:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1877780D5; Wed, 11 Jul 2018 15:54:53 +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 772442010D5C; Wed, 11 Jul 2018 15:54:53 +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 0BFC33F646; Wed, 11 Jul 2018 15:54:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6BFsfJs002220 for ; Wed, 11 Jul 2018 11:54:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6B9BC2026D76; Wed, 11 Jul 2018 15:54:41 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E30D42026D6B for ; Wed, 11 Jul 2018 15:54:40 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Wed, 11 Jul 2018 17:54:29 +0200 Message-Id: <20180711155436.22284-2-abologna@redhat.com> In-Reply-To: <20180711155436.22284-1-abologna@redhat.com> References: <20180711155436.22284-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 1/8] lcitool: Drop shell implementation 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 11 Jul 2018 15:54:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We're going to rewrite the script completely, and getting the current implementation out of the way firts will make the diffs more reasonable. Signed-off-by: Andrea Bolognani --- guests/lcitool | 227 ------------------------------------------------- 1 file changed, 227 deletions(-) delete mode 100755 guests/lcitool diff --git a/guests/lcitool b/guests/lcitool deleted file mode 100755 index 0c1520e..0000000 --- a/guests/lcitool +++ /dev/null @@ -1,227 +0,0 @@ -#!/bin/sh - -# ------------------- -# Utility functions -# ------------------- - -# die MESSAGE -# -# Abort the program after displaying $MESSAGE on standard error. -die() { - echo "$1" >&2 - exit 1 -} - -# hash_file PASS_FILE -# -# Generate a password hash from the contents of PASS_FILE. -hash_file() { - PASS_FILE=3D"$1" - - perl -le ' - my @chars =3D ("A".."Z", "a".."z", "0".."9"); - my $salt; $salt .=3D $chars[rand @chars] for 1..16; - my $handle; open($handle, "'"$PASS_FILE"'"); - my $pass =3D <$handle>; chomp($pass); - print crypt("$pass", "\$6\$$salt\$");' -} - -# yaml_var FILE VAR -# -# Read $FILE and output the value of YAML variable $VAR. Only trivial YAML -# values are supported, eg. strings and numbers that don't depend on the -# value of other variables. That's enough for our use case. -yaml_var() { - grep "^$2:\\s*" "$1" 2>/dev/null | tail -1 | sed "s/$2:\\s*//g" -} - -# 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_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)} - INSTALL_ARCH=3D${INSTALL_ARCH:-$(yaml_var "$1" install_arch)} - INSTALL_MACHINE=3D${INSTALL_MACHINE:-$(yaml_var "$1" install_machine)} - INSTALL_CPU_MODEL=3D${INSTALL_CPU_MODEL:-$(yaml_var "$1" install_cpu_m= odel)} - INSTALL_VCPUS=3D${INSTALL_VCPUS:-$(yaml_var "$1" install_vcpus)} - INSTALL_MEMORY_SIZE=3D${INSTALL_MEMORY_SIZE:-$(yaml_var "$1" install_m= emory_size)} - INSTALL_DISK_SIZE=3D${INSTALL_DISK_SIZE:-$(yaml_var "$1" install_disk_= size)} - INSTALL_STORAGE_POOL=3D${INSTALL_STORAGE_POOL:-$(yaml_var "$1" install= _storage_pool)} - INSTALL_NETWORK=3D${INSTALL_NETWORK:-$(yaml_var "$1" install_network)} -} - -# load_config -# -# Read tool configuration and perform the necessary validation. -load_config() { - CONFIG_DIR=3D"$HOME/.config/$PROGRAM_NAME" - - mkdir -p "$CONFIG_DIR" >/dev/null 2>&1 || { - die "$PROGRAM_NAME: $CONFIG_DIR: Unable to create config directory" - } - - FLAVOR_FILE=3D"$CONFIG_DIR/flavor" - VAULT_PASS_FILE=3D"$CONFIG_DIR/vault-password" - ROOT_PASS_FILE=3D"$CONFIG_DIR/root-password" - - # Two flavors are supported: test (default) and jenkins. Read the - # flavor from configuration, validate it and write it back in case - # it was not present - FLAVOR=3D"$(cat "$FLAVOR_FILE" 2>/dev/null)" - FLAVOR=3D${FLAVOR:-test} - test "$FLAVOR" =3D test || test "$FLAVOR" =3D jenkins || { - die "$PROGRAM_NAME: Invalid flavor '$FLAVOR'" - } - echo "$FLAVOR" >"$FLAVOR_FILE" || { - die "$PROGRAM_NAME: $FLAVOR_FILE: Unable to save flavor" - } - - test "$FLAVOR" =3D jenkins && { - # The vault password is only needed for the jenkins flavor, so only - # validate it in that case - test -f "$VAULT_PASS_FILE" && test "$(cat "$VAULT_PASS_FILE")" || { - die "$PROGRAM_NAME: $VAULT_PASS_FILE: Missing or invalid passw= ord" - } - } || { - # For other flavors, undefine the variable so that Ansible - # will not try to read the file at all - VAULT_PASS_FILE=3D - } - - # Make sure the root password has been configured properly - 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 -# ---------------------- - -do_help() { - echo "\ -Usage: $CALL_NAME ACTION [OPTIONS] - -Actions: - list List known guests - install GUEST Install GUEST - prepare GUEST|all Prepare or update GUEST. Can be run multiple times - update GUEST|all Alias for prepare - help Display this help" -} - -do_list() { - # List all guests present in the inventory. Skip group names, - # comments and empty lines - grep -vE '^#|^\[|^$' inventory | sort -u -} - -do_install() -{ - GUEST=3D"$1" - - test "$GUEST" || { - die "$(do_help)" - } - do_list | grep -q "$GUEST" || { - die "$PROGRAM_NAME: $GUEST: Unknown guest" - } - test -f "host_vars/$GUEST/install.yml" || { - die "$PROGRAM_NAME: $GUEST: Missing configuration, guest must be i= nstalled manually" - } - - load_config - - # 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_install_config "host_vars/$GUEST/install.yml" - load_install_config "group_vars/all/install.yml" - - # 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 - INSTALL_MEMORY_SIZE=3D$(expr "$INSTALL_MEMORY_SIZE" \* 1024 2>/dev/nul= l) - - # preseed files must use a well-known name to be picked up by d-i; - # for kickstart files, we can use whatever name we please but we need - # to point anaconda in the right direction through a kernel argument - case "$INSTALL_CONFIG" in - *kickstart*|*ks*) EXTRA_ARGS=3D"ks=3Dfile:/${INSTALL_CONFIG##*/}" = ;; - esac - - # Only configure autostart for the guest for the jenkins flavor - test "$FLAVOR" =3D jenkins && { - AUTOSTART=3D"--autostart" - } - - virt-install \ - --name "$GUEST" \ - --location "$INSTALL_URL" \ - --virt-type "$INSTALL_VIRT_TYPE" \ - --arch "$INSTALL_ARCH" \ - --machine "$INSTALL_MACHINE" \ - --cpu "$INSTALL_CPU_MODEL" \ - --vcpus "$INSTALL_VCPUS" \ - --memory "$INSTALL_MEMORY_SIZE" \ - --disk "size=3D$INSTALL_DISK_SIZE,pool=3D$INSTALL_STORAGE_POOL,bus= =3Dvirtio" \ - --network "network=3D$INSTALL_NETWORK,model=3Dvirtio" \ - --graphics none \ - --console pty \ - --sound none \ - --initrd-inject "$INSTALL_CONFIG" \ - --extra-args "console=3DttyS0 $EXTRA_ARGS" \ - $AUTOSTART \ - --wait 0 -} - -do_prepare() { - GUEST=3D"$1" - - test "$GUEST" || { - die "$(do_help)" - } - do_list | grep -q "$GUEST" || test "$GUEST" =3D all || { - die "$PROGRAM_NAME: $GUEST: Unknown guest" - } - - load_config - - EXTRA_VARS=3D"flavor=3D$FLAVOR root_password_file=3D$ROOT_HASH_FILE" - - ansible-playbook \ - --vault-password-file "$VAULT_PASS_FILE" \ - --extra-vars "$EXTRA_VARS" \ - -l "$GUEST" \ - site.yml -} - -# --------------------- -# Program entry point -# --------------------- - -CALL_NAME=3D"$0" -PROGRAM_NAME=3D"${0##*/}" - -test -f "$PROGRAM_NAME" || { - die "$PROGRAM_NAME: Must be run from the source directory" -} - -case "$1" in - list) do_list ;; - install) do_install "$2" ;; - prepare|update) do_prepare "$2" ;; - *help) do_help ;; - *) die "$(do_help)" ;; -esac --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 06:30:30 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 1531324488865471.13769306633446; Wed, 11 Jul 2018 08:54:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92CF1307D85E; Wed, 11 Jul 2018 15:54: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 D80872010D5C; Wed, 11 Jul 2018 15:54:45 +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 6D7633F7FF; Wed, 11 Jul 2018 15:54:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6BFsgZM002225 for ; Wed, 11 Jul 2018 11:54:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 145ED2026D76; Wed, 11 Jul 2018 15:54:42 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AA0452026D6B for ; Wed, 11 Jul 2018 15:54:41 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Wed, 11 Jul 2018 17:54:30 +0200 Message-Id: <20180711155436.22284-3-abologna@redhat.com> In-Reply-To: <20180711155436.22284-1-abologna@redhat.com> References: <20180711155436.22284-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 2/8] lcitool: Stub out Python implementation 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 11 Jul 2018 15:54:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Doesn't do much right now, but it's a start :) Signed-off-by: Andrea Bolognani --- guests/lcitool | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 guests/lcitool diff --git a/guests/lcitool b/guests/lcitool new file mode 100755 index 0000000..1cba8ad --- /dev/null +++ b/guests/lcitool @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +# lcitool - libvirt CI guest management tool +# Copyright (C) 2017-2018 Andrea Bolognani +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import argparse +import sys +import textwrap + +# This is necessary to maintain Python 2.7 compatibility +try: + import configparser +except ImportError: + import ConfigParser as configparser + +class Error(Exception): + + def __init__(self, message): + self.message =3D message + +class Application: + + def __init__(self): + self._parser =3D argparse.ArgumentParser( + conflict_handler =3D "resolve", + formatter_class =3D argparse.RawDescriptionHelpFormatter, + description =3D "libvirt CI guest management tool", + epilog =3D textwrap.dedent(""" + supported actions: + """), + ) + self._parser.add_argument( + "-a", + metavar =3D "ACTION", + required =3D True, + help =3D "action to perform (see below)", + ) + + def run(self): + cmdline =3D self._parser.parse_args() + action =3D cmdline.a + + method =3D "_action_{}".format(action.replace("-", "_")) + + if hasattr(self, method): + getattr(self, method).__call__() + else: + raise Error("Invalid action '{}'".format(action)) + +if __name__ =3D=3D "__main__": + try: + Application().run() + except Error as e: + sys.stderr.write("{}: {}\n".format(sys.argv[0], e.message)) + sys.exit(1) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 06:30:30 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 1531324489090773.2140592671399; Wed, 11 Jul 2018 08:54:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4159A85363; Wed, 11 Jul 2018 15:54:47 +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 B921C60F93; Wed, 11 Jul 2018 15:54: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 563D018037F0; Wed, 11 Jul 2018 15:54:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6BFsgF9002233 for ; Wed, 11 Jul 2018 11:54:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id B204C2026D76; Wed, 11 Jul 2018 15:54:42 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 539042026D6B for ; Wed, 11 Jul 2018 15:54:42 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Wed, 11 Jul 2018 17:54:31 +0200 Message-Id: <20180711155436.22284-4-abologna@redhat.com> In-Reply-To: <20180711155436.22284-1-abologna@redhat.com> References: <20180711155436.22284-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 3/8] lcitool: Add tool configuration 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: , 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 11 Jul 2018 15:54:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The on-disk configuration format and its behavior are fully backwards compatible with the previous implementation. Signed-off-by: Andrea Bolognani --- guests/lcitool | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/guests/lcitool b/guests/lcitool index 1cba8ad..6d4010b 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -18,6 +18,10 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. =20 import argparse +import crypt +import os +import random +import string import sys import textwrap =20 @@ -32,9 +36,114 @@ class Error(Exception): def __init__(self, message): self.message =3D message =20 +class Config: + + def _mksalt(self): + alphabeth =3D string.ascii_letters + string.digits + salt =3D "".join(random.choice(alphabeth) for x in range(0, 16)) + return "$6${}$".format(salt) + + def _get_config_file(self, name): + try: + config_dir =3D os.environ["XDG_CONFIG_HOME"] + except KeyError: + config_dir =3D os.path.join(os.environ["HOME"], ".config/") + config_dir =3D os.path.join(config_dir, "lcitool/") + + # Create the directory if it doesn't already exist + if not os.path.exists(config_dir): + try: + os.mkdir(config_dir) + except: + raise Error( + "Can't create configuration directory ({})".format( + config_dir, + ) + ) + + return os.path.join(config_dir, name) + + def get_flavor(self): + flavor_file =3D self._get_config_file("flavor") + + try: + with open(flavor_file, "r") as f: + flavor =3D f.readline().strip() + except: + # If the flavor has not been configured, we choose the default + # and store it on disk to ensure consistent behavior from now = on + flavor =3D "test" + try: + with open(flavor_file, "w") as f: + f.write("{}\n".format(flavor)) + except: + raise Error( + "Can't write flavor file ({})".format( + flavor_file, + ) + ) + + if flavor !=3D "test" and flavor !=3D "jenkins": + raise Error("Invalid flavor '{}'".format(flavor)) + + return flavor + + def get_vault_password_file(self): + vault_pass_file =3D None + + # The vault password is only needed for the jenkins flavor, but in + # that case we want to make sure there's *something* in there + if self.get_flavor() !=3D "test": + vault_pass_file =3D self._get_config_file("vault-password") + + try: + with open(vault_pass_file, 'r') as f: + if len(f.readline().strip()) =3D=3D 0: + raise ValueError + except: + raise Error( + "Missing or invalid vault password file ({})".format( + vault_pass_file, + ) + ) + + return vault_pass_file + + def get_root_password_file(self): + root_pass_file =3D self._get_config_file("root-password") + root_hash_file =3D self._get_config_file(".root-password.hash") + + try: + with open(root_pass_file, "r") as f: + root_pass =3D f.readline().strip() + except: + raise Error( + "Missing or invalid root password file ({})".format( + root_pass_file, + ) + ) + + # The hash will be different every time we run, but that doesn't + # matter - it will still validate the correct root password + root_hash =3D crypt.crypt(root_pass, self._mksalt()) + + try: + with open(root_hash_file, "w") as f: + f.write("{}\n".format(root_hash)) + except: + raise Error( + "Can't write hashed root password file ({})".format( + root_hash_file, + ) + ) + + return root_hash_file + class Application: =20 def __init__(self): + self._config =3D Config() + self._parser =3D argparse.ArgumentParser( conflict_handler =3D "resolve", formatter_class =3D argparse.RawDescriptionHelpFormatter, --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 06:30:30 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 1531324496449549.7245381090406; Wed, 11 Jul 2018 08:54:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A521E91509; Wed, 11 Jul 2018 15:54:53 +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 6ADB25B687; Wed, 11 Jul 2018 15:54:53 +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 05D4418037EC; Wed, 11 Jul 2018 15:54:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6BFshua002240 for ; Wed, 11 Jul 2018 11:54:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6210D2026D76; Wed, 11 Jul 2018 15:54:43 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 019D92026D6B for ; Wed, 11 Jul 2018 15:54:42 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Wed, 11 Jul 2018 17:54:32 +0200 Message-Id: <20180711155436.22284-5-abologna@redhat.com> In-Reply-To: <20180711155436.22284-1-abologna@redhat.com> References: <20180711155436.22284-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 4/8] lcitool: Add inventory 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: , 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 11 Jul 2018 15:54:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We use an actual YAML parser this time around, and bring the behavior more in line with what Ansible is doing, so interoperability should be more solid overall. New in this implementation is more flexibility in defining host lists, including support for explicit lists as well as glob patterns. Signed-off-by: Andrea Bolognani --- guests/lcitool | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/guests/lcitool b/guests/lcitool index 6d4010b..3564eb8 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -19,11 +19,13 @@ =20 import argparse import crypt +import fnmatch import os import random import string import sys import textwrap +import yaml =20 # This is necessary to maintain Python 2.7 compatibility try: @@ -139,10 +141,95 @@ class Config: =20 return root_hash_file =20 +class Inventory: + + def __init__(self): + try: + parser =3D configparser.SafeConfigParser() + parser.read("./ansible.cfg") + inventory_path =3D parser.get("defaults", "inventory") + except: + raise Error("Can't find inventory location in ansible.cfg") + + self._facts =3D {} + try: + # We can only deal with trivial inventories, but that's + # all we need right now and we can expand support further + # later on if necessary + with open(inventory_path, "r") as f: + for line in f: + host =3D line.strip() + self._facts[host] =3D {} + except: + raise Error( + "Missing or invalid inventory ({})".format( + inventory_path, + ) + ) + + for host in self._facts: + try: + self._facts[host] =3D self._read_all_facts(host) + self._facts[host]["inventory_hostname"] =3D host + except: + raise Error("Can't load facts for '{}'".format(host)) + + def _add_facts_from_file(self, facts, yaml_path): + with open(yaml_path, "r") as f: + some_facts =3D yaml.load(f) + for fact in some_facts: + facts[fact] =3D some_facts[fact] + + def _read_all_facts(self, host): + facts =3D {} + + # We load from group_vars/ first and host_vars/ second, sorting + # files alphabetically; doing so should result in our view of + # the facts matching Ansible's + for source in ["./group_vars/all/", "./host_vars/{}/".format(host)= ]: + for item in sorted(os.listdir(source)): + yaml_path =3D os.path.join(source, item) + if not os.path.isfile(yaml_path): + continue + if not yaml_path.endswith(".yml"): + continue + self._add_facts_from_file(facts, yaml_path) + + return facts + + def expand_pattern(self, pattern): + if pattern =3D=3D None: + raise Error("Missing host list") + + if pattern =3D=3D "all": + pattern =3D "*" + + # This works correctly for single hosts as well as more complex + # cases such as explicit lists, glob patterns and any combination + # of the above + matches =3D [] + for partial_pattern in pattern.split(","): + + partial_matches =3D [] + for host in self._facts: + if fnmatch.fnmatch(host, partial_pattern): + partial_matches +=3D [host] + + if len(partial_matches) =3D=3D 0: + raise Error("Invalid host list '{}'".format(pattern)) + + matches +=3D partial_matches + + return list(set(matches)) + + def get_facts(self, host): + return self._facts[host] + class Application: =20 def __init__(self): self._config =3D Config() + self._inventory =3D Inventory() =20 self._parser =3D argparse.ArgumentParser( conflict_handler =3D "resolve", --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 06:30:30 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 1531324500600923.2694748492636; Wed, 11 Jul 2018 08:55:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32D8B914EB; Wed, 11 Jul 2018 15:54:59 +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 D2E8C4C4AB; Wed, 11 Jul 2018 15:54:58 +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 801C03D3BC; Wed, 11 Jul 2018 15:54:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6BFsiwE002248 for ; Wed, 11 Jul 2018 11:54:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A54E2026D76; Wed, 11 Jul 2018 15:54:44 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FE7D2026D6B for ; Wed, 11 Jul 2018 15:54:43 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Wed, 11 Jul 2018 17:54:33 +0200 Message-Id: <20180711155436.22284-6-abologna@redhat.com> In-Reply-To: <20180711155436.22284-1-abologna@redhat.com> References: <20180711155436.22284-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 5/8] lcitool: Implement the 'list' action 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 11 Jul 2018 15:54:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Andrea Bolognani --- guests/lcitool | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/guests/lcitool b/guests/lcitool index 3564eb8..1dd1ec8 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -237,6 +237,7 @@ class Application: description =3D "libvirt CI guest management tool", epilog =3D textwrap.dedent(""" supported actions: + list list all known hosts """), ) self._parser.add_argument( @@ -245,15 +246,25 @@ class Application: required =3D True, help =3D "action to perform (see below)", ) + self._parser.add_argument( + "-h", + metavar =3D "HOSTS", + help =3D "list of hosts to act on (glob patterns are supported= )", + ) + + def _action_list(self, hosts): + for host in self._inventory.expand_pattern("all"): + print(host) =20 def run(self): cmdline =3D self._parser.parse_args() action =3D cmdline.a + hosts =3D cmdline.h =20 method =3D "_action_{}".format(action.replace("-", "_")) =20 if hasattr(self, method): - getattr(self, method).__call__() + getattr(self, method).__call__(hosts) else: raise Error("Invalid action '{}'".format(action)) =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 06:30:30 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 1531324495336419.9535626729919; Wed, 11 Jul 2018 08:54:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E3A793D968; Wed, 11 Jul 2018 15:54:53 +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 A02F35FCA6; Wed, 11 Jul 2018 15:54:53 +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 4988C3F64B; Wed, 11 Jul 2018 15:54:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6BFsi6B002256 for ; Wed, 11 Jul 2018 11:54:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id B00592026D76; Wed, 11 Jul 2018 15:54:44 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 48EB62026D6B for ; Wed, 11 Jul 2018 15:54:44 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Wed, 11 Jul 2018 17:54:34 +0200 Message-Id: <20180711155436.22284-7-abologna@redhat.com> In-Reply-To: <20180711155436.22284-1-abologna@redhat.com> References: <20180711155436.22284-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 6/8] lcitool: Implement the 'install' action 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 11 Jul 2018 15:54:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Andrea Bolognani --- guests/lcitool | 62 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/guests/lcitool b/guests/lcitool index 1dd1ec8..cefce65 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -23,6 +23,7 @@ import fnmatch import os import random import string +import subprocess import sys import textwrap import yaml @@ -237,7 +238,8 @@ class Application: description =3D "libvirt CI guest management tool", epilog =3D textwrap.dedent(""" supported actions: - list list all known hosts + list list all known hosts + install perform unattended host installation """), ) self._parser.add_argument( @@ -256,6 +258,64 @@ class Application: for host in self._inventory.expand_pattern("all"): print(host) =20 + def _action_install(self, hosts): + flavor =3D self._config.get_flavor() + + for host in self._inventory.expand_pattern(hosts): + facts =3D self._inventory.get_facts(host) + + # Both memory size and disk size are stored as GiB in the + # inventory, but virt-install expects the disk size in GiB + # and the memory size in *MiB*, so perform conversion here + memory_arg =3D str(int(facts["install_memory_size"]) * 1024) + + vcpus_arg =3D str(facts["install_vcpus"]) + + disk_arg =3D "size=3D{},pool=3D{},bus=3Dvirtio".format( + facts["install_disk_size"], + facts["install_storage_pool"], + ) + network_arg =3D "network=3D{},model=3Dvirtio".format( + facts["install_network"], + ) + + # preseed files must use a well-known name to be picked up by + # d-i; for kickstart files, we can use whatever name we please + # but we need to point anaconda in the right direction through + # a kernel argument + extra_arg =3D "console=3DttyS0 ks=3Dfile:/{}".format( + facts["install_config"], + ) + + cmd =3D [ + "virt-install", + "--name", host, + "--location", facts["install_url"], + "--virt-type", facts["install_virt_type"], + "--arch", facts["install_arch"], + "--machine", facts["install_machine"], + "--cpu", facts["install_cpu_model"], + "--vcpus", vcpus_arg, + "--memory", memory_arg, + "--disk", disk_arg, + "--network", network_arg, + "--graphics", "none", + "--console", "pty", + "--sound", "none", + "--initrd-inject", facts["install_config"], + "--extra-args", extra_arg, + "--wait", "0", + ] + + # Only configure autostart for the guest for the jenkins flavor + if flavor =3D=3D "jenkins": + cmd +=3D [ "--autostart" ] + + try: + subprocess.check_call(cmd) + except: + raise Error("Failed to install '{}'".format(host)) + def run(self): cmdline =3D self._parser.parse_args() action =3D cmdline.a --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 06:30:30 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 1531324500647682.8504743617996; Wed, 11 Jul 2018 08:55:00 -0700 (PDT) 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 4B6253D12; Wed, 11 Jul 2018 15:54:59 +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 1650F5D9CD; Wed, 11 Jul 2018 15:54:59 +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 B4FF518037F7; Wed, 11 Jul 2018 15:54:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6BFsjHE002268 for ; Wed, 11 Jul 2018 11:54:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 592942026D76; Wed, 11 Jul 2018 15:54:45 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEE652026D6B for ; Wed, 11 Jul 2018 15:54:44 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Wed, 11 Jul 2018 17:54:35 +0200 Message-Id: <20180711155436.22284-8-abologna@redhat.com> In-Reply-To: <20180711155436.22284-1-abologna@redhat.com> References: <20180711155436.22284-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 7/8] lcitool: Implement the 'update' action 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 11 Jul 2018 15:54:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The 'prepare' alias was kinda redundant and offered dubious value, so it has been dropped. Signed-off-by: Andrea Bolognani --- guests/lcitool | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/guests/lcitool b/guests/lcitool index cefce65..c17c174 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -240,6 +240,7 @@ class Application: supported actions: list list all known hosts install perform unattended host installation + update prepare hosts and keep them updated """), ) self._parser.add_argument( @@ -316,6 +317,35 @@ class Application: except: raise Error("Failed to install '{}'".format(host)) =20 + def _action_update(self, hosts): + flavor =3D self._config.get_flavor() + vault_pass_file =3D self._config.get_vault_password_file() + root_pass_file =3D self._config.get_root_password_file() + + ansible_hosts =3D ",".join(self._inventory.expand_pattern(hosts)) + + extra_vars =3D "flavor=3D{} root_password_file=3D{}".format( + flavor, + root_pass_file, + ) + + cmd =3D [ "ansible-playbook" ] + + # Provide the vault password if available + if vault_pass_file is not None: + cmd +=3D [ "--vault-password-file", vault_pass_file ] + + cmd +=3D [ + "--limit", ansible_hosts, + "--extra-vars", extra_vars, + "./site.yml", + ] + + try: + subprocess.check_call(cmd) + except: + raise Error("Failed to update '{}'".format(hosts)) + def run(self): cmdline =3D self._parser.parse_args() action =3D cmdline.a --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 06:30:30 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 1531324508346346.00333336721917; Wed, 11 Jul 2018 08:55:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D08C9307D84A; Wed, 11 Jul 2018 15:55:03 +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 8A37D308BDB4; Wed, 11 Jul 2018 15:55:03 +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 231CC264FB; Wed, 11 Jul 2018 15:55:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6BFsk9E002283 for ; Wed, 11 Jul 2018 11:54:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 020092026D76; Wed, 11 Jul 2018 15:54:46 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 978E62026D6B for ; Wed, 11 Jul 2018 15:54:45 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Wed, 11 Jul 2018 17:54:36 +0200 Message-Id: <20180711155436.22284-9-abologna@redhat.com> In-Reply-To: <20180711155436.22284-1-abologna@redhat.com> References: <20180711155436.22284-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [jenkins-ci PATCH 8/8] guests: Update documentation 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 11 Jul 2018 15:55:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Andrea Bolognani --- guests/README.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guests/README.markdown b/guests/README.markdown index bc780f3..4a40619 100644 --- a/guests/README.markdown +++ b/guests/README.markdown @@ -6,16 +6,16 @@ of the guests used by the Jenkins-based libvirt CI enviro= nment. =20 There are two steps to bringing up a guest: =20 -* `./lcitool install $guest` will perform an unattended installation +* `./lcitool -a install -h $guest` will perform an unattended installation of `$guest`. Not all guests can be installed this way: see the "FreeBSD" section below; =20 -* `./lcitool prepare $guest` will go through all the post-installation +* `./lcitool -a update -h $guest` will go through all the post-installation configuration steps required to make the newly-created guest usable; =20 Once those steps have been performed, maintainance will involve running: =20 -* `./lcitool update $guest` +* `./lcitool -a update -h $guest` =20 periodically to ensure the guest configuration is sane and all installed packages are updated. @@ -40,7 +40,7 @@ you'll want to use the `libvirt_guest` variant of the plu= gin. To keep guests up to date over time, it's recommended to have an entry along the lines of =20 - 0 0 * * * cd ~/libvirt-jenkins-ci/guests && ./lcitool update all + 0 0 * * * cd ~/libvirt-jenkins-ci/guests && ./lcitool -a update -h all =20 in your crontab. =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list