1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012, Red Hat, Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
18
Unit Tests for nova.console.rpcapi
21
from nova.console import rpcapi as console_rpcapi
22
from nova import context
23
from nova import flags
31
class ConsoleRpcAPITestCase(test.TestCase):
34
super(ConsoleRpcAPITestCase, self).setUp()
37
super(ConsoleRpcAPITestCase, self).tearDown()
39
def _test_console_api(self, method, **kwargs):
40
ctxt = context.RequestContext('fake_user', 'fake_project')
41
rpcapi = console_rpcapi.ConsoleAPI()
42
expected_msg = rpcapi.make_msg(method, **kwargs)
43
expected_msg['version'] = rpcapi.RPC_API_VERSION
46
self.cast_topic = None
49
def _fake_cast(_ctxt, _topic, _msg):
50
self.cast_ctxt = _ctxt
51
self.cast_topic = _topic
54
self.stubs.Set(rpc, 'cast', _fake_cast)
56
getattr(rpcapi, method)(ctxt, **kwargs)
58
self.assertEqual(self.cast_ctxt, ctxt)
59
self.assertEqual(self.cast_topic, FLAGS.console_topic)
60
self.assertEqual(self.cast_msg, expected_msg)
62
def test_add_console(self):
63
self._test_console_api('add_console', instance_id='i')
65
def test_remove_console(self):
66
self._test_console_api('remove_console', console_id='i')