tests, ovs: check ovs duplicate names with ipv4 dns is supported

Ref: https://bugzilla.redhat.com/1939557

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
This commit is contained in:
Fernando Fernandez Mancera 2021-03-31 12:00:34 +02:00 committed by Fernando Fernández Mancera
parent 21faecd721
commit c5aee5f73f
3 changed files with 148 additions and 1 deletions

View File

@ -197,6 +197,10 @@ def _get_interface_info_from_plugins(plugins, info_type):
iface_type = InterfaceType.ETHERNET
iface_index = f"{iface_type}.{iface_name}"
if iface_index in all_ifaces:
logging.debug(
f"Interface {iface_index} found. Merging the interface "
"information."
)
existing_iface = all_ifaces[iface_index]
existing_priority = existing_iface[IFACE_PRIORITY_METADATA]
current_priority = plugin.priority

View File

@ -18,6 +18,7 @@
#
from collections import defaultdict
import logging
from libnmstate.error import NmstateValueError
from libnmstate.error import NmstateVerificationError
@ -194,6 +195,11 @@ class RouteState:
self._cur_routes[rt.next_hop_interface].add(rt)
if not ifaces or rt.is_valid(ifaces):
self._routes[rt.next_hop_interface].add(rt)
else:
logging.debug(
f"The current route {entry} has been discarded due"
f" to {rt.invalid_reason}"
)
if des_route_state:
self._merge_routes(des_route_state, ifaces)

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2019-2020 Red Hat, Inc.
# Copyright (c) 2019-2021 Red Hat, Inc.
#
# This file is part of nmstate
#
@ -33,6 +33,7 @@ from ..testlib import statelib
from ..testlib.env import nm_major_minor_version
from ..testlib.ovslib import Bridge
from ..testlib.plugin import tmp_plugin_dir
from ..testlib.retry import retry_till_true_or_timeout
BRIDGE0 = "brtest0"
@ -41,6 +42,9 @@ OVSDB_EXT_IDS_CONF1 = {"foo": "abc", "bak": 1}
OVSDB_EXT_IDS_CONF1_STR = {"foo": "abc", "bak": "1"}
OVSDB_EXT_IDS_CONF2 = {"bak": 2}
OVSDB_EXT_IDS_CONF2_STR = {"bak": "2"}
OVS_DUP_NAME = "br-ex"
ETH1 = "eth1"
VERIFY_RETRY_TMO = 5
@pytest.fixture
@ -260,3 +264,136 @@ class TestNmOvsExternalIds:
assert not new_state[Interface.KEY][1][OvsDB.OVS_DB_SUBTREE][
OvsDB.EXTERNAL_IDS
]
def _nmcli_ovs_bridge_with_ipv4_dns():
nmcli_ovs_interface = (
"nmcli",
"connection",
"add",
"type",
"ovs-interface",
"slave-type",
"ovs-port",
"conn.interface",
"br-ex",
"master",
"ovs-port-br-ex",
"con-name",
"ovs-if-br-ex",
"ipv4.method",
"manual",
"ipv4.addr",
"192.0.2.2/24",
"ipv4.dns",
"192.0.2.1",
"ipv4.routes",
"0.0.0.0/0 192.0.2.1",
)
cmdlib.exec_cmd(nmcli_ovs_interface, check=True)
def _verify_ovs_activated(ovs_name):
ret, out, err = cmdlib.exec_cmd(
f"nmcli --field GENERAL.STATE device show {ovs_name}".split(),
check=True,
)
connected = "connected" in out
ret, out, err = cmdlib.exec_cmd(
f"nmcli --field IP4.ADDRESS device show {ovs_name}".split(),
check=True,
)
ipv4_configured = "192.0.2.2/24" in out
ret, out, err = cmdlib.exec_cmd(
f"nmcli --field IP4.ROUTE device show {ovs_name}".split(),
check=True,
)
route_configured = "0.0.0.0/0" in out
return connected and ipv4_configured and route_configured
@pytest.fixture
def ovs_bridge_first_and_ovs_interface_with_same_name_ipv4():
# The order on this function is important. The OVS bridge must be defined
# before the OVS interface.
cmdlib.exec_cmd(
"nmcli connection add type ovs-port conn.interface br-ex master br-ex "
"con-name ovs-port-br-ex".split(),
check=True,
)
cmdlib.exec_cmd(
"nmcli connection add type ovs-bridge con-name br-ex conn.interface "
"br-ex".split(),
check=True,
)
_nmcli_ovs_bridge_with_ipv4_dns()
# Wait a little bit for NM to activate above interfaces to do not hit race
# problems.
assert retry_till_true_or_timeout(
VERIFY_RETRY_TMO, _verify_ovs_activated, OVS_DUP_NAME
)
yield
cmdlib.exec_cmd(
"nmcli connection del ovs-port-br-ex br-ex ovs-if-br-ex".split(),
check=True,
)
@pytest.fixture
def ovs_interface_first_and_ovs_bridge_with_same_name_ipv4():
# The order on this function is important. The OVS interface must be
# defined before the OVS bridge.
cmdlib.exec_cmd(
"nmcli connection add type ovs-port conn.interface br-ex master br-ex "
"con-name ovs-port-br-ex".split(),
check=True,
)
_nmcli_ovs_bridge_with_ipv4_dns()
cmdlib.exec_cmd(
"nmcli connection add type ovs-bridge con-name br-ex conn.interface "
"br-ex".split(),
check=True,
)
# Wait a little bit for NM to activate above interfaces to do not hit race
# problems.
assert retry_till_true_or_timeout(
VERIFY_RETRY_TMO, _verify_ovs_activated, OVS_DUP_NAME
)
yield
cmdlib.exec_cmd(
"nmcli connection del ovs-port-br-ex br-ex ovs-if-br-ex".split(),
check=True,
)
@pytest.mark.tier1
def test_modify_state_with_ovs_dup_name_ovs_bridge_first_with_ipv4_dns(
ovs_bridge_first_and_ovs_interface_with_same_name_ipv4,
):
desired_state = {
Interface.KEY: [
{
Interface.NAME: ETH1,
Interface.TYPE: InterfaceType.ETHERNET,
Interface.STATE: InterfaceState.UP,
}
]
}
libnmstate.apply(desired_state)
@pytest.mark.tier1
def test_modify_state_with_ovs_dup_name_ovs_interface_first_with_ipv4_dns(
ovs_interface_first_and_ovs_bridge_with_same_name_ipv4,
):
desired_state = {
Interface.KEY: [
{
Interface.NAME: ETH1,
Interface.TYPE: InterfaceType.ETHERNET,
Interface.STATE: InterfaceState.UP,
}
]
}
libnmstate.apply(desired_state)
assertlib.assert_state(desired_state)