summaryrefslogtreecommitdiffstats
path: root/scripts/automation/regression/functional_tests/misc_methods_test.py
blob: 096f86d89ddfe32dba72ec5a841e5e99d9c4c903 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/router/bin/python

import functional_general_test
import misc_methods
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_raises
from nose.tools import raises


class MiscMethods_Test(functional_general_test.CGeneralFunctional_Test):

    def setUp(self):
        self.ipv4_gen = misc_methods.get_network_addr()
        self.ipv6_gen = misc_methods.get_network_addr(ip_type = 'ipv6')
        pass

    def test_ipv4_gen(self):
        for i in range(1, 255):
            assert_equal( next(self.ipv4_gen), [".".join( map(str, [1, 1, i, 0])), '255.255.255.0'] )

    def test_ipv6_gen(self):
        tmp_ipv6_addr = ['2001', 'DB8', 0, '2222', 0, 0, 0, 0]
        for i in range(0, 255):
            tmp_ipv6_addr[2] = hex(i)[2:]
            assert_equal( next(self.ipv6_gen), ":".join( map(str, tmp_ipv6_addr)) )

    def test_get_ipv4_client_addr(self):
        tmp_ipv4_addr = next(self.ipv4_gen)[0]
        assert_equal ( misc_methods.get_single_net_client_addr(tmp_ipv4_addr), '1.1.1.1')
        assert_raises (ValueError, misc_methods.get_single_net_client_addr, tmp_ipv4_addr, {'3' : 255} )
    
    def test_get_ipv6_client_addr(self):
        tmp_ipv6_addr = next(self.ipv6_gen)
        assert_equal ( misc_methods.get_single_net_client_addr(tmp_ipv6_addr, {'7' : 1}, ip_type = 'ipv6'), '2001:DB8:0:2222:0:0:0:1')    
        assert_equal ( misc_methods.get_single_net_client_addr(tmp_ipv6_addr, {'7' : 2}, ip_type = 'ipv6'), '2001:DB8:0:2222:0:0:0:2')    
        assert_raises (ValueError, misc_methods.get_single_net_client_addr, tmp_ipv6_addr, {'7' : 70000} )
        

    @raises(ValueError)
    def test_ipv4_client_addr_exception(self):
        tmp_ipv4_addr = next(self.ipv4_gen)[0]
        misc_methods.get_single_net_client_addr(tmp_ipv4_addr, {'4' : 1})

    @raises(ValueError)
    def test_ipv6_client_addr_exception(self):
        tmp_ipv6_addr = next(self.ipv6_gen)
        misc_methods.get_single_net_client_addr(tmp_ipv6_addr, {'8' : 1}, ip_type = 'ipv6')

    @raises(StopIteration)
    def test_gen_ipv4_to_limit (self):
        while(True):
            next(self.ipv4_gen)

    @raises(StopIteration)
    def test_gen_ipv6_to_limit (self):
        while(True):
            next(self.ipv6_gen)

    def tearDown(self):
        pass