Merge pull request #10977 from yuwata/test-network-remove-state-file

test-network: optionally remove state file of networkd
This commit is contained in:
Yu Watanabe 2018-11-29 13:38:08 +09:00 committed by GitHub
commit 636a13d1ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 6 deletions

View File

@ -14,14 +14,15 @@ import socket
import threading
from shutil import copytree
network_unit_file_path='/var/run/systemd/network'
networkd_ci_path='/var/run/networkd-ci'
network_unit_file_path='/run/systemd/network'
networkd_runtime_directory='/run/systemd/netif'
networkd_ci_path='/run/networkd-ci'
network_sysctl_ipv6_path='/proc/sys/net/ipv6/conf'
network_sysctl_ipv4_path='/proc/sys/net/ipv4/conf'
dnsmasq_config_file='/var/run/networkd-ci/test-dnsmasq.conf'
dnsmasq_pid_file='/var/run/networkd-ci/test-test-dnsmasq.pid'
dnsmasq_log_file='/var/run/networkd-ci/test-dnsmasq-log-file'
dnsmasq_config_file='/run/networkd-ci/test-dnsmasq.conf'
dnsmasq_pid_file='/run/networkd-ci/test-test-dnsmasq.pid'
dnsmasq_log_file='/run/networkd-ci/test-dnsmasq-log-file'
def is_module_available(module_name):
lsmod_output = subprocess.check_output('lsmod', universal_newlines=True)
@ -44,9 +45,15 @@ def setUpModule():
shutil.rmtree(networkd_ci_path)
copytree(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'conf'), networkd_ci_path)
subprocess.check_call('systemctl stop systemd-networkd.socket', shell=True)
def tearDownModule():
shutil.rmtree(networkd_ci_path)
subprocess.check_call('systemctl stop systemd-networkd.service', shell=True)
subprocess.check_call('systemctl start systemd-networkd.socket', shell=True)
subprocess.check_call('systemctl start systemd-networkd.service', shell=True)
class Utilities():
dhcp_server_data = []
@ -118,7 +125,12 @@ class Utilities():
os.remove(dnsmasq_log_file)
def start_networkd(self):
subprocess.check_call('systemctl restart systemd-networkd', shell=True)
if (os.path.exists(os.path.join(networkd_runtime_directory, 'state'))):
subprocess.check_call('systemctl stop systemd-networkd', shell=True)
os.remove(os.path.join(networkd_runtime_directory, 'state'))
subprocess.check_call('systemctl start systemd-networkd', shell=True)
else:
subprocess.check_call('systemctl restart systemd-networkd', shell=True)
time.sleep(5)
global ip