From nobody Fri Jun 6 16:27:02 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bDRY31DRfz5xcxV; Fri, 06 Jun 2025 16:27:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bDRY23QvFz3L2w; Fri, 06 Jun 2025 16:27:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749227222; h=from:from: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; bh=PeGme3/vwH9Rxu5g8BFL7KDAzDexrELvmn9sJolA3Ss=; b=wAl3JNn6nF1N1MCtD3DbLCtcOfuJAum1gxZmBOZithxTq3GzsRlQL1AuGumcpQ54Tgbxv0 xfAjEDij+Y+KwY49VPjmchAE8bcb/T/ePpkAduWBOBjdiNG46TFK1jYnXqbiPU7WfY1tGm ZGo4ZzU2UzP1VQzOrdMaYxoA3+iVHNM92KAL0V+itfR+sGZ0eRfpcBeucFR8wxDhTa5gcL 8stM8unqtKaExKgg7zjl2vCkDxBQhi1dQ6vmWhLhedDU4jvVBU8/72J79i69Zgm3MWZtn+ fRVvQC1fHZAPjRF24tBYKWABaUvAjCFxNdBx4l/nbsnRrXtke8X/JVoeIO2uxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749227222; h=from:from: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; bh=PeGme3/vwH9Rxu5g8BFL7KDAzDexrELvmn9sJolA3Ss=; b=emBQyqhg5Oulb6+GW3QpG4fubs3SR5j3ACvmNanfHQ4YayC663CHXrHJCCEtTahdHiGswI +ENRKpqqMVxVjOn43Z70Kl47r6uG7+6+ahwu4ZI6XdSNW1ewu1yWxORmVtVUDqAl8+w2wY uOTs2qoVyVAAZxOTJuA1C7dwF3z/F+sxXNBrle+oKmmORqMfQrTa2xsJ1xcLcOXCeoMOuA Iq2LFKo0JCfo4rs5sHHn2Jbr7UsgdHhpyqX5b0bRspFsGn9Kh7uTTeXh4rEBeYSmTAIvm+ gAh9JUktmRsl0e/jVxmASWsOLTl5b1g3XpaZ23L3J/GLcDwBCQLhGiT4drSriw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1749227222; a=rsa-sha256; cv=none; b=Or4HsPmjvib51ZrKda38s7ch2PKVEryDKimu97fRBx8g3xEUvv6+7fedcMAKQKsS5VHO/2 NN+3GLgPo88mxcK8AMP/af6qr6YlWV59B0X16RZx5y0TsN747n/qfyz/Zn23jDZAapXVbv 4fZ79NHLOx7lovEvIi69J3K8MiMXGExJTQT7wjsBwTVucHquMQqo9+4hQe+PegezJGJLAM 1zxRbbDSWwJGHAZCxJSCj1LAASfaNIi34BvubWYaPyCC/Hj4C8bV9D0dFhpYjDFURRflfW 655IPIGss+h3FEcNbTmKAspRUscl/N/xC16OY99us/uNiGYki019D5qqI2lY4g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bDRY22lzsz12W9; Fri, 06 Jun 2025 16:27:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 556GR2VO066562; Fri, 6 Jun 2025 16:27:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 556GR28l066559; Fri, 6 Jun 2025 16:27:02 GMT (envelope-from git) Date: Fri, 6 Jun 2025 16:27:02 GMT Message-Id: <202506061627.556GR28l066559@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 682af9601aeb - main - nuageinit: more package related functions List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 682af9601aebb71357d05bb9ffbc137958a437cf Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=682af9601aebb71357d05bb9ffbc137958a437cf commit 682af9601aebb71357d05bb9ffbc137958a437cf Author: Sebastien Baylocq AuthorDate: 2025-06-06 16:24:48 +0000 Commit: Baptiste Daroussin CommitDate: 2025-06-06 16:26:41 +0000 nuageinit: more package related functions Implement package_update and package_upgrade, which allows to launch an update of the metadata and an upgrade of the packages. Sponsored by: OVHCloud --- libexec/nuageinit/nuage.lua | 20 +++++++++++++++++++- libexec/nuageinit/nuageinit | 7 +++++++ libexec/nuageinit/tests/nuageinit.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua index 0fe7400c2bbc..76f2d24ac178 100644 --- a/libexec/nuageinit/nuage.lua +++ b/libexec/nuageinit/nuage.lua @@ -389,6 +389,22 @@ local function install_package(package) return os.execute(install_cmd) end +local function run_pkg_cmd(subcmd) + local cmd = "pkg " .. subcmd .. " -y" + if os.getenv("NUAGE_RUN_TESTS") then + print(cmd) + return true + end + return os.execute(cmd) +end +local function update_packages() + return run_pkg_cmd("update") +end + +local function upgrade_packages() + return run_pkg_cmd("upgrade") +end + local n = { warn = warnmsg, err = errmsg, @@ -401,7 +417,9 @@ local n = { update_sshd_config = update_sshd_config, chpasswd = chpasswd, pkg_bootstrap = pkg_bootstrap, - install_package = install_package + install_package = install_package, + update_packages = update_packages, + upgrade_packages = upgrade_packages } return n diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit index ef5726960978..dda3ae482859 100755 --- a/libexec/nuageinit/nuageinit +++ b/libexec/nuageinit/nuageinit @@ -389,6 +389,13 @@ if line == "#cloud-config" then if obj.packages then install_packages(obj.packages) end + + if obj.package_update then + nuage.update_packages() + end + if obj.package_upgrade then + nuage.upgrade_packages() + end else local res, err = os.execute(path .. "/" .. ud) if not res then diff --git a/libexec/nuageinit/tests/nuageinit.sh b/libexec/nuageinit/tests/nuageinit.sh index e8742be3ba51..5fc811f1dcb5 100644 --- a/libexec/nuageinit/tests/nuageinit.sh +++ b/libexec/nuageinit/tests/nuageinit.sh @@ -25,6 +25,8 @@ atf_test_case nocloud_userdata_cloudconfig_chpasswd_list_string atf_test_case nocloud_userdata_cloudconfig_chpasswd_list_list atf_test_case config2_userdata_runcmd atf_test_case config2_userdata_packages +atf_test_case config2_userdata_update_packages +atf_test_case config2_userdata_upgrade_packages setup_test_adduser() { @@ -741,6 +743,7 @@ config2_userdata_packages_head() { atf_set "require.user" root } + config2_userdata_packages_body() { mkdir -p media/nuageinit @@ -779,6 +782,34 @@ EOF atf_check -o inline:"pkg install -y curl\npkg info -q curl\n" -e inline:"nuageinit: Invalid type : table for packages entry number 2\n" /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 } +config2_userdata_update_packages_body() +{ + mkdir -p media/nuageinit + setup_test_adduser + export NUAGE_RUN_TESTS=1 + printf "{}" > media/nuageinit/meta_data.json + cat > media/nuageinit/user_data << 'EOF' +#cloud-config +package_update: true +EOF + chmod 755 "${PWD}"/media/nuageinit/user_data + atf_check -o inline:"pkg update -y\n" /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 +} + +config2_userdata_upgrade_packages_body() +{ + mkdir -p media/nuageinit + setup_test_adduser + export NUAGE_RUN_TESTS=1 + printf "{}" > media/nuageinit/meta_data.json + cat > media/nuageinit/user_data << 'EOF' +#cloud-config +package_upgrade: true +EOF + chmod 755 "${PWD}"/media/nuageinit/user_data + atf_check -o inline:"pkg upgrade -y\n" /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 +} + atf_init_test_cases() { atf_add_test_case args @@ -800,4 +831,6 @@ atf_init_test_cases() atf_add_test_case nocloud_userdata_cloudconfig_chpasswd_list_list atf_add_test_case config2_userdata_runcmd atf_add_test_case config2_userdata_packages + atf_add_test_case config2_userdata_update_packages + atf_add_test_case config2_userdata_upgrade_packages }