Fix verification on ovsdb when ovs daemon stopped

Resolves: RHBZ#2159679

Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
Gris Ge 2023-01-11 15:23:21 +08:00
parent c670d83cc0
commit 03d759de6f
3 changed files with 80 additions and 2 deletions

View File

@ -0,0 +1,72 @@
From ae3f45a725cb2639ef9e4c6fab1aead0debe7c29 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Tue, 10 Jan 2023 19:56:23 +0800
Subject: [PATCH] ovsdb: Fix verification error when ovs daemon off
When applying `ovs-db: {}` with ovs daemon stopped, nmstate will fail
with:
NmstateError: VerificationError: Verification failure:
ovsdb.external_ids desire '{}', current 'null'
Fixed by treating `ovs-db: {}` as
```yml
ovs-db:
external_ids: {}
other_config: {}
```
Unit test case and integration test case included.
Signed-off-by: Gris Ge <fge@redhat.com>
---
rust/src/lib/query_apply/ovs.rs | 11 ++++++++++-
rust/src/lib/unit_tests/ovsdb.rs | 11 +++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/rust/src/lib/query_apply/ovs.rs b/rust/src/lib/query_apply/ovs.rs
index c1e0cf2e..13c4079d 100644
--- a/rust/src/lib/query_apply/ovs.rs
+++ b/rust/src/lib/query_apply/ovs.rs
@@ -30,8 +30,17 @@ impl MergedOvsDbGlobalConfig {
other_config: Some(other_config),
prop_list: vec!["external_ids", "other_config"],
};
+
let desired_value = serde_json::to_value(&desired)?;
- let current_value = serde_json::to_value(current)?;
+ let current_value = if current.is_none() {
+ serde_json::to_value(&OvsDbGlobalConfig {
+ external_ids: Some(HashMap::new()),
+ other_config: Some(HashMap::new()),
+ prop_list: Vec::new(),
+ })?
+ } else {
+ serde_json::to_value(current)?
+ };
if let Some((reference, desire, current)) = get_json_value_difference(
"ovsdb".to_string(),
diff --git a/rust/src/lib/unit_tests/ovsdb.rs b/rust/src/lib/unit_tests/ovsdb.rs
index 1c9618a2..698f1a65 100644
--- a/rust/src/lib/unit_tests/ovsdb.rs
+++ b/rust/src/lib/unit_tests/ovsdb.rs
@@ -156,3 +156,14 @@ other_config: {}
expect.other_config.as_ref().unwrap()
);
}
+
+#[test]
+fn test_ovsdb_verify_null_current() {
+ let desired: OvsDbGlobalConfig = serde_yaml::from_str("{}").unwrap();
+ let pre_apply_current = desired.clone();
+ let current = desired.clone();
+
+ let merged_ovsdb = MergedOvsDbGlobalConfig::new(desired, pre_apply_current);
+
+ merged_ovsdb.verify(&current).unwrap();
+}
--
2.39.0

View File

@ -4,7 +4,7 @@
Name: nmstate Name: nmstate
Version: 2.2.3 Version: 2.2.3
Release: 2%{?dist} Release: 3%{?dist}
Summary: Declarative network manager API Summary: Declarative network manager API
License: LGPLv2+ License: LGPLv2+
URL: https://github.com/%{srcname}/%{srcname} URL: https://github.com/%{srcname}/%{srcname}
@ -12,6 +12,7 @@ Source0: https://github.com/nmstate/nmstate/releases/download/v%{version}
Source1: https://github.com/nmstate/nmstate/releases/download/v%{version}/nmstate-%{version}.tar.gz.asc Source1: https://github.com/nmstate/nmstate/releases/download/v%{version}/nmstate-%{version}.tar.gz.asc
Source2: https://nmstate.io/nmstate.gpg Source2: https://nmstate.io/nmstate.gpg
Source3: https://github.com/nmstate/nmstate/releases/download/v%{version}/nmstate-vendor-%{version}.tar.xz Source3: https://github.com/nmstate/nmstate/releases/download/v%{version}/nmstate-vendor-%{version}.tar.xz
Patch1: BZ_2159679-ovsdb-Fix-verification-error-when-ovs-daemon-off.patch
BuildRequires: python3-devel BuildRequires: python3-devel
BuildRequires: python3-setuptools BuildRequires: python3-setuptools
BuildRequires: gnupg2 BuildRequires: gnupg2
@ -150,6 +151,9 @@ popd
/sbin/ldconfig /sbin/ldconfig
%changelog %changelog
* Wed Jan 11 2023 Gris Ge <fge@redhat.com> - 2.2.3-3
- Fix OVSDB verification error
* Tue Jan 10 2023 Gris Ge <fge@redhat.com> - 2.2.3-2 * Tue Jan 10 2023 Gris Ge <fge@redhat.com> - 2.2.3-2
- Enable error message for rpm CI gating - Enable error message for rpm CI gating

View File

@ -4,4 +4,6 @@ TMP_FILE=$(mktemp /tmp/nmstate.XXXXXX.yaml)
nmstatectl show > $TMP_FILE nmstatectl show > $TMP_FILE
nmstatectl set $TMP_FILE cat $TMP_FILE
nmstatectl set $TMP_FILE -vvv