nmstate/BZ_2159679-ovsdb-Fix-verifi...

73 lines
2.3 KiB
Diff

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