def test_create_and_delete_ipv4_allocations(self):
        '''Creates a basic IPv4 allocation'''
        datastore = self.__class__.datastore

        # First, get our machine and create an allocation
        machine = Machine('TestMachine', self.datastore)
        ipv4_network = datastore.get_network_by_name('LOC')
        allocation = ipv4_network.create_new_allocation(machine)

        # NetworkBlock should assign us 10.0.2.1/32
        self.assertEquals(allocation.get_allocation_cidr(), '10.0.2.1/32', 'Did not get 10.0.2.1')

        # Check that the machine and NetworkBlock objects have our list
        machine_allocations = machine.list_allocations()
        if not allocation in machine_allocations:
            self.fail ("Allocation not found in list_allocations")

        #unusued_ip = allocation.get_unused_ip()
        #allocation.mark_ip_as_reserved(unusued_ip)

        # Now try to remove it
        allocation.remove()
Example #2
0
    def testBlockAllocations(self):
        '''Tests that blocks can be allocated to machines, and IP statuses set'''

        # NOTE: this relays on the behavior of MySQL AUTO_INCREMENT to predict IDs

        # Test the machine class here
        machine = Machine('TestMachine', self.datastore)
        self.assertEquals(machine.get_id(), 1)
        self.assertEquals(machine.get_name(), 'TestMachine')

        machine = Machine('TestMachine3', self.datastore)
        self.assertEquals(machine.get_id(), 3)
        self.assertEquals(machine.get_name(), 'TestMachine3')

        machine = Machine('TestMachine2', self.datastore)
        self.assertEquals(machine.get_id(), 2)
        self.assertEquals(machine.get_name(), 'TestMachine2')

        machine = Machine('TestMachine', self.datastore)
        networks = self.__class__.datastore.get_networks()
        network = networks.pop()
        allocation = network.create_new_allocation(machine)
        unusued_ip = allocation.get_unused_ip()
        allocation.mark_ip_as_reserved(unusued_ip)