예제 #1
0
 def test_list_resource_classes(self):
     names = []
     for i in range(1, 6):
         resource = utils.create_test_resource_class(
             context=self.context,
             uuid=uuidutils.generate_uuid(),
             name='class' + str(i))
         names.append(str(resource['name']))
     res = dbapi.list_resource_classes(self.context)
     res_names = [r.name for r in res]
     self.assertEqual(sorted(names), sorted(res_names))
예제 #2
0
 def test_list_resource_classes(self):
     names = []
     for i in range(1, 6):
         resource = utils.create_test_resource_class(
             context=self.context,
             uuid=uuidutils.generate_uuid(),
             name='class' + str(i))
         names.append(six.text_type(resource['name']))
     res = dbapi.list_resource_classes(self.context)
     res_names = [r.name for r in res]
     self.assertEqual(sorted(names), sorted(res_names))
예제 #3
0
 def test_list_resource_classes_sorted(self, mock_write, mock_read):
     names = []
     resource_classes = []
     mock_read.side_effect = etcd.EtcdKeyNotFound
     for i in range(1, 6):
         res_class = utils.create_test_resource_class(
             context=self.context, name='class'+str(i))
         resource_classes.append(res_class.as_dict())
         names.append(six.text_type(res_class['name']))
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
         resource_classes)
     res = dbapi.list_resource_classes(self.context, sort_key='name')
     res_names = [r.name for r in res]
     self.assertEqual(sorted(names), res_names)
예제 #4
0
    def test_list_resource_classes_sorted(self):
        names = []
        for i in range(5):
            resource = utils.create_test_resource_class(
                context=self.context,
                uuid=uuidutils.generate_uuid(),
                name='class' + str(i))
            names.append(str(resource.name))
        res = dbapi.list_resource_classes(self.context, sort_key='name')
        res_names = [r.name for r in res]
        self.assertEqual(sorted(names), res_names)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_resource_classes,
                          self.context,
                          sort_key='foo')
예제 #5
0
    def test_list_resource_classes_sorted(self):
        names = []
        for i in range(5):
            resource = utils.create_test_resource_class(
                context=self.context,
                uuid=uuidutils.generate_uuid(),
                name='class' + str(i))
            names.append(six.text_type(resource.name))
        res = dbapi.list_resource_classes(self.context, sort_key='name')
        res_names = [r.name for r in res]
        self.assertEqual(sorted(names), res_names)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_resource_classes,
                          self.context,
                          sort_key='foo')
예제 #6
0
    def list(cls, context, limit=None, marker=None, sort_key=None,
             sort_dir=None):
        """Return a list of ResourceClass 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".
        :returns: a list of :class:`ResourceClass` object.

        """
        db_resources = dbapi.list_resource_classes(
            context, limit=limit, marker=marker, sort_key=sort_key,
            sort_dir=sort_dir)
        return ResourceClass._from_db_object_list(
            db_resources, cls, context)