Exemplo n.º 1
0
    def test_create_leases_with_duplicated_reservation(self):
        """Check duplicated reservation create

        Create two leases with a duplicated reservation,
        and checks it raises an error.
        """
        lease_values = _get_fake_phys_lease_values()

        db_api.lease_create(lease_values)

        lease_values['id'] = _get_fake_random_uuid()
        lease_values['name'] = 'duplicated_reservation'

        self.assertRaises(db_exceptions.BlazarDBDuplicateEntry,
                          db_api.lease_create, lease_values)
Exemplo n.º 2
0
    def test_create_lease_with_event(self):
        """Create a lease including a fake event and check all tables."""

        lease = _get_fake_phys_lease_values()
        lease['events'].append(_get_fake_event_values(lease_id=lease['id']))
        result = db_api.lease_create(lease)
        self.assertEqual(result['name'], _get_fake_phys_lease_values()['name'])
        self.assertEqual(1, len(db_api.event_get_all()))
Exemplo n.º 3
0
    def test_create_leases_with_duplicated_event(self):
        """Check duplicated event create

        Create two leases with a duplicated event,
        and checks it raises an error.
        """
        lease_values = _get_fake_phys_lease_values()
        lease_values['events'] = [_get_fake_event_values()]

        db_api.lease_create(lease_values)

        lease_values['id'] = _get_fake_random_uuid()
        lease_values['name'] = 'duplicated_event'
        lease_values['reservations'][0]['id'] = _get_fake_random_uuid()

        self.assertRaises(db_exceptions.BlazarDBDuplicateEntry,
                          db_api.lease_create, lease_values)
Exemplo n.º 4
0
    def test_create_phys_lease(self):
        """Check physical lease create

        Create a physical lease and verify that all tables have been
        populated.
        """

        result = db_api.lease_create(_get_fake_phys_lease_values())
        self.assertEqual(result['name'], _get_fake_phys_lease_values()['name'])
        self.assertEqual(0, len(db_api.event_get_all()))
        self.assertEqual(1, len(db_api.reservation_get_all()))
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
0
    def test_create_duplicate_leases(self):
        """Create two leases with same names, and checks it raises an error."""

        db_api.lease_create(_get_fake_phys_lease_values())
        self.assertRaises(db_exceptions.BlazarDBDuplicateEntry,
                          db_api.lease_create, _get_fake_phys_lease_values())
Exemplo n.º 8
0
 def test_model_query(self):
     lease = db_api.lease_create(_get_fake_phys_lease_values())
     query = db_api.model_query(models.Lease)
     self.assertEqual([lease.to_dict()], [l.to_dict() for l in query.all()])