rust ovs: Raise DependencyError is NM-ovs plugin not installed

Also fix the systemd `start-limit-hit` when we restart too often during
test. Sleep 2 seconds after daemon restarted.

Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
Gris Ge 2022-04-10 15:58:07 +08:00
parent 14ebc5340d
commit 5a66ed7b06
5 changed files with 42 additions and 12 deletions

View File

@ -8,6 +8,7 @@ pub enum ErrorKind {
NotImplementedError,
NotSupportedError,
KernelIntegerRoundedError,
DependencyError,
}
impl std::fmt::Display for ErrorKind {

View File

@ -3,11 +3,23 @@ use nm_dbus::NmError;
use crate::{ErrorKind, NmstateError};
pub(crate) fn nm_error_to_nmstate(nm_error: NmError) -> NmstateError {
NmstateError::new(
ErrorKind::Bug,
format!(
"{}: {} dbus: {:?}",
nm_error.kind, nm_error.msg, nm_error.dbus_error
),
)
if nm_error
.to_string()
.contains("NetworkManager plugin for 'ovs-bridge' unavailable")
{
NmstateError::new(
ErrorKind::DependencyError,
"NetworkManager does not have OVS plugin installed for \
OVS modification"
.to_string(),
)
} else {
NmstateError::new(
ErrorKind::Bug,
format!(
"{}: {} dbus: {:?}",
nm_error.kind, nm_error.msg, nm_error.dbus_error
),
)
}
}

View File

@ -340,6 +340,10 @@ where
if cur_count == count - 1 {
return Err(e);
} else {
if let Some(zbus::Error::MethodError(..)) = e.dbus_error {
log::error!("{}", e);
return Err(e);
}
log::info!("Retrying on NM dbus failure: {}", e);
std::thread::sleep(std::time::Duration::from_millis(
interval_ms,

View File

@ -16,14 +16,15 @@ from ctypes import c_int, c_char_p, c_uint32, POINTER, byref, cdll
import json
from .error import (
NmstateDependencyError,
NmstateError,
NmstateVerificationError,
NmstateValueError,
NmstateInternalError,
NmstatePluginError,
NmstateNotImplementedError,
NmstateKernelIntegerRoundedError,
NmstateNotImplementedError,
NmstateNotSupportedError,
NmstatePluginError,
NmstateValueError,
NmstateVerificationError,
)
lib = cdll.LoadLibrary("libnmstate.so.2")
@ -216,6 +217,8 @@ def map_error(err_kind, err_msg):
elif err_kind == "KernelIntegerRoundedError":
return NmstateKernelIntegerRoundedError(err_msg)
elif err_kind == "NotSupportedError":
return NmstateNotSupportedError(err_msg);
return NmstateNotSupportedError(err_msg)
elif err_kind == "DependencyError":
return NmstateDependencyError(err_msg)
else:
return NmstateError(f"{err_kind}: {err_msg}")

View File

@ -19,6 +19,7 @@
from contextlib import contextmanager
from subprocess import CalledProcessError
from time import sleep
from . import cmdlib
@ -55,9 +56,18 @@ def mount_devnull_to_path(lib_path):
@contextmanager
def nm_service_restart():
# If we restart too often, systemd will not start NetworkManager due to
# 'start-limit-hit'. Resetting failure count will helps here.
cmdlib.exec_cmd(
"systemctl reset-failed NetworkManager.service".split(), check=False
)
systemctl_restart_nm_cmd = ("systemctl", "restart", "NetworkManager")
cmdlib.exec_cmd(systemctl_restart_nm_cmd, check=True)
# Wait 2 seconds for NetworkManager to start.
sleep(2)
try:
yield
finally:
cmdlib.exec_cmd(systemctl_restart_nm_cmd, check=True)
# Wait 2 seconds for NetworkManager to start.
sleep(2)