Ejemplo n.º 1
0
    def test_host_allocation_get_all(self):
        self.assertFalse(db_api.host_allocation_get_all())

        db_api.host_allocation_create(_get_fake_host_allocation_values(id='1'))
        db_api.host_allocation_create(_get_fake_host_allocation_values(id='2'))

        self.assertEqual(2, len(db_api.host_allocation_get_all()))
Ejemplo n.º 2
0
    def test_host_allocation_get_all(self):
        self.assertFalse(db_api.host_allocation_get_all())

        db_api.host_allocation_create(_get_fake_host_allocation_values(id='1'))
        db_api.host_allocation_create(_get_fake_host_allocation_values(id='2'))

        self.assertEqual(2, len(db_api.host_allocation_get_all()))
Ejemplo n.º 3
0
def _create_physical_lease(values=_get_fake_phys_lease_values(),
                           random=False):
    """Creating fake lease having a single physical resource."""
    if random is True:
        values = _get_fake_phys_lease_values(id=_get_fake_random_uuid(),
                                             name=_get_fake_random_uuid())
    lease = db_api.lease_create(values)
    phys_res = _get_fake_phys_reservation_values()
    for reservation in db_api.reservation_get_all_by_lease_id(lease['id']):
        allocation_values = {
            'id': _get_fake_random_uuid(),
            'compute_host_id': values['reservations'][0]['resource_id'],
            'reservation_id': reservation['id']
        }
        db_api.host_allocation_create(allocation_values)
        computehost_reservations = {
            'id': _get_fake_random_uuid(),
            'reservation_id': values['reservations'][0]['id'],
            'resource_properties': phys_res['resource_properties'],
            'hypervisor_properties': phys_res['hypervisor_properties'],
            'count_range': "{0} - {1}".format(phys_res['min'],
                                              phys_res['max'])
        }
        db_api.host_reservation_create(computehost_reservations)
    return lease
Ejemplo n.º 4
0
    def test_host_allocation_create_for_duplicated_hosts(self):
        db_api.host_allocation_create(
            _get_fake_host_allocation_values(id='1')
        )

        self.assertRaises(db_exceptions.ClimateDBDuplicateEntry,
                          db_api.host_allocation_create,
                          _get_fake_host_allocation_values(id='1'))
Ejemplo n.º 5
0
    def test_host_allocation_get_all_by_values(self):
        db_api.host_allocation_create(_get_fake_host_allocation_values(
            compute_host_id="1", reservation_id="1"))
        db_api.host_allocation_create(_get_fake_host_allocation_values(
            compute_host_id="1", reservation_id="1234"))

        self.assertEqual(2, len(db_api.host_allocation_get_all_by_values()))
        self.assertEqual(1, len(db_api.host_allocation_get_all_by_values(
            reservation_id='1234')))
Ejemplo n.º 6
0
    def test_host_allocation_get_all_by_values(self):
        db_api.host_allocation_create(
            _get_fake_host_allocation_values(compute_host_id="1",
                                             reservation_id="1"))
        db_api.host_allocation_create(
            _get_fake_host_allocation_values(compute_host_id="1",
                                             reservation_id="1234"))

        self.assertEqual(2, len(db_api.host_allocation_get_all_by_values()))
        self.assertEqual(
            1,
            len(db_api.host_allocation_get_all_by_values(
                reservation_id='1234')))
Ejemplo n.º 7
0
def _create_physical_lease(values=_get_fake_phys_lease_values(),
                           random=False):
    """Creating fake lease having a single physical resource."""
    if random is True:
        values = _get_fake_phys_lease_values(id=_get_fake_random_uuid(),
                                             name=_get_fake_random_uuid())
    lease = db_api.lease_create(values)
    for reservation in db_api.reservation_get_all_by_lease_id(lease['id']):
        allocation_values = {
            'id': _get_fake_random_uuid(),
            'compute_host_id': values['reservations'][0]['resource_id'],
            'reservation_id': reservation['id']
        }
        db_api.host_allocation_create(allocation_values)
    return lease
Ejemplo n.º 8
0
    def test_host_allocation_destroy_for_host(self):
        host_allocation = db_api.host_allocation_create(
            _get_fake_host_allocation_values()
        )
        db_api.host_allocation_destroy(host_allocation.id)

        self.assertIsNone(db_api.host_allocation_get(host_allocation.id))
Ejemplo n.º 9
0
    def test_host_allocation_update_for_host(self):
        host_allocation = db_api.host_allocation_create(
            _get_fake_host_allocation_values(compute_host_id="1",
                                             reservation_id="1"))

        new_host_allocation = db_api.host_allocation_update(
            host_allocation.id,
            _get_fake_host_allocation_values(compute_host_id="2",
                                             reservation_id="2"))

        self.assertEqual('2', new_host_allocation.compute_host_id)
        self.assertEqual('2', new_host_allocation.reservation_id)
        self.assertNotEqual(host_allocation.compute_host_id,
                            new_host_allocation.compute_host_id)
Ejemplo n.º 10
0
def _create_physical_lease(values=_get_fake_phys_lease_values(), random=False):
    """Creating fake lease having a single physical resource."""
    if random is True:
        values = _get_fake_phys_lease_values(id=_get_fake_random_uuid(),
                                             name=_get_fake_random_uuid())
    lease = db_api.lease_create(values)
    phys_res = _get_fake_phys_reservation_values()
    for reservation in db_api.reservation_get_all_by_lease_id(lease['id']):
        allocation_values = {
            'id': _get_fake_random_uuid(),
            'compute_host_id': values['reservations'][0]['resource_id'],
            'reservation_id': reservation['id']
        }
        db_api.host_allocation_create(allocation_values)
        computehost_reservations = {
            'id': _get_fake_random_uuid(),
            'reservation_id': values['reservations'][0]['id'],
            'resource_properties': phys_res['resource_properties'],
            'hypervisor_properties': phys_res['hypervisor_properties'],
            'count_range': "{0} - {1}".format(phys_res['min'], phys_res['max'])
        }
        db_api.host_reservation_create(computehost_reservations)
    return lease
Ejemplo n.º 11
0
    def test_host_allocation_update_for_host(self):
        host_allocation = db_api.host_allocation_create(
            _get_fake_host_allocation_values(
                compute_host_id="1",
                reservation_id="1"
            ))

        new_host_allocation = db_api.host_allocation_update(
            host_allocation.id,
            _get_fake_host_allocation_values(
                compute_host_id="2",
                reservation_id="2"
            ))

        self.assertEqual('2', new_host_allocation.compute_host_id)
        self.assertEqual('2', new_host_allocation.reservation_id)
        self.assertNotEqual(host_allocation.compute_host_id,
                            new_host_allocation.compute_host_id)
Ejemplo n.º 12
0
    def test_host_allocation_destroy_for_host(self):
        host_allocation = db_api.host_allocation_create(
            _get_fake_host_allocation_values())
        db_api.host_allocation_destroy(host_allocation.id)

        self.assertIsNone(db_api.host_allocation_get(host_allocation.id))
Ejemplo n.º 13
0
    def test_host_allocation_create_for_duplicated_hosts(self):
        db_api.host_allocation_create(_get_fake_host_allocation_values(id='1'))

        self.assertRaises(db_exceptions.ClimateDBDuplicateEntry,
                          db_api.host_allocation_create,
                          _get_fake_host_allocation_values(id='1'))