Petr Horáček has uploaded a new change for review. Change subject: net: native ovs: OvsCaseBase ......................................................................
net: native ovs: OvsCaseBase Introduce parent test class which handles openvswitch service and cleanup of test bridges. This will be used by ovs switch tests. Change-Id: I11a4d6f06f10b6fe18f304556a1123bc3d761836 Bug-Url: https://bugzilla.redhat.com/1195208 Signed-off-by: Petr Horáček <phora...@redhat.com> --- M tests/network/nettestlib.py M tests/network/ovs_driver_test.py 2 files changed, 42 insertions(+), 39 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/91/56391/1 diff --git a/tests/network/nettestlib.py b/tests/network/nettestlib.py index 2839dfe..0398ef0 100644 --- a/tests/network/nettestlib.py +++ b/tests/network/nettestlib.py @@ -36,8 +36,11 @@ from vdsm.ipwrapper import (addrAdd, linkSet, linkAdd, linkDel, IPRoute2Error, netns_add, netns_delete, netns_exec) from vdsm.netlink import monitor +from vdsm.network.ovs.driver import create from vdsm.commands import execCmd from vdsm.utils import CommandPath, random_iface_name + +from testlib import VdsmTestCase from . import dhcp from . import firewall @@ -438,3 +441,32 @@ 'given timeout.\n') else: raise + + +class OvsTestCase(VdsmTestCase): + TEST_BRIDGE = 'ovs-test-br0' + TEST_BRIDGES = (TEST_BRIDGE, 'ovs-test-br1') + + OVS_CTL = '/usr/share/openvswitch/scripts/ovs-ctl' + + _openvswitch_init_state_is_up = False + + @classmethod + def setup_class(cls): + rc, out, err = execCmd([cls.OVS_CTL, 'status']) + cls._openvswitch_init_state_is_up = (rc == 0) + if not cls._openvswitch_init_state_is_up: + execCmd([cls.OVS_CTL, 'start']) + + @classmethod + def teardown_class(cls): + ovsdb = create() + bridges = ovsdb.list_bridge_info().execute() + + with ovsdb.transaction() as t: + for bridge in bridges: + if bridge in cls.TEST_BRIDGES: + t.add(ovsdb.del_br(bridge['name'])) + + if not cls._openvswitch_init_state_is_up: + execCmd([cls.OVS_CTL, 'stop']) diff --git a/tests/network/ovs_driver_test.py b/tests/network/ovs_driver_test.py index 1aef998..164eb37 100644 --- a/tests/network/ovs_driver_test.py +++ b/tests/network/ovs_driver_test.py @@ -20,42 +20,13 @@ from nose.plugins.attrib import attr -from testlib import VdsmTestCase +from network.nettestlib import OvsTestCase -from vdsm.commands import execCmd from vdsm.network.ovs.driver import create - -TEST_BRIDGE = 'ovs-test-br0' -TEST_BRIDGES = (TEST_BRIDGE, 'ovs-test-br1') - -OVS_CTL = '/usr/share/openvswitch/scripts/ovs-ctl' - -_openvswitch_init_state_is_up = False - - -def setup_module(): - global _openvswitch_init_state_is_up - rc, out, err = execCmd([OVS_CTL, 'status']) - _openvswitch_init_state_is_up = (rc == 0) - if not _openvswitch_init_state_is_up: - execCmd([OVS_CTL, 'start']) - - -def teardown_module(): - ovsdb = create() - bridges = ovsdb.list_bridge_info().execute() - - with ovsdb.transaction() as t: - for bridge in bridges: - if bridge in TEST_BRIDGES: - t.add(ovsdb.del_br(bridge['name'])) - - if not _openvswitch_init_state_is_up: - execCmd([OVS_CTL, 'stop']) @attr(type='integration') -class TestOvsApiBase(VdsmTestCase): +class TestOvsApiBase(OvsTestCase): def test_instantiate_vsctl_implementation(self): self.assertIsNotNone(create('vsctl')) @@ -69,7 +40,7 @@ def test_execute_a_transaction(self): ovsdb = create() - cmd_add_br = ovsdb.add_br(TEST_BRIDGE) + cmd_add_br = ovsdb.add_br(self.TEST_BRIDGE) cmd_list_bridge_info = ovsdb.list_bridge_info() t = ovsdb.transaction() t.add(cmd_add_br) @@ -78,9 +49,9 @@ self.assertEqual(1, len(cmd_list_bridge_info.result)) bridge_name = cmd_list_bridge_info.result[0]['name'] - self.assertIn(TEST_BRIDGE, bridge_name) + self.assertIn(self.TEST_BRIDGE, bridge_name) - cmd_del_br = ovsdb.del_br(TEST_BRIDGE) + cmd_del_br = ovsdb.del_br(self.TEST_BRIDGE) with ovsdb.transaction() as trans: trans.add(cmd_del_br) trans.add(cmd_list_bridge_info) @@ -89,20 +60,20 @@ @attr(type='integration') -class TestOvsApiWithSingleRealBridge(VdsmTestCase): +class TestOvsApiWithSingleRealBridge(OvsTestCase): def setUp(self): self.ovsdb = create() - self.ovsdb.add_br(TEST_BRIDGE).execute() + self.ovsdb.add_br(self.TEST_BRIDGE).execute() def tearDown(self): - self.ovsdb.del_br(TEST_BRIDGE).execute() + self.ovsdb.del_br(self.TEST_BRIDGE).execute() def test_create_vlan_as_fake_bridge(self): with self.ovsdb.transaction() as t: - t.add(self.ovsdb.add_vlan(TEST_BRIDGE, 100)) - t.add(self.ovsdb.add_vlan(TEST_BRIDGE, 101)) + t.add(self.ovsdb.add_vlan(self.TEST_BRIDGE, 100)) + t.add(self.ovsdb.add_vlan(self.TEST_BRIDGE, 101)) bridges = self.ovsdb.list_br().execute() self.assertEqual(3, len(bridges)) -- To view, visit https://gerrit.ovirt.org/56391 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I11a4d6f06f10b6fe18f304556a1123bc3d761836 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Petr Horáček <phora...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches