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)
def setUp(self): self.sysinfo = rift.vcs.SystemInfo(colonies=[], mode='pci', collapsed=True, zookeeper=None) # Define the topology self.sysinfo.subcomponents = [ rift.vcs.Colony(clusters=[ rift.vcs.Cluster(virtual_machines=[ rift.vcs.VirtualMachine(), rift.vcs.VirtualMachine() ]), rift.vcs.Cluster(virtual_machines=[ rift.vcs.VirtualMachine(), rift.vcs.VirtualMachine(), rift.vcs.VirtualMachine() ]) ]) ] # Assign identifiers to each component for index, component in enumerate(self.sysinfo.list_by_class(object)): component.uid = index + 1 # Assign IP addresses to each of the virtual machines pool = rift.vcs.pool.FakeAddressPool() for vm in self.sysinfo.list_by_class(rift.vcs.VirtualMachine): vm.ip = pool.acquire()
def setUp(self): self.sysinfo = rift.vcs.SystemInfo( colonies=[], mode='pci', collapsed=True, zookeeper=None) # Define the topology self.sysinfo.subcomponents = [ rift.vcs.Colony(clusters=[ rift.vcs.Cluster(virtual_machines=[ rift.vcs.VirtualMachine(), rift.vcs.VirtualMachine() ]), rift.vcs.Cluster(virtual_machines=[ rift.vcs.VirtualMachine(), rift.vcs.VirtualMachine(), rift.vcs.VirtualMachine() ]) ]) ] # Assign identifiers to each component for index, component in enumerate(self.sysinfo.list_by_class(object)): component.uid = index + 1 # Assign IP addresses to each of the virtual machines pool = rift.vcs.pool.FakeAddressPool() for vm in self.sysinfo.list_by_class(rift.vcs.VirtualMachine): vm.ip = pool.acquire()
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)
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)
def test_ip_addresses(self): """ This test checks that the IP addresses returned by the system info object are consistent with the addresses that are assigned to the virtual machines in the system. """ # First, create an address pool and then assign an IP to each virtual # machine in the system. pool = rift.vcs.pool.FakeAddressPool() for vm in self.sysinfo.list_by_class(rift.vcs.VirtualMachine): vm.ip = pool.acquire() # Retrieve the list of IP addresses ip_addresses = self.sysinfo.ip_addresses # Check that we have recovered the correct addresses self.assertEqual(3, len(ip_addresses)) for ip in pool._released: self.assertIn(ip, ip_addresses)