diff --git a/fuelclient/cli/actions/environment.py b/fuelclient/cli/actions/environment.py index f509964..6bc1c7c 100644 --- a/fuelclient/cli/actions/environment.py +++ b/fuelclient/cli/actions/environment.py @@ -88,10 +88,11 @@ class EnvironmentAction(Action): data = env.set(mode=params.mode) else: data = env.get_fresh_data() + self.serializer.print_to_output( data, - "Environment '{name}' with id={id}, mode={mode}" - " and network-mode={net_provider} was created!" + u"Environment '{name}' with id={id}, mode={mode}" + u" and network-mode={net_provider} was created!" .format(**data) ) diff --git a/fuelclient/cli/formatting.py b/fuelclient/cli/formatting.py index 6b2d379..dbec002 100644 --- a/fuelclient/cli/formatting.py +++ b/fuelclient/cli/formatting.py @@ -54,18 +54,20 @@ def format_table(data, acceptable_keys=None, column_to_join=None): ) for row in rows: column_widths.update( - (index, max(column_widths[index], len(str(element)))) + (index, max(column_widths[index], len(unicode(element)))) for index, element in enumerate(row) ) - row_template = ' | '.join( - "{{{0}:{1}}}".format(idx, width) + row_template = u' | '.join( + u"{{{0}:{1}}}".format(idx, width) for idx, width in column_widths.iteritems() ) - return '\n'.join( + + return u'\n'.join( (row_template.format(*header), - '-|-'.join(column_widths[column_index] * '-' - for column_index in range(number_of_columns)), - '\n'.join(row_template.format(*map(str, x)) for x in rows)) + u'-|-'.join(column_widths[column_index] * u'-' + for column_index in range(number_of_columns)), + u'\n'.join(row_template.format(*map(unicode, x)) + for x in rows)) ) @@ -243,8 +245,8 @@ def print_health_check(env): ) for test in new_finished_tests: print( - "[{0:2} of {1}] [{status}] '{name}' " - "({taken:.4} s) {message}".format( + u"[{0:2} of {1}] [{status}] '{name}' " + u"({taken:.4} s) {message}".format( test_counter, total_tests_count, **test diff --git a/fuelclient/cli/serializers.py b/fuelclient/cli/serializers.py index 5d78141..627f2d4 100644 --- a/fuelclient/cli/serializers.py +++ b/fuelclient/cli/serializers.py @@ -63,7 +63,7 @@ class Serializer(object): if self.format_flags: self.print_formatted(formatted_data) else: - print_method(arg) + print_method(arg.encode('utf-8')) def prepare_path(self, path): return "{0}.{1}".format( diff --git a/fuelclient/objects/environment.py b/fuelclient/objects/environment.py index f500fc9..13f59b8 100644 --- a/fuelclient/objects/environment.py +++ b/fuelclient/objects/environment.py @@ -247,7 +247,7 @@ class Environment(BaseObject): (serializer or self.serializer).write_to_file( engine_file_path, facts["engine"]) facts = facts["nodes"] - name_template = "{name}" + name_template = u"{name}" else: name_template = "{role}_{uid}" for _fact in facts: diff --git a/tests/test_client.py b/tests/test_client.py index 89ca51b..ca3d6ad 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2013-2014 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -127,6 +129,17 @@ class TestHandlers(BaseTestCase): ) +class TestCharset(BaseTestCase): + + def test_charset_problem(self): + self.load_data_to_nailgun_server() + self.run_cli_commands(( + "env create --name=привет --release=1", + "--env-id=1 node set --node 1 --role=controller", + "env" + )) + + class TestFiles(BaseTestCase): def setUp(self):