Ensure flush cache option obeyed

Make sure that flush cache is correct set first by config file, and
additionally that the CLI overrides any defaults.

In the V2 API work, when moving code around the flush cache option was
accidentally removed from being set by the command line or config
files. This ensures it follows the same behaviour as other similar
options.

Change-Id: I9fb1e234e5ed081ada64855389a87d2f7555469e
This commit is contained in:
Darragh Bailey 2016-07-22 16:55:27 +01:00
parent 4f04de1f9a
commit 652806a751
5 changed files with 11 additions and 4 deletions

View File

@ -84,6 +84,7 @@ class JenkinsJobs(object):
def _parse_additional(self):
self._set_config(self.jjb_config.builder, 'ignore_cache')
self._set_config(self.jjb_config.builder, 'flush_cache')
self._set_config(self.jjb_config.yamlparser, 'allow_empty_variables')
self._set_config(self.jjb_config.jenkins, 'user')
self._set_config(self.jjb_config.jenkins, 'password')

View File

@ -50,7 +50,7 @@ def create_parser():
'--flush-cache',
action='store_true',
dest='flush_cache',
default=False,
default=None,
help='''flush all the cache entries before updating''')
parser.add_argument(
'--version',

View File

@ -160,8 +160,7 @@ class JJBConfig(object):
logger.debug("Config: {0}".format(config))
# check the ignore_cache setting: first from command line,
# if not present check from ini file
# check the ignore_cache setting
if config.has_option('jenkins', 'ignore_cache'):
logging.warn('''ignore_cache option should be moved to the
[job_builder] section in the config file, the one
@ -172,6 +171,10 @@ class JJBConfig(object):
self.ignore_cache = config.getboolean('job_builder',
'ignore_cache')
# check the flush_cache setting
if config.has_option('job_builder', 'flush_cache'):
self.flush_cache = config.getboolean('job_builder', 'flush_cache')
# Jenkins supports access as an anonymous user, which can be used to
# ensure read-only behaviour when querying the version of plugins
# installed for test mode to generate XML output matching what will be

View File

@ -5,3 +5,4 @@ password=jenkins_password
[job_builder]
allow_empty_variables=True
ignore_cache=True
flush_cache=True

View File

@ -87,6 +87,7 @@ class TestConfigs(CmdTestsBase):
self.assertEqual(jjb_config.jenkins['user'], "jenkins_user")
self.assertEqual(jjb_config.jenkins['password'], "jenkins_password")
self.assertEqual(jjb_config.builder['ignore_cache'], True)
self.assertEqual(jjb_config.builder['flush_cache'], True)
self.assertEqual(
jjb_config.yamlparser['allow_empty_variables'], True)
@ -96,12 +97,13 @@ class TestConfigs(CmdTestsBase):
when non of the global CLI options are set.
"""
args = ['--user', 'myuser', '--password', 'mypassword',
'--ignore-cache', '--allow-empty-variables',
'--ignore-cache', '--flush-cache', '--allow-empty-variables',
'test', 'dummy.yaml']
jenkins_jobs = entry.JenkinsJobs(args)
jjb_config = jenkins_jobs.jjb_config
self.assertEqual(jjb_config.jenkins['user'], "myuser")
self.assertEqual(jjb_config.jenkins['password'], "mypassword")
self.assertEqual(jjb_config.builder['ignore_cache'], True)
self.assertEqual(jjb_config.builder['flush_cache'], True)
self.assertEqual(
jjb_config.yamlparser['allow_empty_variables'], True)