From 1165218e8c974ddc8c389a5890d47e8f9614916b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=A1gr?= Date: Tue, 4 Aug 2015 16:54:37 +0200 Subject: [PATCH] Switch for Keystone DB cron job Adds parameter to enable switching off token flush cron job. Partial-bug: rhbz#1249106 Depends-On: I5e51562338f68b4ba1b2e942907e6f6a0ab7a61e Change-Id: If358a096e9880b7564b59072829c52b3a63f82c9 --- docs/packstack.rst | 3 +++ packstack/installer/processors.py | 19 ++++++++++++++++++- packstack/installer/run_setup.py | 3 ++- packstack/plugins/keystone_100.py | 16 ++++++++++++++++ packstack/puppet/templates/keystone.pp | 23 +++++++++++++---------- tests/installer/test_run_setup.py | 11 +++++++++++ 6 files changed, 63 insertions(+), 12 deletions(-) diff --git a/docs/packstack.rst b/docs/packstack.rst index 4793eba35..01f79d154 100644 --- a/docs/packstack.rst +++ b/docs/packstack.rst @@ -291,6 +291,9 @@ Keystone Config parameters **CONFIG_KEYSTONE_DB_PW** Password to use for the Identity service (keystone) to access the database. +**CONFIG_KEYSTONE_DB_PURGE_ENABLE** + Enter y if cron job for removing soft deleted DB rows should be created. + **CONFIG_KEYSTONE_REGION** Default region name to use when creating tenants in the Identity service. diff --git a/packstack/installer/processors.py b/packstack/installer/processors.py index 3ef124849..f9df1b502 100644 --- a/packstack/installer/processors.py +++ b/packstack/installer/processors.py @@ -23,7 +23,8 @@ from .exceptions import ParamProcessingError __all__ = ('ParamProcessingError', 'process_cidr', 'process_host', - 'process_ssh_key') + 'process_ssh_key', 'process_add_quotes_around_values', + 'process_password', 'process_string_nofloat', 'process_bool') def process_cidr(param, param_name, config=None): @@ -135,3 +136,19 @@ def process_string_nofloat(param, param_name, config=None): return param else: param = uuid.uuid4().hex[:16] + + +def process_bool(param, param_name, config=None): + """Converts param to appropriate boolean representation. + + Retunrs True if answer == y|yes|true, False if answer == n|no|false. + """ + if param.lower() in ('y', 'yes', 'true'): + return True + elif param.lower() in ('n', 'no', 'false'): + return False + + +# Define silent processors +for proc_func in (process_bool, process_add_quotes_around_values): + proc_func.silent = True diff --git a/packstack/installer/run_setup.py b/packstack/installer/run_setup.py index ed9fd61a7..4fba98b99 100644 --- a/packstack/installer/run_setup.py +++ b/packstack/installer/run_setup.py @@ -295,12 +295,13 @@ def process_param_value(param, value): _value = value proclist = param.PROCESSORS or [] for proc_func in proclist: + is_silent = getattr(proc_func, 'silent', False) logging.debug("Processing value of parameter " "%s." % param.CONF_NAME) try: new_value = proc_func(_value, param.CONF_NAME, controller.CONF) if new_value != _value: - if param.MASK_INPUT is False: + if param.MASK_INPUT is False and not is_silent: msg = output_messages.INFO_CHANGED_VALUE print(msg % (_value, new_value)) _value = new_value diff --git a/packstack/plugins/keystone_100.py b/packstack/plugins/keystone_100.py index 0bc910dad..b5895fe07 100644 --- a/packstack/plugins/keystone_100.py +++ b/packstack/plugins/keystone_100.py @@ -50,6 +50,22 @@ def initConfig(controller): "NEED_CONFIRM": True, "CONDITION": False}, + {"CMD_OPTION": 'keystone-db-purge-enable', + "PROMPT": ( + "Enter y if cron job for removing soft deleted DB rows " + "should be created" + ), + "OPTION_LIST": ['y', 'n'], + "VALIDATORS": [validators.validate_not_empty], + "PROCESSORS": [processors.process_bool], + "DEFAULT_VALUE": 'y', + "MASK_INPUT": False, + "LOOSE_VALIDATION": False, + "CONF_NAME": 'CONFIG_KEYSTONE_DB_PURGE_ENABLE', + "USE_DEFAULT": False, + "NEED_CONFIRM": True, + "CONDITION": False}, + {"CMD_OPTION": "keystone-region", "PROMPT": "Region name", "OPTION_LIST": [], diff --git a/packstack/puppet/templates/keystone.pp b/packstack/puppet/templates/keystone.pp index c31df8264..411b80d9d 100644 --- a/packstack/puppet/templates/keystone.pp +++ b/packstack/puppet/templates/keystone.pp @@ -119,13 +119,16 @@ if hiera('CONFIG_KEYSTONE_IDENTITY_BACKEND') == 'ldap' { } } -# Run token flush every minute (without output so we won't spam admins) -# Logs are available in /var/log/keystone/keystone-tokenflush.log -class { '::keystone::cron::token_flush': - minute => '*/1', - require => [Service['crond'], User['keystone'], Group['keystone']] -} -service { 'crond': - ensure => 'running', - enable => true, -} +$db_purge = hiera('CONFIG_KEYSTONE_DB_PURGE_ENABLE') +if $db_purge { + # Run token flush every minute (without output so we won't spam admins) + class { '::keystone::cron::token_flush': + minute => '*/1', + destination => '/dev/null', + require => [Service['crond'], User['keystone'], Group['keystone']] + } + service { 'crond': + ensure => 'running', + enable => true, + } + } diff --git a/tests/installer/test_run_setup.py b/tests/installer/test_run_setup.py index 1c3dd28fd..7f4efff3f 100644 --- a/tests/installer/test_run_setup.py +++ b/tests/installer/test_run_setup.py @@ -25,6 +25,7 @@ from packstack.modules import ospluginutils from packstack.modules import puppet from packstack.installer import basedefs from packstack.installer import run_setup +from packstack.installer import validators from ..test_base import FakePopen from ..test_base import PackstackTestCaseMixin @@ -37,6 +38,16 @@ def makefile(path, content): class CommandLineTestCase(PackstackTestCaseMixin, TestCase): + + def setUp(self): + super(CommandLineTestCase, self).setUp() + self._old_validate_ssh = validators.validate_ssh + validators.validate_ssh = lambda param, options=None: None + + def tearDown(self): + super(CommandLineTestCase, self).tearDown() + validators.validate_ssh = self._old_validate_ssh + def test_running_install_hosts(self): """ Test packstack.installer.run_setup.main