From nobody Fri Jun 6 16:26:59 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 4bDRXz6dBTz5xcjd; Fri, 06 Jun 2025 16:26:59 +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 4bDRXz2brfz3L2N; Fri, 06 Jun 2025 16:26:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749227219; 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=3bIbeYC/MdA2PIgNtlbXD6/TXWRLV0Hl1OrAzLz1Klw=; b=CEXaOEdmeTsJkU+9ZgqUT9cX5LSPJxXRwVo2oJOosfhTpYWS19KeRUwH4VB0swwg3QVVDq cUcRMqwydzqLMuz4ITck8XlElVVbH2+PnXMpKhpD4n06Nz6hRe3BQRTkTMQxjyjgiYRYTf 5Eis53uwfDlvu5kWP3hpdpHLdzsgA1ewGJU+EoT9oh0DFiyw18XfpLN6Y9VrMOUag4DtYS jnxzB0yBjsfrG5ZZ0ux3V6TNW7NLU/l+FyPohZm2gwgxSTvone/l4FvGqJdwFbyaXlTdZX u2yH/4s9BjCj4NU7jrtwo3JT6aAHtJMSsSvR3Rhxkr+JANsEoxsWKZ9qJxmGuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749227219; 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=3bIbeYC/MdA2PIgNtlbXD6/TXWRLV0Hl1OrAzLz1Klw=; b=kxGjFm/Btxsi80hFdtvaMamqTP7iqAsQsidq3zNe7LSRQiQj4mwW7QnjDfLAir5zCtKwQS T/41hiZlCy2pd0dr+67/wvG/uSnzismIpJDRJF30LNBPu+ghCACLHL6XJf1lWgujgk8JH7 G5yBHFZ6D44sITlzuqr21zaeh4nngUA5KTIdgx9nu0KXPqo9qlB4eM8gcwaGYSlpybFciz Oiwpg9TPm2pAww6bym+Zir/d9NXqnRQHOCTCOeSU0bM9veUN0z4bZ4FAchW27B9sF1JCu/ 6pILNcpx0Qk8n8GyYfZD9j/wFG0Y7RqCACyE58reKCNQc3DdchlB4bG3VOQehw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1749227219; a=rsa-sha256; cv=none; b=VMV5YPWqm9qurH2PXlbNR4m59+oP05I+6IcjH2s146L3zLAtzGFvsquJ3ot7RWo9s2KuPG z5Rter/BbLQQAFpYxXUNhq1yE54NC3ChGVpJyjSkKXp2Rrb8hQ2Wj3m9gWD80PcfHIoSLu 2l83JnUSkH5HEWWwbrDj5FnQlEP3dIv0mkDE3Muo6TVE+slGKJxxLPSN0nI5NF3J6QbqvV 8mGHn6I+YkulJVpGO/IeMabVv6QCXnZ+Q6tTE6GqKp4qEsWfUZ+gmQEKz7WeCNfmXsdjXS LKhYLrUBsgFI+7khiwKawzTYLpys6QowZidePDxfXQF01HDQMQtMvCBDiqVWOw== 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 4bDRXz0wPRz12Zm; Fri, 06 Jun 2025 16:26:59 +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 556GQxQk066441; Fri, 6 Jun 2025 16:26:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 556GQx10066435; Fri, 6 Jun 2025 16:26:59 GMT (envelope-from git) Date: Fri, 6 Jun 2025 16:26:59 GMT Message-Id: <202506061626.556GQx10066435@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: 2f35a5218323 - main - nuageinit: implement runcmd 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: 2f35a5218323b3da7fb71933778c03bbb1c2bb7f Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=2f35a5218323b3da7fb71933778c03bbb1c2bb7f commit 2f35a5218323b3da7fb71933778c03bbb1c2bb7f Author: Sebastien Baylocq AuthorDate: 2025-06-05 21:11:33 +0000 Commit: Baptiste Daroussin CommitDate: 2025-06-06 16:26:37 +0000 nuageinit: implement runcmd runcmd contains a list of string, each item will be executed in order. Sponsored by: OVHCloud --- libexec/nuageinit/nuageinit | 9 ++++++++- libexec/nuageinit/tests/nuageinit.sh | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit index 74a75c88098a..ef215af00924 100755 --- a/libexec/nuageinit/nuageinit +++ b/libexec/nuageinit/nuageinit @@ -362,7 +362,14 @@ if line == "#cloud-config" then if obj.chpasswd ~= nil then nuage.chpasswd(obj.chpasswd) end - + if obj.runcmd then + for _, c in ipairs(obj.runcmd) do + if not os.execute(c) then + nuage.warn("Failed to execute '" .. c .. "'") + -- execute the next command anyway -- + end + end + 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 811eb9c0c73b..06f4a12d7503 100644 --- a/libexec/nuageinit/tests/nuageinit.sh +++ b/libexec/nuageinit/tests/nuageinit.sh @@ -23,6 +23,7 @@ atf_test_case nocloud_userdata_cloudconfig_ssh_pwauth atf_test_case nocloud_userdata_cloudconfig_chpasswd atf_test_case nocloud_userdata_cloudconfig_chpasswd_list_string atf_test_case nocloud_userdata_cloudconfig_chpasswd_list_list +atf_test_case config2_userdata_runcmd setup_test_adduser() { @@ -700,6 +701,41 @@ EOF atf_check -o match:'root:\$.*:0:0::0:0:Charlie &:/root:/bin/sh$' pw -R $(pwd) usershow root } +config2_userdata_runcmd_head() +{ + atf_set "require.user" root +} +config2_userdata_runcmd_body() +{ + mkdir -p media/nuageinit + setup_test_adduser + printf "{}" > media/nuageinit/meta_data.json + cat > media/nuageinit/user_data << 'EOF' +#cloud-config +runcmd: +EOF + chmod 755 "${PWD}"/media/nuageinit/user_data + atf_check -s exit:1 -e match:"attempt to index a nil value" /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 + cat > media/nuageinit/user_data << 'EOF' +#cloud-config +runcmd: + - plop +EOF + chmod 755 "${PWD}"/media/nuageinit/user_data + atf_check -s exit:0 -e inline:"sh: plop: not found\nnuageinit: Failed to execute 'plop'\n" /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 + + cat > media/nuageinit/user_data << 'EOF' +#cloud-config +runcmd: + - echo "yeah!" > "${PWD}"/media/nuageinit/runcmd_echo + - uname -s > "${PWD}"/media/nuageinit/runcmd_uname +EOF + chmod 755 "${PWD}"/media/nuageinit/user_data + atf_check /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 + atf_check -s exit:0 -o inline:"yeah!\n" cat "${PWD}"/media/nuageinit/runcmd_echo + atf_check -s exit:0 -o inline:"FreeBSD\n" cat "${PWD}"/media/nuageinit/runcmd_uname +} + atf_init_test_cases() { atf_add_test_case args @@ -719,4 +755,5 @@ atf_init_test_cases() atf_add_test_case nocloud_userdata_cloudconfig_chpasswd atf_add_test_case nocloud_userdata_cloudconfig_chpasswd_list_string atf_add_test_case nocloud_userdata_cloudconfig_chpasswd_list_list + atf_add_test_case config2_userdata_runcmd }