Merge "client.logger.warning wrongly used in migrations"

This commit is contained in:
Jenkins 2017-06-06 07:51:22 +00:00 committed by Gerrit Code Review
commit a12dcfb046
3 changed files with 21 additions and 4 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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