From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
by lore.proxmox.com (Postfix) with ESMTPS id 0B7C81FF15F
for <inbox@lore.proxmox.com>; Mon, 26 Aug 2024 14:28:48 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
by firstgate.proxmox.com (Proxmox) with ESMTP id E5BCF12612;
Mon, 26 Aug 2024 14:29:13 +0200 (CEST)
From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: Daniel Kral <d.kral@proxmox.com>
In-Reply-To: <20240826120513.136481-2-d.kral@proxmox.com> (Daniel Kral's
message of "Mon, 26 Aug 2024 14:05:13 +0200")
References: <20240826120513.136481-1-d.kral@proxmox.com>
<20240826120513.136481-2-d.kral@proxmox.com>
Date: Mon, 26 Aug 2024 14:28:40 +0200
Message-ID: <s8obk1f4gef.fsf@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results: 0
AWL 0.106 Adjusted score from AWL reputation of From: address
BAYES_00 -1.9 Bayes spam probability is 0 to 1%
DMARC_MISSING 0.1 Missing DMARC policy
KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
Validity was blocked. See
https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
information.
RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
Validity was blocked. See
https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
information.
RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
Validity was blocked. See
https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
information.
SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record
SPF_PASS -0.001 SPF: sender matches SPF record
T_SCC_BODY_TEXT_LINE -0.01 -
Subject: Re: [pbs-devel] [PATCH proxmox-backup v2 2/2] pbs2to3: add test
cases for kernel version compatibility
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
<pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>,
<mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>,
<mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>
Daniel Kral <d.kral@proxmox.com> writes:
Some small nits commented bellow.
> Implements test cases for the kernel version compatibility check in
> `pbs2to3` for a set of expected and unexpected kernel versions. They are
> tested for both cases, when PBS was already upgraded to v3.x and when it
> is still on v2.x.
>
> The kernel versions in the test cases were mostly hand-picked from the
> current Proxmox Backup Server repositories, excluding the kernel
> versions 5.19.* and 6.1.* because they were both not expected before
> this patch. I also added a fictional kernel version 7.1.0 as an
> unexpected case to make sure that the initial objective of only allowing
> arbitrary kernel versions above 6.2.* were marked as expected.
>
> Suggested-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
> Signed-off-by: Daniel Kral <d.kral@proxmox.com>
> ---
> src/bin/pbs2to3.rs | 61 ++++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 54 insertions(+), 7 deletions(-)
>
> diff --git a/src/bin/pbs2to3.rs b/src/bin/pbs2to3.rs
> index 194a077e..2f6a8dcc 100644
> --- a/src/bin/pbs2to3.rs
> +++ b/src/bin/pbs2to3.rs
> @@ -123,18 +123,26 @@ impl Checker {
> Ok(())
> }
>
> + fn is_kernel_version_compatible(&self, running_version: &str) -> bool {
> + let re = if self.upgraded {
> + r"^6\.(?:2\.(?:[2-9]\d+|1[6-8]|1\d\d+)|([5-9]|\d{2,}))[^~]*$"
> + } else {
> + r"^(?:5\.(?:13|15)|6\.2)"
> + };
> + let re = Regex::new(re).expect("failed to compile kernel compat regex");
> +
> + re.is_match(running_version)
> + }
> +
> fn check_kernel_compat(
> &mut self,
> pkg_versions: &[pbs_api_types::APTUpdateInfo],
> ) -> Result<(), Error> {
> self.output.log_info("Check running kernel version..")?;
> - let (krunning, kinstalled) = if self.upgraded {
> - (
> - Regex::new(r"^6\.(?:2\.(?:[2-9]\d+|1[6-8]|1\d\d+)|([5-9]|\d{2,}))[^~]*$")?,
> - "proxmox-kernel-6.2",
> - )
> + let kinstalled = if self.upgraded {
> + "proxmox-kernel-6.2"
> } else {
> - (Regex::new(r"^(?:5\.(?:13|15)|6\.2)")?, "pve-kernel-5.15")
> + "pve-kernel-5.15"
> };
>
> let output = std::process::Command::new("uname").arg("-r").output();
> @@ -144,7 +152,7 @@ impl Checker {
> .log_fail("unable to determine running kernel version.")?,
> Ok(ret) => {
> let running_version = std::str::from_utf8(&ret.stdout[..ret.stdout.len() - 1])?;
> - if krunning.is_match(running_version) {
> + if self.is_kernel_version_compatible(running_version) {
> if self.upgraded {
> self.output.log_pass(format!(
> "running new kernel '{running_version}' after upgrade."
> @@ -620,3 +628,42 @@ impl ConsoleOutput {
> Ok(())
> }
> }
> +
> +#[cfg(test)]
> +mod tests {
> + use super::*;
> +
> + fn test_is_kernel_version_compatible(
> + expected_versions: &[&str],
> + unexpected_versions: &[&str],
> + upgraded: bool,
> + ) {
> + let checker = Checker {
> + output: ConsoleOutput::new(),
> + upgraded,
> + };
> +
> + for version in expected_versions {
> + assert!(checker.is_kernel_version_compatible(version));
> + }
> + for version in unexpected_versions.iter() {
The `iter()` should not be necessary here.
> + assert!(!checker.is_kernel_version_compatible(version));
> + }
> + }
> +
> + #[test]
> + fn test_is_pve_kernel_version_compatible() {
> + let expected_versions = vec!["5.13.19-6-pve", "5.15.158-2-pve", "6.2.16-5-pve"];
> + let unexpected_versions = vec!["6.1.10-1-pve", "5.19.17-2-pve"];
Both of these could be slices instead of `vec!`.
> +
> + test_is_kernel_version_compatible(&expected_versions, &unexpected_versions, false);
Which also would entail removing the `&`s here.
> + }
> +
> + #[test]
> + fn test_is_proxmox_kernel_version_compatible() {
> + let expected_versions = vec!["6.2.16-20-pve", "6.5.13-6-pve", "6.8.12-1-pve"];
> + let unexpected_versions = vec!["5.13.19-6-pve", "6.1.15-1-pve", "7.1.0-1-pve"];
Ditto
> +
> + test_is_kernel_version_compatible(&expected_versions, &unexpected_versions, true);
> + }
> +}
--
Maximiliano
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel