Read config file on image build indirection
This commit is contained in:
parent
b2a53c9753
commit
d467810c7c
3 changed files with 65 additions and 3 deletions
|
|
@ -5830,6 +5830,21 @@ def handle_image_build_indirection(options, session, args):
|
|||
help="Do not display progress of the upload")
|
||||
|
||||
(task_options, args) = parser.parse_args(args)
|
||||
if task_options.config:
|
||||
section = 'image-build-indirection'
|
||||
config = koji.read_config_files([(task_options.config, True)])
|
||||
if not config.has_section(section):
|
||||
parser.error("single section called [%s] is required" % section)
|
||||
|
||||
# We avoid manually listing options
|
||||
parser_options = [opt.dest for opt in parser.option_list]
|
||||
parser_options.remove(None) # --help has a dest of None, remove it to avoid errors
|
||||
for opt in parser_options:
|
||||
if not config.has_option(section, opt):
|
||||
continue
|
||||
|
||||
setattr(task_options, opt, config.get(section, opt))
|
||||
|
||||
_build_image_indirection(options, task_options, session, args)
|
||||
|
||||
|
||||
|
|
|
|||
12
tests/test_cli/data/image-build-indirection-config.conf
Normal file
12
tests/test_cli/data/image-build-indirection-config.conf
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[image-build-indirection]
|
||||
name = fedora-server-docker
|
||||
version = 26
|
||||
release = 1
|
||||
target = f26-candidate
|
||||
arch = x86_64
|
||||
|
||||
base_image_build = fedora-base
|
||||
utility_image_build = fedora-utility
|
||||
indirection_template = fedora-indirection.tdl
|
||||
indirection_template_url = git://git.fedorahosted.org/git/indirection-templates.git?fedora26#68c40eb7
|
||||
results_loc = fedora-indirection.tar
|
||||
|
|
@ -1,13 +1,20 @@
|
|||
from __future__ import absolute_import
|
||||
import mock
|
||||
import six
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import koji
|
||||
import mock
|
||||
import six
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_image_build_indirection, _build_image_indirection
|
||||
from . import utils
|
||||
|
||||
if six.PY2:
|
||||
ConfigParser = six.moves.configparser.SafeConfigParser
|
||||
else:
|
||||
ConfigParser = six.moves.configparser.ConfigParser
|
||||
|
||||
|
||||
TASK_OPTIONS = {
|
||||
"background": True,
|
||||
|
|
@ -67,6 +74,8 @@ class TestBuildImageIndirection(utils.CliTestCase):
|
|||
self.session.buildImageIndirection.return_value = self.task_id
|
||||
self.unique_path.return_value = '/path/to/cli-image-indirection'
|
||||
|
||||
self.configparser = mock.patch('six.moves.configparser.ConfigParser').start()
|
||||
|
||||
def tearDown(self):
|
||||
mock.patch.stopall()
|
||||
|
||||
|
|
@ -183,6 +192,32 @@ class TestBuildImageIndirection(utils.CliTestCase):
|
|||
self.assertEqual(str(cm.exception), expected)
|
||||
self.activate_session.assert_called_with(self.session, self.options)
|
||||
|
||||
@mock.patch('koji_cli.commands._build_image_indirection')
|
||||
def test_image_build_indirection_configuration(self, build_image_indirection_mock):
|
||||
"""Test handle_image_build."""
|
||||
self.configparser.return_value = ConfigParser()
|
||||
|
||||
config_file = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'data/image-build-indirection-config.conf'
|
||||
)
|
||||
TASK_OPTIONS['config'] = config_file
|
||||
|
||||
handle_image_build_indirection(
|
||||
self.options,
|
||||
self.session,
|
||||
['--config', config_file,
|
||||
'--arch', 'x386']
|
||||
)
|
||||
|
||||
args, _ = build_image_indirection_mock.call_args
|
||||
merged_options = args[1].__dict__
|
||||
|
||||
self.assertEqual("x86_64", merged_options["arch"]) # Overrides command line
|
||||
self.assertEqual("fedora-base", merged_options["base_image_build"])
|
||||
self.assertEqual("fedora-indirection.tdl", merged_options["indirection_template"])
|
||||
self.session.activate_session_mock.assert_not_called()
|
||||
|
||||
|
||||
class TestImageBuildIndirection(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue