def test_update_share_type(self): expected = self.fake_type_update['test_type_update'] self.mock_object(db, 'share_type_update', mock.Mock(side_effect=return_share_type_update)) self.mock_object(db, 'share_type_get', mock.Mock(return_value=expected)) new_name = "new_name" new_description = "new_description" is_public = True self.assertRaises(exception.ShareTypeUpdateFailed, share_types.update, self.context, id='444', name=new_name, description=new_description, is_public=is_public) share_types.update(self.context, '888', new_name, new_description, is_public) st_update = share_types.get_share_type(self.context, '888') self.assertEqual(new_name, st_update['name']) self.assertEqual(new_description, st_update['description']) self.assertEqual(is_public, st_update['is_public'])
def update(self, req, id, body): """Update name description is_public for a given share type.""" context = req.environ['manila.context'] if (not self.is_valid_body(body, 'share_type') and not self.is_valid_body(body, 'volume_type')): raise webob.exc.HTTPBadRequest() elif self.is_valid_body(body, 'share_type'): sha_type = body['share_type'] else: sha_type = body['volume_type'] name = sha_type.get('name') description = sha_type.get('description') is_public = sha_type.get('share_type_access:is_public', None) if is_public is not None: try: is_public = strutils.bool_from_string(is_public, strict=True) except ValueError: msg = _("share_type_access:is_public has a non-boolean" " value.") raise webob.exc.HTTPBadRequest(explanation=msg) # If name specified, name can not be empty or greater than 255. if name is not None: if len(name.strip()) == 0: msg = _("Share type name cannot be empty.") raise webob.exc.HTTPBadRequest(explanation=msg) if len(name) > 255: msg = _("Share type name cannot be greater than 255 " "characters in length.") raise webob.exc.HTTPBadRequest(explanation=msg) # If description specified, length can not greater than 255. if description and len(description) > 255: msg = _("Share type description cannot be greater than 255 " "characters in length.") raise webob.exc.HTTPBadRequest(explanation=msg) # Name, description and is_public can not be None. # Specify one of them, or a combination thereof. if name is None and description is None and is_public is None: msg = _("Specify share type name, description, " "share_type_access:is_public or a combination thereof.") raise webob.exc.HTTPBadRequest(explanation=msg) try: share_types.update(context, id, name, description, is_public=is_public) # Get the updated sha_type = self._show_share_type_details(context, id) req.cache_resource(sha_type, name='types') self._notify_share_type_info( context, 'share_type.update', sha_type) except exception.ShareTypeNotFound as err: notifier_err = {"id": id, "error_message": err} self._notify_share_type_error( context, 'share_type.update', notifier_err) # Not found exception will be handled at the wsgi level raise except exception.ShareTypeExists as err: notifier_err = {"share_type": sha_type, "error_message": err} self._notify_share_type_error( context, 'share_type.update', notifier_err) raise webob.exc.HTTPConflict(explanation=err.msg) except exception.ShareTypeUpdateFailed as err: notifier_err = {"share_type": sha_type, "error_message": err} self._notify_share_type_error( context, 'share_type.update', notifier_err) raise webob.exc.HTTPInternalServerError( explanation=err.msg) return self._view_builder.show(req, sha_type)