From nobody Mon Jun 23 07:44:08 2025 X-Original-To: dev-commits-src-all@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 4bQg7s0SCyz5ywT6; Mon, 23 Jun 2025 07:44:09 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bQg7r67sbz4Brh; Mon, 23 Jun 2025 07:44:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750664648; 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=eI82HhXoDZVx2RkoABeuVjtfDWjMkaaTNScyxbxMehw=; b=b69RSuycZn+3FmKJCDyhOH2FbkVC3Ew+cy3OHbExVF4BDI9DlioWPBRlbiJFixCJGZFEN3 RGSAPDhcXfQz23Rq9oLeqq95xfBq9meWq+3YR4J3Qm+BqiIqB1jL/kcILcC2QuO5MK0Pp6 /Vaic+j7ACw0upHjgbJlx6xGBoCZRVUNXken6Nwd5OoKBfYzzCrLLIO8LwPgPC4TiQyFaT SC2PvXqo5ildp6ub0BeymjA0V6DvNqT/7l4sRazFdzEIOrhy9u3QQYVR9nT5uGN3rj494K 9NdJ6TJRsvvSzDrweqqa+EtzTnlh54Mvyx8NHgVxIRHEgk7JSHo5FlWAbZ+qUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750664648; 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=eI82HhXoDZVx2RkoABeuVjtfDWjMkaaTNScyxbxMehw=; b=i+oo3KKZcr6aWfELFRcWEemZakiMoNq4eBnIBnsBGxe6rwkeLcFJF5QcWsRMjuWfFtVS1p 2ZOgbniXVVPuF+MGR3tVjBuvHDS7IK1EhQtisGKi82q4T0b8rvdzWzvGQGmoTxUHAgvsGo btPYPcFsrb0mGx/5q/Sx11JpIOrRvNMk9gjqbI5ZehWgy370qXL8ciOxgrqb2UR7e+glT7 6vVDgGxaoRuUC5BPjJwJMYRDtZnb9AFjfqcULSoavdSYfJZIEUhvBdqbVqAMhrvyc/N0fv HJRucpsnkJKmov/K+OTsuX2zS1n4Cvdxu4uNt+MZse2YgADs8NyM0KTbmNRDdw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750664648; a=rsa-sha256; cv=none; b=h94tH5FlzQe7z3l7+mdLAO4M6xQ2l0Gubq91ohB5A4O4SmhoLLZydl2onfBBcTK06ehyeo a2Fu4C+XDejGJYtsr2VqhXvsVZw0fIZK/sHp5tZdjbPjQERW/JbPR2PbpsLIHhcnTIbBUM 50MdoHmHP/UN/QQkyR3Bd9oz8Y+9ba2xl4+EXIOuXmSvY+xQtybT3ueMfrFcoc4OJFSpXU GFD0+LWFq6lCuOCYKUeAaaN8ZHZToaHXpfxTVLMG3JWJe4HSfnwIaZtCi9bWQ6uIS17fBN utdQztJS6T/zaqUnJoflo0m15V+XPYyMAZjAYJny2BTpGM+j1OJgWKBXYxYoEQ== 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 4bQg7r5k0WztYr; Mon, 23 Jun 2025 07:44:08 +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 55N7i8Ug067151; Mon, 23 Jun 2025 07:44:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55N7i8FL067148; Mon, 23 Jun 2025 07:44:08 GMT (envelope-from git) Date: Mon, 23 Jun 2025 07:44:08 GMT Message-Id: <202506230744.55N7i8FL067148@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: 5444803b745e - stable/14 - nuageinit: implement runcmd List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 5444803b745efe61f5cbb5cb56e41369b16e7228 Auto-Submitted: auto-generated The branch stable/14 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=5444803b745efe61f5cbb5cb56e41369b16e7228 commit 5444803b745efe61f5cbb5cb56e41369b16e7228 Author: Sebastien Baylocq AuthorDate: 2025-06-05 21:11:33 +0000 Commit: Baptiste Daroussin CommitDate: 2025-06-23 07:43:12 +0000 nuageinit: implement runcmd runcmd contains a list of string, each item will be executed in order. Sponsored by: OVHCloud (cherry picked from commit 2f35a5218323b3da7fb71933778c03bbb1c2bb7f) --- 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 }