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
This commit is contained in:
parent
3e9a98b838
commit
9a27201416
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue