def _test_rpcapi(self, method, rpc_method, **kwargs): rpcapi = conductor_rpcapi.API(topic='fake-topic') expected_retval = 'hello world' if rpc_method == 'call' else None expected_topic = 'fake-topic' if 'host' in kwargs: expected_topic += ".%s" % kwargs['host'] target = { "topic": expected_topic, "version": kwargs.pop('version', 1.0) } expected_msg = copy.deepcopy(kwargs) self.fake_args = None self.fake_kwargs = None def _fake_prepare_method(*args, **kwargs): for kwd in kwargs: self.assertEqual(kwargs[kwd], target[kwd]) return rpcapi._client def _fake_rpc_method(*args, **kwargs): self.fake_args = args self.fake_kwargs = kwargs if expected_retval: return expected_retval with mock.patch.object(rpcapi._client, "prepare") as mock_prepared: mock_prepared.side_effect = _fake_prepare_method with mock.patch.object(rpcapi._client, rpc_method) as mock_method: mock_method.side_effect = _fake_rpc_method retval = getattr(rpcapi, method)(**kwargs) self.assertEqual(retval, expected_retval) expected_args = [None, method, expected_msg] for arg, expected_arg in zip(self.fake_args, expected_args): self.assertEqual(arg, expected_arg)
def before(self, state): state.request.rpcapi = conductor_api.API(context=state.request.context)
def __init__(self): super(MagnumObjectIndirectionAPI, self).__init__() from magnum.conductor import api as conductor_api self._conductor = conductor_api.API()
**kwargs): collection = ContainerCollection() collection.containers = [ Container.convert_with_links(p, expand) for p in rpc_containers ] collection.next = collection.get_next(limit, url=url, **kwargs) return collection @classmethod def sample(cls): sample = cls() sample.containers = [Container.sample(expand=False)] return sample backend_api = api.API(context=magnum_context.RequestContext()) class StartController(object): @wsme_pecan.wsexpose(wtypes.text, wtypes.text) def _default(self, container_uuid): if pecan.request.method != 'PUT': pecan.abort( 405, ('HTTP method %s is not allowed' % pecan.request.method)) LOG.debug('Calling backend_api.container_start with %s' % container_uuid) return backend_api.container_start(container_uuid) class StopController(object): @wsme_pecan.wsexpose(wtypes.text, wtypes.text)