Merge changes I36ff7c05,If43658b9
* changes: Stop using nova.exception from nova.rpc. Make use of openstack.common.jsonutils.
This commit is contained in:
@@ -21,6 +21,7 @@ from nova import flags
|
|||||||
from nova import log as logging
|
from nova import log as logging
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import jsonutils
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
|
|
||||||
@@ -121,7 +122,7 @@ def notify(context, publisher_id, event_type, priority, payload):
|
|||||||
_('%s not in valid priorities') % priority)
|
_('%s not in valid priorities') % priority)
|
||||||
|
|
||||||
# Ensure everything is JSON serializable.
|
# Ensure everything is JSON serializable.
|
||||||
payload = utils.to_primitive(payload, convert_instances=True)
|
payload = jsonutils.to_primitive(payload, convert_instances=True)
|
||||||
|
|
||||||
driver = importutils.import_module(FLAGS.notification_driver)
|
driver = importutils.import_module(FLAGS.notification_driver)
|
||||||
msg = dict(message_id=str(uuid.uuid4()),
|
msg = dict(message_id=str(uuid.uuid4()),
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ from eventlet import pools
|
|||||||
from eventlet import semaphore
|
from eventlet import semaphore
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova import exception
|
|
||||||
from nova import log as logging
|
from nova import log as logging
|
||||||
from nova.openstack.common import excutils
|
from nova.openstack.common import excutils
|
||||||
from nova.openstack.common import local
|
from nova.openstack.common import local
|
||||||
@@ -141,7 +140,7 @@ class ConnectionContext(rpc_common.Connection):
|
|||||||
if self.connection:
|
if self.connection:
|
||||||
return getattr(self.connection, key)
|
return getattr(self.connection, key)
|
||||||
else:
|
else:
|
||||||
raise exception.InvalidRPCConnectionReuse()
|
raise rpc_common.InvalidRPCConnectionReuse()
|
||||||
|
|
||||||
|
|
||||||
def msg_reply(conf, msg_id, connection_pool, reply=None, failure=None,
|
def msg_reply(conf, msg_id, connection_pool, reply=None, failure=None,
|
||||||
@@ -250,7 +249,6 @@ class ProxyCallback(object):
|
|||||||
return
|
return
|
||||||
self.pool.spawn_n(self._process_data, ctxt, method, args)
|
self.pool.spawn_n(self._process_data, ctxt, method, args)
|
||||||
|
|
||||||
@exception.wrap_exception()
|
|
||||||
def _process_data(self, ctxt, method, args):
|
def _process_data(self, ctxt, method, args):
|
||||||
"""Thread that magically looks for a method on the proxy
|
"""Thread that magically looks for a method on the proxy
|
||||||
object and calls it.
|
object and calls it.
|
||||||
|
|||||||
@@ -21,17 +21,38 @@ import copy
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from nova import exception
|
|
||||||
from nova import log as logging
|
from nova import log as logging
|
||||||
from nova.openstack.common import cfg
|
from nova.openstack.common import cfg
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
from nova import utils
|
from nova.openstack.common import jsonutils
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RemoteError(exception.NovaException):
|
class RPCException(Exception):
|
||||||
|
message = _("An unknown RPC related exception occurred.")
|
||||||
|
|
||||||
|
def __init__(self, message=None, **kwargs):
|
||||||
|
self.kwargs = kwargs
|
||||||
|
|
||||||
|
if not message:
|
||||||
|
try:
|
||||||
|
message = self.message % kwargs
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
# kwargs doesn't match a variable in the message
|
||||||
|
# log the issue and the kwargs
|
||||||
|
LOG.exception(_('Exception in string format operation'))
|
||||||
|
for name, value in kwargs.iteritems():
|
||||||
|
LOG.error("%s: %s" % (name, value))
|
||||||
|
# at least get the core message out if something happened
|
||||||
|
message = self.message
|
||||||
|
|
||||||
|
super(RPCException, self).__init__(message)
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteError(RPCException):
|
||||||
"""Signifies that a remote class has raised an exception.
|
"""Signifies that a remote class has raised an exception.
|
||||||
|
|
||||||
Contains a string representation of the type of the original exception,
|
Contains a string representation of the type of the original exception,
|
||||||
@@ -51,7 +72,7 @@ class RemoteError(exception.NovaException):
|
|||||||
traceback=traceback)
|
traceback=traceback)
|
||||||
|
|
||||||
|
|
||||||
class Timeout(exception.NovaException):
|
class Timeout(RPCException):
|
||||||
"""Signifies that a timeout has occurred.
|
"""Signifies that a timeout has occurred.
|
||||||
|
|
||||||
This exception is raised if the rpc_response_timeout is reached while
|
This exception is raised if the rpc_response_timeout is reached while
|
||||||
@@ -60,6 +81,10 @@ class Timeout(exception.NovaException):
|
|||||||
message = _("Timeout while waiting on RPC response.")
|
message = _("Timeout while waiting on RPC response.")
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidRPCConnectionReuse(RPCException):
|
||||||
|
message = _("Invalid reuse of an RPC connection.")
|
||||||
|
|
||||||
|
|
||||||
class Connection(object):
|
class Connection(object):
|
||||||
"""A connection, returned by rpc.create_connection().
|
"""A connection, returned by rpc.create_connection().
|
||||||
|
|
||||||
@@ -174,13 +199,13 @@ def serialize_remote_exception(failure_info):
|
|||||||
'kwargs': kwargs
|
'kwargs': kwargs
|
||||||
}
|
}
|
||||||
|
|
||||||
json_data = utils.dumps(data)
|
json_data = jsonutils.dumps(data)
|
||||||
|
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
|
|
||||||
def deserialize_remote_exception(conf, data):
|
def deserialize_remote_exception(conf, data):
|
||||||
failure = utils.loads(str(data))
|
failure = jsonutils.loads(str(data))
|
||||||
|
|
||||||
trace = failure.get('tb', [])
|
trace = failure.get('tb', [])
|
||||||
message = failure.get('message', "") + "\n" + "\n".join(trace)
|
message = failure.get('message', "") + "\n" + "\n".join(trace)
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ import mox
|
|||||||
import StringIO
|
import StringIO
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import utils
|
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.compute import power_state
|
from nova.compute import power_state
|
||||||
|
from nova.openstack.common import jsonutils
|
||||||
from nova.tests import fake_utils
|
from nova.tests import fake_utils
|
||||||
from nova import exception
|
from nova import exception
|
||||||
|
|
||||||
@@ -95,8 +95,8 @@ class DomainReadWriteTestCase(test.TestCase):
|
|||||||
|
|
||||||
def assertJSONEquals(self, x, y):
|
def assertJSONEquals(self, x, y):
|
||||||
"""Check if two json strings represent the equivalent Python object"""
|
"""Check if two json strings represent the equivalent Python object"""
|
||||||
self.assertEquals(utils.loads(x), utils.loads(y))
|
self.assertEquals(jsonutils.loads(x), jsonutils.loads(y))
|
||||||
return utils.loads(x) == utils.loads(y)
|
return jsonutils.loads(x) == jsonutils.loads(y)
|
||||||
|
|
||||||
def test_write_domain(self):
|
def test_write_domain(self):
|
||||||
"""Write the domain to file"""
|
"""Write the domain to file"""
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
|
|
||||||
import nova.db.api
|
import nova.db.api
|
||||||
from nova.notifier import capacity_notifier as cn
|
from nova.notifier import capacity_notifier as cn
|
||||||
|
from nova.openstack.common import jsonutils
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova import utils
|
|
||||||
|
|
||||||
|
|
||||||
class CapacityNotifierTestCase(test.TestCase):
|
class CapacityNotifierTestCase(test.TestCase):
|
||||||
@@ -24,7 +24,7 @@ class CapacityNotifierTestCase(test.TestCase):
|
|||||||
|
|
||||||
def _make_msg(self, host, event):
|
def _make_msg(self, host, event):
|
||||||
usage_info = dict(memory_mb=123, disk_gb=456)
|
usage_info = dict(memory_mb=123, disk_gb=456)
|
||||||
payload = utils.to_primitive(usage_info, convert_instances=True)
|
payload = jsonutils.to_primitive(usage_info, convert_instances=True)
|
||||||
return dict(
|
return dict(
|
||||||
publisher_id="compute.%s" % host,
|
publisher_id="compute.%s" % host,
|
||||||
event_type="compute.instance.%s" % event,
|
event_type="compute.instance.%s" % event,
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ from nova import exception
|
|||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
from nova import log as logging
|
||||||
from nova.openstack.common import importutils
|
from nova.openstack.common import importutils
|
||||||
|
from nova.openstack.common import jsonutils
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fake_network
|
from nova.tests import fake_network
|
||||||
from nova.tests import fake_libvirt_utils
|
from nova.tests import fake_libvirt_utils
|
||||||
@@ -1405,7 +1406,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
conn = connection.LibvirtConnection(False)
|
conn = connection.LibvirtConnection(False)
|
||||||
info = conn.get_instance_disk_info(instance_ref.name)
|
info = conn.get_instance_disk_info(instance_ref.name)
|
||||||
info = utils.loads(info)
|
info = jsonutils.loads(info)
|
||||||
self.assertEquals(info[0]['type'], 'raw')
|
self.assertEquals(info[0]['type'], 'raw')
|
||||||
self.assertEquals(info[0]['path'], '/test/disk')
|
self.assertEquals(info[0]['path'], '/test/disk')
|
||||||
self.assertEquals(info[0]['disk_size'], 10737418240)
|
self.assertEquals(info[0]['disk_size'], 10737418240)
|
||||||
@@ -2507,7 +2508,7 @@ class LibvirtConnectionTestCase(test.TestCase):
|
|||||||
'virt_disk_size': '10737418240',
|
'virt_disk_size': '10737418240',
|
||||||
'backing_file': '/base/disk.local',
|
'backing_file': '/base/disk.local',
|
||||||
'disk_size':'83886080'}]
|
'disk_size':'83886080'}]
|
||||||
disk_info_text = utils.dumps(disk_info)
|
disk_info_text = jsonutils.dumps(disk_info)
|
||||||
|
|
||||||
def fake_get_instance_disk_info(instance):
|
def fake_get_instance_disk_info(instance):
|
||||||
return disk_info_text
|
return disk_info_text
|
||||||
@@ -2578,7 +2579,7 @@ class LibvirtConnectionTestCase(test.TestCase):
|
|||||||
'local_gb': 10, 'backing_file': '/base/disk'},
|
'local_gb': 10, 'backing_file': '/base/disk'},
|
||||||
{'type': 'raw', 'path': '/test/disk.local',
|
{'type': 'raw', 'path': '/test/disk.local',
|
||||||
'local_gb': 10, 'backing_file': '/base/disk.local'}]
|
'local_gb': 10, 'backing_file': '/base/disk.local'}]
|
||||||
disk_info_text = utils.dumps(disk_info)
|
disk_info_text = jsonutils.dumps(disk_info)
|
||||||
|
|
||||||
def fake_extend(path, size):
|
def fake_extend(path, size):
|
||||||
pass
|
pass
|
||||||
@@ -2668,4 +2669,4 @@ class LibvirtNonblockingTestCase(test.TestCase):
|
|||||||
"""Test bug 962840"""
|
"""Test bug 962840"""
|
||||||
import nova.virt.libvirt.connection
|
import nova.virt.libvirt.connection
|
||||||
connection = nova.virt.libvirt.connection.get_connection('')
|
connection = nova.virt.libvirt.connection.get_connection('')
|
||||||
utils.to_primitive(connection._conn, convert_instances=True)
|
jsonutils.to_primitive(connection._conn, convert_instances=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user