Example #1
0
    def _test_console_api(self, method, rpc_method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')

        rpcapi = console_rpcapi.ConsoleAPI()
        self.assertIsNotNone(rpcapi.client)
        self.assertEqual(rpcapi.client.target.topic, CONF.console_topic)

        orig_prepare = rpcapi.client.prepare
        expected_version = kwargs.pop('version', rpcapi.client.target.version)

        with contextlib.nested(
            mock.patch.object(rpcapi.client, rpc_method),
            mock.patch.object(rpcapi.client, 'prepare'),
            mock.patch.object(rpcapi.client, 'can_send_version'),
        ) as (
            rpc_mock, prepare_mock, csv_mock
        ):
            prepare_mock.return_value = rpcapi.client
            rpc_mock.return_value = 'foo' if rpc_method == 'call' else None
            csv_mock.side_effect = (
                lambda v: orig_prepare(version=v).can_send_version())

            retval = getattr(rpcapi, method)(ctxt, **kwargs)
            self.assertEqual(retval, rpc_mock.return_value)

            prepare_mock.assert_called_once_with(version=expected_version)
            rpc_mock.assert_called_once_with(ctxt, method, **kwargs)
Example #2
0
    def _test_console_api(self, method, rpc_method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')
        rpcapi = console_rpcapi.ConsoleAPI()
        expected_retval = 'foo' if method == 'call' else None
        expected_version = kwargs.pop('version', rpcapi.BASE_RPC_API_VERSION)
        expected_msg = rpcapi.make_msg(method, **kwargs)
        expected_msg['version'] = expected_version

        self.fake_args = None
        self.fake_kwargs = None

        def _fake_rpc_method(*args, **kwargs):
            self.fake_args = args
            self.fake_kwargs = kwargs
            if expected_retval:
                return expected_retval

        self.stubs.Set(rpc, rpc_method, _fake_rpc_method)

        retval = getattr(rpcapi, method)(ctxt, **kwargs)

        self.assertEqual(retval, expected_retval)
        expected_args = [ctxt, CONF.console_topic, expected_msg]
        for arg, expected_arg in zip(self.fake_args, expected_args):
            self.assertEqual(arg, expected_arg)
Example #3
0
 def delete_console(self, context, instance_id, console_uuid):
     instance_id = self._translate_uuid_if_necessary(context, instance_uuid)
     console = self.db.console_get(context, console_id, instance_uuid)
     topic = rpc.queue_get_for(context, FLAGS.console_topic,
                               pool['host'])
     rpcapi = console_rpcapi.ConsoleAPI(topic=topic)
     rpcapi.remove_console(context, console['id'])
Example #4
0
 def create_console(self, context, instance_id):
     #NOTE(mdragon): If we wanted to return this the console info
     #               here, as we would need to do a call.
     #               They can just do an index later to fetch
     #               console info. I am not sure which is better
     #               here.
     instance = self._get_instance(context, instance_id)
     topic = self._get_console_topic(context, instance['host']),
     rpcapi = console_rpcapi.ConsoleAPI(topic=topic)
     rpcapi.add_console(context, instance['id'])
Example #5
0
    def test_create_console(self):
        self.mox.StubOutWithMock(compute_rpcapi.ComputeAPI,
                                 'get_console_topic')

        compute_rpcapi.ComputeAPI.get_console_topic(
            self.context, 'fake_host').AndReturn('compute.fake_host')
        self.mox.StubOutClassWithMocks(console_rpcapi, 'ConsoleAPI')
        console_api_mock = console_rpcapi.ConsoleAPI(topic='compute.fake_host')
        console_api_mock.add_console(self.context, self.fake_instance['id'])

        self.mox.ReplayAll()

        self.console_api.create_console(self.context, self.fake_uuid)
Example #6
0
 def create_console(self, context, instance_uuid):
     # NOTE(mdragon): If we wanted to return this the console info
     #                here, as we would need to do a call.
     #                They can just do an index later to fetch
     #                console info. I am not sure which is better
     #                here.
     instance = objects.Instance.get_by_uuid(context, instance_uuid)
     topic = self._get_console_topic(context, instance.host)
     server = None
     if '.' in topic:
         topic, server = topic.split('.', 1)
     rpcapi = console_rpcapi.ConsoleAPI(topic=topic, server=server)
     rpcapi.add_console(context, instance.id)
Example #7
0
    def _test_console_api(self, method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')
        rpcapi = console_rpcapi.ConsoleAPI()
        expected_msg = rpcapi.make_msg(method, **kwargs)
        expected_msg['version'] = rpcapi.BASE_RPC_API_VERSION

        self.cast_ctxt = None
        self.cast_topic = None
        self.cast_msg = None

        def _fake_cast(_ctxt, _topic, _msg):
            self.cast_ctxt = _ctxt
            self.cast_topic = _topic
            self.cast_msg = _msg

        self.stubs.Set(rpc, 'cast', _fake_cast)

        getattr(rpcapi, method)(ctxt, **kwargs)

        self.assertEqual(self.cast_ctxt, ctxt)
        self.assertEqual(self.cast_topic, CONF.console_topic)
        self.assertEqual(self.cast_msg, expected_msg)
Example #8
0
File: api.py Project: blahRus/nova
 def get_backdoor_port(self, context, host):
     topic = self._get_console_topic(context, host)
     rpcapi = console_rpcapi.ConsoleAPI(topic=topic)
     return rpcapi.get_backdoor_port(context, host)
Example #9
0
File: api.py Project: blahRus/nova
 def delete_console(self, context, instance_uuid, console_uuid):
     console = self.db.console_get(context, console_uuid, instance_uuid)
     topic = rpc.queue_get_for(context, CONF.console_topic,
                               console['pool']['host'])
     rpcapi = console_rpcapi.ConsoleAPI(topic=topic)
     rpcapi.remove_console(context, console['id'])
Example #10
0
 def delete_console(self, context, instance_uuid, console_uuid):
     console = self.db.console_get(context, console_uuid, instance_uuid)
     rpcapi = console_rpcapi.ConsoleAPI(topic=CONF.console_topic,
                                        server=console['pool']['host'])
     rpcapi.remove_console(context, console['id'])