summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-05-16 16:31:39 -0400
committerRussell Bryant <rbryant@redhat.com>2012-05-23 07:11:03 -0400
commitf50ce35c9cf2e05d205485586da1cb6d5433ba56 (patch)
treed24d4c4900a63bbc695609056a7d45adf9b7ec32 /nova
parent82f38e44ae5504bc56e05446266912cb700a329e (diff)
downloadnova-f50ce35c9cf2e05d205485586da1cb6d5433ba56.tar.gz
nova-f50ce35c9cf2e05d205485586da1cb6d5433ba56.tar.xz
nova-f50ce35c9cf2e05d205485586da1cb6d5433ba56.zip
Add version to console rpc API.
Part of blueprint versioned-rpc-apis. Change-Id: I17d6e3094c56d8628688dabdc8d40b2f4f815af4
Diffstat (limited to 'nova')
-rw-r--r--nova/console/api.py23
-rw-r--r--nova/console/manager.py2
-rw-r--r--nova/console/rpcapi.py47
-rw-r--r--nova/tests/console/__init__.py19
-rw-r--r--nova/tests/console/test_console.py (renamed from nova/tests/test_console.py)10
-rw-r--r--nova/tests/console/test_rpcapi.py66
6 files changed, 148 insertions, 19 deletions
diff --git a/nova/console/api.py b/nova/console/api.py
index dd166052f..0feaae488 100644
--- a/nova/console/api.py
+++ b/nova/console/api.py
@@ -17,6 +17,7 @@
"""Handles ConsoleProxy API requests."""
+from nova.console import rpcapi as console_rpcapi
from nova.db import base
from nova import flags
from nova import rpc
@@ -42,16 +43,11 @@ class API(base.Base):
def delete_console(self, context, instance_id, console_id):
instance_id = self._translate_uuid_if_necessary(context, instance_id)
- console = self.db.console_get(context,
- console_id,
- instance_id)
- pool = console['pool']
- rpc.cast(context,
- self.db.queue_get_for(context,
- FLAGS.console_topic,
- pool['host']),
- {'method': 'remove_console',
- 'args': {'console_id': console['id']}})
+ console = self.db.console_get(context, console_id, instance_id)
+ topic = self.db.queue_get_for(context, FLAGS.console_topic,
+ pool['host'])
+ rpcapi = console_rpcapi.ConsoleAPI(topic=topic)
+ rpcapi.remove_console(context, console['id'])
def create_console(self, context, instance_id):
#NOTE(mdragon): If we wanted to return this the console info
@@ -60,10 +56,9 @@ class API(base.Base):
# console info. I am not sure which is better
# here.
instance = self._get_instance(context, instance_id)
- rpc.cast(context,
- self._get_console_topic(context, instance['host']),
- {'method': 'add_console',
- 'args': {'instance_id': instance['id']}})
+ topic = self._get_console_topic(context, instance['host']),
+ rpcapi = console_rpcapi.ConsoleAPI(topic=topic)
+ rpcapi.add_console(context, instance['id'])
def _get_console_topic(self, context, instance_host):
topic = self.db.queue_get_for(context,
diff --git a/nova/console/manager.py b/nova/console/manager.py
index 335de3284..8a42b449a 100644
--- a/nova/console/manager.py
+++ b/nova/console/manager.py
@@ -53,6 +53,8 @@ class ConsoleProxyManager(manager.Manager):
"""
+ RPC_API_VERSION = '1.0'
+
def __init__(self, console_driver=None, *args, **kwargs):
if not console_driver:
console_driver = FLAGS.console_driver
diff --git a/nova/console/rpcapi.py b/nova/console/rpcapi.py
new file mode 100644
index 000000000..8f0c5b97f
--- /dev/null
+++ b/nova/console/rpcapi.py
@@ -0,0 +1,47 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012, Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""
+Client side of the console RPC API.
+"""
+
+from nova import flags
+import nova.rpc.proxy
+
+
+FLAGS = flags.FLAGS
+
+
+class ConsoleAPI(nova.rpc.proxy.RpcProxy):
+ '''Client side of the console rpc API.
+
+ API version history:
+
+ 1.0 - Initial version.
+ '''
+
+ RPC_API_VERSION = '1.0'
+
+ def __init__(self, topic=None):
+ topic = topic if topic else FLAGS.console_topic
+ super(ConsoleAPI, self).__init__(topic=topic,
+ default_version=self.RPC_API_VERSION)
+
+ def add_console(self, ctxt, instance_id):
+ self.cast(ctxt, self.make_msg('add_console', instance_id=instance_id))
+
+ def remove_console(self, ctxt, console_id):
+ self.cast(ctxt, self.make_msg('remove_console', console_id=console_id))
diff --git a/nova/tests/console/__init__.py b/nova/tests/console/__init__.py
new file mode 100644
index 000000000..7e04e7c73
--- /dev/null
+++ b/nova/tests/console/__init__.py
@@ -0,0 +1,19 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# NOTE(vish): this forces the fixtures from tests/__init.py:setup() to work
+from nova.tests import *
diff --git a/nova/tests/test_console.py b/nova/tests/console/test_console.py
index c65d3c126..626cf2206 100644
--- a/nova/tests/test_console.py
+++ b/nova/tests/console/test_console.py
@@ -56,7 +56,8 @@ class ConsoleTestCase(test.TestCase):
return db.instance_create(self.context, inst)['id']
def test_get_pool_for_instance_host(self):
- pool = self.console.get_pool_for_instance_host(self.context, self.host)
+ pool = self.console.get_pool_for_instance_host(self.context,
+ self.host)
self.assertEqual(pool['compute_host'], self.host)
def test_get_pool_creates_new_pool_if_needed(self):
@@ -67,7 +68,7 @@ class ConsoleTestCase(test.TestCase):
self.console.host,
self.console.driver.console_type)
pool = self.console.get_pool_for_instance_host(self.context,
- self.host)
+ self.host)
pool2 = db.console_pool_get_by_host_type(self.context,
self.host,
self.console.host,
@@ -91,9 +92,8 @@ class ConsoleTestCase(test.TestCase):
self.console.add_console(self.context, instance_id)
instance = db.instance_get(self.context, instance_id)
pool = db.console_pool_get_by_host_type(self.context,
- instance['host'],
- self.console.host,
- self.console.driver.console_type)
+ instance['host'], self.console.host,
+ self.console.driver.console_type)
console_instances = [con['instance_id'] for con in pool.consoles]
self.assert_(instance_id in console_instances)
diff --git a/nova/tests/console/test_rpcapi.py b/nova/tests/console/test_rpcapi.py
new file mode 100644
index 000000000..132657697
--- /dev/null
+++ b/nova/tests/console/test_rpcapi.py
@@ -0,0 +1,66 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012, Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""
+Unit Tests for nova.console.rpcapi
+"""
+
+from nova.console import rpcapi as console_rpcapi
+from nova import context
+from nova import flags
+from nova import rpc
+from nova import test
+
+
+FLAGS = flags.FLAGS
+
+
+class ConsoleRpcAPITestCase(test.TestCase):
+
+ def setUp(self):
+ super(ConsoleRpcAPITestCase, self).setUp()
+
+ def tearDown(self):
+ super(ConsoleRpcAPITestCase, self).tearDown()
+
+ 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.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, FLAGS.console_topic)
+ self.assertEqual(self.cast_msg, expected_msg)
+
+ def test_add_console(self):
+ self._test_console_api('add_console', instance_id='i')
+
+ def test_remove_console(self):
+ self._test_console_api('remove_console', console_id='i')