]> git.proxmox.com Git - mirror_ifupdown2.git/blame - tests/ifstatetest
Merge pull request #80 from BarbarossaTM/tunnel-fixes-master
[mirror_ifupdown2.git] / tests / ifstatetest
CommitLineData
2c8c4ce7
RP
1#!/usr/bin/python
2
3""" test for testing and profiling state manager """
4
5import cProfile
6
7from ifupdown.networkinterfaces import *
8from ifupdown.iface import *
9from ifupdown.statemanager import pickling
10import os
11
12ifaceobjdict = {}
13state_file = '/tmp/ifstatetest'
14
15def save_iface(ifaceobj):
16 ifaceobjdict[ifaceobj.get_name()] = ifaceobj
17
18def read_default_iface_config():
19 """ Reads default network interface config /etc/network/interfaces. """
20 nifaces = networkInterfaces()
21 nifaces.subscribe('iface_found', save_iface)
22 nifaces.load()
23
24def save_state():
25 try:
26 with open(state_file, 'w') as f:
27 for ifaceobj in ifaceobjdict.values():
28 pickling.save_obj(f, ifaceobj)
29 except:
30 raise
31
32def load_state():
33 global ifaceobjdict
34
35 if not os.path.exists(state_file):
36 return
37
38 del ifaceobjdict
39 ifaceobjdict = {}
40
41 # Read all ifaces from file
42 for ifaceobj in pickling.load(state_file):
43 save_iface(ifaceobj)
44
45
46print 'Reading iface config files ..'
47cProfile.run('read_default_iface_config()')
48print 'number of objects: %d' %len(ifaceobjdict)
49
50print 'saving iface state ..'
51cProfile.run('save_state()')
52
53print 'loading iface state ..'
54cProfile.run('load_state()')
55print 'number of objects: %d' %len(ifaceobjdict)
56