def __call__(self, target, creds, enforcer): """Check http: rules by calling to a remote server. This example implementation simply verifies that the response is exactly 'True'. """ url = ('http:' + self.match) % target data = {'target': jsonutils.dumps(target), 'credentials': jsonutils.dumps(creds)} post_data = urlparse.urlencode(data) f = urlrequest.urlopen(url, post_data) return f.read() == "True"
def _check_http(brain, match_kind, match, target_dict, cred_dict): """Check http: rules by calling to a remote server. This example implementation simply verifies that the response is exactly 'True'. A custom brain using response codes could easily be implemented. """ url = 'http:' + (match % target_dict) data = {'target': jsonutils.dumps(target_dict), 'credentials': jsonutils.dumps(cred_dict)} post_data = urllib.urlencode(data) f = urllib2.urlopen(url, post_data) return f.read() == "True"
def __call__(self, target, creds, enforcer): """Check http: rules by calling to a remote server. This example implementation simply verifies that the response is exactly 'True'. """ url = ('http:' + self.match) % target data = { 'target': jsonutils.dumps(target), 'credentials': jsonutils.dumps(creds) } post_data = urlparse.urlencode(data) f = urlrequest.urlopen(url, post_data) return f.read() == "True"
def _pack_json_msg(self, msg): """Qpid cannot serialize dicts containing strings longer than 65535 characters. This function dumps the message content to a JSON string, which Qpid is able to handle. :param msg: May be either a Qpid Message object or a bare dict. :returns: A Qpid Message with its content field JSON encoded. """ try: msg.content = jsonutils.dumps(msg.content) except AttributeError: # Need to have a Qpid message so we can set the content_type. msg = qpid_messaging.Message(jsonutils.dumps(msg)) msg.content_type = JSON_CONTENT_TYPE return msg
def serialize_remote_exception(failure_info, log_failure=True): """Prepares exception data to be sent over rpc. Failure_info should be a sys.exc_info() tuple. """ tb = traceback.format_exception(*failure_info) failure = failure_info[1] if log_failure: LOG.error(_("Returning exception %s to caller"), unicode(failure)) LOG.error(tb) kwargs = {} if hasattr(failure, 'kwargs'): kwargs = failure.kwargs data = { 'class': str(failure.__class__.__name__), 'module': str(failure.__class__.__module__), 'message': unicode(failure), 'tb': tb, 'args': failure.args, 'kwargs': kwargs } json_data = jsonutils.dumps(data) return json_data
def __init__(self, conf, session, node_name, node_opts=None): """Init the Publisher class with the exchange_name, routing_key, and other options """ self.sender = None self.session = session if conf.qpid_topology_version == 1: addr_opts = { "create": "always", "node": { "type": "topic", "x-declare": { "durable": False, # auto-delete isn't implemented for exchanges in qpid, # but put in here anyway "auto-delete": True, }, }, } if node_opts: addr_opts["node"]["x-declare"].update(node_opts) self.address = "%s ; %s" % (node_name, jsonutils.dumps(addr_opts)) elif conf.qpid_topology_version == 2: self.address = node_name else: raise_invalid_topology_version() self.reconnect(session)
def serialize_msg(raw_msg): # NOTE(russellb) See the docstring for _RPC_ENVELOPE_VERSION for more # information about this format. msg = {_VERSION_KEY: _RPC_ENVELOPE_VERSION, _MESSAGE_KEY: jsonutils.dumps(raw_msg)} return msg
def format(self, record): message = {'message': record.getMessage(), 'asctime': self.formatTime(record, self.datefmt), 'name': record.name, 'msg': record.msg, 'args': record.args, 'levelname': record.levelname, 'levelno': record.levelno, 'pathname': record.pathname, 'filename': record.filename, 'module': record.module, 'lineno': record.lineno, 'funcname': record.funcName, 'created': record.created, 'msecs': record.msecs, 'relative_created': record.relativeCreated, 'thread': record.thread, 'thread_name': record.threadName, 'process_name': record.processName, 'process': record.process, 'traceback': None} if hasattr(record, 'extra'): message['extra'] = record.extra if record.exc_info: message['traceback'] = self.formatException(record.exc_info) return jsonutils.dumps(message)
def test_member_force_delete_share(self): share = db.share_create(self.admin_context, {'size': 1}) req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id']) req.method = 'POST' req.headers['content-type'] = 'application/json' req.body = jsonutils.dumps({'os-force_delete': {}}) req.environ['manila.context'] = self.member_context resp = req.get_response(app()) self.assertEqual(resp.status_int, 403)
def test_update_item_nonexistent_share(self): self.stubs.Set(manila.db, "share_get", return_share_nonexistent) req = fakes.HTTPRequest.blank("/v1.1/fake/shares/asdf/metadata/key1") req.method = "PUT" body = {"meta": {"key1": "value1"}} req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" self.assertRaises(webob.exc.HTTPNotFound, self.controller.update, req, self.req_id, "key1", body)
def test_update_all_nonexistent_share(self): self.stubs.Set(manila.db, "share_get", return_share_nonexistent) req = fakes.HTTPRequest.blank(self.url) req.method = "PUT" req.content_type = "application/json" body = {"metadata": {"key10": "value10"}} req.body = jsonutils.dumps(body) self.assertRaises(webob.exc.HTTPNotFound, self.controller.update_all, req, "100", body)
def test_update_item_body_uri_mismatch(self): self.stubs.Set(manila.db, "share_metadata_update", return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url + "/bad") req.method = "PUT" body = {"meta": {"key1": "value1"}} req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, req, self.req_id, "bad", body)
def __init__(self, conf, session, callback, node_name, node_opts, link_name, link_opts): """Declare a queue on an amqp session. 'session' is the amqp session to use 'callback' is the callback to call when messages are received 'node_name' is the first part of the Qpid address string, before ';' 'node_opts' will be applied to the "x-declare" section of "node" in the address string. 'link_name' goes into the "name" field of the "link" in the address string 'link_opts' will be applied to the "x-declare" section of "link" in the address string. """ self.callback = callback self.receiver = None self.session = None if conf.qpid_topology_version == 1: addr_opts = { "create": "always", "node": { "type": "topic", "x-declare": { "durable": True, "auto-delete": True, }, }, "link": { "durable": True, "x-declare": { "durable": False, "auto-delete": True, "exclusive": False, }, }, } addr_opts["node"]["x-declare"].update(node_opts) elif conf.qpid_topology_version == 2: addr_opts = { "link": { "x-declare": { "auto-delete": True, "exclusive": False, }, }, } else: raise_invalid_topology_version() addr_opts["link"]["x-declare"].update(link_opts) if link_name: addr_opts["link"]["name"] = link_name self.address = "%s ; %s" % (node_name, jsonutils.dumps(addr_opts)) self.connect(session)
def test_update_all_malformed_data(self): self.stubs.Set(manila.db, "share_metadata_update", return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = "PUT" req.content_type = "application/json" expected = {"metadata": ["asdf"]} req.body = jsonutils.dumps(expected) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update_all, req, self.req_id, expected)
def test_update_all_empty_container(self): self.stubs.Set(manila.db, "share_metadata_update", return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = "PUT" req.content_type = "application/json" expected = {"metadata": {}} req.body = jsonutils.dumps(expected) res_dict = self.controller.update_all(req, self.req_id, expected) self.assertEqual(expected, res_dict)
def test_update_item_nonexistent_share(self): self.stubs.Set(manila.db, 'share_get', return_share_nonexistent) req = fakes.HTTPRequest.blank('/v1.1/fake/shares/asdf/metadata/key1') req.method = 'PUT' body = {"meta": {"key1": "value1"}} req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" self.assertRaises(webob.exc.HTTPNotFound, self.controller.update, req, self.req_id, 'key1', body)
def test_update_item(self): self.stubs.Set(manila.db, "share_metadata_update", return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url + "/key1") req.method = "PUT" body = {"meta": {"key1": "value1"}} req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" res_dict = self.controller.update(req, self.req_id, "key1", body) expected = {"meta": {"key1": "value1"}} self.assertEqual(expected, res_dict)
def api_put(self, relative_uri, body, **kwargs): kwargs['method'] = 'PUT' if body: headers = kwargs.setdefault('headers', {}) headers['Content-Type'] = 'application/json' kwargs['body'] = jsonutils.dumps(body) kwargs.setdefault('check_response_status', [200, 202, 204]) response = self.api_request(relative_uri, **kwargs) return self._decode_json(response)
def test_update_all_nonexistent_share(self): self.stubs.Set(manila.db, 'share_get', return_share_nonexistent) req = fakes.HTTPRequest.blank(self.url) req.method = 'PUT' req.content_type = "application/json" body = {'metadata': {'key10': 'value10'}} req.body = jsonutils.dumps(body) self.assertRaises(webob.exc.HTTPNotFound, self.controller.update_all, req, '100', body)
def test_update_item_empty_key(self): self.stubs.Set(manila.db, 'share_metadata_update', return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url + '/key1') req.method = 'PUT' body = {"meta": {"": "value1"}} req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, req, self.req_id, '', body)
def test_update_all_malformed_data(self): self.stubs.Set(manila.db, 'share_metadata_update', return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = 'PUT' req.content_type = "application/json" expected = {'metadata': ['asdf']} req.body = jsonutils.dumps(expected) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update_all, req, self.req_id, expected)
def test_invalid_metadata_items_on_create(self): self.stubs.Set(manila.db, "share_metadata_update", return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = "POST" req.headers["content-type"] = "application/json" # test for long key data = {"metadata": {"a" * 260: "value1"}} req.body = jsonutils.dumps(data) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, req, self.req_id, data) # test for long value data = {"metadata": {"key": "v" * 1025}} req.body = jsonutils.dumps(data) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, req, self.req_id, data) # test for empty key. data = {"metadata": {"": "value1"}} req.body = jsonutils.dumps(data) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, req, self.req_id, data)
def test_update_all_empty_container(self): self.stubs.Set(manila.db, 'share_metadata_update', return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = 'PUT' req.content_type = "application/json" expected = {'metadata': {}} req.body = jsonutils.dumps(expected) res_dict = self.controller.update_all(req, self.req_id, expected) self.assertEqual(expected, res_dict)
def test_create_nonexistent_share(self): self.stubs.Set(manila.db, "share_get", return_share_nonexistent) self.stubs.Set(manila.db, "share_metadata_get", return_share_metadata) self.stubs.Set(manila.db, "share_metadata_update", return_create_share_metadata) req = fakes.HTTPRequest.blank("/v1/share_metadata") req.method = "POST" req.content_type = "application/json" body = {"metadata": {"key9": "value9"}} req.body = jsonutils.dumps(body) self.assertRaises(webob.exc.HTTPNotFound, self.controller.create, req, self.req_id, body)
def test_update_item(self): self.stubs.Set(manila.db, 'share_metadata_update', return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url + '/key1') req.method = 'PUT' body = {"meta": {"key1": "value1"}} req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" res_dict = self.controller.update(req, self.req_id, 'key1', body) expected = {'meta': {'key1': 'value1'}} self.assertEqual(expected, res_dict)
def test_create(self): self.stubs.Set(manila.db, "share_metadata_get", return_empty_share_metadata) self.stubs.Set(manila.db, "share_metadata_update", return_create_share_metadata) req = fakes.HTTPRequest.blank("/v1/share_metadata") req.method = "POST" req.content_type = "application/json" body = {"metadata": {"key9": "value9"}} req.body = jsonutils.dumps(body) res_dict = self.controller.create(req, self.req_id, body) self.assertEqual(body, res_dict)
def _serialize(data): """ Serialization wrapper We prefer using JSON, but it cannot encode all types. Error if a developer passes us bad data. """ try: return jsonutils.dumps(data, ensure_ascii=True) except TypeError: with excutils.save_and_reraise_exception(): LOG.error(_("JSON serialization failed."))
def notify(_context, message): """Notifies the recipient of the desired event given the model. Log notifications using openstack's default logging system""" priority = message.get('priority', CONF.default_notification_level) priority = priority.lower() logger = logging.getLogger( 'manila.openstack.common.notification.%s' % message['event_type']) getattr(logger, priority)(jsonutils.dumps(message))
def test_get_configuration_second_time_no_change(self): last_checked = datetime.datetime(2011, 1, 1, 1, 1, 1) now = datetime.datetime(2012, 1, 1, 1, 1, 1) file_old = datetime.datetime(2012, 1, 1, 1, 1, 1) file_now = datetime.datetime(2012, 1, 1, 1, 1, 1) data = dict(a=1, b=2, c=3) jdata = jsonutils.dumps(data) fake = FakeSchedulerOptions(last_checked, now, file_old, file_now, data, jdata) self.assertEquals(data, fake.get_configuration("foo.json")) self.assertFalse(fake.file_was_loaded)
def test_get_configuration_first_time_happy_day(self): last_checked = None now = datetime.datetime(2012, 1, 1, 1, 1, 1) file_old = None file_now = datetime.datetime(2012, 1, 1, 1, 1, 1) data = dict(a=1, b=2, c=3) jdata = jsonutils.dumps(data) fake = FakeSchedulerOptions(last_checked, now, file_old, file_now, {}, jdata) self.assertEquals(data, fake.get_configuration("foo.json")) self.assertTrue(fake.file_was_loaded)
def test_update_all_malformed_container(self): self.stubs.Set(manila.db, 'share_metadata_update', return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = 'PUT' req.content_type = "application/json" expected = {'meta': {}} req.body = jsonutils.dumps(expected) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update_all, req, self.req_id, expected)
def test_create_nonexistent_share(self): self.stubs.Set(manila.db, 'share_get', return_share_nonexistent) self.stubs.Set(manila.db, 'share_metadata_get', return_share_metadata) self.stubs.Set(manila.db, 'share_metadata_update', return_create_share_metadata) req = fakes.HTTPRequest.blank('/v1/share_metadata') req.method = 'POST' req.content_type = "application/json" body = {"metadata": {"key9": "value9"}} req.body = jsonutils.dumps(body) self.assertRaises(webob.exc.HTTPNotFound, self.controller.create, req, self.req_id, body)
def test_member_force_delete_snapshot(self): snapshot = stubs.stub_snapshot(1, host='foo') self.stubs.Set(db, 'share_get', lambda x, y: snapshot) self.stubs.Set(db, 'share_snapshot_get', lambda x, y: snapshot) self.stubs.Set(share_api.API, 'delete_snapshot', lambda *x, **y: True) path = '/v1/fake/snapshots/%s/action' % snapshot['id'] req = webob.Request.blank(path) req.method = 'POST' req.headers['content-type'] = 'application/json' req.body = jsonutils.dumps({'os-force_delete': {}}) req.environ['manila.context'] = self.member_context resp = req.get_response(app()) self.assertEqual(resp.status_int, 403)
def setUp(self): super(HostFiltersTestCase, self).setUp() self.context = context.RequestContext('fake', 'fake') self.json_query = jsonutils.dumps( ['and', ['>=', '$free_capacity_gb', 1024], ['>=', '$total_capacity_gb', 10 * 1024]]) # This has a side effect of testing 'get_filter_classes' # when specifying a method (in this case, our standard filters) filter_handler = filters.HostFilterHandler('manila.scheduler.filters') classes = filter_handler.get_all_classes() self.class_map = {} for cls in classes: self.class_map[cls.__name__] = cls
def test_create(self): self.stubs.Set(manila.db, 'share_metadata_get', return_empty_share_metadata) self.stubs.Set(manila.db, 'share_metadata_update', return_create_share_metadata) req = fakes.HTTPRequest.blank('/v1/share_metadata') req.method = 'POST' req.content_type = "application/json" body = {"metadata": {"key9": "value9"}} req.body = jsonutils.dumps(body) res_dict = self.controller.create(req, self.req_id, body) self.assertEqual(body, res_dict)
def test_get_configuration_first_time_happy_day(self): last_checked = None now = datetime.datetime(2012, 1, 1, 1, 1, 1) file_old = None file_now = datetime.datetime(2012, 1, 1, 1, 1, 1) data = dict(a=1, b=2, c=3) jdata = jsonutils.dumps(data) fake = FakeSchedulerOptions(last_checked, now, file_old, file_now, {}, jdata) self.assertEqual(data, fake.get_configuration('foo.json')) self.assertTrue(fake.file_was_loaded)
def test_get_configuration_second_time_no_change(self): last_checked = datetime.datetime(2011, 1, 1, 1, 1, 1) now = datetime.datetime(2012, 1, 1, 1, 1, 1) file_old = datetime.datetime(2012, 1, 1, 1, 1, 1) file_now = datetime.datetime(2012, 1, 1, 1, 1, 1) data = dict(a=1, b=2, c=3) jdata = jsonutils.dumps(data) fake = FakeSchedulerOptions(last_checked, now, file_old, file_now, data, jdata) self.assertEqual(data, fake.get_configuration('foo.json')) self.assertFalse(fake.file_was_loaded)
def __str__(self): """Dumps a string representation of the rules.""" # Start by building the canonical strings for the rules out_rules = {} for key, value in self.items(): # Use empty string for singleton TrueCheck instances if isinstance(value, TrueCheck): out_rules[key] = '' else: out_rules[key] = str(value) # Dump a pretty-printed JSON representation return jsonutils.dumps(out_rules, indent=4)
def test_get_configuration_second_time_too_fast(self): last_checked = datetime.datetime(2011, 1, 1, 1, 1, 1) now = datetime.datetime(2011, 1, 1, 1, 1, 2) file_old = datetime.datetime(2012, 1, 1, 1, 1, 1) file_now = datetime.datetime(2013, 1, 1, 1, 1, 1) old_data = dict(a=1, b=2, c=3) data = dict(a=11, b=12, c=13) jdata = jsonutils.dumps(data) fake = FakeSchedulerOptions(last_checked, now, file_old, file_now, old_data, jdata) self.assertEqual(old_data, fake.get_configuration('foo.json')) self.assertFalse(fake.file_was_loaded)
def setUp(self): super(HostFiltersTestCase, self).setUp() self.context = context.RequestContext('fake', 'fake') self.json_query = jsonutils.dumps([ 'and', ['>=', '$free_capacity_gb', 1024], ['>=', '$total_capacity_gb', 10 * 1024] ]) # This has a side effect of testing 'get_filter_classes' # when specifying a method (in this case, our standard filters) filter_handler = filters.HostFilterHandler('manila.scheduler.filters') classes = filter_handler.get_all_classes() self.class_map = {} for cls in classes: self.class_map[cls.__name__] = cls
def test_invalid_metadata_items_on_create(self): self.stubs.Set(manila.db, 'share_metadata_update', return_create_share_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = 'POST' req.headers["content-type"] = "application/json" # test for long key data = {"metadata": {"a" * 260: "value1"}} req.body = jsonutils.dumps(data) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, req, self.req_id, data) # test for long value data = {"metadata": {"key": "v" * 1025}} req.body = jsonutils.dumps(data) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, req, self.req_id, data) # test for empty key. data = {"metadata": {"": "value1"}} req.body = jsonutils.dumps(data) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, req, self.req_id, data)
def test_reset_status_as_admin(self): # current status is available share = db.share_create(self.admin_context, {'status': 'available'}) req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id']) req.method = 'POST' req.headers['content-type'] = 'application/json' # request status of 'error' req.body = jsonutils.dumps({'os-reset_status': {'status': 'error'}}) # attach admin context to request req.environ['manila.context'] = self.admin_context resp = req.get_response(app()) # request is accepted self.assertEqual(resp.status_int, 202) share = db.share_get(self.admin_context, share['id']) # status changed to 'error' self.assertEqual(share['status'], 'error')
def test_malformed_reset_status_body(self): # current status is available share = db.share_create(self.admin_context, {'status': 'available'}) req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id']) req.method = 'POST' req.headers['content-type'] = 'application/json' # malformed request body req.body = jsonutils.dumps({'os-reset_status': {'x-status': 'bad'}}) # attach admin context to request req.environ['manila.context'] = self.admin_context resp = req.get_response(app()) # bad request self.assertEqual(resp.status_int, 400) share = db.share_get(self.admin_context, share['id']) # status is still 'available' self.assertEqual(share['status'], 'available')
def check_for_delay(self, verb, path, username=None): body = jsonutils.dumps({"verb": verb, "path": path}) headers = {"Content-Type": "application/json"} conn = httplib.HTTPConnection(self.limiter_address) if username: conn.request("POST", "/%s" % (username), body, headers) else: conn.request("POST", "/", body, headers) resp = conn.getresponse() if 200 >= resp.status < 300: return None, None return resp.getheader("X-Wait-Seconds"), resp.read() or None
def test_reset_status_as_non_admin(self): # current status is 'error' share = db.share_create(context.get_admin_context(), {'status': 'error'}) req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id']) req.method = 'POST' req.headers['content-type'] = 'application/json' # request changing status to available req.body = jsonutils.dumps({'os-reset_status': {'status': 'available'}}) # non-admin context req.environ['manila.context'] = self.member_context resp = req.get_response(app()) # request is not authorized self.assertEqual(resp.status_int, 403) share = db.share_get(context.get_admin_context(), share['id']) # status is still 'error' self.assertEqual(share['status'], 'error')
def test_reset_status_for_missing_share(self): # missing-share-id req = webob.Request.blank('/v1/fake/shares/%s/action' % 'missing-share-id') req.method = 'POST' req.headers['content-type'] = 'application/json' # malformed request body req.body = jsonutils.dumps( {'os-reset_status': { 'status': 'available' }}) # attach admin context to request req.environ['manila.context'] = self.admin_context resp = req.get_response(app()) # not found self.assertEqual(resp.status_int, 404) self.assertRaises(exception.NotFound, db.share_get, self.admin_context, 'missing-share-id')
def test_snapshot_reset_status(self): # snapshot in 'error_deleting' share = db.share_create(self.admin_context, {}) snapshot = db.share_snapshot_create(self.admin_context, { 'status': 'error_deleting', 'share_id': share['id'] }) req = webob.Request.blank('/v1/fake/snapshots/%s/action' % snapshot['id']) req.method = 'POST' req.headers['content-type'] = 'application/json' # request status of 'error' req.body = jsonutils.dumps({'os-reset_status': {'status': 'error'}}) # attach admin context to request req.environ['manila.context'] = self.admin_context resp = req.get_response(app()) # request is accepted self.assertEqual(resp.status_int, 202) snapshot = db.share_snapshot_get(self.admin_context, snapshot['id']) # status changed to 'error' self.assertEqual(snapshot['status'], 'error')
def test_invalid_status_for_snapshot(self): # snapshot in 'available' share = db.share_create(self.admin_context, {}) snapshot = db.share_snapshot_create(self.admin_context, { 'status': 'available', 'share_id': share['id'] }) req = webob.Request.blank('/v1/fake/snapshots/%s/action' % snapshot['id']) req.method = 'POST' req.headers['content-type'] = 'application/json' # 'attaching' is not a valid status for snapshots req.body = jsonutils.dumps({'os-reset_status': {'status': 'attaching'}}) # attach admin context to request req.environ['manila.context'] = self.admin_context resp = req.get_response(app()) # request is accepted self.assertEqual(resp.status_int, 400) snapshot = db.share_snapshot_get(self.admin_context, snapshot['id']) # status is still 'available' self.assertEqual(snapshot['status'], 'available')
def _request_data(self, verb, path): """Get data decribing a limit request verb/path.""" return jsonutils.dumps({"verb": verb, "path": path})
def default(self, data): return jsonutils.dumps(data)