Esempio n. 1
0
    def _get_share_group_types(self, req):
        """Helper function that returns a list of share group type dicts."""
        filters = {}
        context = req.environ['manila.context']
        if context.is_admin:
            # Only admin has query access to all group types
            filters['is_public'] = common.parse_is_public(
                req.params.get('is_public'))
        else:
            filters['is_public'] = True

        group_specs = req.params.get('group_specs', {})
        group_specs_disallowed = (req.api_version_request <
                                  api_version.APIVersionRequest("2.66"))

        if group_specs and group_specs_disallowed:
            msg = _("Filter by 'group_specs' is not supported by this "
                    "microversion. Use 2.66 or greater microversion to "
                    "be able to use filter search by 'group_specs.")
            raise webob.exc.HTTPBadRequest(explanation=msg)
        elif group_specs:
            filters['group_specs'] = ast.literal_eval(group_specs)

        limited_types = share_group_types.get_all(
            context, search_opts=filters).values()
        return list(limited_types)
Esempio n. 2
0
    def test_get_all_types_search(self):
        share_group_type = self.fake_type_w_extra
        search_filter = {"group_specs": {"gold": "True"}, 'is_public': True}
        self.mock_object(db, 'share_group_type_get_all',
                         mock.Mock(return_value=share_group_type))

        returned_type = share_group_types.get_all(self.context,
                                                  search_opts=search_filter)

        db.share_group_type_get_all.assert_called_once_with(
            mock.ANY, 0, filters={'is_public': True})
        self.assertItemsEqual(share_group_type, returned_type)
        search_filter = {"group_specs": {"gold": "False"}}
        returned_type = share_group_types.get_all(self.context,
                                                  search_opts=search_filter)
        self.assertEqual({}, returned_type)
Esempio n. 3
0
    def test_get_all_types(self, share_group_type):
        self.mock_object(
            db, 'share_group_type_get_all',
            mock.Mock(return_value=copy.deepcopy(share_group_type)))

        returned_type = share_group_types.get_all(self.context)

        self.assertItemsEqual(share_group_type, returned_type)
    def test_get_all_types(self, share_group_type):
        self.mock_object(
            db, 'share_group_type_get_all',
            mock.Mock(return_value=copy.deepcopy(share_group_type)))

        returned_type = share_group_types.get_all(self.context)

        self.assertItemsEqual(share_group_type, returned_type)
    def test_get_all_types_search(self):
        share_group_type = self.fake_type_w_extra
        search_filter = {"group_specs": {"gold": "True"}, 'is_public': True}
        self.mock_object(
            db, 'share_group_type_get_all',
            mock.Mock(return_value=share_group_type))

        returned_type = share_group_types.get_all(
            self.context, search_opts=search_filter)

        db.share_group_type_get_all.assert_called_once_with(
            mock.ANY, 0, filters={'is_public': True})
        self.assertItemsEqual(share_group_type, returned_type)
        search_filter = {"group_specs": {"gold": "False"}}
        returned_type = share_group_types.get_all(
            self.context, search_opts=search_filter)
        self.assertEqual({}, returned_type)
Esempio n. 6
0
 def _get_share_group_types(self, req):
     """Helper function that returns a list of share group type dicts."""
     filters = {}
     context = req.environ['manila.context']
     if context.is_admin:
         # Only admin has query access to all group types
         filters['is_public'] = self._parse_is_public(
             req.params.get('is_public'))
     else:
         filters['is_public'] = True
     limited_types = share_group_types.get_all(
         context, search_opts=filters).values()
     return list(limited_types)
Esempio n. 7
0
 def _get_share_group_types(self, req):
     """Helper function that returns a list of share group type dicts."""
     filters = {}
     context = req.environ['manila.context']
     if context.is_admin:
         # Only admin has query access to all group types
         filters['is_public'] = self._parse_is_public(
             req.params.get('is_public'))
     else:
         filters['is_public'] = True
     limited_types = share_group_types.get_all(
         context, search_opts=filters).values()
     return list(limited_types)