Skip to content

Commit

Permalink
tests: skip some cases if OVS is not installed
Browse files Browse the repository at this point in the history
Some unit-tests might fail when the /usr/bin/ovs-vsctl binary from the
openvswitch-switch is not installed at build time. This can happen primarily
on 32bit architectures where newer versions of OVS are not built anymore.
OVS is not a hard dependency, though. So we can skip/ignore those cases.
  • Loading branch information
slyon committed Jan 16, 2024
1 parent b44de52 commit 89ba9f2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tests/cli/test_get_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import yaml

from netplan_cli.cli.commands.set import FALLBACK_FILENAME
from netplan_cli.cli.ovs import OPENVSWITCH_OVS_VSCTL

from netplan import NetplanException
from tests.test_utils import call_cli

Expand Down Expand Up @@ -517,6 +519,8 @@ def test_set_delete_bridge_subparams(self):
self.assertNotIn('eno2', out['network']['bridges']['br0']['parameters']['port-priority'])
self.assertEqual(14, out['network']['bridges']['br0']['parameters']['port-priority']['eno1'])

@unittest.skipIf(not os.path.exists(OPENVSWITCH_OVS_VSCTL),
'OpenVSwitch not installed')
def test_set_delete_ovs_other_config(self):
with open(self.path, 'w') as f:
f.write('''network:
Expand Down
4 changes: 2 additions & 2 deletions tests/ctests/test_netplan_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test_netplan_parser_new_parser(__unused void** state)
void
test_netplan_parser_load_yaml(__unused void** state)
{
const char* filename = FIXTURESDIR "/ovs.yaml";
const char* filename = FIXTURESDIR "/bridge.yaml";
GError *error = NULL;
NetplanParser* npp = netplan_parser_new();

Expand All @@ -45,7 +45,7 @@ test_netplan_parser_load_yaml(__unused void** state)
void
test_netplan_parser_load_yaml_from_fd(__unused void** state)
{
const char* filename = FIXTURESDIR "/ovs.yaml";
const char* filename = FIXTURESDIR "/bridge.yaml";
FILE* f = fopen(filename, "r");
GError *error = NULL;

Expand Down
6 changes: 6 additions & 0 deletions tests/generator/test_ovs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import unittest

from netplan_cli.cli.ovs import OPENVSWITCH_OVS_VSCTL
from .base import TestBase, ND_EMPTY, ND_WITHIP, ND_DHCP4, ND_DHCP6, \
OVS_PHYSICAL, OVS_VIRTUAL, \
OVS_BR_EMPTY, OVS_BR_DEFAULT, \
OVS_CLEANUP


@unittest.skipIf(not os.path.exists(OPENVSWITCH_OVS_VSCTL),
'OpenVSwitch not installed')
class TestOpenVSwitch(TestBase):
'''OVS output'''

Expand Down
3 changes: 3 additions & 0 deletions tests/test_configmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import unittest

from netplan_cli.configmanager import ConfigManager, ConfigurationError
from netplan_cli.cli.ovs import OPENVSWITCH_OVS_VSCTL


class TestConfigManager(unittest.TestCase):
Expand Down Expand Up @@ -229,6 +230,8 @@ def test_parse_merging(self):
self.assertIn('eth0', state.ethernets)
self.assertIn('eth42', state.ethernets)

@unittest.skipIf(not os.path.exists(OPENVSWITCH_OVS_VSCTL),
'OpenVSwitch not installed')
def test_parse_merging_ovs(self):
state = self.configmanager.parse(extra_config=[os.path.join(self.workdir.name, "ovs_merging.yaml")])
self.assertIn('eth0', state.ethernets)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_libnetplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import os
import shutil
import tempfile
import unittest
import io
import yaml

Expand All @@ -30,6 +31,7 @@

from utils import state_from_yaml
from netplan_cli.cli.commands.set import FALLBACK_FILENAME
from netplan_cli.cli.ovs import OPENVSWITCH_OVS_VSCTL

import netplan
from netplan.netdef import NetplanRoute
Expand Down Expand Up @@ -615,6 +617,8 @@ def test_filepath(self):
netdef = state['eth0']
self.assertEqual(os.path.join(self.confdir, "a.yaml"), netdef.filepath)

@unittest.skipIf(not os.path.exists(OPENVSWITCH_OVS_VSCTL),
'OpenVSwitch not installed')
def test_filepath_for_ovs_ports(self):
state = state_from_yaml(self.confdir, '''network:
version: 2
Expand All @@ -634,6 +638,8 @@ def test_filepath_for_ovs_ports(self):
self.assertEqual(os.path.join(self.confdir, "a.yaml"), netdef_port1.filepath)
self.assertEqual(os.path.join(self.confdir, "a.yaml"), netdef_port2.filepath)

@unittest.skipIf(not os.path.exists(OPENVSWITCH_OVS_VSCTL),
'OpenVSwitch not installed')
def test_filepath_for_ovs_ports_when_conf_is_redefined(self):
state = netplan.State()
parser = netplan.Parser()
Expand Down Expand Up @@ -793,6 +799,8 @@ def test_interface_pointer_to_bond_is_none(self):

self.assertIsNone(state['eth0'].links.get('bond'))

@unittest.skipIf(not os.path.exists(OPENVSWITCH_OVS_VSCTL),
'OpenVSwitch not installed')
def test_interface_has_pointer_to_peer(self):
state = state_from_yaml(self.confdir, '''network:
openvswitch:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_ovs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import unittest

from unittest.mock import patch, call
Expand All @@ -26,6 +27,8 @@
import tempfile


@unittest.skipIf(not os.path.exists(OVS),
'OpenVSwitch not installed')
class TestOVS(unittest.TestCase):

@patch('subprocess.check_call')
Expand Down

0 comments on commit 89ba9f2

Please sign in to comment.