test ovs: Fix test_ovs_remove_port

The test is checking whether NM connection proxy port profile got
deleted along OVS interface. The code checking `ovs-vsctl` does not
reflect that as `ovs-vsctl` does not keep empty OVS port.

Changing to use `nmcli` to check the OVS proxy port profile.

Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
Gris Ge 2020-03-30 21:31:24 +08:00 committed by Edward Haas
parent b4bc868fbe
commit 6ab66726dc
2 changed files with 39 additions and 15 deletions

View File

@ -17,6 +17,8 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
from subprocess import CalledProcessError
import pytest
import libnmstate
@ -29,11 +31,13 @@ from libnmstate.error import NmstateDependencyError
from libnmstate.error import NmstateValueError
from .testlib import assertlib
from .testlib import cmdlib
from .testlib import statelib
from .testlib.nmplugin import disable_nm_plugin
from .testlib.ovslib import Bridge
from .testlib.ovslib import get_proxy_port_name_of_ovs_interface
from .testlib.servicelib import disable_service
from .testlib.ovslib import get_proxy_port_profile_name_of_ovs_interface
from .testlib.ovslib import get_nm_active_profiles
from .testlib.vlan import vlan_interface
@ -205,7 +209,13 @@ def test_ovs_service_missing():
@pytest.mark.tier1
def test_ovs_remove_port(bridge_with_ports):
for port_name in bridge_with_ports.ports_names:
assert get_proxy_port_name_of_ovs_interface(port_name)
active_profiles = get_nm_active_profiles()
assert port_name in active_profiles
proxy_port_profile = get_proxy_port_profile_name_of_ovs_interface(
port_name
)
assert proxy_port_profile
assert proxy_port_profile in active_profiles
libnmstate.apply(
{
Interface.KEY: [
@ -216,7 +226,12 @@ def test_ovs_remove_port(bridge_with_ports):
]
}
)
assert not get_proxy_port_name_of_ovs_interface(port_name)
with pytest.raises(CalledProcessError):
cmdlib.exec_cmd(
f"nmcli connection show {proxy_port_profile}".split(" "),
check=True,
)
@pytest.fixture

View File

@ -135,16 +135,25 @@ def _set_ifaces_state(ifaces, state):
return ifaces
def get_proxy_port_name_of_ovs_interface(iface_name):
output = cmdlib.exec_cmd("ovs-vsctl show".split(" "), check=True)[1]
port_name = None
port_line_re = re.compile(r'^\s+Port\s"(.+)"$')
iface_line_re = re.compile(rf'^\s+Interface\s"{iface_name}"$')
for line in output.split("\n"):
match = port_line_re.match(line)
def get_nm_active_profiles():
all_profiles_output = cmdlib.exec_cmd(
"nmcli -g NAME connection show --active".split(" "), check=True
)[1]
return all_profiles_output.split("\n")
def get_proxy_port_profile_name_of_ovs_interface(iface_name):
proxy_port_iface_name = cmdlib.exec_cmd(
f"nmcli -g connection.master connection show {iface_name}".split(" "),
check=True,
)[1].strip()
all_profiles_output = cmdlib.exec_cmd(
"nmcli -g NAME,DEVICE connection show".split(" "), check=True
)[1]
proxy_port_re = re.compile(
f"^(?P<profile_name>.+):{proxy_port_iface_name}$"
)
for line in all_profiles_output.split("\n"):
match = proxy_port_re.match(line)
if match:
port_name = match.groups()[0]
continue
if iface_line_re.match(line):
return port_name
return None
return match.group("profile_name")