Changeset 6637 for trunk


Ignore:
Timestamp:
Jan 24, 2009, 1:33:22 PM (16 years ago)
Author:
roland
Message:

Major work on unittest:
-almost finished test_wlipcalc, need to check for a masterip input in

ipcalc.init

-finished test_wllogic, all functions in wllogic.py are tested.
-fixed a bug in wllogic
-did some 80 characters linewrap clean up.
-updated base.cfg for new django_command_extensions.
-moved some stuff around in models.py (nothing major)

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/base.cfg

    r6491 r6637  
    77
    88[versions]
    9 djangorecipe=0.12.1
     9djangorecipe=0.15
    1010zc.recipe.egg=1.0.0
    1111zc.recipe.testrunner=1.0.0
     
    2929recipe = iw.recipe.subversion
    3030urls =
    31   http://django-command-extensions.googlecode.com/svn/trunk@135 django-command-extensions
     31  http://django-command-extensions.googlecode.com/svn/trunk@178 django-command-extensions
    3232
    3333[django]
  • trunk/exodus/models.py

    r6606 r6637  
    117117
    118118class Interface(models.Model):
    119 
    120     def all(self):
    121         return Interface.objects.all()
    122119    node = models.ForeignKey(Node)
    123120    ethernet_to_wifi = models.ForeignKey(EthernetToWifiBridge, blank=True,
  • trunk/exodus/tests/base.py

    r6607 r6637  
    2727        # create multiple nodes.
    2828        from exodus.models import Node
    29         nod1 = Node.objects.create(name='Roland', location=loc1, status='up',
    30             network=network, masterip='172.16.0.1') 
    31         nod2 = Node.objects.create(name='Rick', location=loc2, status='up',
     29        self.nod1 = Node.objects.create(name='Roland', location=loc1,
     30            status='up', network=network, masterip='172.16.0.1') 
     31        self.nod2 = Node.objects.create(name='Rick', location=loc2, status='up',
    3232            network=network, masterip='172.16.1.1') 
    33         nod3 = Node.objects.create(name='Andrea', location=loc3, status='up',
    34             network=network, masterip='172.16.2.1') 
     33        self.nod3 = Node.objects.create(name='Andrea', location=loc3,
     34            status='up', network=network, masterip='172.16.2.1') 
    3535
    3636    def tearDown(self):
  • trunk/exodus/tests/test_wlipcalc.py

    r6608 r6637  
    44class IPCalcTest(BootstrapTestCase):
    55
    6     def ipcalc(a):
     6    def setUp(self):
     7        super(IPCalcTest, self).setUp()
     8        from exodus.models import Interface
     9        self.iface1 = Interface.objects.create(node = self.nod1, type='eth',
     10                iface='eth0', ip='172.16.0.2', netmask=32, link=None)
     11        self.iface2 = Interface.objects.create(node = self.nod1, type='11b',
     12                iface='wi0', ip='172.16.0.5', netmask=30, link=None)
     13        self.iface3 = Interface.objects.create(node = self.nod2, type='11b',
     14                iface='wi0', ip='172.16.0.6', netmask=30, link=self.iface2)
     15
     16    def ipcalc(self, a):
    717        from exodus.models import Node 
    818        node = Node.objects.get(pk=1)
     
    2232
    2333    def test_ipcalc_get_used_ips_with_link(self):
    24         from exodus.models import Interface
    25         link_id = Interface.objects.get(pk=1).id
     34        link_id = self.iface2.id
    2635        list = set(['172.16.0.1', '172.16.0.2'])
    2736        from exodus.wlipcalc import IPCalc
    28         used_list = IPCalc(self.node, 30, link_id)._get_used_ips()
     37        used_list = IPCalc(self.nod1, 30, link_id)._get_used_ips()
    2938        self.failUnlessEqual(list, used_list)
    3039
     
    4352        from exodus.models import Interface
    4453        iface = Interface.objects.create(
    45             node = self.node, type = 'eth', iface ='eth3',
    46             ip = '172.16.0.130', netmask = 25)
     54            node = self.nod1, type = 'eth', iface ='eth3',
     55            ip = '172.16.0.130', netmask = 25, link=None)
    4756       
    4857        self.failUnlessRaises(Exception, self.ipcalc, 25)
     
    5463       
    5564        self.failUnlessEqual(ipcalc.network, ip)
    56         self.failUnlessEqual(ipcalc.ips, ip)
     65        # ipcalc.ips returns a list, which in this case has one ip.
     66        self.failUnlessEqual(ipcalc.ips, [ip])
    5767        self.failUnlessEqual(ipcalc.broadcast, ip)
    5868        self.failUnlessEqual(ipcalc.netmask, netmask)
  • trunk/exodus/tests/test_wllogic.py

    r6608 r6637  
    1818    def test_new_ssid(self):
    1919        #XXX: need to test 'ap', direction and multiple aps on one node.
     20        class Interface_Set(object):
     21            def filter(self, accesspoint):
     22                return ()
    2023        class node(object):
    2124            name = 'CeTIM'
     25            interface_set = Interface_Set()
     26
    2227        class network(object):
    2328            name = 'wleiden.net'
    2429        from exodus.wllogic import new_ssid
     30        # plain
    2531        ssid = new_ssid(network(), node(), 'ath0')       
    26        
    2732        self.failUnlessEqual(ssid, 'ath0.CeTIM.wleiden.net')
     33        # with an ap
     34        ssid = new_ssid(network(), node(), 'ath0', accesspoint=True)
     35        self.failUnlessEqual(ssid, 'ap.CeTIM.wleiden.net')
     36        # with a direction
     37        ssid = new_ssid(network(), node(), 'ath0', direction='sw')
     38        self.failUnlessEqual(ssid, 'sw.CeTIM.wleiden.net')
     39        # with an ap and a direction
     40        ssid = new_ssid(network(), node(), 'ath0', accesspoint=True,
     41                direction='sw')
     42        self.failUnlessEqual(ssid, 'ap.CeTIM.wleiden.net')
     43        # with two aps, first ap is ap.CeTIM.wleiden.net.
     44        class iface(object):
     45            def __init__(self, number):
     46                essid = "ap%s.CeTIM.wleiden.net"
     47                if number == 1:
     48                    self.ssid = essid % ("")
     49                else:
     50                    self.ssid = essid % (number)
     51               
     52        class Interface_Set(object):
     53            def filter(self, accesspoint):
     54                return (iface(1),)
     55        class node(object):
     56            name = 'CeTIM'
     57            interface_set = Interface_Set()
     58
     59        ssid = new_ssid(network(), node(), 'ath0', accesspoint=True)
     60        self.failUnlessEqual(ssid, 'ap2.CeTIM.wleiden.net')
     61        # with two aps. second ap is ap2.CeTIM.wleiden.net
     62        class Interface_Set(object):
     63            def filter(self, accesspoint):
     64                return (iface(2),)
     65        class node(object):
     66            name = 'CeTIM'
     67            interface_set = Interface_Set()
     68
     69        ssid = new_ssid(network(), node(), 'ath0', accesspoint=True)
     70        self.failUnlessEqual(ssid, 'ap.CeTIM.wleiden.net')
     71       
    2872
    2973    def test_new_ssid_for_existing_interface(self):
    30         self.fail('Not yet implemented')
     74        class nic(object):
     75            iface='ath0'
     76            accesspoint=False
     77            def get_direction_display(self):
     78               return 'sw'
     79            class node(object):
     80                name='CeTIM'
     81                class network(object):
     82                    name='wleiden.net'
     83
     84        from exodus.wllogic import new_ssid_for_existing_interface
     85        ssid = new_ssid_for_existing_interface(nic())
     86        self.failUnlessEqual(ssid, 'sw.CeTIM.wleiden.net')
    3187
    3288    def test_parse_show_addr(self):
     
    188244        self.failUnless(link_is_wireless(self.link20))
    189245        self.failUnless(link_is_wireless(self.link30))
     246
    190247def suite():
    191248    s = unittest.TestSuite()
  • trunk/exodus/views.py

    r6618 r6637  
    5959            else:
    6060                mode = 'slave'
    61             writer.writerow([nic.iface, node.name, nic.type, nic.ssid, nic.channel,
    62                 nic.antenna, nic.get_polar_display(), nic.get_direction_display(),
    63                 mode, nic.ip, nic.netmask, nic.link.node, nic.link.iface])
     61            writer.writerow([nic.iface, node.name, nic.type, nic.ssid,
     62                    nic.channel, nic.antenna, nic.get_polar_display(),
     63                    nic.get_direction_display(), mode, nic.ip, nic.netmask,
     64                    nic.link.node, nic.link.iface])
    6465    return response
    6566
  • trunk/exodus/wllogic.py

    r6608 r6637  
    117117        return show_addr(i+1)
    118118
     119def calc_subnet(number_ifaces):
     120    #XXX: rename this to calc_netmask
     121        """Returns the netmask.
     122
     123        We need the subnet with number_ifaces available in subnet. As such
     124        we correct for the broadcast and network address.
     125        """
     126        if number_ifaces > 254 or number_ifaces < 1:
     127                raise ValueError, 'Number of ifaces is out of bounds'
     128        if number_ifaces == 1:
     129                return 32       
     130        return int(32) - int(ceil(log(number_ifaces+2,2)))
     131
    119132def link_is_wireless(iface):
    120133        """Check if the interface is wireless"""
     
    133146        return link1.node != link2.node
    134147
    135 def calc_subnet(number_ifaces):
    136     #XXX: rename this to calc_netmask
    137         """Returns the netmask.
    138 
    139         We need the subnet with number_ifaces available in subnet. As such
    140         we correct for the broadcast and network address.
    141         """
    142         if number_ifaces > 254 or number_ifaces < 1:
    143                 raise ValueError, 'Number of ifaces is out of bounds'
    144         if number_ifaces == 1:
    145                 return 32       
    146         return int(32) - int(ceil(log(number_ifaces+2,2)))
Note: See TracChangeset for help on using the changeset viewer.