Upgrade to 2.2.10

Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
Gris Ge 2023-04-23 18:51:18 +08:00
parent bea67c799a
commit 3128e422e0
5 changed files with 131 additions and 76 deletions

2
.gitignore vendored
View File

@ -91,3 +91,5 @@
/nmstate-2.2.8.tar.gz.asc /nmstate-2.2.8.tar.gz.asc
/nmstate-2.2.9.tar.gz /nmstate-2.2.9.tar.gz
/nmstate-2.2.9.tar.gz.asc /nmstate-2.2.9.tar.gz.asc
/nmstate-2.2.10.tar.gz
/nmstate-2.2.10.tar.gz.asc

View File

@ -1,71 +0,0 @@
From f9d3f0cdcabfa18d465068508d7b69b2a65823bc Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Thu, 23 Mar 2023 21:35:08 +0800
Subject: [PATCH] dependency: Upgrade to nix 0.26 and env_logger 0.10
Signed-off-by: Gris Ge <fge@redhat.com>
---
rust/src/cli/Cargo.toml | 2 +-
rust/src/lib/Cargo.toml | 2 +-
rust/src/lib/nispor/hostname.rs | 14 +++++++++-----
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/rust/src/cli/Cargo.toml b/rust/src/cli/Cargo.toml
index 350c9fcc..2902804a 100644
--- a/rust/src/cli/Cargo.toml
+++ b/rust/src/cli/Cargo.toml
@@ -21,7 +21,7 @@ nmstate = {path = "../lib", version = "2.2", default-features = false}
serde_yaml = "0.9"
clap = { version = "3.1", features = ["cargo"] }
serde = { version = "1.0", features = ["derive"] }
-env_logger = "0.9.0"
+env_logger = "0.10.0"
log = "0.4.14"
serde_json = "1.0.75"
ctrlc = { version = "3.2.1", optional = true }
diff --git a/rust/src/lib/Cargo.toml b/rust/src/lib/Cargo.toml
index 721fe6a3..4a6b6b3e 100644
--- a/rust/src/lib/Cargo.toml
+++ b/rust/src/lib/Cargo.toml
@@ -55,7 +55,7 @@ default-features = false
features = ["derive"]
[dependencies.nix]
-version = "0.24.1"
+version = "0.26.0"
optional = true
default-features = false
features = ["feature", "hostname"]
diff --git a/rust/src/lib/nispor/hostname.rs b/rust/src/lib/nispor/hostname.rs
index 517bf7c7..5e9f1ba8 100644
--- a/rust/src/lib/nispor/hostname.rs
+++ b/rust/src/lib/nispor/hostname.rs
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: Apache-2.0
+
use std::io::Read;
use crate::{ErrorKind, HostNameState, NmstateError};
@@ -5,12 +7,14 @@ use crate::{ErrorKind, HostNameState, NmstateError};
const HOST_NAME_MAX: usize = 64;
pub(crate) fn get_hostname_state() -> Option<HostNameState> {
- let mut buffer = [0u8; HOST_NAME_MAX];
- let running = match nix::unistd::gethostname(&mut buffer) {
+ let running = match nix::unistd::gethostname() {
Ok(hostname_cstr) => match hostname_cstr.to_str() {
- Ok(h) => Some(h.to_string()),
- Err(e) => {
- log::error!("Failed to convert hostname to String: {}", e);
+ Some(h) => Some(h.to_string()),
+ None => {
+ log::error!(
+ "Failed to convert hostname from OsString \
+ to String: {hostname_cstr:?}"
+ );
None
}
},
--
2.40.0

124
0002-fix_nix_deps.patch Normal file
View File

@ -0,0 +1,124 @@
From 4fc0b3e09ad892e2b2da975b6786998729511ac6 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Sun, 23 Apr 2023 17:37:00 +0800
Subject: [PATCH 1/2] dep: Upgrade to nix 0.26.2
Signed-off-by: Gris Ge <fge@redhat.com>
---
rust/src/lib/Cargo.toml | 2 +-
rust/src/lib/nispor/hostname.rs | 15 ++++++++-------
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/rust/src/lib/Cargo.toml b/rust/src/lib/Cargo.toml
index 29fe4c34..1a4e96c4 100644
--- a/rust/src/lib/Cargo.toml
+++ b/rust/src/lib/Cargo.toml
@@ -55,7 +55,7 @@ default-features = false
features = ["derive"]
[dependencies.nix]
-version = "0.24.1"
+version = "0.26.2"
optional = true
default-features = false
features = ["feature", "hostname"]
diff --git a/rust/src/lib/nispor/hostname.rs b/rust/src/lib/nispor/hostname.rs
index 517bf7c7..b96fb3f3 100644
--- a/rust/src/lib/nispor/hostname.rs
+++ b/rust/src/lib/nispor/hostname.rs
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: Apache-2.0
+
use std::io::Read;
use crate::{ErrorKind, HostNameState, NmstateError};
@@ -5,17 +7,16 @@ use crate::{ErrorKind, HostNameState, NmstateError};
const HOST_NAME_MAX: usize = 64;
pub(crate) fn get_hostname_state() -> Option<HostNameState> {
- let mut buffer = [0u8; HOST_NAME_MAX];
- let running = match nix::unistd::gethostname(&mut buffer) {
- Ok(hostname_cstr) => match hostname_cstr.to_str() {
- Ok(h) => Some(h.to_string()),
- Err(e) => {
- log::error!("Failed to convert hostname to String: {}", e);
+ let running = match nix::unistd::gethostname() {
+ Ok(hostname_cstr) => match hostname_cstr.into_string() {
+ Ok(h) => Some(h),
+ Err(s) => {
+ log::error!("Failed to convert hostname to String: {:?}", s);
None
}
},
Err(e) => {
- log::error!("Failed to get hostname: {}", e);
+ log::error!("Failed to get hostname {}", e);
None
}
};
--
2.40.0
From c9fd1e80d3c87e1f844edcd86e9d36ae499ce717 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Sun, 23 Apr 2023 16:01:29 +0800
Subject: [PATCH 2/2] cli: Do nothing for `persist-nic-names` when got
`net.ifnames=0`
When `net.ifnames=0` is defined in kernel argument, systemd will disable
the predicable network interface name which make no sense for nmstate to
pin the interface names. Hence we do nothing in `persist-nic-names` in
that case.
Manually tested in CentOS stream 9 VM.
Signed-off-by: Gris Ge <fge@redhat.com>
---
rust/src/cli/persist_nic.rs | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/rust/src/cli/persist_nic.rs b/rust/src/cli/persist_nic.rs
index 6b126d58..61b07dbb 100644
--- a/rust/src/cli/persist_nic.rs
+++ b/rust/src/cli/persist_nic.rs
@@ -7,6 +7,8 @@
//!
//! The logic currently is:
//!
+//! - Do nothing if kernel argument contains `net.ifnames=0` which disabled the
+//! predicable network interface name, hence not fit our use case here.
//! - Iterate over all active NICs
//! - Pin every ethernet interface to its MAC address (prefer permanent MAC
//! address)
@@ -70,6 +72,14 @@ pub(crate) fn run_persist_immediately(
PersistAction::CleanUpDryRun => return clean_up(root, true),
};
+ if is_prediable_ifname_disabled() {
+ log::info!(
+ "Systemd predicable network interface name is disabled \
+ by kernel argument `net.ifnames=0`, will do nothing"
+ );
+ return Ok("".to_string());
+ }
+
let stamp_path = Path::new(root)
.join(SYSTEMD_NETWORK_LINK_FOLDER)
.join(NMSTATE_PERSIST_STAMP);
@@ -317,3 +327,12 @@ fn is_nmstate_generated_systemd_link_file(file_path: &PathBuf) -> bool {
.map(|_| buff == PERSIST_GENERATED_BY.as_bytes())
.unwrap_or_default()
}
+
+const KERNEL_CMDLINE_FILE: &str = "/proc/cmdline";
+
+fn is_prediable_ifname_disabled() -> bool {
+ std::fs::read(KERNEL_CMDLINE_FILE)
+ .map(|v| String::from_utf8(v).unwrap_or_default())
+ .map(|c| c.contains("net.ifnames=0"))
+ .unwrap_or_default()
+}
--
2.40.0

View File

@ -2,7 +2,7 @@
%define libname libnmstate %define libname libnmstate
Name: nmstate Name: nmstate
Version: 2.2.9 Version: 2.2.10
Release: %autorelease Release: %autorelease
Summary: Declarative network manager API Summary: Declarative network manager API
License: LGPLv2+ License: LGPLv2+
@ -14,7 +14,7 @@ Source2: https://nmstate.io/nmstate.gpg
# https://bugzilla.redhat.com/show_bug.cgi?id=2161128 # https://bugzilla.redhat.com/show_bug.cgi?id=2161128
# but list Requires manually # but list Requires manually
Patch1: 0001-Workaround-for-Fedora-rust-packaging.patch Patch1: 0001-Workaround-for-Fedora-rust-packaging.patch
Patch2: 0002-Upgrade-to-nix-0.26-and-env_logger-0.10.patch Patch2: 0002-fix_nix_deps.patch
BuildRequires: patchelf BuildRequires: patchelf
BuildRequires: python3-devel BuildRequires: python3-devel
BuildRequires: python3-setuptools BuildRequires: python3-setuptools

View File

@ -1,3 +1,3 @@
SHA512 (nmstate.gpg) = 91c6b1d8aef4944520d4bdd4e90121bbbbaf772444f5eb6081cee81e17b21b66798437cdc09a117c6fc77c54d798aaa30400857aa090cb2102b47841f45cf6eb SHA512 (nmstate-2.2.10.tar.gz) = dc103f30ea3c9326cca5e67cf271b057db7c8cbf756241b8d8d66351e61824c2b002b3922d63779206748c62945688e9823b499e4fcc41c882c68b8692e86af6
SHA512 (nmstate-2.2.9.tar.gz) = 117ed9a903be298691883b87b0727d4bddb6dfb744023611e645c87602bfec578008db38d21dde4279dc8ff2dc7b0838ab35248ddb5e250484cc694003f93094 SHA512 (nmstate-2.2.10.tar.gz.asc) = 1923e59420d62a98a471b05fe6c73767d887f1b227c9cdc3ed1bb9ed7dda986a082ccc4e31d7224b4f79c482bb548939920719b73ed657bb33e8bd60a4ff8ef6
SHA512 (nmstate-2.2.9.tar.gz.asc) = 1bcde90966d188d94ef02c6d4b00f8cb63f6d4e0115c4f1900d13eb4b59c9fd21891b7eaea7e240465899b281c8e4ea340b7ce6326c217b6eede0cca8859425e SHA512 (nmstate.gpg) = 8c0188d64660757030772096b3e836f354dbf1f3591bebd1b588aa8abef9c2e37996904e6edb8ee8797afb57237f29dd942a2ceffd24dac50af9e898c0b48c97