tests, integ: fix missing plugin tests
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
This commit is contained in:
parent
3a6d116a5e
commit
026ed90713
@ -25,7 +25,6 @@ import pytest
|
||||
|
||||
import libnmstate
|
||||
|
||||
from .testlib import cmdlib
|
||||
from .testlib import ifacelib
|
||||
|
||||
|
||||
@ -99,17 +98,3 @@ def _get_osname():
|
||||
if line.startswith("PRETTY_NAME="):
|
||||
return line.split("=", maxsplit=1)[1].strip().strip('"')
|
||||
return ""
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def download_packages():
|
||||
cmdlib.exec_cmd(
|
||||
(
|
||||
"dnf",
|
||||
"install",
|
||||
"-y",
|
||||
"--downloadonly",
|
||||
"NetworkManager-ovs",
|
||||
"NetworkManager-team",
|
||||
)
|
||||
)
|
||||
|
@ -17,8 +17,6 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
import pytest
|
||||
|
||||
import libnmstate
|
||||
@ -30,8 +28,8 @@ from libnmstate.schema import OVSBridge
|
||||
from libnmstate.error import NmstateLibnmError
|
||||
|
||||
from .testlib import assertlib
|
||||
from .testlib import cmdlib
|
||||
from .testlib import nmlib
|
||||
from .testlib.nmplugin import disable_nm_plugin
|
||||
from .testlib.ovslib import Bridge
|
||||
from .testlib.vlan import vlan_interface
|
||||
|
||||
@ -40,20 +38,6 @@ BRIDGE1 = "br1"
|
||||
PORT1 = "ovs1"
|
||||
VLAN_IFNAME = "eth101"
|
||||
|
||||
DNF_REMOVE_NM_OVS_CMD = (
|
||||
"rpm",
|
||||
"-e",
|
||||
"NetworkManager-ovs",
|
||||
)
|
||||
DNF_INSTALL_NM_OVS_CMD = (
|
||||
"dnf",
|
||||
"install",
|
||||
"-y",
|
||||
"--cacheonly",
|
||||
"NetworkManager-ovs",
|
||||
)
|
||||
SYSTEMCTL_RESTART_NM_CMD = ("systemctl", "restart", "NetworkManager")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def bridge_with_ports(port0_up):
|
||||
@ -163,11 +147,8 @@ def test_ovs_interface_with_max_length_name():
|
||||
assertlib.assert_absent(ovs_interface_name)
|
||||
|
||||
|
||||
@pytest.mark.xfail(
|
||||
reason="https://github.com/nmstate/nmstate/issues/759", run=False
|
||||
)
|
||||
def test_nm_ovs_plugin_missing():
|
||||
with disable_nm_ovs_plugin():
|
||||
with disable_nm_plugin("ovs"):
|
||||
with pytest.raises(NmstateLibnmError):
|
||||
libnmstate.apply(
|
||||
{
|
||||
@ -202,17 +183,6 @@ def test_ovs_remove_port(bridge_with_ports):
|
||||
assert not nmlib.list_profiles_by_iface_name(nm_port_profile_name)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def disable_nm_ovs_plugin():
|
||||
cmdlib.exec_cmd(DNF_REMOVE_NM_OVS_CMD)
|
||||
cmdlib.exec_cmd(SYSTEMCTL_RESTART_NM_CMD)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
cmdlib.exec_cmd(DNF_INSTALL_NM_OVS_CMD)
|
||||
cmdlib.exec_cmd(SYSTEMCTL_RESTART_NM_CMD)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vlan_on_eth1(eth1_up):
|
||||
with vlan_interface(
|
||||
|
@ -30,25 +30,9 @@ from libnmstate.schema import InterfaceType
|
||||
from libnmstate.schema import Team
|
||||
|
||||
from .testlib import assertlib
|
||||
from .testlib import cmdlib
|
||||
from .testlib.nmplugin import disable_nm_plugin
|
||||
|
||||
|
||||
DNF_INSTALL_NM_TEAM_PLUGIN_CMD = (
|
||||
"dnf",
|
||||
"install",
|
||||
"-y",
|
||||
"--cacheonly",
|
||||
"NetworkManager-team",
|
||||
)
|
||||
|
||||
DNF_REMOVE_NM_TEAM_PLUGIN_CMD = (
|
||||
"rpm",
|
||||
"-e",
|
||||
"NetworkManager-team",
|
||||
)
|
||||
|
||||
SYSTEMCTL_RESTART_NM_CMD = ("systemctl", "restart", "NetworkManager")
|
||||
|
||||
TEAM0 = "team0"
|
||||
|
||||
|
||||
@ -78,7 +62,7 @@ def test_edit_team_iface():
|
||||
|
||||
|
||||
def test_nm_team_plugin_missing():
|
||||
with disable_nm_team_plugin():
|
||||
with disable_nm_plugin("team"):
|
||||
with pytest.raises(NmstateLibnmError):
|
||||
libnmstate.apply(
|
||||
{
|
||||
@ -118,14 +102,3 @@ def team_interface(ifname):
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def disable_nm_team_plugin():
|
||||
cmdlib.exec_cmd(DNF_REMOVE_NM_TEAM_PLUGIN_CMD)
|
||||
cmdlib.exec_cmd(SYSTEMCTL_RESTART_NM_CMD)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
cmdlib.exec_cmd(DNF_INSTALL_NM_TEAM_PLUGIN_CMD)
|
||||
cmdlib.exec_cmd(SYSTEMCTL_RESTART_NM_CMD)
|
||||
|
61
tests/integration/testlib/nmplugin.py
Normal file
61
tests/integration/testlib/nmplugin.py
Normal file
@ -0,0 +1,61 @@
|
||||
#
|
||||
# Copyright (c) 2020 Red Hat, Inc.
|
||||
#
|
||||
# This file is part of nmstate
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from contextlib import contextmanager
|
||||
from subprocess import CalledProcessError
|
||||
|
||||
from . import cmdlib
|
||||
|
||||
|
||||
@contextmanager
|
||||
def disable_nm_plugin(plugin):
|
||||
try:
|
||||
_, rpm_output, _ = cmdlib.exec_cmd(
|
||||
("rpm", "-ql", f"NetworkManager-{plugin}"), check=True
|
||||
)
|
||||
except CalledProcessError:
|
||||
yield
|
||||
else:
|
||||
lib_path = [l for l in rpm_output.split() if l.endswith(".so")][0]
|
||||
with mount_devnull_to_path(lib_path):
|
||||
yield
|
||||
|
||||
|
||||
@contextmanager
|
||||
def mount_devnull_to_path(lib_path):
|
||||
try:
|
||||
cmdlib.exec_cmd(("mount", "--bind", "/dev/null", lib_path), check=True)
|
||||
with nm_service_restart():
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
cmdlib.exec_cmd(("umount", lib_path), check=True)
|
||||
except CalledProcessError:
|
||||
cmdlib.exec_cmd(("umount", lib_path), check=True)
|
||||
raise
|
||||
|
||||
|
||||
@contextmanager
|
||||
def nm_service_restart():
|
||||
systemctl_restart_nm_cmd = ("systemctl", "restart", "NetworkManager")
|
||||
cmdlib.exec_cmd(systemctl_restart_nm_cmd, check=True)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
cmdlib.exec_cmd(systemctl_restart_nm_cmd, check=True)
|
Loading…
x
Reference in New Issue
Block a user