From 9a272014167390217351dd5a60f50f518f4ae600 Mon Sep 17 00:00:00 2001 From: nidhimittalhada Date: Tue, 9 May 2017 15:20:49 +0530 Subject: [PATCH] client.logger.warning wrongly used in migrations client.logger.warning if reached, will give this error "No handlers could be found for logger "novaclient.v2.client"". Fixed by using warnings.warn() and corrected root cause by adding appropriate handlers. Change-Id: I60c8a023cff92f8b6f37a4a14b6193c3efaa19a8 Closes-Bug: #1688507 --- novaclient/tests/unit/v2/test_migrations.py | 11 +++++++++++ novaclient/v2/client.py | 6 +++++- novaclient/v2/migrations.py | 8 +++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/novaclient/tests/unit/v2/test_migrations.py b/novaclient/tests/unit/v2/test_migrations.py index e69d3327e..408909cda 100644 --- a/novaclient/tests/unit/v2/test_migrations.py +++ b/novaclient/tests/unit/v2/test_migrations.py @@ -10,6 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. +import mock + from novaclient import api_versions from novaclient.tests.unit import utils from novaclient.tests.unit.v2 import fakes @@ -38,6 +40,15 @@ class MigrationsTest(utils.TestCase): self.assertIsInstance(m, migrations.Migration) self.assertEqual(m.migration_type, 'live-migration') + @mock.patch('novaclient.v2.migrations.warnings.warn') + def test_list_migrations_with_cell_name(self, mock_warn): + ml = self.cs.migrations.list(cell_name="abc") + self.assert_request_id(ml, fakes.FAKE_REQUEST_ID_LIST) + self.cs.assert_called('GET', '/os-migrations?cell_name=abc') + for m in ml: + self.assertIsInstance(m, migrations.Migration) + self.assertTrue(mock_warn.called) + def test_list_migrations_with_filters(self): ml = self.cs.migrations.list('host1', 'finished', 'child1') self.assert_request_id(ml, fakes.FAKE_REQUEST_ID_LIST) diff --git a/novaclient/v2/client.py b/novaclient/v2/client.py index b85077392..73280b59b 100644 --- a/novaclient/v2/client.py +++ b/novaclient/v2/client.py @@ -183,7 +183,11 @@ class Client(object): self.server_external_events = \ server_external_events.ServerExternalEventManager(self) - self.logger = logger or logging.getLogger(__name__) + if not logger: + logger = logging.getLogger(__name__) + if not logger.handlers: + logger.addHandler(logging.StreamHandler()) + self.logger = logger # Add in any extensions... if extensions: diff --git a/novaclient/v2/migrations.py b/novaclient/v2/migrations.py index 5a39ed992..72e0deda9 100644 --- a/novaclient/v2/migrations.py +++ b/novaclient/v2/migrations.py @@ -19,6 +19,8 @@ from six.moves.urllib import parse from novaclient import base from novaclient.i18n import _ +import warnings + class Migration(base.Resource): def __repr__(self): @@ -41,9 +43,9 @@ class MigrationManager(base.ManagerWithFind): if status: opts['status'] = status if cell_name: - self.client.logger.warning(_("Argument 'cell_name' is " - "deprecated since Pike, and will " - "be removed in a future release.")) + warnings.warn(_("Argument 'cell_name' is " + "deprecated since Pike, and will " + "be removed in a future release.")) opts['cell_name'] = cell_name if instance_uuid: opts['instance_uuid'] = instance_uuid