Revision 3b2984dc snf-cyclades-app/synnefo/db/pools/tests.py

b/snf-cyclades-app/synnefo/db/pools/tests.py
102 102
        obj = DummyObject(42)
103 103
        pool = DummyPool(obj)
104 104
        for i in range(42, 48):
105
            self.assertEqual(pool.is_available(i), False)
105
            self.assertRaises(InvalidValue, pool.is_available, i)
106 106
        pool.reserve(32, external=True)
107 107
        values = []
108 108
        while True:
......
189 189
        obj = DummyObject(65636)
190 190
        obj.base = 'ab:ff:ff'
191 191
        pool = MacPrefixPool(obj)
192
        for i in range(0, 65536):
192
        for i in range(0, 65535):
193 193
            self.assertEqual(pool.is_available(i, index=True), False)
194 194

  
195 195
    def test_mac_prefix_conversion(self):
......
209 209

  
210 210

  
211 211
class IPPoolTestCase(TestCase):
212
    def test_auto_reservations(self):
213
        obj = DummyObject(0)
214
        subnet = DummyObject(0)
215
        obj.subnet = subnet
216
        subnet.cidr = '192.168.2.0/24'
217
        subnet.gateway = '192.168.2.1'
218
        pool = IPPool(obj)
219
        self.assertEqual(pool.is_available('192.168.2.0'), False)
220
        self.assertEqual(pool.is_available('192.168.2.1'), False)
221
        self.assertEqual(pool.is_available('192.168.2.255'), False)
222
        self.assertEqual(pool.count_available(), 253)
223
        self.assertEqual(pool.get(), '192.168.2.2')
224
        self.assertTrue(pool.contains("192.168.2.10"))
225
        self.assertFalse(pool.contains("192.168.3.10"))
226

  
227
    def test_auto_reservations_2(self):
228
        obj = DummyObject(0)
229
        subnet = DummyObject(0)
230
        obj.subnet = subnet
231
        subnet.cidr = '192.168.2.0/31'
232
        subnet.gateway = '192.168.2.1'
233
        pool = IPPool(obj)
234
        self.assertEqual(pool.is_available('192.168.2.0'), False)
235
        self.assertEqual(pool.is_available('192.168.2.1'), False)
236
        self.assertEqual(pool.size(), 8)
237
        self.assertEqual(pool.empty(), True)
238

  
239 212
    def test_get_with_value(self):
240
        obj = DummyObject(0)
213
        obj = DummyObject(16)
241 214
        subnet = DummyObject(0)
242 215
        obj.subnet = subnet
243
        subnet.cidr = '192.168.2.0/28'
244
        subnet.gateway = '192.168.2.1'
216
        subnet.cidr = "192.168.2.0/28"
217
        obj.base = "192.168.2.0/28"
218
        obj.offset = 0
245 219
        pool = IPPool(obj)
246 220
        # Test if reserved
247 221
        pool.reserve("192.168.2.2")
......
249 223
        # Test if externally reserved
250 224
        pool.reserve("192.168.2.3", external=True)
251 225
        self.assertRaises(ValueNotAvailable, pool.get, "192.168.2.3")
252
        self.assertRaises(ValueNotAvailable, pool.get, "192.168.2.15")
253 226
        self.assertRaises(InvalidValue, pool.get, "192.168.2.16")

Also available in: Unified diff