1 |
|
import sys
|
|
1 |
# Copyright 2012 GRNET S.A. All rights reserved.
|
|
2 |
#
|
|
3 |
# Redistribution and use in source and binary forms, with or
|
|
4 |
# without modification, are permitted provided that the following
|
|
5 |
# conditions are met:
|
|
6 |
#
|
|
7 |
# 1. Redistributions of source code must retain the above
|
|
8 |
# copyright notice, this list of conditions and the following
|
|
9 |
# disclaimer.
|
|
10 |
#
|
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
|
12 |
# copyright notice, this list of conditions and the following
|
|
13 |
# disclaimer in the documentation and/or other materials
|
|
14 |
# provided with the distribution.
|
|
15 |
#
|
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
|
28 |
#
|
|
29 |
# The views and conclusions contained in the software and
|
|
30 |
# documentation are those of the authors and should not be
|
|
31 |
# interpreted as representing official policies, either expressed
|
|
32 |
# or implied, of GRNET S.A.
|
|
33 |
|
|
34 |
|
|
35 |
from django.test import TestCase
|
2 |
36 |
from synnefo.db.pools import (PoolManager, EmptyPool, BridgePool,
|
3 |
37 |
MacPrefixPool, IPPool)
|
4 |
38 |
from bitarray import bitarray
|
5 |
39 |
|
6 |
|
# Use backported unittest functionality if Python < 2.7
|
7 |
|
try:
|
8 |
|
import unittest2 as unittest
|
9 |
|
except ImportError:
|
10 |
|
if sys.version_info < (2, 7):
|
11 |
|
raise Exception("The unittest2 package is required for Python < 2.7")
|
12 |
|
import unittest
|
13 |
|
|
14 |
40 |
|
15 |
41 |
class DummyObject():
|
16 |
42 |
def __init__(self, size):
|
... | ... | |
31 |
57 |
return value
|
32 |
58 |
|
33 |
59 |
|
34 |
|
class PoolManagerTestCase(unittest.TestCase):
|
|
60 |
class PoolManagerTestCase(TestCase):
|
35 |
61 |
def test_created_pool(self):
|
36 |
62 |
obj = DummyObject(42)
|
37 |
63 |
pool = DummyPool(obj)
|
... | ... | |
111 |
137 |
self.assertEqual(pool.reserved, bitarray('1' * 39 + '0' * 1))
|
112 |
138 |
|
113 |
139 |
|
114 |
|
class BridgePoolTestCase(unittest.TestCase):
|
|
140 |
class BridgePoolTestCase(TestCase):
|
115 |
141 |
def test_bridge_conversion(self):
|
116 |
142 |
obj = DummyObject(13)
|
117 |
143 |
obj.base = "bridge"
|
... | ... | |
125 |
151 |
self.assertEqual(pool.empty(), True)
|
126 |
152 |
|
127 |
153 |
|
128 |
|
class MacPrefixPoolTestCase(unittest.TestCase):
|
|
154 |
class MacPrefixPoolTestCase(TestCase):
|
129 |
155 |
def test_invalid_mac_reservation(self):
|
130 |
156 |
obj = DummyObject(65636)
|
131 |
157 |
obj.base = 'ab:ff:ff'
|
... | ... | |
133 |
159 |
for i in range(0, 65536):
|
134 |
160 |
self.assertEqual(pool.is_available(i, index=True), False)
|
135 |
161 |
|
136 |
|
class IPPoolTestCase(unittest.TestCase):
|
|
162 |
|
|
163 |
class IPPoolTestCase(TestCase):
|
137 |
164 |
def test_auto_reservations(self):
|
138 |
165 |
obj = DummyObject(0)
|
139 |
166 |
network = DummyObject(0)
|
... | ... | |
158 |
185 |
self.assertEqual(pool.is_available('192.168.2.1'), False)
|
159 |
186 |
self.assertEqual(pool.size(), 8)
|
160 |
187 |
self.assertEqual(pool.empty(), True)
|
161 |
|
|
162 |
|
|
163 |
|
if __name__ == '__main__':
|
164 |
|
unittest.main()
|