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 b384bf90ec)
This commit is contained in:
Matthew Mosesohn
2016-04-08 12:34:11 +03:00
parent 76cc06ca3f
commit fe194d8589
3 changed files with 32 additions and 6 deletions

View File

@@ -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))

View File

@@ -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)

View File

@@ -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()