mirror of
				https://github.com/CumulusNetworks/ifupdown2.git
				synced 2024-05-06 15:54:50 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			57 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/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)
 | 
						|
 |