tests integ: Execute ifaces cleanup before each test

In order to start each test from a clean state and assure there is no
dependency between the tests, the tested interfaces (eth1, eth2) are
taken down using a dedicated fixture.

Signed-off-by: Edward Haas <edwardh@redhat.com>
This commit is contained in:
Edward Haas 2018-10-24 06:42:06 +03:00 committed by Till Maas
parent 305be5d8b9
commit a49f97e2f4

View File

@ -19,9 +19,33 @@ import logging
import pytest
from libnmstate import netapplier
from .testlib import statelib
from .testlib.statelib import INTERFACES
@pytest.fixture(scope='session', autouse=True)
def logging_setup():
logging.basicConfig(
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
level=logging.DEBUG)
@pytest.fixture(scope='function', autouse=True)
def cleanup_test_interfaces():
ifaces_down_state = {
INTERFACES: []
}
current_state = statelib.show_only(('eth1', 'eth2'))
for iface_state in current_state[INTERFACES]:
if iface_state['state'] == 'up':
ifaces_down_state[INTERFACES].append(
{
'name': iface_state['name'],
'type': iface_state['type'],
'state': 'down'
}
)
if ifaces_down_state[INTERFACES]:
netapplier.apply(ifaces_down_state)