Merge "Allow `test` command to use conf files"

This commit is contained in:
Jenkins 2014-08-12 19:41:05 +00:00 committed by Gerrit Code Review
commit ca6335d770
3 changed files with 20 additions and 3 deletions

View File

@ -118,12 +118,12 @@ def setup_config_settings(options):
config = ConfigParser.ConfigParser()
## Load default config always
config.readfp(cStringIO.StringIO(DEFAULT_CONF))
if options.command == 'test':
logger.debug("Not reading config for test output generation")
elif os.path.isfile(conf):
if os.path.isfile(conf):
logger.debug("Reading config from {0}".format(conf))
conffp = open(conf, 'r')
config.readfp(conffp)
elif options.command == 'test':
logger.debug("Not requiring config for test output generation")
else:
raise JenkinsJobsException(
"A valid configuration file is required when not run as a test"

View File

@ -0,0 +1,2 @@
[jenkins]
url=http://test-jenkins.with.non.default.url:8080/

View File

@ -83,3 +83,18 @@ class CmdTests(testtools.TestCase):
'r',
'utf-8').read()
self.assertEqual(console_out.getvalue(), xml_content)
def test_config_with_test(self):
"""
Run test mode and pass a config file
"""
args = self.parser.parse_args(['--conf',
os.path.join(self.fixtures_path,
'cmd-001.conf'),
'test',
os.path.join(self.fixtures_path,
'cmd-001.yaml'),
'foo-job'])
config = cmd.setup_config_settings(args)
self.assertEqual(config.get('jenkins', 'url'),
"http://test-jenkins.with.non.default.url:8080/")