コード例 #1
0
ファイル: test_api.py プロジェクト: electrocucaracha/neutron
    def test_get_objects_pass_marker_obj_when_limit_and_marker_passed(self):
        ctxt = context.get_admin_context()
        model = mock.sentinel.model
        marker = mock.sentinel.marker
        limit = mock.sentinel.limit
        pager = base.Pager(marker=marker, limit=limit)

        plugin = manager.NeutronManager.get_plugin()
        with mock.patch.object(plugin, "_get_collection") as get_collection:
            with mock.patch.object(api, "get_object") as get_object:
                api.get_objects(ctxt, model, _pager=pager)
        get_object.assert_called_with(ctxt, model, id=marker)
        get_collection.assert_called_with(
            ctxt, model, mock.ANY, filters={}, limit=limit, marker_obj=get_object.return_value
        )
コード例 #2
0
ファイル: base.py プロジェクト: FedericoRessi/neutron
 def get_objects(cls, context, **kwargs):
     cls.validate_filters(**kwargs)
     db_objs = obj_db_api.get_objects(context, cls.db_model, **kwargs)
     objs = [cls(context, **db_obj) for db_obj in db_objs]
     for obj in objs:
         obj.obj_reset_changes()
     return objs
コード例 #3
0
ファイル: test_api.py プロジェクト: sebrandon1/neutron
    def test_delete_objects_removes_all_matching_objects(self):
        # create some objects with identical description
        for i in range(10):
            api.create_object(
                self.ctxt, self.model,
                {'name': 'foo%d' % i, 'description': 'bar'})
        # create some more objects with a different description
        descriptions = set()
        for i in range(10, 20):
            desc = 'bar%d' % i
            descriptions.add(desc)
            api.create_object(
                self.ctxt, self.model,
                {'name': 'foo%d' % i, 'description': desc})
        # make sure that all objects are in the database
        self.assertEqual(20, api.count(self.ctxt, self.model))
        # now delete just those with the 'bar' description
        api.delete_objects(self.ctxt, self.model, description='bar')

        # check that half of objects are gone, and remaining have expected
        # descriptions
        objs = api.get_objects(self.ctxt, self.model)
        self.assertEqual(10, len(objs))
        self.assertEqual(
            descriptions,
            {obj.description for obj in objs})
コード例 #4
0
ファイル: base.py プロジェクト: openstack/neutron
    def get_objects(cls, context, _pager=None, validate_filters=True,
                    fields=None, **kwargs):
        """Fetch a list of objects

        Fetch all results from DB and convert them to versioned objects.

        :param context:
        :param _pager: a Pager object representing advanced sorting/pagination
                       criteria
        :param validate_filters: Raises an error in case of passing an unknown
                                 filter
        :param fields: indicate which fields the caller is interested in
                       using. Note that currently this is limited to
                       avoid loading synthetic fields when possible, and
                       does not affect db queries. Default is None, which
                       is the same as []. Example: ['id', 'name']
        :param kwargs: multiple keys defined by key=value pairs
        :return: list of objects of NeutronDbObject class or empty list
        """
        if validate_filters:
            cls.validate_filters(**kwargs)
        with cls.db_context_reader(context):
            db_objs = obj_db_api.get_objects(
                cls, context, _pager=_pager, **cls.modify_fields_to_db(kwargs))

            return [cls._load_object(context, db_obj, fields=fields)
                    for db_obj in db_objs]
コード例 #5
0
    def test_get_objects_pass_marker_obj_when_limit_and_marker_passed(self):
        ctxt = context.get_admin_context()
        marker = mock.sentinel.marker
        limit = mock.sentinel.limit
        pager = base.Pager(marker=marker, limit=limit)

        with mock.patch.object(
                model_query, 'get_collection') as get_collection:
            with mock.patch.object(api, 'get_object') as get_object:
                api.get_objects(FakeObj, ctxt, _pager=pager)
        get_object.assert_called_with(FakeObj, ctxt, id=marker)
        get_collection.assert_called_with(
            ctxt, FakeObj.db_model, dict_func=None,
            filters={},
            limit=limit,
            marker_obj=get_object.return_value)
コード例 #6
0
    def get_objects(cls,
                    context,
                    _pager=None,
                    validate_filters=True,
                    fields=None,
                    **kwargs):
        """Fetch a list of objects

        Fetch all results from DB and convert them to versioned objects.

        :param context:
        :param _pager: a Pager object representing advanced sorting/pagination
                       criteria
        :param validate_filters: Raises an error in case of passing an unknown
                                 filter
        :param fields: indicate which fields the caller is interested in
                       using. Note that currently this is limited to
                       avoid loading synthetic fields when possible, and
                       does not affect db queries. Default is None, which
                       is the same as []. Example: ['id', 'name']
        :param kwargs: multiple keys defined by key=value pairs
        :return: list of objects of NeutronDbObject class or empty list
        """
        if validate_filters:
            cls.validate_filters(**kwargs)
        with cls.db_context_reader(context):
            db_objs = obj_db_api.get_objects(cls,
                                             context,
                                             _pager=_pager,
                                             **cls.modify_fields_to_db(kwargs))

            return [
                cls._load_object(context, db_obj, fields=fields)
                for db_obj in db_objs
            ]
コード例 #7
0
ファイル: test_api.py プロジェクト: rohitmalaga/neutron
    def test_delete_objects_removes_all_matching_objects(self):
        # create some objects with identical description
        for i in range(10):
            api.create_object(self.ctxt, self.model, {
                'name': 'foo%d' % i,
                'description': 'bar'
            })
        # create some more objects with a different description
        descriptions = set()
        for i in range(10, 20):
            desc = 'bar%d' % i
            descriptions.add(desc)
            api.create_object(self.ctxt, self.model, {
                'name': 'foo%d' % i,
                'description': desc
            })
        # make sure that all objects are in the database
        self.assertEqual(20, api.count(self.ctxt, self.model))
        # now delete just those with the 'bar' description
        api.delete_objects(self.ctxt, self.model, description='bar')

        # check that half of objects are gone, and remaining have expected
        # descriptions
        objs = api.get_objects(self.ctxt, self.model)
        self.assertEqual(10, len(objs))
        self.assertEqual(descriptions, {obj.description for obj in objs})
コード例 #8
0
ファイル: base.py プロジェクト: kitch/neutron
 def get_objects(cls, context, **kwargs):
     cls.validate_filters(**kwargs)
     db_objs = obj_db_api.get_objects(context, cls.db_model, **kwargs)
     objs = [cls(context, **db_obj) for db_obj in db_objs]
     for obj in objs:
         obj.obj_reset_changes()
     return objs
コード例 #9
0
 def test_get_objects_with_None_value_in_filters(self):
     obj = api.create_object(self.obj_cls, self.ctxt, {'name': 'foo'})
     new_objs = api.get_objects(self.obj_cls,
                                self.ctxt,
                                name='foo',
                                status=None)
     self.assertEqual(obj, new_objs[0])
コード例 #10
0
ファイル: test_api.py プロジェクト: igordcard/neutron
    def test_get_objects_pass_marker_obj_when_limit_and_marker_passed(self):
        ctxt = context.get_admin_context()
        marker = mock.sentinel.marker
        limit = mock.sentinel.limit
        pager = base.Pager(marker=marker, limit=limit)

        with mock.patch.object(
                model_query, 'get_collection') as get_collection:
            with mock.patch.object(api, 'get_object') as get_object:
                api.get_objects(FakeObj, ctxt, _pager=pager)
        get_object.assert_called_with(FakeObj, ctxt, id=marker)
        get_collection.assert_called_with(
            ctxt, FakeObj.db_model, dict_func=None,
            filters={},
            limit=limit,
            marker_obj=get_object.return_value)
コード例 #11
0
ファイル: base.py プロジェクト: zhunzhong/neutron
    def get_objects(cls,
                    context,
                    _pager=None,
                    validate_filters=True,
                    **kwargs):
        """Fetch a list of objects

        Fetch all results from DB and convert them to versioned objects.

        :param context:
        :param _pager: a Pager object representing advanced sorting/pagination
                       criteria
        :param validate_filters: Raises an error in case of passing an unknown
                                 filter
        :param kwargs: multiple keys defined by key=value pairs
        :return: list of objects of NeutronDbObject class or empty list
        """
        if validate_filters:
            cls.validate_filters(**kwargs)
        with cls.db_context_reader(context):
            db_objs = obj_db_api.get_objects(cls,
                                             context,
                                             _pager=_pager,
                                             **cls.modify_fields_to_db(kwargs))
            return [cls._load_object(context, db_obj) for db_obj in db_objs]
コード例 #12
0
 def get_objects(cls, context, **kwargs):
     cls.validate_filters(**kwargs)
     db_objs = obj_db_api.get_objects(context, cls.db_model, **kwargs)
     result = []
     for db_obj in db_objs:
         obj = cls(context, **cls.modify_fields_from_db(db_obj))
         obj.obj_reset_changes()
         result.append(obj)
     return result
コード例 #13
0
ファイル: test_api.py プロジェクト: rohitmalaga/neutron
    def test_get_objects_pass_marker_obj_when_limit_and_marker_passed(self):
        ctxt = context.get_admin_context()
        model = mock.sentinel.model
        marker = mock.sentinel.marker
        limit = mock.sentinel.limit
        pager = base.Pager(marker=marker, limit=limit)

        plugin = directory.get_plugin()
        with mock.patch.object(plugin, '_get_collection') as get_collection:
            with mock.patch.object(api, 'get_object') as get_object:
                api.get_objects(ctxt, model, _pager=pager)
        get_object.assert_called_with(ctxt, model, id=marker)
        get_collection.assert_called_with(ctxt,
                                          model,
                                          mock.ANY,
                                          filters={},
                                          limit=limit,
                                          marker_obj=get_object.return_value)
コード例 #14
0
ファイル: test_api.py プロジェクト: igordcard/neutron
    def test_get_objects_with_string_matching_filters_starts(self):
        obj1 = api.create_object(self.obj_cls, self.ctxt, {'name': 'pre_obj1'})
        obj2 = api.create_object(self.obj_cls, self.ctxt, {'name': 'pre_obj2'})
        obj3 = api.create_object(self.obj_cls, self.ctxt, {'name': 'obj_3'})

        objs = api.get_objects(
            self.obj_cls, self.ctxt, name=obj_utils.StringStarts('pre'))
        self.assertEqual(2, len(objs))
        self.assertIn(obj1, objs)
        self.assertIn(obj2, objs)
        self.assertNotIn(obj3, objs)
コード例 #15
0
ファイル: test_api.py プロジェクト: eayunstack/neutron
    def test_get_objects_with_string_matching_filters_ends(self):
        obj1 = api.create_object(self.ctxt, self.model, {'name': 'obj1_end'})
        obj2 = api.create_object(self.ctxt, self.model, {'name': 'obj2_end'})
        obj3 = api.create_object(self.ctxt, self.model, {'name': 'obj_3'})

        objs = api.get_objects(
            self.ctxt, self.model, name=obj_utils.StringEnds('end'))
        self.assertEqual(2, len(objs))
        self.assertIn(obj1, objs)
        self.assertIn(obj2, objs)
        self.assertNotIn(obj3, objs)
コード例 #16
0
    def test_get_objects_with_string_matching_filters_ends(self):
        obj1 = api.create_object(self.obj_cls, self.ctxt, {'name': 'obj1_end'})
        obj2 = api.create_object(self.obj_cls, self.ctxt, {'name': 'obj2_end'})
        obj3 = api.create_object(self.obj_cls, self.ctxt, {'name': 'obj_3'})

        objs = api.get_objects(
            self.obj_cls, self.ctxt, name=obj_utils.StringEnds('end'))
        self.assertEqual(2, len(objs))
        self.assertIn(obj1, objs)
        self.assertIn(obj2, objs)
        self.assertNotIn(obj3, objs)
コード例 #17
0
    def test_get_objects_with_string_matching_filters_ends(self):
        obj1 = api.create_object(self.obj_cls, self.ctxt, {'name': 'obj1_end'})
        obj2 = api.create_object(self.obj_cls, self.ctxt, {'name': 'obj2_end'})
        api.create_object(self.obj_cls, self.ctxt, {'name': 'obj_3'})

        objs = api.get_objects(
            self.obj_cls, self.ctxt, name=obj_utils.StringEnds('end'),
            _pager=base.Pager(sorts=[('name', True)]))
        self.assertEqual(2, len(objs))
        self._compare_objs(obj1, objs[0])
        self._compare_objs(obj2, objs[1])
コード例 #18
0
ファイル: test_api.py プロジェクト: zxt2012bs/neutron
    def test_get_objects_with_string_matching_filters_starts(self):
        obj1 = api.create_object(self.ctxt, self.model, {'name': 'pre_obj1'})
        obj2 = api.create_object(self.ctxt, self.model, {'name': 'pre_obj2'})
        obj3 = api.create_object(self.ctxt, self.model, {'name': 'obj_3'})

        objs = api.get_objects(self.ctxt,
                               self.model,
                               name=obj_utils.StringStarts('pre'))
        self.assertEqual(2, len(objs))
        self.assertIn(obj1, objs)
        self.assertIn(obj2, objs)
        self.assertNotIn(obj3, objs)
コード例 #19
0
ファイル: base.py プロジェクト: ISCAS-VDI/neutron-base
    def get_objects(cls, context, _pager=None, **kwargs):
        """
        Fetch objects from DB and convert them to versioned objects.

        :param context:
        :param _pager: a Pager object representing advanced sorting/pagination
                       criteria
        :param kwargs: multiple keys defined by key=value pairs
        :return: list of objects of NeutronDbObject class
        """
        cls.validate_filters(**kwargs)
        with db_api.autonested_transaction(context.session):
            db_objs = obj_db_api.get_objects(
                context, cls.db_model, _pager=_pager, **kwargs)
            return [cls._load_object(context, db_obj) for db_obj in db_objs]
コード例 #20
0
    def get_objects(cls, context, _pager=None, **kwargs):
        """
        Fetch objects from DB and convert them to versioned objects.

        :param context:
        :param _pager: a Pager object representing advanced sorting/pagination
                       criteria
        :param kwargs: multiple keys defined by key=value pairs
        :return: list of objects of NeutronDbObject class
        """
        cls.validate_filters(**kwargs)
        with db_api.autonested_transaction(context.session):
            db_objs = obj_db_api.get_objects(context,
                                             cls.db_model,
                                             _pager=_pager,
                                             **kwargs)
            return [cls._load_object(context, db_obj) for db_obj in db_objs]
コード例 #21
0
ファイル: base.py プロジェクト: mmalchuk/openstack-neutron
    def get_objects(cls, context, _pager=None, validate_filters=True,
                    **kwargs):
        """
        Fetch all results from DB and convert them to versioned objects.

        :param context:
        :param _pager: a Pager object representing advanced sorting/pagination
                       criteria
        :param validate_filters: Raises an error in case of passing an unknown
                                 filter
        :param kwargs: multiple keys defined by key=value pairs
        :return: list of objects of NeutronDbObject class or empty list
        """
        if validate_filters:
            cls.validate_filters(**kwargs)
        with cls.db_context_reader(context):
            db_objs = obj_db_api.get_objects(
                cls, context, _pager=_pager, **cls.modify_fields_to_db(kwargs))
            return [cls._load_object(context, db_obj) for db_obj in db_objs]
コード例 #22
0
ファイル: base.py プロジェクト: vpnsquad/neutron
 def get_objects(cls, context, **kwargs):
     cls.validate_filters(**kwargs)
     with db_api.autonested_transaction(context.session):
         db_objs = obj_db_api.get_objects(context, cls.db_model, **kwargs)
         return [cls._load_object(context, db_obj) for db_obj in db_objs]
コード例 #23
0
ファイル: test_api.py プロジェクト: eayunstack/neutron
 def test_get_objects_with_None_value_in_filters(self):
     obj = api.create_object(self.ctxt, self.model, {'name': 'foo'})
     new_objs = api.get_objects(
         self.ctxt, self.model, name='foo', status=None)
     self.assertEqual(obj, new_objs[0])
コード例 #24
0
ファイル: base.py プロジェクト: sanakhan-libre/neutron
 def get_objects(cls, context, **kwargs):
     cls.validate_filters(**kwargs)
     with db_api.autonested_transaction(context.session):
         db_objs = obj_db_api.get_objects(context, cls.db_model, **kwargs)
         return [cls._load_object(context, db_obj) for db_obj in db_objs]