Replace BaseLinuxTestCase by BaseSudoTestCase

BaseLinuxTestCase provides 2 methods which are used once/three time(s),
this change inlines these methods and removes BaseLinuxTestCase and
replaces it by BaseSudoTestCase.

Change-Id: I2b60abf55193f535fc7d7637bcb2f15c6a372a87
This commit is contained in:
Cedric Brandily 2015-03-05 21:43:09 +00:00
parent e61447d55a
commit 954b553439
6 changed files with 21 additions and 28 deletions

View File

@ -15,8 +15,7 @@
import testscenarios
from neutron.tests import base as tests_base
from neutron.tests.common import net_helpers
from neutron.tests.functional import base as functional_base
from neutron.tests.functional import base
MARK_VALUE = '0x1'
@ -31,19 +30,10 @@ ICMP_BLOCK_RULE = '-p icmp -j DROP'
get_rand_name = tests_base.get_rand_name
class BaseLinuxTestCase(functional_base.BaseSudoTestCase):
def _create_namespace(self, prefix=net_helpers.NS_PREFIX):
return self.useFixture(net_helpers.NamespaceFixture(prefix)).ip_wrapper
def create_veth(self):
return self.useFixture(net_helpers.VethFixture()).ports
# Regarding MRO, it goes BaseOVSLinuxTestCase, WithScenarios,
# BaseLinuxTestCase, ..., UnitTest, object. setUp is not dfined in
# WithScenarios, so it will correctly be found in BaseLinuxTestCase.
class BaseOVSLinuxTestCase(testscenarios.WithScenarios, BaseLinuxTestCase):
# BaseSudoTestCase, ..., UnitTest, object. setUp is not dfined in
# WithScenarios, so it will correctly be found in BaseSudoTestCase.
class BaseOVSLinuxTestCase(testscenarios.WithScenarios, base.BaseSudoTestCase):
scenarios = [
('vsctl', dict(ovsdb_interface='vsctl')),
('native', dict(ovsdb_interface='native')),

View File

@ -12,11 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron.tests.functional.agent.linux import base
from neutron.tests.functional.agent.linux import helpers
from neutron.tests.functional import base
class TestRootHelperProcess(base.BaseLinuxTestCase):
class TestRootHelperProcess(base.BaseSudoTestCase):
def test_process_read_write(self):
proc = helpers.RootHelperProcess(['tee'], run_as_root=True)

View File

@ -44,7 +44,7 @@ class OVSInterfaceDriverTestCase(base.BaseOVSLinuxTestCase):
def test_plug_succeeds(self):
device_name = tests_base.get_rand_name()
mac_address = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
namespace = self._create_namespace()
namespace = self.useFixture(net_helpers.NamespaceFixture()).name
bridge = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
self.assertFalse(bridge.get_port_name_list())
@ -53,6 +53,6 @@ class OVSInterfaceDriverTestCase(base.BaseOVSLinuxTestCase):
device_name=device_name,
mac_address=mac_address,
bridge=bridge.br_name,
namespace=namespace.namespace)
namespace=namespace)
self.assertIn(device_name, bridge.get_port_name_list())
self.assertTrue(ip_lib.device_exists(device_name, namespace.namespace))
self.assertTrue(ip_lib.device_exists(device_name, namespace))

View File

@ -25,13 +25,14 @@ from neutron.agent.linux import interface
from neutron.agent.linux import ip_lib
from neutron.common import utils
from neutron.tests.functional.agent.linux import base
from neutron.tests.functional import base as functional_base
LOG = logging.getLogger(__name__)
Device = collections.namedtuple('Device',
'name ip_cidrs mac_address namespace')
class IpLibTestFramework(base.BaseLinuxTestCase):
class IpLibTestFramework(functional_base.BaseSudoTestCase):
def setUp(self):
super(IpLibTestFramework, self).setUp()
self._configure()

View File

@ -46,8 +46,8 @@ from neutron.common import utils as common_utils
from neutron.openstack.common import uuidutils
from neutron.tests.common import machine_fixtures
from neutron.tests.common import net_helpers
from neutron.tests.functional.agent.linux import base
from neutron.tests.functional.agent.linux import helpers
from neutron.tests.functional import base
from neutron.tests.unit.agent.l3 import test_agent as test_l3_agent
LOG = logging.getLogger(__name__)
@ -60,7 +60,7 @@ def get_ovs_bridge(br_name):
return ovs_lib.OVSBridge(br_name)
class L3AgentTestFramework(base.BaseLinuxTestCase):
class L3AgentTestFramework(base.BaseSudoTestCase):
def setUp(self):
super(L3AgentTestFramework, self).setUp()
mock.patch('neutron.agent.l3.agent.L3PluginApi').start()
@ -709,7 +709,7 @@ class L3HATestFramework(L3AgentTestFramework):
br_int_2 = get_ovs_bridge(
self.failover_agent.conf.ovs_integration_bridge)
veth1, veth2 = self.create_veth()
veth1, veth2 = self.useFixture(net_helpers.VethFixture()).ports
br_int_1.add_port(veth1.name)
br_int_2.add_port(veth2.name)

View File

@ -33,14 +33,16 @@ class ARPSpoofTestCase(test_ovs_lib.OVSBridgeTestBase,
super(ARPSpoofTestCase, self).setUp()
self.src_addr = '192.168.0.1'
self.dst_addr = '192.168.0.2'
self.src_ns = self._create_namespace()
self.dst_ns = self._create_namespace()
self.src_namespace = self.useFixture(
net_helpers.NamespaceFixture()).name
self.dst_namespace = self.useFixture(
net_helpers.NamespaceFixture()).name
self.pinger = machine_fixtures.Pinger(
self.src_ns.namespace, max_attempts=2)
self.src_namespace, max_attempts=2)
self.src_p = self.useFixture(
net_helpers.OVSPortFixture(self.br, self.src_ns.namespace)).port
net_helpers.OVSPortFixture(self.br, self.src_namespace)).port
self.dst_p = self.useFixture(
net_helpers.OVSPortFixture(self.br, self.dst_ns.namespace)).port
net_helpers.OVSPortFixture(self.br, self.dst_namespace)).port
# wait to add IPs until after anti-spoof rules to ensure ARP doesn't
# happen before