From nobody Thu Sep 26 11:06:18 2024 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 4XDrPk5zSgz5X7wD; Thu, 26 Sep 2024 11:06:18 +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 4XDrPk4g60z4HCB; Thu, 26 Sep 2024 11:06:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727348778; 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=96EofNjN2cXWfZHkm/WrOxrsY3U9k0abKdM/2kvebwc=; b=HnI/JGrdm4S3BLgt0AOOBsg59jy3zJs3qrMqBTuDWQJJ+wJdzc0QrS8BAlxaYU8OVpQAVX fDnZvUWK0AuhAUU/N5Bsm2thZEaYiXA/eY5Q8/MJCD1YsNK2kmPsRmyWWHcb8qtoEYg08x 4H2NdPvW5prkdNZQ6w9jttYpIaOi4CyQv3eJZ00fVPVJMN7mri2HH62RHFD6k2Q9HbTpJC wnbxESrDv/7CRB5iNyRjJD2F9+X7S9rGhd2+Nnvr95utIxExoyN0a4THcAB6fLry5WA/Ud N0avffi5kiluLDWr+BmHByrLRHUy3I1oW3zjg0FyY+x3RGu1rtyyBm3kCsiZgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727348778; 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=96EofNjN2cXWfZHkm/WrOxrsY3U9k0abKdM/2kvebwc=; b=Rugg6cQK/qT3j+MlpddSdDzi76Mp1U67pCpLAU8yRHTPuns+svO3As2MpVg7XwrlypR92c zVDasl/isEH1JEi1Zu2qTH7x4ttRjuCQP3yunJ7DWzGppPMTUJtovZ3Gf7SGBnPoB4DaaE 4EHhIH6Qb0LBW08LjJpUYkD2mqX3cIEmg7KS1QoU228KMbzZHVyA0LzJavnxlPUVIJvS8Z O5lETALP/DZRfYJU8hJIdnMJN4ZiNT8bG86LBn/RnpNNnGHEg1XHanIFazmwqxLaHNlS8s Z/ef2zUOA9tM79HY42PnzqUA+b0/KfX+0ENLNR7CEXlaFlVT0iV/SaGPX/IaZA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727348778; a=rsa-sha256; cv=none; b=xiJi9do1FQBVYsKlAPq82ZPBXCu/vMUA74cKEJm0rWtZWVNgAyEQu8qswloK3IReNTnQ2V 5eMkf4jS7HDQy9t2jeFwcqTekNRm4ptkdYiXdHUhKXDNxJZikOwBnXBs69VajZpCAkFIXd QJS7ig4Ul+JxKtlRqBBM45GEjF7tGwEmsFWGBCkAMOy9AM7sgKW3xEGpQKRkSp/Jwod5U3 clURA9Sn5W000QwfdbzhhIkgZmXO9gATdktgBH9eyH7NHirs4hu7NECbXc/Yl2xw4ALDr/ ux1KrDiXGlpi7JMy1S7asadyJ7rAGTUX04bET1r5nKy/6G47+6U7MilobOkXIw== 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 4XDrPk32yWztg9; Thu, 26 Sep 2024 11:06:18 +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 48QB6Ilw063514; Thu, 26 Sep 2024 11:06:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48QB6IcC063511; Thu, 26 Sep 2024 11:06:18 GMT (envelope-from git) Date: Thu, 26 Sep 2024 11:06:18 GMT Message-Id: <202409261106.48QB6IcC063511@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: 945632ca7611 - main - nuageinit: Standardize warning/error messages 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: 945632ca76117029e7bd1f46d17ccb378973daf7 Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=945632ca76117029e7bd1f46d17ccb378973daf7 commit 945632ca76117029e7bd1f46d17ccb378973daf7 Author: Jose Luis Duran AuthorDate: 2024-07-30 01:18:11 +0000 Commit: Baptiste Daroussin CommitDate: 2024-09-26 10:59:14 +0000 nuageinit: Standardize warning/error messages Standardize the utilities from nuage.lua, to return nil on failure, plus an error message as a second result, and some value different from nil on success. Make warnmsg() and errmsg() append "nuageinit: " by default. Pass an optional second parameter as false to avoid printing this tag. Signed-off-by: Jose Luis Duran --- libexec/nuageinit/nuage.lua | 21 ++++++++++++++------- libexec/nuageinit/nuageinit | 26 +++++++++++++------------- libexec/nuageinit/tests/nuage.sh | 4 ++-- libexec/nuageinit/tests/nuageinit.sh | 4 ++-- libexec/nuageinit/tests/utils.sh | 4 ++-- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/libexec/nuageinit/nuage.lua b/libexec/nuageinit/nuage.lua index 1f035036f802..c27b66b23be2 100644 --- a/libexec/nuageinit/nuage.lua +++ b/libexec/nuageinit/nuage.lua @@ -7,12 +7,19 @@ local unistd = require("posix.unistd") local sys_stat = require("posix.sys.stat") local lfs = require("lfs") -local function warnmsg(str) - io.stderr:write(str .. "\n") +local function warnmsg(str, prepend) + if not str then + return + end + local tag = "" + if prepend ~= false then + tag = "nuageinit: " + end + io.stderr:write(tag .. str .. "\n") end -local function errmsg(str) - io.stderr:write(str .. "\n") +local function errmsg(str, prepend) + warnmsg(str, prepend) os.exit(1) end @@ -129,7 +136,7 @@ local function adduser(pwd) local r = os.execute(cmd) if not r then - warnmsg("nuageinit: fail to add user " .. pwd.name) + warnmsg("fail to add user " .. pwd.name) warnmsg(cmd) return nil end @@ -172,7 +179,7 @@ local function addgroup(grp) cmd = cmd .. "groupadd -n " .. grp.name .. extraargs local r = os.execute(cmd) if not r then - warnmsg("nuageinit: fail to add group " .. grp.name) + warnmsg("fail to add group " .. grp.name) warnmsg(cmd) return false end @@ -201,7 +208,7 @@ local function addsshkey(homedir, key) local f = io.open(ak_path, "a") if not f then - warnmsg("nuageinit: impossible to open " .. ak_path) + warnmsg("impossible to open " .. ak_path) return end f:write(key .. "\n") diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit index 50d77dfef9f5..8c289fea6b1d 100755 --- a/libexec/nuageinit/nuageinit +++ b/libexec/nuageinit/nuageinit @@ -9,7 +9,7 @@ local ucl = require("ucl") local yaml = require("yaml") if #arg ~= 2 then - nuage.err("Usage " .. arg[0] .. " [config-2|nocloud]") + nuage.err("Usage " .. arg[0] .. " [config-2|nocloud]", false) end local path = arg[1] local citype = arg[2] @@ -32,7 +32,7 @@ local function open_config(name) nuage.mkdir_p(root .. "/etc/rc.conf.d") local f, err = io.open(root .. "/etc/rc.conf.d/" .. name, "w") if not f then - nuage.err("nuageinit: unable to open " .. name .. " config: " .. err) + nuage.err("unable to open " .. name .. " config: " .. err) end return f end @@ -69,14 +69,14 @@ local function config2_network(p) f:close() local res, err = parser:parse_file(p .. "/network_data.json") if not res then - nuage.warn("nuageinit: error parsing network_data.json: " .. err) + nuage.warn("error parsing network_data.json: " .. err) return end local obj = parser:get_object() local ifaces = get_ifaces() if not ifaces then - nuage.warn("nuageinit: no network interfaces found") + nuage.warn("no network interfaces found") return end local mylinks = {} @@ -167,7 +167,7 @@ if citype == "config-2" then local res, err = parser:parse_file(path .. "/meta_data.json") if not res then - nuage.err("nuageinit: error parsing config-2: meta_data.json: " .. err) + nuage.err("error parsing config-2 meta_data.json: " .. err) end local obj = parser:get_object() if obj.public_keys then @@ -183,12 +183,12 @@ if citype == "config-2" then elseif citype == "nocloud" then local f, err = io.open(path .. "/meta-data") if err then - nuage.err("nuageinit: error parsing nocloud meta-data: " .. err) + nuage.err("error parsing nocloud meta-data: " .. err) end local obj = yaml.eval(f:read("*a")) f:close() if not obj then - nuage.err("nuageinit: error parsing nocloud meta-data") + nuage.err("error parsing nocloud meta-data") end local hostname = obj["local-hostname"] if not hostname then @@ -222,21 +222,21 @@ if line == "#cloud-config" then local obj = yaml.eval(f:read("*a")) f:close() if not obj then - nuage.err("nuageinit: error parsing cloud-config file: " .. ud) + nuage.err("error parsing cloud-config file: " .. ud) end if obj.groups then for n, g in pairs(obj.groups) do if (type(g) == "string") then local r = nuage.addgroup({name = g}) if not r then - nuage.warn("nuageinit: failed to add group: " .. g) + nuage.warn("failed to add group: " .. g) end elseif type(g) == "table" then for k, v in pairs(g) do nuage.addgroup({name = k, members = v}) end else - nuage.warn("nuageinit: invalid type: " .. type(g) .. " for users entry number " .. n) + nuage.warn("invalid type: " .. type(g) .. " for users entry number " .. n) end end end @@ -260,7 +260,7 @@ if line == "#cloud-config" then end end else - nuage.warn("nuageinit: invalid type : " .. type(u) .. " for users entry number " .. n) + nuage.warn("invalid type : " .. type(u) .. " for users entry number " .. n) end ::unext:: end @@ -288,7 +288,7 @@ if line == "#cloud-config" then goto next end if not ifaces[v.match.macaddress] then - nuage.warn("nuageinit: not interface matching: " .. v.match.macaddress) + nuage.warn("not interface matching: " .. v.match.macaddress) goto next end local interface = ifaces[v.match.macaddress] @@ -325,6 +325,6 @@ if line == "#cloud-config" then else local res, err = os.execute(path .. "/" .. ud) if not res then - nuage.err("nuageinit: error executing user-data script: " .. err) + nuage.err("error executing user-data script: " .. err) end end diff --git a/libexec/nuageinit/tests/nuage.sh b/libexec/nuageinit/tests/nuage.sh index 4e2353176b16..6d8a2746de1f 100644 --- a/libexec/nuageinit/tests/nuage.sh +++ b/libexec/nuageinit/tests/nuage.sh @@ -42,7 +42,7 @@ adduser_body() printf "root:*:0:0::0:0:Charlie &:/root:/bin/csh\n" > etc/master.passwd pwd_mkdb -d etc etc/master.passwd printf "wheel:*:0:root\n" > etc/group - atf_check -e inline:"Argument should be a table\nArgument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/adduser.lua + atf_check -e inline:"nuageinit: Argument should be a table\nnuageinit: Argument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/adduser.lua test -d home/impossible_username || atf_fail "home not created" atf_check -o inline:"impossible_username::1001:1001::0:0:impossible_username User:/home/impossible_username:/bin/sh\n" grep impossible_username etc/master.passwd } @@ -52,7 +52,7 @@ addgroup_body() export NUAGE_FAKE_ROOTDIR="$(pwd)" mkdir etc printf "wheel:*:0:root\n" > etc/group - atf_check -e inline:"Argument should be a table\nArgument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/addgroup.lua + atf_check -e inline:"nuageinit: Argument should be a table\nnuageinit: Argument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/addgroup.lua atf_check -o inline:"impossible_groupname:*:1001:\n" grep impossible_groupname etc/group } diff --git a/libexec/nuageinit/tests/nuageinit.sh b/libexec/nuageinit/tests/nuageinit.sh index 64ac066fefbf..f3fc55e87523 100644 --- a/libexec/nuageinit/tests/nuageinit.sh +++ b/libexec/nuageinit/tests/nuageinit.sh @@ -22,7 +22,7 @@ args_body() atf_check -s exit:1 -e inline:"Usage /usr/libexec/nuageinit [config-2|nocloud]\n" /usr/libexec/nuageinit atf_check -s exit:1 -e inline:"Usage /usr/libexec/nuageinit [config-2|nocloud]\n" /usr/libexec/nuageinit bla atf_check -s exit:1 -e inline:"Usage /usr/libexec/nuageinit [config-2|nocloud]\n" /usr/libexec/nuageinit bla meh plop - atf_check -s exit:1 -e inline:"Unknown cloud init type: meh\n" /usr/libexec/nuageinit bla meh + atf_check -s exit:1 -e inline:"nuageinit: Unknown cloud init type: meh\n" /usr/libexec/nuageinit bla meh } nocloud_body() @@ -174,7 +174,7 @@ config2_body() { here=$(pwd) mkdir -p media/nuageinit - atf_check -s exit:1 -e match:"nuageinit: error parsing config-2: meta_data.json.*" /usr/libexec/nuageinit ${here}/media/nuageinit config-2 + atf_check -s exit:1 -e match:"nuageinit: error parsing config-2 meta_data.json:.*" /usr/libexec/nuageinit ${here}/media/nuageinit config-2 printf "{}" > media/nuageinit/meta_data.json atf_check /usr/libexec/nuageinit ${here}/media/nuageinit config-2 cat > media/nuageinit/meta_data.json << EOF diff --git a/libexec/nuageinit/tests/utils.sh b/libexec/nuageinit/tests/utils.sh index c3b5b8212938..26f117d81d60 100644 --- a/libexec/nuageinit/tests/utils.sh +++ b/libexec/nuageinit/tests/utils.sh @@ -10,12 +10,12 @@ atf_test_case dirname warn_body() { - atf_check -e "inline:plop\n" -s exit:0 /usr/libexec/flua $(atf_get_srcdir)/warn.lua + atf_check -e "inline:nuageinit: plop\n" -s exit:0 /usr/libexec/flua $(atf_get_srcdir)/warn.lua } err_body() { - atf_check -e "inline:plop\n" -s exit:1 /usr/libexec/flua $(atf_get_srcdir)/err.lua + atf_check -e "inline:nuageinit: plop\n" -s exit:1 /usr/libexec/flua $(atf_get_srcdir)/err.lua } dirname_body()