Allow the container build tools to run config-less

This change allows the container build tools to run without a
provided configuration file. The container configuration file
still in service was derived from our old kolla implementation
which no longer needs to exist. The build process will now
simply walk the build path and build all containers found when
a configuration file is not defined or present. Logging has
been added to inform the user of the tools discoveries which
should provide a nice user experience when running container
builds.

In the event a container configuration file is used, the tools
will now ensure all dependent images are inherently part of the
build preparation.

Tests have been updated to ensure that the client is operational
in both a config and config-less situation.

Change-Id: I89aebb0ae9734b0371bd3fdbd34643babfcca8f3
Signed-off-by: Kevin Carter <kecarter@redhat.com>
This commit is contained in:
Kevin Carter 2020-08-20 17:04:33 -05:00 committed by Emilien Macchi
parent 94344ae5b6
commit 4d23eee41e
2 changed files with 36 additions and 18 deletions

View File

@ -206,9 +206,7 @@ class TestContainerImages(deploy_fakes.TestDeployOvercloud):
("config_file", "not-a-file-config.yaml"),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(IOError, self.cmd.take_action, parsed_args)
self.check_parser(self.cmd, arglist, verifylist)
def test_image_build_failure_no_config_dir(self):
arglist = ["--config-path", "not-a-path"]

View File

@ -377,12 +377,6 @@ class Build(command.Command):
os.path.dirname(self.tcib_config_path),
parsed_args.config_file,
)
if not os.path.isfile(self.config_file):
raise IOError(
"Configuration file {} was not found.".format(
self.config_file
)
)
self.log.debug("take_action({})".format(parsed_args))
excludes = parsed_args.excludes
@ -421,16 +415,42 @@ class Build(command.Command):
)
os.makedirs(work_dir)
with open(self.config_file, "r") as f:
containers_yaml = yaml.safe_load(f)
if os.path.isfile(self.config_file):
self.log.info(
"Configuration file found: {}".format(self.config_file)
)
with open(self.config_file, "r") as f:
containers_yaml = yaml.safe_load(f)
for c in containers_yaml["container_images"]:
entry = dict(c)
if not entry.get("image_source", "") == "tripleo":
continue
image = self.imagename_to_regex(entry.get("imagename"))
if image and image not in excludes:
images_to_prepare.append(image)
for c in containers_yaml["container_images"]:
entry = dict(c)
if not entry.get("image_source", "") == "tripleo":
continue
image = self.imagename_to_regex(entry.get("imagename"))
if image and image not in excludes:
images_to_prepare.append(image)
# NOTE(cloudnull): Ensure all dependent images are in the build
# tree. Once an image has been added to the
# prepare array, we walk it back and ensure
# dependencies are also part of the build
# process.
image_parent = self.image_parents.get(image)
while image_parent:
if image_parent not in images_to_prepare:
images_to_prepare.insert(0, image_parent)
image_parent = self.image_parents.get(image_parent)
else:
self.log.warning(
"Configuration file not found: {}".format(self.config_file)
)
self.log.warning(
"All identified images will be prepared: {}".format(
self.config_file
)
)
images_to_prepare.extend(self.identified_images)
tcib_inventory = {"all": {"hosts": {}}}
tcib_inventory_hosts = tcib_inventory["all"]["hosts"]