From 652806a7513d017529774854965cf41ad60f6ef1 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Fri, 22 Jul 2016 16:55:27 +0100 Subject: [PATCH] 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 --- jenkins_jobs/cli/entry.py | 1 + jenkins_jobs/cli/parser.py | 2 +- jenkins_jobs/config.py | 7 +++++-- tests/cmd/fixtures/settings_from_config.ini | 1 + tests/cmd/test_config.py | 4 +++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/jenkins_jobs/cli/entry.py b/jenkins_jobs/cli/entry.py index c4cba4286..e0e6fd075 100644 --- a/jenkins_jobs/cli/entry.py +++ b/jenkins_jobs/cli/entry.py @@ -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') diff --git a/jenkins_jobs/cli/parser.py b/jenkins_jobs/cli/parser.py index 29bb9246c..9563738f3 100644 --- a/jenkins_jobs/cli/parser.py +++ b/jenkins_jobs/cli/parser.py @@ -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', diff --git a/jenkins_jobs/config.py b/jenkins_jobs/config.py index 2ec2c87db..fce036631 100644 --- a/jenkins_jobs/config.py +++ b/jenkins_jobs/config.py @@ -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 diff --git a/tests/cmd/fixtures/settings_from_config.ini b/tests/cmd/fixtures/settings_from_config.ini index 4bbd8023d..2001a81a7 100644 --- a/tests/cmd/fixtures/settings_from_config.ini +++ b/tests/cmd/fixtures/settings_from_config.ini @@ -5,3 +5,4 @@ password=jenkins_password [job_builder] allow_empty_variables=True ignore_cache=True +flush_cache=True diff --git a/tests/cmd/test_config.py b/tests/cmd/test_config.py index 7447703a9..d32af6674 100644 --- a/tests/cmd/test_config.py +++ b/tests/cmd/test_config.py @@ -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)