"""Common Policy Engine Implementation"""
-import json
import urllib
import urllib2
+from cinder.openstack.common import jsonutils
+
class NotAuthorized(Exception):
pass
@classmethod
def load_json(cls, data, default_rule=None):
"""Init a brain using json instead of a rules dictionary."""
- rules_dict = json.loads(data)
+ rules_dict = jsonutils.loads(data)
return cls(rules=rules_dict, default_rule=default_rule)
def __init__(self, rules=None, default_rule=None):
"""
url = match % target_dict
- data = {'target': json.dumps(target_dict),
- 'credentials': json.dumps(cred_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"
import cStringIO
import inspect
import itertools
-import json
import logging
import logging.config
import logging.handlers
import cinder
from cinder import flags
from cinder.openstack.common import cfg
+from cinder.openstack.common import jsonutils
from cinder.openstack.common import local
from cinder import version
if record.exc_info:
message['traceback'] = self.formatException(record.exc_info)
- return json.dumps(message)
+ return jsonutils.dumps(message)
class LegacyCinderFormatter(logging.Formatter):
# License for the specific language governing permissions and limitations
# under the License.
-import json
from cinder import flags
from cinder import log as logging
+from cinder.openstack.common import jsonutils
FLAGS = flags.FLAGS
priority = priority.lower()
logger = logging.getLogger(
'cinder.notification.%s' % message['event_type'])
- getattr(logger, priority)(json.dumps(message))
+ getattr(logger, priority)(jsonutils.dumps(message))
# License for the specific language governing permissions and limitations
# under the License.
-import json
-
import webob
-def webob_factory(url):
- """Factory for removing duplicate webob code from tests"""
-
- base_url = url
-
- def web_request(url, method=None, body=None):
- req = webob.Request.blank("%s%s" % (base_url, url))
- if method:
- req.content_type = "application/json"
- req.method = method
- if body:
- req.body = json.dumps(body)
- return req
- return web_request
-
-
def compare_links(actual, expected):
"""Compare xml atom links."""
# License for the specific language governing permissions and limitations
# under the License.
-import json
from xml.dom import minidom
import webob
from cinder import test
from cinder.api.openstack import common
from cinder.api.openstack import wsgi
+from cinder.openstack.common import jsonutils
class TestFaults(test.TestCase):
"code": 400,
},
}
- actual = json.loads(response.body)
+ actual = jsonutils.loads(response.body)
self.assertEqual(response.content_type, "application/json")
self.assertEqual(expected, actual)
"retryAfter": 4,
},
}
- actual = json.loads(response.body)
+ actual = jsonutils.loads(response.body)
self.assertEqual(response.content_type, "application/json")
self.assertEqual(expected, actual)
from lxml import etree
import webob
-import json
from cinder.api.openstack.volume.contrib import extended_snapshot_attributes
-from cinder import volume
from cinder import exception
from cinder import flags
+from cinder.openstack.common import jsonutils
from cinder import test
from cinder.tests.api.openstack import fakes
+from cinder import volume
FLAGS = flags.FLAGS
return res
def _get_snapshot(self, body):
- return json.loads(body).get('snapshot')
+ return jsonutils.loads(body).get('snapshot')
def _get_snapshots(self, body):
- return json.loads(body).get('snapshots')
+ return jsonutils.loads(body).get('snapshots')
def assertSnapshotAttributes(self, snapshot, project_id, progress):
self.assertEqual(snapshot.get('%sproject_id' % self.prefix),
# License for the specific language governing permissions and limitations
# under the License.
-import datetime
-import json
-
import webob
-from cinder.api.openstack import volume as volume_api
from cinder import volume
-from cinder import context
-from cinder import exception
from cinder import flags
from cinder import test
+from cinder.openstack.common import jsonutils
from cinder.tests.api.openstack import fakes
from cinder import utils
req = webob.Request.blank('/v1/fake/volumes/%s/action' %
self.UUID)
req.method = 'POST'
- req.body = json.dumps({_action: None})
+ req.body = jsonutils.dumps({_action: None})
req.content_type = 'application/json'
res = req.get_response(app)
self.assertEqual(res.status_int, 202)
body = {'os-initialize_connection': {'connector': 'fake'}}
req = webob.Request.blank('/v1/fake/volumes/1/action')
req.method = "POST"
- req.body = json.dumps(body)
+ req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
- output = json.loads(res.body)
+ output = jsonutils.loads(res.body)
self.assertEqual(res.status_int, 200)
def test_terminate_connection(self):
body = {'os-terminate_connection': {'connector': 'fake'}}
req = webob.Request.blank('/v1/fake/volumes/1/action')
req.method = "POST"
- req.body = json.dumps(body)
+ req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
'mountpoint': '/dev/vdc'}}
req = webob.Request.blank('/v1/fake/volumes/1/action')
req.method = "POST"
- req.body = json.dumps(body)
+ req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
# License for the specific language governing permissions and limitations
# under the License.
-import json
import webob
from lxml import etree
from cinder.api.openstack import volume
from cinder.api.openstack import xmlutil
from cinder import flags
+from cinder.openstack.common import jsonutils
from cinder import test
FLAGS = flags.FLAGS
self.assertEqual(200, response.status_int)
# Make sure we have all the extensions, extra extensions being OK.
- data = json.loads(response.body)
+ data = jsonutils.loads(response.body)
names = [str(x['name']) for x in data['extensions']
if str(x['name']) in self.ext_list]
names.sort()
url = '/fake/extensions/%s' % ext['alias']
request = webob.Request.blank(url)
response = request.get_response(app)
- output = json.loads(response.body)
+ output = jsonutils.loads(response.body)
self.assertEqual(output['extension']['alias'], ext['alias'])
def test_get_extension_json(self):
response = request.get_response(app)
self.assertEqual(200, response.status_int)
- data = json.loads(response.body)
+ data = jsonutils.loads(response.body)
self.assertEqual(data['extension'], {
"namespace": "http://www.fox.in.socks/api/ext/pie/v1.0",
"name": "Fox In Socks",
# License for the specific language governing permissions and limitations
# under the License.
-import json
import httplib
import urllib
import urlparse
from cinder import log as logging
+from cinder.openstack.common import jsonutils
LOG = logging.getLogger(__name__)
body = response.read()
LOG.debug(_("Decoding JSON: %s") % (body))
if body:
- return json.loads(body)
+ return jsonutils.loads(body)
else:
return ""
if body:
headers = kwargs.setdefault('headers', {})
headers['Content-Type'] = 'application/json'
- kwargs['body'] = json.dumps(body)
+ kwargs['body'] = jsonutils.dumps(body)
kwargs.setdefault('check_response_status', [200, 202])
response = self.api_request(relative_uri, **kwargs)
if body:
headers = kwargs.setdefault('headers', {})
headers['Content-Type'] = 'application/json'
- kwargs['body'] = json.dumps(body)
+ kwargs['body'] = jsonutils.dumps(body)
kwargs.setdefault('check_response_status', [200, 202, 204])
response = self.api_request(relative_uri, **kwargs)
import cStringIO
-import json
import logging
-import sys
from cinder import context
from cinder import flags
from cinder import log
+from cinder.openstack.common import jsonutils
from cinder.notifier import api as notifier
from cinder import test
test_data = {'test': 'log'}
self.log.debug(test_msg, test_data)
- data = json.loads(self.stream.getvalue())
+ data = jsonutils.loads(self.stream.getvalue())
self.assertTrue(data)
self.assertTrue('extra' in data)
self.assertEqual('test-json', data['name'])
except Exception:
self.log.exception(test_msg, test_data)
- data = json.loads(self.stream.getvalue())
+ data = jsonutils.loads(self.stream.getvalue())
self.assertTrue(data)
self.assertTrue('extra' in data)
self.assertEqual('test-json', data['name'])
.. moduleauthor:: Yuriy Taraday <yorik.sar@gmail.com>
"""
-import json
import urllib2
+from cinder.openstack.common import jsonutils
from cinder.volume import nexenta
from cinder import log as logging
obj, method)
def __call__(self, *args):
- data = json.dumps({'object': self.obj,
+ data = jsonutils.dumps({'object': self.obj,
'method': self.method,
'params': args})
auth = ('%s:%s' % (self.user, self.password)).encode('base64')[:-1]
response_data = response_obj.read()
LOG.debug(_('Got response: %s'), response_data)
- response = json.loads(response_data)
+ response = jsonutils.loads(response_data)
if response.get('error') is not None:
raise NexentaJSONException(response['error'].get('message', ''))
else:
import base64
import httplib
-import json
import os
import paramiko
import random
from cinder import flags
from cinder import log as logging
from cinder.openstack.common import cfg
+from cinder.openstack.common import jsonutils
from cinder import utils
import cinder.volume.driver
if params is not None:
command['params'] = params
- payload = json.dumps(command, ensure_ascii=False)
+ payload = jsonutils.dumps(command, ensure_ascii=False)
payload.encode('utf-8')
# we use json-rpc, webserver needs to see json-rpc in header
header = {'Content-Type': 'application/json-rpc; charset=utf-8'}
else:
data = response.read()
try:
- data = json.loads(data)
+ data = jsonutils.loads(data)
except (TypeError, ValueError), exc:
connection.close()