From 3d0272f9fe3d18c18f0cca732ee02321797d2e93 Mon Sep 17 00:00:00 2001 From: jichenjc Date: Wed, 7 Oct 2015 10:44:54 +0800 Subject: [PATCH] Remove stub_compute config options console use stub_compute to perform easy unit test, it can use mock to do the test without config option, so remove it and it's safe because it's only related to test purpose and no side effect to end user. Change-Id: If38148e178e50a348810312826b16cbd34ba550b --- nova/conf/console.py | 3 --- nova/console/manager.py | 7 +------ nova/tests/unit/console/test_console.py | 26 ++++++++++++++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/nova/conf/console.py b/nova/conf/console.py index 975e7beb0781..38c22dea75eb 100644 --- a/nova/conf/console.py +++ b/nova/conf/console.py @@ -29,9 +29,6 @@ console_opts = [ cfg.StrOpt('console_driver', default='nova.console.xvp.XVPConsoleProxy', help='Driver to use for the console proxy'), - cfg.BoolOpt('stub_compute', - default=False, - help='Stub calls to compute worker for tests'), cfg.StrOpt('console_public_hostname', default=socket.gethostname(), help='Publicly visible name for this console host'), diff --git a/nova/console/manager.py b/nova/console/manager.py index 52e1b9f26d0c..b4a9f1fc1ea2 100644 --- a/nova/console/manager.py +++ b/nova/console/manager.py @@ -104,12 +104,7 @@ class ConsoleProxyManager(manager.Manager): # NOTE(mdragon): Right now, the only place this info exists is the # compute worker's flagfile, at least for # xenserver. Thus we ned to ask. - if CONF.stub_compute: - pool_info = {'address': '127.0.0.1', - 'username': 'test', - 'password': '1234pass'} - else: - pool_info = self.compute_rpcapi.get_console_pool_info(context, + pool_info = self.compute_rpcapi.get_console_pool_info(context, console_type, instance_host) pool_info['password'] = self.driver.fix_pool_password( pool_info['password']) diff --git a/nova/tests/unit/console/test_console.py b/nova/tests/unit/console/test_console.py index 8eefa13bdea0..8101984c9c8c 100644 --- a/nova/tests/unit/console/test_console.py +++ b/nova/tests/unit/console/test_console.py @@ -35,13 +35,15 @@ class ConsoleTestCase(test.TestCase): """Test case for console proxy manager.""" def setUp(self): super(ConsoleTestCase, self).setUp() - self.flags(console_driver='nova.console.fake.FakeConsoleProxy', - stub_compute=True) + self.flags(console_driver='nova.console.fake.FakeConsoleProxy') self.console = importutils.import_object(CONF.console_manager) self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) self.host = 'test_compute_host' + self.pool_info = {'address': '127.0.0.1', + 'username': 'test', + 'password': '1234pass'} def test_reset(self): with mock.patch('nova.compute.rpcapi.ComputeAPI') as mock_rpc: @@ -62,12 +64,16 @@ class ConsoleTestCase(test.TestCase): inst['ami_launch_index'] = 0 return db.instance_create(self.context, inst) - def test_get_pool_for_instance_host(self): + @mock.patch.object(compute_rpcapi.ComputeAPI, 'get_console_pool_info') + def test_get_pool_for_instance_host(self, mock_get): + mock_get.return_value = self.pool_info 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): + @mock.patch.object(compute_rpcapi.ComputeAPI, 'get_console_pool_info') + def test_get_pool_creates_new_pool_if_needed(self, mock_get): + mock_get.return_value = self.pool_info self.assertRaises(exception.NotFound, db.console_pool_get_by_host_type, self.context, @@ -94,7 +100,9 @@ class ConsoleTestCase(test.TestCase): 'sometesthostname') self.assertEqual(pool['id'], new_pool['id']) - def test_add_console(self): + @mock.patch.object(compute_rpcapi.ComputeAPI, 'get_console_pool_info') + def test_add_console(self, mock_get): + mock_get.return_value = self.pool_info instance = self._create_instance() self.console.add_console(self.context, instance['id']) instance = db.instance_get(self.context, instance['id']) @@ -106,14 +114,18 @@ class ConsoleTestCase(test.TestCase): self.assertIn(instance['uuid'], console_instances) db.instance_destroy(self.context, instance['uuid']) - def test_add_console_does_not_duplicate(self): + @mock.patch.object(compute_rpcapi.ComputeAPI, 'get_console_pool_info') + def test_add_console_does_not_duplicate(self, mock_get): + mock_get.return_value = self.pool_info instance = self._create_instance() cons1 = self.console.add_console(self.context, instance['id']) cons2 = self.console.add_console(self.context, instance['id']) self.assertEqual(cons1, cons2) db.instance_destroy(self.context, instance['uuid']) - def test_remove_console(self): + @mock.patch.object(compute_rpcapi.ComputeAPI, 'get_console_pool_info') + def test_remove_console(self, mock_get): + mock_get.return_value = self.pool_info instance = self._create_instance() console_id = self.console.add_console(self.context, instance['id']) self.console.remove_console(self.context, console_id)