Beispiel #1
0
    def test_list_inventories_with_filters(self):
        provider = utils.create_test_resource_provider(
            context=self.context)
        inventory1 = utils.create_test_inventory(
            total=10,
            resource_provider_id=provider.id,
            resource_class_id=1,
            context=self.context)
        inventory2 = utils.create_test_inventory(
            total=20,
            resource_provider_id=provider.id,
            resource_class_id=2,
            context=self.context)

        res = dbapi.list_inventories(
            self.context, filters={'total': 10})
        self.assertEqual([inventory1.id], [r.id for r in res])

        res = dbapi.list_inventories(
            self.context, filters={'total': 20})
        self.assertEqual([inventory2.id], [r.id for r in res])

        res = dbapi.list_inventories(
            self.context, filters={'total': 11111})
        self.assertEqual([], [r.id for r in res])

        res = dbapi.list_inventories(
            self.context,
            filters={'total': inventory1.total})
        self.assertEqual([inventory1.id], [r.id for r in res])
Beispiel #2
0
 def test_create_inventory_already_exists(self):
     utils.create_test_inventory(
         context=self.context, resource_provider_id=1, resource_class_id=1)
     fields = {'resource_provider_id': 1, 'resource_class_id': 1}
     with self.assertRaisesRegex(exception.UniqueConstraintViolated,
                                 'A resource with %s *' % fields):
         utils.create_test_inventory(
             context=self.context, resource_provider_id=1,
             resource_class_id=1)
Beispiel #3
0
 def test_get_inventory_by_id(self):
     provider = utils.create_test_resource_provider(
         context=self.context)
     inventory = utils.create_test_inventory(
         resource_provider_id=provider.id, context=self.context)
     res = dbapi.get_inventory(self.context, inventory.id)
     self.assertEqual(inventory.id, res.id)
Beispiel #4
0
    def test_update_inventory(self):
        inventory = utils.create_test_inventory(context=self.context)
        old_total = inventory.total
        new_total = 100
        self.assertNotEqual(old_total, new_total)

        res = dbapi.update_inventory(self.context, inventory.id,
                                     {'total': new_total})
        self.assertEqual(new_total, res.total)
Beispiel #5
0
 def test_list_inventories(self):
     totals = []
     for i in range(1, 6):
         provider = utils.create_test_resource_provider(
             id=i, uuid=uuidutils.generate_uuid(), context=self.context)
         inventory = utils.create_test_inventory(
             id=i,
             resource_provider_id=provider.id,
             total=i,
             context=self.context)
         totals.append(inventory['total'])
     res = dbapi.list_inventories(self.context)
     res_totals = [r.total for r in res]
     self.assertEqual(sorted(totals), sorted(res_totals))
Beispiel #6
0
 def test_list_inventories(self):
     totals = []
     for i in range(1, 6):
         provider = utils.create_test_resource_provider(
             id=i,
             uuid=uuidutils.generate_uuid(),
             context=self.context)
         inventory = utils.create_test_inventory(
             id=i,
             resource_provider_id=provider.id,
             total=i,
             context=self.context)
         totals.append(inventory['total'])
     res = dbapi.list_inventories(self.context)
     res_totals = [r.total for r in res]
     self.assertEqual(sorted(totals), sorted(res_totals))
Beispiel #7
0
    def test_list_inventories_sorted(self):
        totals = []
        for i in range(5):
            provider = utils.create_test_resource_provider(
                id=i, uuid=uuidutils.generate_uuid(), context=self.context)
            inventory = utils.create_test_inventory(
                id=i,
                resource_provider_id=provider.id,
                total=10 - i,
                context=self.context)
            totals.append(inventory['total'])
        res = dbapi.list_inventories(self.context, sort_key='total')
        res_totals = [r.total for r in res]
        self.assertEqual(sorted(totals), res_totals)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_inventories,
                          self.context,
                          sort_key='foo')
Beispiel #8
0
    def test_list_inventories_sorted(self):
        totals = []
        for i in range(5):
            provider = utils.create_test_resource_provider(
                id=i,
                uuid=uuidutils.generate_uuid(),
                context=self.context)
            inventory = utils.create_test_inventory(
                id=i,
                resource_provider_id=provider.id,
                total=10 - i,
                context=self.context)
            totals.append(inventory['total'])
        res = dbapi.list_inventories(self.context,
                                     sort_key='total')
        res_totals = [r.total for r in res]
        self.assertEqual(sorted(totals), res_totals)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_inventories,
                          self.context,
                          sort_key='foo')
Beispiel #9
0
 def test_create_inventory(self):
     utils.create_test_inventory(context=self.context)
Beispiel #10
0
 def test_destroy_inventory_by_id(self):
     inventory = utils.create_test_inventory(context=self.context)
     dbapi.destroy_inventory(self.context, inventory.id)
     self.assertRaises(exception.InventoryNotFound,
                       dbapi.get_inventory,
                       self.context, inventory.id)