Exemple #1
0
    def test_get_reservations_by_host_id(self):
        self._setup_leases()

        self.check_reservation([], 'r1', '2030-01-01 07:00',
                               '2030-01-01 08:59')

        ret = db_api.reservation_get_all_by_lease_id('lease1')
        self.check_reservation(ret, 'r1', '2030-01-01 08:00',
                               '2030-01-01 10:00')

        ret = db_api.reservation_get_all_by_lease_id('lease1')
        ret.extend(db_api.reservation_get_all_by_lease_id('lease3'))
        self.check_reservation(ret, 'r1', '2030-01-01 08:00',
                               '2030-01-01 15:30')

        self.check_reservation([], 'r4', '2030-01-01 07:00',
                               '2030-01-01 15:00')
Exemple #2
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': reservation['resource_id'],
            'reservation_id': reservation['id']
        }
        db_api.host_allocation_create(allocation_values)
    return lease
Exemple #3
0
    def test_get_reservation_allocations_by_host_ids_with_reservation_id(self):
        self._setup_leases()
        reservation1 = db_api.reservation_get_all_by_lease_id('lease1')[0]

        # query allocations of lease1
        expected = [
            self._create_allocation_tuple('lease1'),
        ]
        ret = db_utils.get_reservation_allocations_by_host_ids(
            ['r1', 'r2'],
            '2030-01-01 08:00',
            '2030-01-01 15:00',
            reservation_id=reservation1['id'])

        self.assertListEqual(expected, ret)
    def test_get_reservation_allocations_by_host_ids_with_reservation_id(self):
        def create_allocation_tuple(lease_id):
            reservation = db_api.reservation_get_all_by_lease_id(lease_id)[0]
            allocation = db_api.host_allocation_get_all_by_values(
                reservation_id=reservation['id'])[0]
            return (reservation['id'], allocation['id'])

        self._setup_leases()
        reservation1 = db_api.reservation_get_all_by_lease_id('lease1')[0]

        # query allocations of lease1
        expected = [
            create_allocation_tuple('lease1'),
        ]
        ret = db_utils.get_reservation_allocations_by_host_ids(
            ['r1', 'r2'],
            '2030-01-01 08:00',
            '2030-01-01 15:00',
            reservation_id=reservation1['id'])

        self.assertListEqual(expected, [(r['id'], a['id']) for r, a in ret])
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
Exemple #6
0
 def _create_allocation_tuple(self, lease_id):
     reservation = db_api.reservation_get_all_by_lease_id(lease_id)[0]
     allocation = db_api.host_allocation_get_all_by_values(
         reservation_id=reservation['id'])[0]
     return (reservation['id'], reservation['lease_id'],
             allocation['compute_host_id'])
 def create_allocation_tuple(lease_id):
     reservation = db_api.reservation_get_all_by_lease_id(lease_id)[0]
     allocation = db_api.host_allocation_get_all_by_values(
         reservation_id=reservation['id'])[0]
     return (reservation['id'], allocation['id'])