From fe194d85899a02fcb84f69fc08c98a19186a0417 Mon Sep 17 00:00:00 2001 From: Matthew Mosesohn Date: Fri, 8 Apr 2016 12:34:11 +0300 Subject: [PATCH] Add notice about updating fuel_client.yaml when updating pass Users are advised to update their configuration after changing their Fuel Admin password. Change-Id: Ie4f7e29092002cb316829ef394e4c938ebf30766 Partial-Bug: #1555262 (cherry picked from commit b384bf90ec774dd8c67c49ba53ec74008f54e1c1) --- fuelclient/cli/actions/user.py | 7 +++++++ fuelclient/fuelclient_settings.py | 12 +++++++----- fuelclient/tests/unit/v1/test_user_action.py | 19 ++++++++++++++++++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/fuelclient/cli/actions/user.py b/fuelclient/cli/actions/user.py index adf9c6da..62733ca2 100644 --- a/fuelclient/cli/actions/user.py +++ b/fuelclient/cli/actions/user.py @@ -18,6 +18,7 @@ from fuelclient.cli.actions.base import Action import fuelclient.cli.arguments as Args from fuelclient.cli.error import ArgumentException from fuelclient.client import APIClient +from fuelclient import fuelclient_settings class UserAction(Action): @@ -56,3 +57,9 @@ class UserAction(Action): password = self._get_password_from_prompt() APIClient.update_own_password(password) + settings = fuelclient_settings.get_settings() + self.serializer.print_to_output( + None, "\nPassword changed.\nPlease note that configuration " + "is not automatically updated.\nYou may want to update " + "{0}.".format( + settings.user_settings)) diff --git a/fuelclient/fuelclient_settings.py b/fuelclient/fuelclient_settings.py index 0eab0e29..9a94652f 100644 --- a/fuelclient/fuelclient_settings.py +++ b/fuelclient/fuelclient_settings.py @@ -61,17 +61,19 @@ class FuelClientSettings(object): default_settings = pkg_resources.resource_filename('fuelclient', 'fuel_client.yaml') - user_settings = os.path.join(user_conf_dir, 'fuel', 'fuel_client.yaml') + self.user_settings = os.path.join(user_conf_dir, 'fuel', + 'fuel_client.yaml') custom_settings = os.getenv('FUELCLIENT_CUSTOM_SETTINGS') - if not os.path.exists(user_settings) and not custom_settings: - self.populate_default_settings(default_settings, user_settings) + if not os.path.exists(self.user_settings) and not custom_settings: + self.populate_default_settings(default_settings, + self.user_settings) six.print_('Settings for Fuel Client have been saved to {0}.\n' 'Consider changing default values to the ones which ' - 'are appropriate for you.'.format(user_settings)) + 'are appropriate for you.'.format(self.user_settings)) self._add_file_if_exists(default_settings, settings_files) - self._add_file_if_exists(user_settings, settings_files) + self._add_file_if_exists(self.user_settings, settings_files) # Add a custom settings file specified by user self._add_file_if_exists(custom_settings, settings_files) diff --git a/fuelclient/tests/unit/v1/test_user_action.py b/fuelclient/tests/unit/v1/test_user_action.py index 6b416250..f6848757 100644 --- a/fuelclient/tests/unit/v1/test_user_action.py +++ b/fuelclient/tests/unit/v1/test_user_action.py @@ -21,6 +21,9 @@ from fuelclient.tests.unit.v1 import base class TestChangePassword(base.UnitTestCase): + def assert_print(self, print_mock, result, msg): + print_mock.assert_called_once_with(result, msg) + def test_get_password_from_prompt(self): user_action = UserAction() passwd = 'secret!' @@ -38,12 +41,17 @@ class TestChangePassword(base.UnitTestCase): ArgumentException, 'Passwords are not the same'): user_action._get_password_from_prompt() + @mock.patch('fuelclient.cli.serializers.Serializer.print_to_output') + @mock.patch('fuelclient.cli.actions.user.fuelclient_settings') @mock.patch('fuelclient.cli.actions.user.APIClient') - def test_change_password(self, mapiclient): + def test_change_password(self, mapiclient, settings_mock, print_mock): user_action = UserAction() params = mock.Mock() params.newpass = None password = 'secret' + conf_file = '/tmp/fuel_client.yaml' + settings_mock.get_settings.return_value = mock.Mock( + user_settings=conf_file) with mock.patch('fuelclient.cli.actions.user.getpass', return_value=password) as mgetpass: @@ -57,6 +65,15 @@ class TestChangePassword(base.UnitTestCase): mgetpass.assert_has_calls(calls) mapiclient.update_own_password.assert_called_once_with(password) + msg = "\nPassword changed.\nPlease note that configuration " \ + "is not automatically updated.\nYou may want to update " \ + "{0}.".format(conf_file) + + self.assert_print( + print_mock, + None, + msg) + @mock.patch('fuelclient.cli.actions.user.APIClient') def test_change_password_w_newpass(self, mapiclient): user_action = UserAction()