Allow for building specific images
It was not possible to build a single image if the yaml files passed had multiple images defined. This adds a --image-name parameter to tripleo-build-images to allow for that. Change-Id: I5644656bbdc534f54c254edc7e939ae36f1f98ca Closes-Bug: #1618566
This commit is contained in:
parent
6f2d71ef74
commit
3a8c9f9964
@ -53,7 +53,13 @@ _opts = [
|
||||
cfg.BoolOpt('json-output',
|
||||
default=False,
|
||||
help="""Skip build and only output the configuration in a """
|
||||
"""structured JSON format.""")
|
||||
"""structured JSON format."""),
|
||||
cfg.MultiOpt('name',
|
||||
item_type=types.String(),
|
||||
default=None,
|
||||
help="""Name of image to build. May be specified multiple """
|
||||
"""times. If unspecified, will build all images in """
|
||||
"""given YAML files."""),
|
||||
]
|
||||
CONF.register_group(image_opt_group)
|
||||
CONF.register_cli_opts(_opts, group=image_opt_group)
|
||||
@ -65,7 +71,8 @@ def main(argv=sys.argv):
|
||||
|
||||
manager = ImageBuildManager(CONF.image.config_file,
|
||||
output_directory=CONF.image.output_directory,
|
||||
skip=CONF.image.skip)
|
||||
skip=CONF.image.skip,
|
||||
images=CONF.image.name)
|
||||
if CONF.image.json_output:
|
||||
manager.json_output()
|
||||
else:
|
||||
|
@ -29,8 +29,9 @@ class BaseImageManager(object):
|
||||
APPEND_ATTRIBUTES = ['elements', 'options', 'packages']
|
||||
CONFIG_SECTIONS = ['disk_images', 'uploads']
|
||||
|
||||
def __init__(self, config_files):
|
||||
def __init__(self, config_files, images=None):
|
||||
self.config_files = config_files
|
||||
self.images = images
|
||||
|
||||
def _extend_or_set_attribute(self, existing_image, image, attribute_name):
|
||||
attribute = image.get(attribute_name, [])
|
||||
@ -56,6 +57,11 @@ class BaseImageManager(object):
|
||||
self.logger.error(msg)
|
||||
raise ImageSpecificationException(msg)
|
||||
|
||||
if self.images is not None and \
|
||||
image_name not in self.images:
|
||||
self.logger.debug('Image %s ignored' % image_name)
|
||||
continue
|
||||
|
||||
existing_image = config_data.get(image_name)
|
||||
if not existing_image:
|
||||
config_data[image_name] = item
|
||||
|
@ -34,8 +34,9 @@ class ImageBuildManager(BaseImageManager):
|
||||
|
||||
APPEND_ATTRIBUTES = BaseImageManager.APPEND_ATTRIBUTES + ['environment']
|
||||
|
||||
def __init__(self, config_files, output_directory='.', skip=False):
|
||||
super(ImageBuildManager, self).__init__(config_files)
|
||||
def __init__(self, config_files, images=None, output_directory='.',
|
||||
skip=False):
|
||||
super(ImageBuildManager, self).__init__(config_files, images)
|
||||
self.output_directory = re.sub('[/]$', '', output_directory)
|
||||
self.skip = skip
|
||||
|
||||
|
@ -119,3 +119,44 @@ class TestBaseImageManager(testbase.TestCase):
|
||||
base_manager = BaseImageManager(['yamlfile'])
|
||||
self.assertRaises(ImageSpecificationException,
|
||||
base_manager.load_config_files, 'disk_images')
|
||||
|
||||
@mock.patch('yaml.load', autospec=True)
|
||||
@mock.patch('os.path.isfile', autospec=True)
|
||||
def test_load_config_files_single_image(self, mock_os_path_isfile,
|
||||
mock_yaml_load):
|
||||
mock_yaml_load.side_effect = [{
|
||||
'disk_images': [
|
||||
{
|
||||
'arch': 'amd64',
|
||||
'imagename': 'overcloud',
|
||||
'distro': 'some_awesome_distro',
|
||||
'type': 'qcow2',
|
||||
'elements': ['image_element']
|
||||
},
|
||||
{
|
||||
'arch': 'amd64',
|
||||
'imagename': 'not-overcloud',
|
||||
'distro': 'some_other_distro',
|
||||
'type': 'qcow2',
|
||||
'elements': ['other_element']
|
||||
}
|
||||
]}]
|
||||
|
||||
mock_os_path_isfile.return_value = True
|
||||
|
||||
mock_open_context = mock.mock_open()
|
||||
mock_open_context().read.return_value = "YAML"
|
||||
|
||||
with mock.patch('six.moves.builtins.open', mock_open_context):
|
||||
base_manager = BaseImageManager(['yamlfile1'],
|
||||
images=['not-overcloud'])
|
||||
disk_images = base_manager.load_config_files('disk_images')
|
||||
|
||||
self.assertEqual(1, mock_yaml_load.call_count)
|
||||
self.assertEqual([{
|
||||
'arch': 'amd64',
|
||||
'distro': 'some_other_distro',
|
||||
'imagename': 'not-overcloud',
|
||||
'type': 'qcow2',
|
||||
'elements': ['other_element'],
|
||||
}], disk_images)
|
||||
|
Loading…
x
Reference in New Issue
Block a user