Fix additional output encoding issues
This is a followup to https://review.openstack.org/#/c/541609/ that changes most outstanding direct uses of sys.stdout to use the encoded stdout set up by cliff. Change-Id: I07cfc418385fc787d3b7d3c32d39676cf81bb91f
This commit is contained in:
parent
9a17356854
commit
6df58b6366
@ -20,7 +20,6 @@ import getpass
|
|||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
from novaclient.v2 import servers
|
from novaclient.v2 import servers
|
||||||
from osc_lib.cli import parseractions
|
from osc_lib.cli import parseractions
|
||||||
@ -189,12 +188,6 @@ def _prep_server_detail(compute_client, image_client, server):
|
|||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
def _show_progress(progress):
|
|
||||||
if progress:
|
|
||||||
sys.stdout.write('\rProgress: %s' % progress)
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
|
|
||||||
class AddFixedIP(command.Command):
|
class AddFixedIP(command.Command):
|
||||||
_description = _("Add fixed IP address to server")
|
_description = _("Add fixed IP address to server")
|
||||||
|
|
||||||
@ -580,6 +573,12 @@ class CreateServer(command.ShowOne):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
|
def _show_progress(progress):
|
||||||
|
if progress:
|
||||||
|
self.app.stdout.write('\rProgress: %s' % progress)
|
||||||
|
self.app.stdout.flush()
|
||||||
|
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.volume
|
||||||
image_client = self.app.client_manager.image
|
image_client = self.app.client_manager.image
|
||||||
@ -814,11 +813,11 @@ class CreateServer(command.ShowOne):
|
|||||||
server.id,
|
server.id,
|
||||||
callback=_show_progress,
|
callback=_show_progress,
|
||||||
):
|
):
|
||||||
sys.stdout.write('\n')
|
self.app.stdout.write('\n')
|
||||||
else:
|
else:
|
||||||
LOG.error(_('Error creating server: %s'),
|
LOG.error(_('Error creating server: %s'),
|
||||||
parsed_args.server_name)
|
parsed_args.server_name)
|
||||||
sys.stdout.write(_('Error creating server\n'))
|
self.app.stdout.write(_('Error creating server\n'))
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
details = _prep_server_detail(compute_client, image_client, server)
|
details = _prep_server_detail(compute_client, image_client, server)
|
||||||
@ -872,6 +871,12 @@ class DeleteServer(command.Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
|
def _show_progress(progress):
|
||||||
|
if progress:
|
||||||
|
self.app.stdout.write('\rProgress: %s' % progress)
|
||||||
|
self.app.stdout.flush()
|
||||||
|
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
for server in parsed_args.server:
|
for server in parsed_args.server:
|
||||||
server_obj = utils.find_resource(
|
server_obj = utils.find_resource(
|
||||||
@ -883,11 +888,11 @@ class DeleteServer(command.Command):
|
|||||||
server_obj.id,
|
server_obj.id,
|
||||||
callback=_show_progress,
|
callback=_show_progress,
|
||||||
):
|
):
|
||||||
sys.stdout.write('\n')
|
self.app.stdout.write('\n')
|
||||||
else:
|
else:
|
||||||
LOG.error(_('Error deleting server: %s'),
|
LOG.error(_('Error deleting server: %s'),
|
||||||
server_obj.id)
|
server_obj.id)
|
||||||
sys.stdout.write(_('Error deleting server\n'))
|
self.app.stdout.write(_('Error deleting server\n'))
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
|
|
||||||
@ -1290,6 +1295,11 @@ class MigrateServer(command.Command):
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
|
def _show_progress(progress):
|
||||||
|
if progress:
|
||||||
|
self.app.stdout.write('\rProgress: %s' % progress)
|
||||||
|
self.app.stdout.flush()
|
||||||
|
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
|
|
||||||
server = utils.find_resource(
|
server = utils.find_resource(
|
||||||
@ -1315,11 +1325,11 @@ class MigrateServer(command.Command):
|
|||||||
server.id,
|
server.id,
|
||||||
callback=_show_progress,
|
callback=_show_progress,
|
||||||
):
|
):
|
||||||
sys.stdout.write(_('Complete\n'))
|
self.app.stdout.write(_('Complete\n'))
|
||||||
else:
|
else:
|
||||||
LOG.error(_('Error migrating server: %s'),
|
LOG.error(_('Error migrating server: %s'),
|
||||||
server.id)
|
server.id)
|
||||||
sys.stdout.write(_('Error migrating server\n'))
|
self.app.stdout.write(_('Error migrating server\n'))
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
|
|
||||||
@ -1380,6 +1390,12 @@ class RebootServer(command.Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
|
def _show_progress(progress):
|
||||||
|
if progress:
|
||||||
|
self.app.stdout.write('\rProgress: %s' % progress)
|
||||||
|
self.app.stdout.flush()
|
||||||
|
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
server = utils.find_resource(
|
server = utils.find_resource(
|
||||||
compute_client.servers, parsed_args.server)
|
compute_client.servers, parsed_args.server)
|
||||||
@ -1391,11 +1407,11 @@ class RebootServer(command.Command):
|
|||||||
server.id,
|
server.id,
|
||||||
callback=_show_progress,
|
callback=_show_progress,
|
||||||
):
|
):
|
||||||
sys.stdout.write(_('Complete\n'))
|
self.app.stdout.write(_('Complete\n'))
|
||||||
else:
|
else:
|
||||||
LOG.error(_('Error rebooting server: %s'),
|
LOG.error(_('Error rebooting server: %s'),
|
||||||
server.id)
|
server.id)
|
||||||
sys.stdout.write(_('Error rebooting server\n'))
|
self.app.stdout.write(_('Error rebooting server\n'))
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
|
|
||||||
@ -1428,6 +1444,12 @@ class RebuildServer(command.ShowOne):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
|
def _show_progress(progress):
|
||||||
|
if progress:
|
||||||
|
self.app.stdout.write('\rProgress: %s' % progress)
|
||||||
|
self.app.stdout.flush()
|
||||||
|
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
image_client = self.app.client_manager.image
|
image_client = self.app.client_manager.image
|
||||||
|
|
||||||
@ -1445,11 +1467,11 @@ class RebuildServer(command.ShowOne):
|
|||||||
server.id,
|
server.id,
|
||||||
callback=_show_progress,
|
callback=_show_progress,
|
||||||
):
|
):
|
||||||
sys.stdout.write(_('Complete\n'))
|
self.app.stdout.write(_('Complete\n'))
|
||||||
else:
|
else:
|
||||||
LOG.error(_('Error rebuilding server: %s'),
|
LOG.error(_('Error rebuilding server: %s'),
|
||||||
server.id)
|
server.id)
|
||||||
sys.stdout.write(_('Error rebuilding server\n'))
|
self.app.stdout.write(_('Error rebuilding server\n'))
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
details = _prep_server_detail(compute_client, image_client, server)
|
details = _prep_server_detail(compute_client, image_client, server)
|
||||||
@ -1727,6 +1749,11 @@ the new server and restart the old one.""")
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
|
def _show_progress(progress):
|
||||||
|
if progress:
|
||||||
|
self.app.stdout.write('\rProgress: %s' % progress)
|
||||||
|
self.app.stdout.flush()
|
||||||
|
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
server = utils.find_resource(
|
server = utils.find_resource(
|
||||||
compute_client.servers,
|
compute_client.servers,
|
||||||
@ -1745,11 +1772,11 @@ the new server and restart the old one.""")
|
|||||||
success_status=['active', 'verify_resize'],
|
success_status=['active', 'verify_resize'],
|
||||||
callback=_show_progress,
|
callback=_show_progress,
|
||||||
):
|
):
|
||||||
sys.stdout.write(_('Complete\n'))
|
self.app.stdout.write(_('Complete\n'))
|
||||||
else:
|
else:
|
||||||
LOG.error(_('Error resizing server: %s'),
|
LOG.error(_('Error resizing server: %s'),
|
||||||
server.id)
|
server.id)
|
||||||
sys.stdout.write(_('Error resizing server\n'))
|
self.app.stdout.write(_('Error resizing server\n'))
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
elif parsed_args.confirm:
|
elif parsed_args.confirm:
|
||||||
compute_client.servers.confirm_resize(server)
|
compute_client.servers.confirm_resize(server)
|
||||||
@ -1915,7 +1942,9 @@ class ShowServer(command.ShowOne):
|
|||||||
if parsed_args.diagnostics:
|
if parsed_args.diagnostics:
|
||||||
(resp, data) = server.diagnostics()
|
(resp, data) = server.diagnostics()
|
||||||
if not resp.status_code == 200:
|
if not resp.status_code == 200:
|
||||||
sys.stderr.write(_("Error retrieving diagnostics data\n"))
|
self.app.stderr.write(_(
|
||||||
|
"Error retrieving diagnostics data\n"
|
||||||
|
))
|
||||||
return ({}, {})
|
return ({}, {})
|
||||||
else:
|
else:
|
||||||
data = _prep_server_detail(compute_client,
|
data = _prep_server_detail(compute_client,
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
|
|
||||||
"""Compute v2 Server action implementations"""
|
"""Compute v2 Server action implementations"""
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
@ -26,12 +24,6 @@ import six
|
|||||||
from openstackclient.i18n import _
|
from openstackclient.i18n import _
|
||||||
|
|
||||||
|
|
||||||
def _show_progress(progress):
|
|
||||||
if progress:
|
|
||||||
sys.stderr.write('\rProgress: %s' % progress)
|
|
||||||
sys.stderr.flush()
|
|
||||||
|
|
||||||
|
|
||||||
class CreateServerBackup(command.ShowOne):
|
class CreateServerBackup(command.ShowOne):
|
||||||
_description = _("Create a server backup image")
|
_description = _("Create a server backup image")
|
||||||
|
|
||||||
@ -74,6 +66,12 @@ class CreateServerBackup(command.ShowOne):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
|
def _show_progress(progress):
|
||||||
|
if progress:
|
||||||
|
self.app.stderr.write('\rProgress: %s' % progress)
|
||||||
|
self.app.stderr.flush()
|
||||||
|
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
|
|
||||||
server = utils.find_resource(
|
server = utils.find_resource(
|
||||||
@ -114,7 +112,7 @@ class CreateServerBackup(command.ShowOne):
|
|||||||
image.id,
|
image.id,
|
||||||
callback=_show_progress,
|
callback=_show_progress,
|
||||||
):
|
):
|
||||||
sys.stdout.write('\n')
|
self.app.stdout.write('\n')
|
||||||
else:
|
else:
|
||||||
msg = _('Error creating server backup: %s') % parsed_args.name
|
msg = _('Error creating server backup: %s') % parsed_args.name
|
||||||
raise exceptions.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
"""Compute v2 Server action implementations"""
|
"""Compute v2 Server action implementations"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
|
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
@ -30,12 +29,6 @@ from openstackclient.i18n import _
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _show_progress(progress):
|
|
||||||
if progress:
|
|
||||||
sys.stdout.write('\rProgress: %s' % progress)
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
|
|
||||||
class CreateServerImage(command.ShowOne):
|
class CreateServerImage(command.ShowOne):
|
||||||
_description = _("Create a new server disk image from an existing server")
|
_description = _("Create a new server disk image from an existing server")
|
||||||
|
|
||||||
@ -64,6 +57,12 @@ class CreateServerImage(command.ShowOne):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
|
def _show_progress(progress):
|
||||||
|
if progress:
|
||||||
|
self.app.stdout.write('\rProgress: %s' % progress)
|
||||||
|
self.app.stdout.flush()
|
||||||
|
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
|
|
||||||
server = utils.find_resource(
|
server = utils.find_resource(
|
||||||
@ -92,7 +91,7 @@ class CreateServerImage(command.ShowOne):
|
|||||||
image_id,
|
image_id,
|
||||||
callback=_show_progress,
|
callback=_show_progress,
|
||||||
):
|
):
|
||||||
sys.stdout.write('\n')
|
self.app.stdout.write('\n')
|
||||||
else:
|
else:
|
||||||
LOG.error(_('Error creating server image: %s'),
|
LOG.error(_('Error creating server image: %s'),
|
||||||
parsed_args.server)
|
parsed_args.server)
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
"""Usage action implementations"""
|
"""Usage action implementations"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import sys
|
|
||||||
|
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
@ -96,7 +95,7 @@ class ListUsage(command.Lister):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if parsed_args.formatter == 'table' and len(usage_list) > 0:
|
if parsed_args.formatter == 'table' and len(usage_list) > 0:
|
||||||
sys.stdout.write(_("Usage from %(start)s to %(end)s: \n") % {
|
self.app.stdout.write(_("Usage from %(start)s to %(end)s: \n") % {
|
||||||
"start": start.strftime(dateformat),
|
"start": start.strftime(dateformat),
|
||||||
"end": end.strftime(dateformat),
|
"end": end.strftime(dateformat),
|
||||||
})
|
})
|
||||||
@ -168,8 +167,9 @@ class ShowUsage(command.ShowOne):
|
|||||||
usage = compute_client.usage.get(project, start, end)
|
usage = compute_client.usage.get(project, start, end)
|
||||||
|
|
||||||
if parsed_args.formatter == 'table':
|
if parsed_args.formatter == 'table':
|
||||||
sys.stdout.write(_("Usage from %(start)s to %(end)s on "
|
self.app.stdout.write(_(
|
||||||
"project %(project)s: \n") % {
|
"Usage from %(start)s to %(end)s on project %(project)s: \n"
|
||||||
|
) % {
|
||||||
"start": start.strftime(dateformat),
|
"start": start.strftime(dateformat),
|
||||||
"end": end.strftime(dateformat),
|
"end": end.strftime(dateformat),
|
||||||
"project": project,
|
"project": project,
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
"""Group action implementations"""
|
"""Group action implementations"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
|
|
||||||
from keystoneauth1 import exceptions as ks_exc
|
from keystoneauth1 import exceptions as ks_exc
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
@ -122,7 +121,7 @@ class CheckUserInGroup(command.Command):
|
|||||||
'user': parsed_args.user,
|
'user': parsed_args.user,
|
||||||
'group': parsed_args.group,
|
'group': parsed_args.group,
|
||||||
}
|
}
|
||||||
sys.stderr.write(msg)
|
self.app.stderr.write(msg)
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
@ -130,7 +129,7 @@ class CheckUserInGroup(command.Command):
|
|||||||
'user': parsed_args.user,
|
'user': parsed_args.user,
|
||||||
'group': parsed_args.group,
|
'group': parsed_args.group,
|
||||||
}
|
}
|
||||||
sys.stdout.write(msg)
|
self.app.stdout.write(msg)
|
||||||
|
|
||||||
|
|
||||||
class CreateGroup(command.ShowOne):
|
class CreateGroup(command.ShowOne):
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
|
|
||||||
from glanceclient.common import utils as gc_utils
|
from glanceclient.common import utils as gc_utils
|
||||||
from osc_lib.cli import parseractions
|
from osc_lib.cli import parseractions
|
||||||
@ -653,7 +652,7 @@ class SaveImage(command.Command):
|
|||||||
if data.wrapped is None:
|
if data.wrapped is None:
|
||||||
msg = _('Image %s has no data.') % image.id
|
msg = _('Image %s has no data.') % image.id
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
sys.stdout.write(msg + '\n')
|
self.app.stdout.write(msg + '\n')
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
gc_utils.save_image(data, parsed_args.file)
|
gc_utils.save_image(data, parsed_args.file)
|
||||||
|
@ -925,7 +925,7 @@ class TestServerCreate(TestServer):
|
|||||||
mock_wait_for_status.assert_called_once_with(
|
mock_wait_for_status.assert_called_once_with(
|
||||||
self.servers_mock.get,
|
self.servers_mock.get,
|
||||||
self.new_server.id,
|
self.new_server.id,
|
||||||
callback=server._show_progress,
|
callback=mock.ANY,
|
||||||
)
|
)
|
||||||
|
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
@ -975,7 +975,7 @@ class TestServerCreate(TestServer):
|
|||||||
mock_wait_for_status.assert_called_once_with(
|
mock_wait_for_status.assert_called_once_with(
|
||||||
self.servers_mock.get,
|
self.servers_mock.get,
|
||||||
self.new_server.id,
|
self.new_server.id,
|
||||||
callback=server._show_progress,
|
callback=mock.ANY,
|
||||||
)
|
)
|
||||||
|
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
@ -1494,7 +1494,7 @@ class TestServerDelete(TestServer):
|
|||||||
mock_wait_for_delete.assert_called_once_with(
|
mock_wait_for_delete.assert_called_once_with(
|
||||||
self.servers_mock,
|
self.servers_mock,
|
||||||
servers[0].id,
|
servers[0].id,
|
||||||
callback=server._show_progress
|
callback=mock.ANY,
|
||||||
)
|
)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
@ -1516,7 +1516,7 @@ class TestServerDelete(TestServer):
|
|||||||
mock_wait_for_delete.assert_called_once_with(
|
mock_wait_for_delete.assert_called_once_with(
|
||||||
self.servers_mock,
|
self.servers_mock,
|
||||||
servers[0].id,
|
servers[0].id,
|
||||||
callback=server._show_progress
|
callback=mock.ANY,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -2152,7 +2152,7 @@ class TestServerRebuild(TestServer):
|
|||||||
mock_wait_for_status.assert_called_once_with(
|
mock_wait_for_status.assert_called_once_with(
|
||||||
self.servers_mock.get,
|
self.servers_mock.get,
|
||||||
self.server.id,
|
self.server.id,
|
||||||
callback=server._show_progress,
|
callback=mock.ANY,
|
||||||
# **kwargs
|
# **kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -2177,7 +2177,7 @@ class TestServerRebuild(TestServer):
|
|||||||
mock_wait_for_status.assert_called_once_with(
|
mock_wait_for_status.assert_called_once_with(
|
||||||
self.servers_mock.get,
|
self.servers_mock.get,
|
||||||
self.server.id,
|
self.server.id,
|
||||||
callback=server._show_progress
|
callback=mock.ANY,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.servers_mock.get.assert_called_with(self.server.id)
|
self.servers_mock.get.assert_called_with(self.server.id)
|
||||||
@ -2619,7 +2619,7 @@ class TestServerResize(TestServer):
|
|||||||
mock_wait_for_status.assert_called_once_with(
|
mock_wait_for_status.assert_called_once_with(
|
||||||
self.servers_mock.get,
|
self.servers_mock.get,
|
||||||
self.server.id,
|
self.server.id,
|
||||||
callback=server._show_progress,
|
callback=mock.ANY,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -2659,7 +2659,7 @@ class TestServerResize(TestServer):
|
|||||||
mock_wait_for_status.assert_called_once_with(
|
mock_wait_for_status.assert_called_once_with(
|
||||||
self.servers_mock.get,
|
self.servers_mock.get,
|
||||||
self.server.id,
|
self.server.id,
|
||||||
callback=server._show_progress,
|
callback=mock.ANY,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user