mirror of
https://git.proxmox.com/git/mirror_ifupdown2
synced 2025-08-15 01:57:41 +00:00
state manager test
Ticket: Reviewed By: Testing Done:
This commit is contained in:
parent
91067b3d23
commit
08179c9d2e
56
tests/ifstatetest
Executable file
56
tests/ifstatetest
Executable file
@ -0,0 +1,56 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
""" test for testing and profiling state manager """
|
||||
|
||||
import cProfile
|
||||
|
||||
from ifupdown.networkinterfaces import *
|
||||
from ifupdown.iface import *
|
||||
from ifupdown.statemanager import pickling
|
||||
import os
|
||||
|
||||
ifaceobjdict = {}
|
||||
state_file = '/tmp/ifstatetest'
|
||||
|
||||
def save_iface(ifaceobj):
|
||||
ifaceobjdict[ifaceobj.get_name()] = ifaceobj
|
||||
|
||||
def read_default_iface_config():
|
||||
""" Reads default network interface config /etc/network/interfaces. """
|
||||
nifaces = networkInterfaces()
|
||||
nifaces.subscribe('iface_found', save_iface)
|
||||
nifaces.load()
|
||||
|
||||
def save_state():
|
||||
try:
|
||||
with open(state_file, 'w') as f:
|
||||
for ifaceobj in ifaceobjdict.values():
|
||||
pickling.save_obj(f, ifaceobj)
|
||||
except:
|
||||
raise
|
||||
|
||||
def load_state():
|
||||
global ifaceobjdict
|
||||
|
||||
if not os.path.exists(state_file):
|
||||
return
|
||||
|
||||
del ifaceobjdict
|
||||
ifaceobjdict = {}
|
||||
|
||||
# Read all ifaces from file
|
||||
for ifaceobj in pickling.load(state_file):
|
||||
save_iface(ifaceobj)
|
||||
|
||||
|
||||
print 'Reading iface config files ..'
|
||||
cProfile.run('read_default_iface_config()')
|
||||
print 'number of objects: %d' %len(ifaceobjdict)
|
||||
|
||||
print 'saving iface state ..'
|
||||
cProfile.run('save_state()')
|
||||
|
||||
print 'loading iface state ..'
|
||||
cProfile.run('load_state()')
|
||||
print 'number of objects: %d' %len(ifaceobjdict)
|
||||
|
Loading…
Reference in New Issue
Block a user