Improve user experience involving token flush

Currently with the use of memcache it is no longer necessary to use
the token_flush command. Running this command with KVS driver enabled
fails and throws a Traceback and NotImplemented errors. For a better
UX, we allow the implementation to pass and log a warning message

Change-Id: I95addc8df3a39135fb3fe3c63b6b21c1c279ace8
Closes-Bug: #1520321
This commit is contained in:
“Richard 2016-07-12 19:51:55 +00:00
parent c7b72705b1
commit 21d8686181
2 changed files with 20 additions and 1 deletions

View File

@ -540,7 +540,14 @@ class TokenFlush(BaseApp):
@classmethod
def main(cls):
token_manager = token.persistence.PersistenceManager()
token_manager.flush_expired_tokens()
try:
token_manager.flush_expired_tokens()
except exception.NotImplemented:
# NOTE(ravelar159): Stop NotImplemented from unsupported token
# driver when using token_flush and print out warning instead
LOG.warning(_LW('Token driver %s does not support token_flush. '
'The token_flush command had no effect.'),
CONF.token.driver)
class MappingPurge(BaseApp):

View File

@ -45,6 +45,18 @@ class CliTestCase(unit.SQLDriverOverrides, unit.TestCase):
self.load_backends()
cli.TokenFlush.main()
# NOTE(ravelar): the following method tests that the token_flush command,
# when used in conjunction with an unsupported token driver like kvs,
# will yield a LOG.warning message informing the user that the
# command had no effect.
def test_token_flush_excepts_not_implemented_and_logs_warning(self):
self.useFixture(database.Database())
self.load_backends()
self.config_fixture.config(group='token', driver='memcache')
log_info = self.useFixture(fixtures.FakeLogger(level=log.WARN))
cli.TokenFlush.main()
self.assertIn("token_flush command had no effect", log_info.output)
class CliNoConfigTestCase(unit.BaseTestCase):