Esempio n. 1
0
    def test_list_resource_providers_with_filters(self):
        provider1 = utils.create_test_resource_provider(
            name='provider-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        provider2 = utils.create_test_resource_provider(
            name='provider-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        res = dbapi.list_resource_providers(self.context,
                                            filters={'name': 'provider-one'})
        self.assertEqual([provider1.id], [r.id for r in res])

        res = dbapi.list_resource_providers(self.context,
                                            filters={'name': 'provider-two'})
        self.assertEqual([provider2.id], [r.id for r in res])

        res = dbapi.list_resource_providers(self.context,
                                            filters={'name': 'bad-provider'})
        self.assertEqual([], [r.id for r in res])

        res = dbapi.list_resource_providers(self.context,
                                            filters={'name': provider1.name})
        self.assertEqual([provider1.id], [r.id for r in res])
    def test_list_resource_providers_with_filters(self):
        provider1 = utils.create_test_resource_provider(
            name='provider-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        provider2 = utils.create_test_resource_provider(
            name='provider-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        res = dbapi.list_resource_providers(
            self.context, filters={'name': 'provider-one'})
        self.assertEqual([provider1.id], [r.id for r in res])

        res = dbapi.list_resource_providers(
            self.context, filters={'name': 'provider-two'})
        self.assertEqual([provider2.id], [r.id for r in res])

        res = dbapi.list_resource_providers(
            self.context, filters={'name': 'bad-provider'})
        self.assertEqual([], [r.id for r in res])

        res = dbapi.list_resource_providers(
            self.context,
            filters={'name': provider1.name})
        self.assertEqual([provider1.id], [r.id for r in res])
Esempio n. 3
0
    def list(cls,
             context,
             limit=None,
             marker=None,
             sort_key=None,
             sort_dir=None,
             filters=None):
        """Return a list of ResourceProvider objects.

        :param context: Security context.
        :param limit: maximum number of resources to return in a single result.
        :param marker: pagination marker for large data sets.
        :param sort_key: column to sort results by.
        :param sort_dir: direction to sort. "asc" or "desc".
        :param filters: filters when list resource providers.
        :returns: a list of :class:`ResourceProvider` object.

        """
        db_providers = dbapi.list_resource_providers(context,
                                                     limit=limit,
                                                     marker=marker,
                                                     sort_key=sort_key,
                                                     sort_dir=sort_dir,
                                                     filters=filters)
        return ResourceProvider._from_db_object_list(db_providers, cls,
                                                     context)
Esempio n. 4
0
 def test_list_resource_providers(self):
     uuids = []
     for i in range(1, 6):
         provider = utils.create_test_resource_provider(
             uuid=uuidutils.generate_uuid(),
             context=self.context,
             name='provider' + str(i))
         uuids.append(six.text_type(provider['uuid']))
     res = dbapi.list_resource_providers(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), sorted(res_uuids))
 def test_list_resource_providers(self):
     uuids = []
     for i in range(1, 6):
         provider = utils.create_test_resource_provider(
             uuid=uuidutils.generate_uuid(),
             context=self.context,
             name='provider' + str(i))
         uuids.append(six.text_type(provider['uuid']))
     res = dbapi.list_resource_providers(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), sorted(res_uuids))
Esempio n. 6
0
    def test_list_resource_providers_sorted(self):
        uuids = []
        for i in range(5):
            provider = utils.create_test_resource_provider(
                uuid=uuidutils.generate_uuid(),
                context=self.context,
                name='provider' + str(i))
            uuids.append(six.text_type(provider.uuid))
        res = dbapi.list_resource_providers(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_resource_providers,
                          self.context,
                          sort_key='foo')
    def test_list_resource_providers_sorted(self):
        uuids = []
        for i in range(5):
            provider = utils.create_test_resource_provider(
                uuid=uuidutils.generate_uuid(),
                context=self.context,
                name='provider' + str(i))
            uuids.append(six.text_type(provider.uuid))
        res = dbapi.list_resource_providers(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_resource_providers,
                          self.context,
                          sort_key='foo')
Esempio n. 8
0
    def list(cls, context, limit=None, marker=None,
             sort_key=None, sort_dir=None, filters=None):
        """Return a list of ResourceProvider objects.

        :param context: Security context.
        :param limit: maximum number of resources to return in a single result.
        :param marker: pagination marker for large data sets.
        :param sort_key: column to sort results by.
        :param sort_dir: direction to sort. "asc" or "desc".
        :param filters: filters when list resource providers.
        :returns: a list of :class:`ResourceProvider` object.

        """
        db_providers = dbapi.list_resource_providers(
            context, limit=limit, marker=marker, sort_key=sort_key,
            sort_dir=sort_dir, filters=filters)
        return ResourceProvider._from_db_object_list(
            db_providers, cls, context)