Changeset 6440
- Timestamp:
- Dec 11, 2008, 5:42:21 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/README
r6436 r6440 33 33 34 34 Run script from commandline with verbose 35 ./bin/django runscript --verbosity=2 --traceback genesis_to_exodus35 $ ./bin/django runscript --verbosity=2 --traceback genesis_to_exodus 36 36 -
trunk/exodus/forms.py
r6437 r6440 20 20 else: 21 21 #XXX: Need to update ipconfigurations for depending interfaces 22 #XXX: Need to set netmask 22 23 masterip = free_master_ip(new_network) 23 24 return masterip 24 25 25 26 26 class InterfaceForm(forms.ModelForm): … … 60 60 # convert master to slave 61 61 #XXX: update mode 62 #XXX: update ssids 62 63 old_slave = link 63 64 old_master = old_slave.link 64 65 old_master.link = old_slave 65 66 old_slave.link = old_slave 67 68 #XXX: do ip address switch stuff 69 # 70 # Save 66 71 old_slave.save() 67 72 old_master.save() 68 #XXX: do ip address switch stuff69 73 return link 70 74 … … 76 80 %(link.type, type)) 77 81 78 79 82 return link 80 83 -
trunk/exodus/tests.py
r6432 r6440 7 7 self.client = Client() 8 8 9 #Set up thedatabase9 #Set up a inmemory database 10 10 from exodus import settings 11 11 self.olddbname = settings.DATABASE_NAME … … 23 23 connection.creation.destroy_test_db(self.olddbname, 0) 24 24 25 def test_addlocation(self):26 post_data = {'description': 'JohnLaan2', 'longitude': '34.55', \27 'latitude' : '44.55', 'proceed': 'OK, proceed'}28 response = self.client.post('/add/location/new/', post_data)29 30 self.failUnlessEqual(response.status_code, 302)31 self.failUnlessEqual(response['Location'], \32 'http://testserver/add/node/new/?location=2')33 34 from exodus.models import Location35 36 l = Location.objects.get(description = 'JohnLaan2')37 self.failUnless(str(l.longitude), '34.55')38 self.failUnless(str(l.latitude), '44.55')39 40 def test_addnode(self):41 post_data = {'name' : 'Tabitha', 'location' : 1, \42 'status' : 'up', 'network' : 1, 'proceed': 'OK, proceed'}43 response = self.client.post('/add/node/new/', post_data)44 45 self.failUnlessEqual(response.status_code, 302)46 self.failUnlessEqual(response['Location'], \47 'http://testserver/view/node/Tabitha/')48 49 from exodus.models import Node50 51 try:52 n = Node.objects.get(name = 'Tabitha')53 except Node.DoesNotExist:54 self.fail("Node wasn't added.")55 56 node = n57 self.failUnlessEqual(n.location.id, 1)58 self.failUnlessEqual(n.status, 'up')59 self.failUnlessEqual(n.network.id, 1)60 61 c = {}62 63 for i in n.as_list():64 c[i[0]] = i[1]65 66 self.failUnless(c.has_key('masterip'))67 25 68 26 class wllogic(unittest.TestCase): … … 82 40 connection.creation.destroy_test_db(self.olddbname, 0) 83 41 84 def test_new_ SSID_name(self):42 def test_new_ssid(self): 85 43 class node(object): 86 44 name = 'CeTIM' … … 160 118 def test_free_master_ip(self): 161 119 from wllogic import free_master_ip 162 from exodus.models import Node, Network 163 164 node = Node.objects.create(location_id = 1, \ 165 masterip = '172.16.0.1', name = 'testnode') 120 from exodus.models import Network, Node 121 nodes = Node.objects.all() 122 ip_list = [] 123 for i in nodes: 124 ip_list.append(i.masterip) 166 125 network = Network.objects.get(pk=1) 167 126 ip = free_master_ip(network) 168 self.failIfEqual(ip, '172.16.0.1') 169 self.failUnlessEqual(ip, '172.16.1.1') 170 171 def test_free_publicap_ip(self): 172 from wllogic import free_publicap_ip 173 self.fail('test not implemented') 174 175 def test_free_interlink_ip(self): 176 from wllogic import free_interlink_ip 177 self.fail('Test not implemented') 178 179 def test_add_interlink_ip(self): 180 from wllogic import add_interlink_ip 181 self.fail('Test not implemented') 182 127 self.failIf(ip in ip_list) 128 self.failUnlessEqual(ip, '172.16.2.1') 129 130 def test_calc_subnet(self): 131 from wllogic import calc_subnet 132 self.failUnlessEqual(calc_subnet(1), 32) 133 self.failUnlessRaises(ValueError, calc_subnet, 0) 134 self.failUnlessRaises(ValueError, calc_subnet, 255) 135 136 l = [] 137 for i in range(1,255): 138 l.append(calc_subnet(i)) 139 k = [] 140 for i in range(24,33): 141 k.append(l.count(i)) 142 n = [128, 64, 32, 16, 8, 4, 1, 0, 1] 143 self.failUnlessEqual(k,n) 144 183 145 class Link(unittest.TestCase): 184 146 def setUp(self): … … 201 163 202 164 # test link to self 203 self.failUnless(link_has_compat_type(self.link00, self.link00)) 165 self.failUnless(link_has_compat_type(self.link00.type, 166 self.link00.type)) 204 167 # test eth 205 self.failUnless(link_has_compat_type(self.link00, self.link01)) 168 self.failUnless(link_has_compat_type(self.link00.type, 169 self.link01.type)) 206 170 # test 11a 207 self.failUnless(link_has_compat_type(self.link10, self.link11)) 171 self.failUnless(link_has_compat_type(self.link10.type, 172 self.link11.type)) 208 173 # test 11b 209 self.failUnless(link_has_compat_type(self.link20, self.link21)) 174 self.failUnless(link_has_compat_type(self.link20.type, 175 self.link21.type)) 210 176 # test 11g 211 self.failUnless(link_has_compat_type(self.link30, self.link31)) 177 self.failUnless(link_has_compat_type(self.link30.type, 178 self.link31.type)) 212 179 # test 11b vs 11g 213 self.failUnless(link_has_compat_type(self.link20, self.link30)) 214 self.failUnless(link_has_compat_type(self.link30, self.link20)) 180 self.failUnless(link_has_compat_type(self.link20.type, 181 self.link30.type)) 182 self.failUnless(link_has_compat_type(self.link30.type, 183 self.link20.type)) 215 184 216 185 # test fail eth vs 11a -
trunk/exodus/wllogic.py
r6437 r6440 3 3 from exodus.models import Node, Interface 4 4 from exodus.settings import MASTERIP_NETMASK 5 from math import ceil, log 5 6 6 7 def new_ssid(node, nic, desc): … … 16 17 # 17 18 def parse_addr(s): 18 """Remember when using an address has a section which is higher than19 """Remember when using an address which has a section which is higher than 19 20 255, such as 172.16.0.256, the ip address from show_addr turns out as 20 21 172.16.1.0 … … 58 59 # requested subnet 59 60 60 def free_master_ip(city_network, netmask = None): 61 if netmask == None: 62 netmask = MASTERIP_NETMASK 63 64 if netmask < 0 or netmask > 32 : 61 def free_master_ip(city_network, netmask = MASTERIP_NETMASK): 62 """Calculates the next free masterip.""" 63 if netmask < 0 or netmask > 32: 65 64 raise ValueError, 'netmask out of bounds' 66 65 … … 129 128 return show_addr(i) 130 129 131 def add_interlink_ip(master Link):130 def add_interlink_ip(master_link): 132 131 taken = {} 133 132 134 for interface in Interface.objects.filter(link=master Link):133 for interface in Interface.objects.filter(link=master_link): 135 134 #Grr, needs all interfaces which are master requires a bit of a hack 136 135 addr = parse_addr(interface.ip) … … 139 138 size = 32 140 139 numaddrs = 1 << (32 - size) 141 i = network(master Link.ip, masterLink.netmask) + 1140 i = network(master_link.ip, master_link.netmask) + 1 142 141 while taken.has_key(i): 143 142 i = i + 1 … … 164 163 165 164 def link_is_not_to_itself(link1, link2): 166 # check if a link is not going itself 167 if link1.node != link2.node: 168 return True 165 """check if a link referenced itself.""" 166 return link1.node != link2.node 169 167 168 def calc_subnet(number_ifaces): 169 """Returns the subnetmask. 170 171 We need the subnet with number_ifaces available in subnet. As such 172 we correct for the broadcast and network address. 173 """ 174 if number_ifaces > 254 or number_ifaces < 1: 175 raise ValueError, 'Number of ifaces is out of bounds' 176 if number_ifaces == 1: 177 return 32 178 return int(32) - int(ceil(log(number_ifaces+2,2)))
Note:
See TracChangeset
for help on using the changeset viewer.