Fix fuel cli output function

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

Change-Id: Ia116df52e431e74fda9505147f90561e46283d85
Closes-Bug: #1576682
This commit is contained in:
Mikhail
2016-07-05 17:37:36 +03:00
parent ea5ca4adcd
commit ba4e35a72a
4 changed files with 20 additions and 82 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
class DeployChangesAction(Action):
@@ -33,6 +32,12 @@ class DeployChangesAction(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 deploy all applied changes to some environment:
fuel --env 1 deploy-changes
@@ -43,4 +48,4 @@ class DeployChangesAction(Action):
self.serializer.print_to_output(
deploy_task.data,
deploy_task,
print_method=print_deploy_progress)
print_method=self.print_deploy_info)

View File

@@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import curses
from functools import partial
from itertools import chain
import math
@@ -22,7 +21,6 @@ import sys
from time import sleep
import urllib2
from fuelclient.cli.error import DeployProgressError
from fuelclient.cli.error import exit_with_error
@@ -138,82 +136,6 @@ def download_snapshot_with_progress_bar(
print()
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

@@ -21,6 +21,7 @@ except ImportError:
import logging
import os
import re
import shutil
import subprocess
import sys
@@ -183,6 +184,12 @@ class BaseTestCase(UnitTestCase):
call = self.run_cli_command(command, check_errors=check_errors)
self.assertEqual(call.stdout, msg)
def check_for_stdout_by_regexp(self, command, pattern, check_errors=True):
call = self.run_cli_command(command, check_errors=check_errors)
result = re.search(pattern, call.stdout)
self.assertIsNotNone(result)
return result
def check_for_stderr(self, command, msg, check_errors=True):
call = self.run_cli_command(command, check_errors=check_errors)
self.assertIn(msg, call.stderr)

View File

@@ -428,10 +428,14 @@ class TestDownloadUploadNodeAttributes(base.BaseTestCase):
class TestDeployChanges(base.BaseTestCase):
pattern_success = (r"^Deployment task with id (\d{1,}) "
r"for the environment 1 has been started.\n$")
def test_deploy_changes_no_failure(self):
self.load_data_to_nailgun_server()
release_id = self.get_first_deployable_release_id()
env_create = "env create --name=test --release={0}".format(release_id)
add_node = "--env-id=1 node set --node 1 --role=controller"
deploy_changes = "deploy-changes --env 1"
self.run_cli_commands((env_create, add_node, deploy_changes))
self.run_cli_commands((env_create, add_node))
self.check_for_stdout_by_regexp(deploy_changes, self.pattern_success)