Fix fuel cli output function

This patch removes printing deployment progress function
and shows message such as fuel2.

Change-Id: Ia85db174976cb0dbacaf20e6378fcbb9f1ed7cf0
Closes-Bug: #1565026
This commit is contained in:
Mikhail 2016-06-07 14:49:11 +03:00
parent dcc1cabcfc
commit 91a2163966
3 changed files with 18 additions and 108 deletions

View File

@ -11,11 +11,10 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import six
from fuelclient.cli.actions.base import Action
import fuelclient.cli.arguments as Args
from fuelclient.cli.formatting import print_deploy_progress
from fuelclient.objects.environment import Environment
@ -34,6 +33,12 @@ class ChangesAction(Action):
(None, self.deploy_changes),
)
def print_deploy_info(self, deploy_task):
six.print_("Deployment task with id {t} for the environment {e} "
"has been started.".format(t=deploy_task.id,
e=deploy_task.env.id)
)
def deploy_changes(self, params):
"""To apply all changes to some environment:
fuel --env 1 {action_name}
@ -46,7 +51,7 @@ class ChangesAction(Action):
self.serializer.print_to_output(
deploy_task.data,
deploy_task,
print_method=print_deploy_progress)
print_method=self.print_deploy_info)
class DeployChangesAction(ChangesAction):

View File

@ -12,18 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import curses
from functools import partial
from itertools import chain
import math
from operator import itemgetter
import sys
from time import sleep
import six
from fuelclient.cli.error import DeployProgressError
def format_table(data, acceptable_keys=None, column_to_join=None):
"""Format list of dicts to table in a string form
@ -122,96 +116,6 @@ def quote_and_join(words):
return '"{0}"'.format(words[0])
def get_bar_for_progress(full_width, progress):
"""get_bar_for_progress - returns string with a width of 'full_width'
which illustrates specific progress value.
"""
number_of_equal_signs = int(
math.ceil(progress * float(full_width - 2) / 100)
)
return "[{0}{1}{2}]".format(
"=" * number_of_equal_signs,
">" if number_of_equal_signs < full_width - 2 else "",
" " * (full_width - 3 - number_of_equal_signs)
)
def print_deploy_progress(deploy_task):
"""Receives 'deploy_task' and depending on terminal availability
starts progress printing routines with or without curses.
"""
try:
terminal_screen = curses.initscr()
print_deploy_progress_with_terminal(deploy_task, terminal_screen)
except curses.error:
print_deploy_progress_without_terminal(deploy_task)
def print_deploy_progress_without_terminal(deploy_task):
print("Deploying changes to environment with id={0}".format(
deploy_task.env.id
))
message_len = 0
try:
for progress, nodes in deploy_task:
sys.stdout.write("\r" * message_len)
message_len = 0
deployment_message = "[Deployment: {0:3}%]".format(progress)
sys.stdout.write(deployment_message)
message_len += len(deployment_message)
for index, node in enumerate(nodes):
node_message = "[Node{id:2} {progress:3}%]".format(
**node.data
)
message_len += len(node_message)
sys.stdout.write(node_message)
print("\nFinished deployment!")
except DeployProgressError as de:
print(de.message)
def print_deploy_progress_with_terminal(deploy_task, terminal_screen):
scr_width = terminal_screen.getmaxyx()[1]
curses.noecho()
curses.cbreak()
total_progress_bar = partial(get_bar_for_progress, scr_width - 17)
node_bar = partial(get_bar_for_progress, scr_width - 28)
env_id = deploy_task.env.id
try:
for progress, nodes in deploy_task:
terminal_screen.refresh()
terminal_screen.addstr(
0, 0,
"Deploying changes to environment with id={0}".format(
env_id
)
)
terminal_screen.addstr(
1, 0,
"Deployment: {0} {1:3}%".format(
total_progress_bar(progress),
progress
)
)
for index, node in enumerate(nodes):
terminal_screen.addstr(
index + 2, 0,
"Node{id:3} {status:13}: {bar} {progress:3}%"
.format(bar=node_bar(node.progress), **node.data)
)
except DeployProgressError as de:
close_curses()
print(de.message)
finally:
close_curses()
def close_curses():
curses.echo()
curses.nocbreak()
curses.endwin()
def print_health_check(env):
tests_states = [{"status": "not finished"}]
finished_tests = set()

View File

@ -422,10 +422,8 @@ class TestDeployChanges(base.CLIv1TestCase):
cmd_deploy_changes = "deploy-changes --env 1"
cmd_redeploy_changes = "redeploy-changes --env 1"
messages_success = [
"Deploying changes to environment with id=1\n",
"Finished deployment!\n"
]
pattern_success = (r"^Deployment task with id (\d{1,}) "
r"for the environment 1 has been started.\n$")
def setUp(self):
super(TestDeployChanges, self).setUp()
@ -438,13 +436,16 @@ class TestDeployChanges(base.CLIv1TestCase):
))
def test_deploy_changes(self):
self.check_all_in_msg(self.cmd_deploy_changes,
self.messages_success)
self.check_for_stdout_by_regexp(self.cmd_deploy_changes,
self.pattern_success)
def test_redeploy_changes(self):
self.run_cli_command(self.cmd_deploy_changes)
self.check_all_in_msg(self.cmd_redeploy_changes,
self.messages_success)
result = self.check_for_stdout_by_regexp(self.cmd_deploy_changes,
self.pattern_success)
task_id = result.group(1)
self.wait_task_ready(task_id)
self.check_for_stdout_by_regexp(self.cmd_redeploy_changes,
self.pattern_success)
class TestDirectoryDoesntExistErrorMessages(base.CLIv1TestCase):