Пример #1
0
    def test_fake_pool(self):
        pool = rift.vcs.pool.FakeAddressPool(prefix='192.168.0.')

        # Check the starting number of addresses
        self.assertEqual(0, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Acquire 2 addresses and check the lists
        addr1 = pool.acquire()
        addr2 = pool.acquire()
        self.assertEqual('192.168.0.1', addr1)
        self.assertEqual('192.168.0.2', addr2)
        self.assertEqual(0, len(pool._addresses))
        self.assertEqual(2, len(pool._released))

        # Trying to release an address that did not come from the pool will
        # raise an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release('10.0.0.3')

        # Release the addresses
        pool.release(addr1)
        pool.release(addr2)

        # Check that the pool is back in its initial state
        self.assertEqual(2, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Trying to release an address that has already been released will raise
        # an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release(addr1)
Пример #2
0
    def test_fake_pool(self):
        pool = rift.vcs.pool.FakeAddressPool(prefix='192.168.0.')

        # Check the starting number of addresses
        self.assertEqual(0, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Acquire 2 addresses and check the lists
        addr1 = pool.acquire()
        addr2 = pool.acquire()
        self.assertEqual('192.168.0.1', addr1)
        self.assertEqual('192.168.0.2', addr2)
        self.assertEqual(0, len(pool._addresses))
        self.assertEqual(2, len(pool._released))

        # Trying to release an address that did not come from the pool will
        # raise an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release('10.0.0.3')

        # Release the addresses
        pool.release(addr1)
        pool.release(addr2)

        # Check that the pool is back in its initial state
        self.assertEqual(2, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Trying to release an address that has already been released will raise
        # an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release(addr1)
Пример #3
0
    def test_reserved_pool(self):
        addresses = [
                '10.0.0.1',
                '10.0.0.2']

        # Instead of making a call to the reservation system in a unit test,
        # which would be a bad idea, we mock the fuction used by the
        # ReservedAddressPool class to return a defined set of addresses.
        ndl.get_vms = mock.Mock(return_value=addresses)

        pool = rift.vcs.pool.ReservedAddressPool(
                username='******',
                num_addresses=len(addresses))

        # Check the starting number of addresses
        self.assertEqual(2, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Acquire 2 addresses and check the lists
        addr1 = pool.acquire()
        addr2 = pool.acquire()
        self.assertEqual(0, len(pool._addresses))
        self.assertEqual(2, len(pool._released))

        # Acquiring more than the available number of addresses will raise an
        # exception
        with self.assertRaises(rift.vcs.pool.NoAvailableAddresses):
            pool.acquire()

        # Trying to release an address that did not come from the pool will
        # raise an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release('10.0.0.3')

        # Release the addresses
        pool.release(addr1)
        pool.release(addr2)

        # Check that the pool is back in its initial state
        self.assertEqual(2, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Trying to release an address that has already been released will raise
        # an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release(addr1)
Пример #4
0
    def test_reserved_pool(self):
        addresses = [
                '10.0.0.1',
                '10.0.0.2']

        # Instead of making a call to the reservation system in a unit test,
        # which would be a bad idea, we mock the fuction used by the
        # ReservedAddressPool class to return a defined set of addresses.
        ndl.get_vms = mock.Mock(return_value=addresses)

        pool = rift.vcs.pool.ReservedAddressPool(
                username='******',
                num_addresses=len(addresses))

        # Check the starting number of addresses
        self.assertEqual(2, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Acquire 2 addresses and check the lists
        addr1 = pool.acquire()
        addr2 = pool.acquire()
        self.assertEqual(0, len(pool._addresses))
        self.assertEqual(2, len(pool._released))

        # Acquiring more than the available number of addresses will raise an
        # exception
        with self.assertRaises(rift.vcs.pool.NoAvailableAddresses):
            pool.acquire()

        # Trying to release an address that did not come from the pool will
        # raise an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release('10.0.0.3')

        # Release the addresses
        pool.release(addr1)
        pool.release(addr2)

        # Check that the pool is back in its initial state
        self.assertEqual(2, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Trying to release an address that has already been released will raise
        # an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release(addr1)
Пример #5
0
    def test_static_pool(self):
        addresses = [
                '10.0.0.1',
                '10.0.0.2']

        pool = rift.vcs.pool.StaticAddressPool(addresses)

        # Check the starting number of addresses
        self.assertEqual(2, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Acquire 2 addresses and check the lists
        addr1 = pool.acquire()
        addr2 = pool.acquire()
        self.assertEqual(0, len(pool._addresses))
        self.assertEqual(2, len(pool._released))

        # Acquiring more than the available number of addresses will raise an
        # exception
        with self.assertRaises(rift.vcs.pool.NoAvailableAddresses):
            pool.acquire()

        # Trying to release an address that did not come from the pool will
        # raise an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release('10.0.0.3')

        # Release the addresses
        pool.release(addr1)
        pool.release(addr2)

        # Check that the pool is back in its initial state
        self.assertEqual(2, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Trying to release an address that has already been released will raise
        # an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release(addr1)
Пример #6
0
    def test_static_pool(self):
        addresses = [
                '10.0.0.1',
                '10.0.0.2']

        pool = rift.vcs.pool.StaticAddressPool(addresses)

        # Check the starting number of addresses
        self.assertEqual(2, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Acquire 2 addresses and check the lists
        addr1 = pool.acquire()
        addr2 = pool.acquire()
        self.assertEqual(0, len(pool._addresses))
        self.assertEqual(2, len(pool._released))

        # Acquiring more than the available number of addresses will raise an
        # exception
        with self.assertRaises(rift.vcs.pool.NoAvailableAddresses):
            pool.acquire()

        # Trying to release an address that did not come from the pool will
        # raise an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release('10.0.0.3')

        # Release the addresses
        pool.release(addr1)
        pool.release(addr2)

        # Check that the pool is back in its initial state
        self.assertEqual(2, len(pool._addresses))
        self.assertEqual(0, len(pool._released))

        # Trying to release an address that has already been released will raise
        # an exception
        with self.assertRaises(rift.vcs.pool.UnrecognizedAddress):
            pool.release(addr1)