Changeset 6440


Ignore:
Timestamp:
Dec 11, 2008, 5:42:21 PM (16 years ago)
Author:
roland
Message:

Added calc_subnet, added test, removed tests with regards to views.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/README

    r6436 r6440  
    3333
    3434Run script from commandline with verbose
    35 ./bin/django runscript --verbosity=2 --traceback genesis_to_exodus
     35$ ./bin/django runscript --verbosity=2 --traceback genesis_to_exodus
    3636
  • trunk/exodus/forms.py

    r6437 r6440  
    2020            else:
    2121                #XXX: Need to update ipconfigurations for depending interfaces
     22                #XXX: Need to set netmask
    2223                masterip = free_master_ip(new_network)
    2324        return masterip       
    24 
    2525
    2626class InterfaceForm(forms.ModelForm):
     
    6060                # convert master to slave
    6161                #XXX: update mode
     62                #XXX: update ssids
    6263                old_slave = link
    6364                old_master = old_slave.link
    6465                old_master.link = old_slave
    6566                old_slave.link = old_slave
     67
     68                #XXX: do ip address switch stuff
     69                #
     70                # Save
    6671                old_slave.save()
    6772                old_master.save()
    68                 #XXX: do ip address switch stuff
    6973                return link
    7074
     
    7680                    %(link.type, type))
    7781               
    78  
    7982        return link
    8083
  • trunk/exodus/tests.py

    r6432 r6440  
    77        self.client = Client()
    88       
    9         #Set up the database
     9        #Set up a inmemory database
    1010        from exodus import settings
    1111        self.olddbname = settings.DATABASE_NAME
     
    2323        connection.creation.destroy_test_db(self.olddbname, 0)
    2424
    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 Location
    35    
    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 Node
    50    
    51         try:
    52              n = Node.objects.get(name = 'Tabitha')
    53         except Node.DoesNotExist:
    54             self.fail("Node wasn't added.")
    55 
    56         node = n
    57         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'))
    6725
    6826class wllogic(unittest.TestCase):
     
    8240        connection.creation.destroy_test_db(self.olddbname, 0)
    8341
    84     def test_new_SSID_name(self):
     42    def test_new_ssid(self):
    8543        class node(object):
    8644            name = 'CeTIM'
     
    160118    def test_free_master_ip(self):
    161119        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)
    166125        network = Network.objects.get(pk=1)
    167126        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       
    183145class Link(unittest.TestCase):
    184146    def setUp(self):
     
    201163       
    202164        # 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))
    204167        # 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))
    206170        # 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))
    208173        # 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))
    210176        # 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))
    212179        # 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))
    215184
    216185        # test fail eth vs 11a
  • trunk/exodus/wllogic.py

    r6437 r6440  
    33from exodus.models import Node, Interface
    44from exodus.settings import MASTERIP_NETMASK
     5from math import ceil, log
    56
    67def new_ssid(node, nic, desc):
     
    1617#
    1718def parse_addr(s):
    18         """Remember when using an address has a section which is higher than
     19        """Remember when using an address which has a section which is higher than
    1920        255, such as 172.16.0.256, the ip address from show_addr turns out as
    2021        172.16.1.0
     
    5859#     requested subnet
    5960
    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 :
     61def free_master_ip(city_network, netmask = MASTERIP_NETMASK):
     62        """Calculates the next free masterip."""
     63        if netmask < 0 or netmask > 32:
    6564                raise ValueError, 'netmask out of bounds'       
    6665
     
    129128        return show_addr(i)
    130129
    131 def add_interlink_ip(masterLink):
     130def add_interlink_ip(master_link):
    132131        taken = {}
    133132       
    134         for interface in Interface.objects.filter(link=masterLink):
     133        for interface in Interface.objects.filter(link=master_link):
    135134                #Grr, needs all interfaces which are master requires a bit of a hack
    136135                addr = parse_addr(interface.ip)
     
    139138        size = 32
    140139        numaddrs = 1 << (32 - size)
    141         i = network(masterLink.ip, masterLink.netmask) + 1
     140        i = network(master_link.ip, master_link.netmask) + 1
    142141        while taken.has_key(i):
    143142                i = i + 1
     
    164163
    165164def 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
    169167
     168def 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.