def _create(self, req, body): """Creates a new share group type.""" context = req.environ['manila.context'] if not self.is_valid_body(body, 'share_group_type'): raise webob.exc.HTTPBadRequest() share_group_type = body['share_group_type'] name = share_group_type.get('name') specs = share_group_type.get('group_specs', {}) is_public = share_group_type.get('is_public', True) if not share_group_type.get('share_types'): msg = _("Supported share types must be provided.") raise webob.exc.HTTPBadRequest(explanation=msg) share_types = share_group_type.get('share_types') if name is None or name == "" or len(name) > 255: msg = _("Share group type name is not valid.") raise webob.exc.HTTPBadRequest(explanation=msg) try: share_group_types.create( context, name, share_types, specs, is_public) share_group_type = share_group_types.get_by_name( context, name) except exception.ShareGroupTypeExists as err: raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.ShareTypeDoesNotExist as err: raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) except exception.NotFound: raise webob.exc.HTTPNotFound() return self._view_builder.show(req, share_group_type)
def _create(self, req, body): """Creates a new share group type.""" context = req.environ['manila.context'] if not self.is_valid_body(body, 'share_group_type'): raise webob.exc.HTTPBadRequest() share_group_type = body['share_group_type'] name = share_group_type.get('name') specs = share_group_type.get('group_specs', {}) is_public = share_group_type.get('is_public', True) if not share_group_type.get('share_types'): msg = _("Supported share types must be provided.") raise webob.exc.HTTPBadRequest(explanation=msg) share_types = share_group_type.get('share_types') if name is None or name == "" or len(name) > 255: msg = _("Share group type name is not valid.") raise webob.exc.HTTPBadRequest(explanation=msg) try: share_group_types.create(context, name, share_types, specs, is_public) share_group_type = share_group_types.get_by_name(context, name) except exception.ShareGroupTypeExists as err: raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.ShareTypeDoesNotExist as err: raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) except exception.NotFound: raise webob.exc.HTTPNotFound() return self._view_builder.show(req, share_group_type)
def test_add_access(self): project_id = '456' share_group_type = share_group_types.create(self.context, 'type2', []) share_group_type_id = share_group_type.get('id') share_group_types.add_share_group_type_access( self.context, share_group_type_id, project_id) stype_access = db.share_group_type_access_get_all( self.context, share_group_type_id) self.assertIn(project_id, [a.project_id for a in stype_access])
def test_add_access(self): project_id = '456' share_group_type = share_group_types.create(self.context, 'type2', []) share_group_type_id = share_group_type.get('id') share_group_types.add_share_group_type_access( self.context, share_group_type_id, project_id) stype_access = db.share_group_type_access_get_all( self.context, share_group_type_id) self.assertIn(project_id, [a.project_id for a in stype_access])
def test_remove_access(self): project_id = '456' share_group_type = share_group_types.create( self.context, 'type3', [], projects=['456']) share_group_type_id = share_group_type.get('id') share_group_types.remove_share_group_type_access( self.context, share_group_type_id, project_id) stype_access = db.share_group_type_access_get_all( self.context, share_group_type_id) self.assertNotIn(project_id, stype_access)
def test_remove_access(self): project_id = '456' share_group_type = share_group_types.create( self.context, 'type3', [], projects=['456']) share_group_type_id = share_group_type.get('id') share_group_types.remove_share_group_type_access( self.context, share_group_type_id, project_id) stype_access = db.share_group_type_access_get_all( self.context, share_group_type_id) self.assertNotIn(project_id, stype_access)
def _create(self, req, body): """Creates a new share group type.""" context = req.environ['manila.context'] if not self.is_valid_body(body, 'share_group_type'): raise webob.exc.HTTPBadRequest() share_group_type = body['share_group_type'] name = share_group_type.get('name') specs = share_group_type.get('group_specs', {}) is_public = share_group_type.get('is_public', True) if not share_group_type.get('share_types'): msg = _("Supported share types must be provided.") raise webob.exc.HTTPBadRequest(explanation=msg) share_types = share_group_type.get('share_types') if name is None or name == "" or len(name) > 255: msg = _("Share group type name is not valid.") raise webob.exc.HTTPBadRequest(explanation=msg) if not (specs is None or isinstance(specs, dict)): msg = _("Group specs can be either of 'None' or 'dict' types.") raise webob.exc.HTTPBadRequest(explanation=msg) if specs: for element in list(specs.keys()) + list(specs.values()): if not isinstance(element, six.string_types): msg = _("Group specs keys and values should be strings.") raise webob.exc.HTTPBadRequest(explanation=msg) try: share_group_types.create( context, name, share_types, specs, is_public) share_group_type = share_group_types.get_by_name( context, name) except exception.ShareGroupTypeExists as err: raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.ShareTypeDoesNotExist as err: raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) except exception.NotFound: raise webob.exc.HTTPNotFound() return self._view_builder.show(req, share_group_type)
def _create(self, req, body): """Creates a new share group type.""" context = req.environ['manila.context'] if not self.is_valid_body(body, 'share_group_type'): raise webob.exc.HTTPBadRequest() share_group_type = body['share_group_type'] name = share_group_type.get('name') specs = share_group_type.get('group_specs', {}) is_public = share_group_type.get('is_public', True) if not share_group_type.get('share_types'): msg = _("Supported share types must be provided.") raise webob.exc.HTTPBadRequest(explanation=msg) share_types = share_group_type.get('share_types') if name is None or name == "" or len(name) > 255: msg = _("Share group type name is not valid.") raise webob.exc.HTTPBadRequest(explanation=msg) if not (specs is None or isinstance(specs, dict)): msg = _("Group specs can be either of 'None' or 'dict' types.") raise webob.exc.HTTPBadRequest(explanation=msg) if specs: for element in list(specs.keys()) + list(specs.values()): if not isinstance(element, six.string_types): msg = _("Group specs keys and values should be strings.") raise webob.exc.HTTPBadRequest(explanation=msg) try: share_group_types.create( context, name, share_types, specs, is_public) share_group_type = share_group_types.get_by_name( context, name) except exception.ShareGroupTypeExists as err: raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.ShareTypeDoesNotExist as err: raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) except exception.NotFound: raise webob.exc.HTTPNotFound() return self._view_builder.show(req, share_group_type)