ovs: Fix genconf mode for OVS external_ids
Add support of ovs external ids for genconf mode. Integration test case included. Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
parent
dee647ee1b
commit
8e723a15d2
@ -275,6 +275,9 @@ impl NmConnection {
|
||||
if let Some(ib) = &self.infiniband {
|
||||
sections.push(("infiniband", ib.to_keyfile()?));
|
||||
}
|
||||
if let Some(ovs_eids) = &self.ovs_ext_ids {
|
||||
sections.push(("ovs-external-ids", ovs_eids.to_keyfile()?));
|
||||
}
|
||||
|
||||
keyfile_sections_to_string(§ions)
|
||||
}
|
||||
|
@ -237,6 +237,18 @@ impl NmSettingOvsExtIds {
|
||||
}));
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
pub(crate) fn to_keyfile(
|
||||
&self,
|
||||
) -> Result<HashMap<String, zvariant::Value>, NmError> {
|
||||
let mut ret = HashMap::new();
|
||||
if let Some(data) = self.data.as_ref() {
|
||||
for (k, v) in data {
|
||||
ret.insert(format!("data.{}", k), zvariant::Value::new(v));
|
||||
}
|
||||
}
|
||||
Ok(ret)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default, Deserialize)]
|
||||
|
@ -48,6 +48,7 @@ from .testlib import iprule
|
||||
from .testlib import statelib
|
||||
from .testlib.bondlib import bond_interface
|
||||
from .testlib.env import nm_major_minor_version
|
||||
from .testlib.genconf import gen_conf_apply
|
||||
from .testlib.nmplugin import disable_nm_plugin
|
||||
from .testlib.ovslib import Bridge
|
||||
from .testlib.statelib import state_match
|
||||
@ -1249,3 +1250,43 @@ def test_move_ovs_system_interface_to_bond(bridge_with_ports):
|
||||
}
|
||||
)
|
||||
libnmstate.apply(desired_state)
|
||||
|
||||
|
||||
def test_genconf_ovsdb_iface_external_ids(eth1_up):
|
||||
desired_state = {
|
||||
Interface.KEY: [
|
||||
{
|
||||
Interface.NAME: BRIDGE1,
|
||||
Interface.TYPE: InterfaceType.OVS_BRIDGE,
|
||||
OVSBridge.CONFIG_SUBTREE: {
|
||||
OVSBridge.PORT_SUBTREE: [
|
||||
{
|
||||
OVSBridge.Port.NAME: PORT1,
|
||||
},
|
||||
{
|
||||
OVSBridge.Port.NAME: "eth1",
|
||||
},
|
||||
]
|
||||
},
|
||||
OvsDB.OVS_DB_SUBTREE: {
|
||||
OvsDB.EXTERNAL_IDS: {"foo": "abe", "bak": 3}
|
||||
},
|
||||
},
|
||||
{
|
||||
Interface.NAME: "eth1",
|
||||
Interface.TYPE: InterfaceType.ETHERNET,
|
||||
OvsDB.OVS_DB_SUBTREE: {
|
||||
OvsDB.EXTERNAL_IDS: {"foo": "abd", "bak": 2}
|
||||
},
|
||||
},
|
||||
{
|
||||
Interface.NAME: PORT1,
|
||||
Interface.TYPE: InterfaceType.OVS_INTERFACE,
|
||||
OvsDB.OVS_DB_SUBTREE: {
|
||||
OvsDB.EXTERNAL_IDS: {"foo": "abc", "bak": 1}
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
with gen_conf_apply(desired_state):
|
||||
assertlib.assert_state_match(desired_state)
|
||||
|
57
tests/integration/testlib/genconf.py
Normal file
57
tests/integration/testlib/genconf.py
Normal file
@ -0,0 +1,57 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
|
||||
import libnmstate
|
||||
from libnmstate.schema import Interface
|
||||
from libnmstate.schema import InterfaceState
|
||||
|
||||
from .cmdlib import exec_cmd
|
||||
|
||||
NM_CONN_FOLDER = "/etc/NetworkManager/system-connections"
|
||||
|
||||
|
||||
@contextmanager
|
||||
def gen_conf_apply(desire_state):
|
||||
iface_names = [
|
||||
iface[Interface.NAME] for iface in desire_state.get(Interface.KEY, [])
|
||||
]
|
||||
file_paths = []
|
||||
try:
|
||||
conns = libnmstate.generate_configurations(desire_state).get(
|
||||
"NetworkManager", []
|
||||
)
|
||||
for conn in conns:
|
||||
file_paths.append(save_nmconnection(conn[0], conn[1]))
|
||||
reload_nm_connection()
|
||||
yield
|
||||
finally:
|
||||
absent_state = {Interface.KEY: []}
|
||||
for iface_name in iface_names:
|
||||
absent_state[Interface.KEY].append(
|
||||
{
|
||||
Interface.NAME: iface_name,
|
||||
Interface.STATE: InterfaceState.ABSENT,
|
||||
}
|
||||
)
|
||||
libnmstate.apply(absent_state, verify_change=False)
|
||||
for file_path in file_paths:
|
||||
try:
|
||||
os.unlink(file_path)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def save_nmconnection(file_name, content):
|
||||
file_path = f"{NM_CONN_FOLDER}/{file_name}"
|
||||
with open(file_path, "w") as fd:
|
||||
fd.write(content)
|
||||
|
||||
os.chmod(file_path, 0o600)
|
||||
os.chown(file_path, 0, 0)
|
||||
return file_path
|
||||
|
||||
|
||||
def reload_nm_connection():
|
||||
exec_cmd("nmcli c reload".split(), check=True)
|
Loading…
x
Reference in New Issue
Block a user