Changeset 6420 for branches


Ignore:
Timestamp:
Dec 8, 2008, 4:57:03 PM (16 years ago)
Author:
roland
Message:

Fixed str to unicode on models.
Made save Node better.
Added some unittests.
Added link checks in wllogic.

Location:
branches/exodus-roland/exodus
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/exodus-roland/exodus/admin.py

    r6411 r6420  
    2929    fieldsets = (
    3030        (None, {
    31             'fields' : (('name', 'status') , 'location', 'network', 'masterip')
     31            'fields' : ('name', 'status', 'location', 'network', 'masterip')
    3232        }),
    3333    )
    34     inlines = [InterfaceInline, ]
     34
     35    #inlines = [InterfaceInline, ]
    3536
    3637class NodeInline(admin.TabularInline):
  • branches/exodus-roland/exodus/forms.py

    r6404 r6420  
    55
    66class NodeForm(forms.ModelForm):
    7     masterip = forms.IPAddressField()
    87    class Meta:
    98       model = Node
    10     #def clean(self):
    11     #    self.data['masterip'] = \
    12     #            self.cleaned_data['masterip'] = \
    13     #            free_masterip(self.cleaned_data['network'])
    14     #    return super(NodeForm, self).clean()
    15 
  • branches/exodus-roland/exodus/models.py

    r6411 r6420  
    3737        verbose_name = 'Antenna'
    3838
    39     def __str__(self):
     39    def __unicode__(self):
    4040        return self.type
    4141
     
    4848        verbose_name = 'Location'
    4949
    50     def __str__(self):
     50    def __unicode__(self):
    5151        return self.description
    5252
     
    6060        verbose_name = 'Dns Server'
    6161   
    62     def __str__(self):
     62    def __unicode__(self):
    6363        return "%s, %s"% (self.domainname, self.ipaddress )
    64 
    6564
    6665class Network(models.Model):
     
    7271        verbose_name = 'Network'
    7372
    74         def __str__(self):
     73        def __unicode__(self):
    7574                return self.name
    7675
     
    8786        verbose_name = 'Node'
    8887
    89     def __str__(self):
     88    def __unicode__(self):
    9089        return self.name
    9190
     91    def save(self, force_insert=False, force_update=False):
     92        #XXX: Maybe move this to a model form,
     93        from wllogic import free_masterip
     94        # check if there is a masterip, if not generate one.
     95        # check if there is a network change, if so, generate a new masterip.
     96        if self.masterip:
     97            old = Node.objects.get(pk=self.pk)
     98            if old.network != self.network:
     99                self.masterip = free_masterip(self.network)
     100        else:
     101            self.masterip = free_masterip(self.network)
     102        super(Node, self).save(force_insert, force_update)
    92103
    93104class Interface(models.Model):
     
    112123                verbose_name = 'Interface'
    113124       
    114         def __str__(self):
     125        def __unicode__(self):
    115126                return "%s/%s" % (self.node, self.iface)
    116127
     
    124135        link = models.ForeignKey(Interface, blank=True, null=True)
    125136       
    126         def __str__(self):
     137        def __unicode__(self):
    127138                return "Alias %s" % (self.iface)
    128139
     
    144155        verbose_name = "Public Access Point"
    145156
    146     def __str__(self):
     157    def __unicode__(self):
    147158        return "%s:%s" % (self.iface,self.pk)
    148159
     
    156167        verbose_name = "Static host"
    157168
    158     def __str__(self):
     169    def __unicode__(self):
    159170        return self.hostname
  • branches/exodus-roland/exodus/tests.py

    r6411 r6420  
    181181        self.fail('Test not implemented')
    182182
    183 class Manager(unittest.TestCase):
    184         def test_interface_manager(self):
    185                 class link(object):
    186                         def __init__(self, type):
    187                                 self.type = type
    188                 from exodus.manager import InterfaceManager
    189                 11a_link =
    190    
     183class Link(unittest.TestCase):
     184    def setUp(self):
     185        class link(object):
     186            def __init__(self, type, node):
     187                self.type = type
     188                self.node = node
     189
     190        self.link00 = link('eth', 1)
     191        self.link01 = link('eth', 2)
     192        self.link10 = link('11a', 1)
     193        self.link11 = link('11a', 2)
     194        self.link20 = link('11b', 1)
     195        self.link21 = link('11b', 2)
     196        self.link30 = link('11g', 1)           
     197        self.link31 = link('11g', 2)
     198
     199    def test_link_has_compat_type(self):
     200        from wllogic import link_has_compat_type
     201       
     202        # test link to self
     203        self.failUnless(link_has_compat_type(self.link00, self.link00))
     204        # test eth
     205        self.failUnless(link_has_compat_type(self.link00, self.link01))
     206        # test 11a
     207        self.failUnless(link_has_compat_type(self.link10, self.link11))
     208        # test 11b
     209        self.failUnless(link_has_compat_type(self.link20, self.link21))
     210        # test 11g
     211        self.failUnless(link_has_compat_type(self.link30, self.link31))
     212        # 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))
     215
     216        # test fail eth vs 11a
     217        self.failIf(link_has_compat_type(self.link00, self.link10))
     218        # test fail eth vs 11b
     219        self.failIf(link_has_compat_type(self.link00, self.link20))
     220        # test fail eth vs 11g
     221        self.failIf(link_has_compat_type(self.link00, self.link30))
     222        # test fail 11a vs 11b
     223        self.failIf(link_has_compat_type(self.link10, self.link20))
     224        # test fail 11a vs 11g
     225        self.failIf(link_has_compat_type(self.link10, self.link30))
     226   
     227    def test_link_not_same_node(self):
     228        from wllogic import link_is_not_to_itself
     229        self.failUnless(link_is_not_to_itself(self.link00, self.link01))
     230        self.failIf(link_is_not_to_itself(self.link20, self.link30))
     231   
     232    def test_link_is_wireless(self):
     233        from wllogic import link_is_wireless
     234        self.failIf(link_is_wireless(self.link00))
     235        self.failUnless(link_is_wireless(self.link10))
     236        self.failUnless(link_is_wireless(self.link20))
     237        self.failUnless(link_is_wireless(self.link30))
     238               
    191239def suite():
    192240    s = unittest.TestSuite()
    193241    s.addTest(unittest.makeSuite(AddTest))
    194242    s.addTest(unittest.makeSuite(wllogic))
     243    s.addTest(unittest.makeSuite(Link))
    195244
    196245    return s
  • branches/exodus-roland/exodus/wllogic.py

    r6373 r6420  
    144144       
    145145        return show_addr(i)
     146
     147def link_is_valid(link1, link2):
     148        if not link_has_compat_type(link1, link2):
     149                return False
     150
     151def link_is_wireless(link1):
     152        wireless = ('11a', '11b', '11g')
     153        if link1.type in wireless:
     154                return True
     155
     156def link_has_compat_type(link1, link2):
     157        # if this is a link to self, the link is always valid
     158        if link1 == link2:
     159                return True
     160        # link types must the same
     161        if link1.type == link2.type:
     162                return True
     163        # or link types must be compatible
     164        compat = ('11b', '11g')
     165        if link1.type in compat and link2.type in compat:
     166                return True
     167
     168def link_is_not_to_itself(link1, link2):
     169        # check if a link is not going itself
     170        if link1.node != link2.node:
     171                return True
     172
Note: See TracChangeset for help on using the changeset viewer.