test, integ: clean auto_routes and auto_dns in the needed tests
In some platforms it is not possible to lose the connectivity during a long time. In order to fix this, we are only cleaning auto_dns and auto_routes in the tests when necessary. Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
This commit is contained in:
parent
aa74b099b4
commit
74cbd30e86
@ -25,8 +25,6 @@ import pytest
|
||||
|
||||
import libnmstate
|
||||
from libnmstate.schema import DNS
|
||||
from libnmstate.schema import Interface
|
||||
from libnmstate.schema import InterfaceIP
|
||||
from libnmstate.schema import Route
|
||||
from libnmstate.schema import RouteRule
|
||||
|
||||
@ -87,14 +85,6 @@ def _empty_net_state():
|
||||
}
|
||||
desired_state[RouteRule.KEY] = {RouteRule.CONFIG: []}
|
||||
|
||||
for iface_state in desired_state[Interface.KEY]:
|
||||
if iface_state[Interface.IPV4][InterfaceIP.ENABLED]:
|
||||
iface_state[Interface.IPV4][InterfaceIP.AUTO_DNS] = False
|
||||
iface_state[Interface.IPV4][InterfaceIP.AUTO_ROUTES] = False
|
||||
if iface_state[Interface.IPV6][InterfaceIP.ENABLED]:
|
||||
iface_state[Interface.IPV6][InterfaceIP.AUTO_DNS] = False
|
||||
iface_state[Interface.IPV6][InterfaceIP.AUTO_ROUTES] = False
|
||||
|
||||
libnmstate.apply(desired_state)
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
from contextlib import contextmanager
|
||||
from copy import deepcopy
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
@ -1145,7 +1146,7 @@ def dhcpcli_up_with_dns_cleanup(dhcpcli_up):
|
||||
libnmstate.apply({DNS.KEY: {DNS.CONFIG: {}}})
|
||||
|
||||
|
||||
def test_dynamic_ip_with_static_dns(dhcpcli_up_with_dns_cleanup):
|
||||
def test_dynamic_ip_with_static_dns(dhcpcli_up_with_dns_cleanup, clean_state):
|
||||
iface_state = {
|
||||
Interface.NAME: DHCP_CLI_NIC,
|
||||
Interface.STATE: InterfaceState.UP,
|
||||
@ -1176,3 +1177,22 @@ def test_dynamic_ip_with_static_dns(dhcpcli_up_with_dns_cleanup):
|
||||
new_state = libnmstate.show()
|
||||
assert dns_config[DNS.CONFIG] == new_state[DNS.KEY][DNS.CONFIG]
|
||||
assert dns_config[DNS.CONFIG] == new_state[DNS.KEY][DNS.RUNNING]
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def clean_state():
|
||||
current_state = libnmstate.show()
|
||||
desired_state = deepcopy(current_state)
|
||||
for iface_state in desired_state[Interface.KEY]:
|
||||
if iface_state[Interface.IPV4][InterfaceIPv4.ENABLED]:
|
||||
iface_state[Interface.IPV4][InterfaceIPv4.AUTO_DNS] = False
|
||||
iface_state[Interface.IPV4][InterfaceIPv4.AUTO_ROUTES] = False
|
||||
if iface_state[Interface.IPV6][InterfaceIPv6.ENABLED]:
|
||||
iface_state[Interface.IPV6][InterfaceIPv6.AUTO_DNS] = False
|
||||
iface_state[Interface.IPV6][InterfaceIPv6.AUTO_ROUTES] = False
|
||||
|
||||
libnmstate.apply(desired_state)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
libnmstate.apply(current_state)
|
||||
|
Loading…
x
Reference in New Issue
Block a user