~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/rpc/impl_fake.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import inspect
21
21
import json
22
 
import signal
23
 
import sys
24
22
import time
25
 
import traceback
26
23
 
27
24
import eventlet
28
25
 
29
26
from nova import context
30
 
from nova import flags
31
27
from nova.rpc import common as rpc_common
32
28
 
33
29
CONSUMERS = {}
34
30
 
35
 
FLAGS = flags.FLAGS
36
 
 
37
31
 
38
32
class RpcContext(context.RequestContext):
39
33
    def __init__(self, *args, **kwargs):
53
47
        self.topic = topic
54
48
        self.proxy = proxy
55
49
 
56
 
    def call(self, context, method, args, timeout):
57
 
        node_func = getattr(self.proxy, method)
58
 
        node_args = dict((str(k), v) for k, v in args.iteritems())
 
50
    def call(self, context, version, method, args, timeout):
59
51
        done = eventlet.event.Event()
60
52
 
61
53
        def _inner():
62
54
            ctxt = RpcContext.from_dict(context.to_dict())
63
55
            try:
64
 
                rval = node_func(context=ctxt, **node_args)
 
56
                rval = self.proxy.dispatch(context, version, method, **args)
65
57
                res = []
66
58
                # Caller might have called ctxt.reply() manually
67
59
                for (reply, failure) in ctxt._response:
77
69
                    else:
78
70
                        res.append(rval)
79
71
                done.send(res)
80
 
            except Exception:
81
 
                exc_info = sys.exc_info()
82
 
                done.send_exception(
83
 
                        rpc_common.RemoteError(exc_info[0].__name__,
84
 
                            str(exc_info[1]),
85
 
                            ''.join(traceback.format_exception(*exc_info))))
 
72
            except Exception as e:
 
73
                done.send_exception(e)
86
74
 
87
75
        thread = eventlet.greenthread.spawn(_inner)
88
76
 
120
108
        pass
121
109
 
122
110
 
123
 
def create_connection(new=True):
 
111
def create_connection(conf, new=True):
124
112
    """Create a connection"""
125
113
    return Connection()
126
114
 
130
118
    json.dumps(msg)
131
119
 
132
120
 
133
 
def multicall(context, topic, msg, timeout=None):
 
121
def multicall(conf, context, topic, msg, timeout=None):
134
122
    """Make a call that returns multiple times."""
135
123
 
136
124
    check_serialize(msg)
139
127
    if not method:
140
128
        return
141
129
    args = msg.get('args', {})
 
130
    version = msg.get('version', None)
142
131
 
143
132
    try:
144
133
        consumer = CONSUMERS[topic][0]
145
134
    except (KeyError, IndexError):
146
135
        return iter([None])
147
136
    else:
148
 
        return consumer.call(context, method, args, timeout)
149
 
 
150
 
 
151
 
def call(context, topic, msg, timeout=None):
 
137
        return consumer.call(context, version, method, args, timeout)
 
138
 
 
139
 
 
140
def call(conf, context, topic, msg, timeout=None):
152
141
    """Sends a message on a topic and wait for a response."""
153
 
    rv = multicall(context, topic, msg, timeout)
 
142
    rv = multicall(conf, context, topic, msg, timeout)
154
143
    # NOTE(vish): return the last result from the multicall
155
144
    rv = list(rv)
156
145
    if not rv:
158
147
    return rv[-1]
159
148
 
160
149
 
161
 
def cast(context, topic, msg):
 
150
def cast(conf, context, topic, msg):
162
151
    try:
163
 
        call(context, topic, msg)
164
 
    except rpc_common.RemoteError:
 
152
        call(conf, context, topic, msg)
 
153
    except Exception:
165
154
        pass
166
155
 
167
156
 
168
 
def notify(context, topic, msg):
 
157
def notify(conf, context, topic, msg):
169
158
    check_serialize(msg)
170
159
 
171
160
 
173
162
    pass
174
163
 
175
164
 
176
 
def fanout_cast(context, topic, msg):
 
165
def fanout_cast(conf, context, topic, msg):
177
166
    """Cast to all consumers of a topic"""
178
167
    check_serialize(msg)
179
168
    method = msg.get('method')
184
173
    for consumer in CONSUMERS.get(topic, []):
185
174
        try:
186
175
            consumer.call(context, method, args, None)
187
 
        except rpc_common.RemoteError:
 
176
        except Exception:
188
177
            pass
 
178
 
 
179
 
 
180
def register_opts(conf):
 
181
    pass