From 811af24e484548c56c686251030d929e901e09c5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Mar 2024 18:56:24 +0100 Subject: [PATCH] bib: rename `--config` to `--iso-config` Rename the --config option to --iso-config and error if it is used for anything other than the ISO image. --- bib/cmd/bootc-image-builder/main.go | 19 ++++++++------ test/test_opts.py | 39 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/bib/cmd/bootc-image-builder/main.go b/bib/cmd/bootc-image-builder/main.go index b72125bc..c57d639d 100644 --- a/bib/cmd/bootc-image-builder/main.go +++ b/bib/cmd/bootc-image-builder/main.go @@ -235,7 +235,7 @@ func manifestFromCobra(cmd *cobra.Command, args []string) ([]byte, error) { } imgref := args[0] - configFile, _ := cmd.Flags().GetString("config") + isoConfigFile, _ := cmd.Flags().GetString("iso-config") imgTypes, _ := cmd.Flags().GetStringArray("type") rpmCacheRoot, _ := cmd.Flags().GetString("rpmmd") targetArch, _ := cmd.Flags().GetString("target-arch") @@ -262,11 +262,16 @@ func manifestFromCobra(cmd *cobra.Command, args []string) ([]byte, error) { return nil, err } + // bootc does not yet support arbitray blueprint customizations + if buildType != BuildTypeISO && isoConfigFile != "" { + return nil, fmt.Errorf("the --iso-config switch is only supported for ISO images") + } + var config *BuildConfig - if configFile != "" { - config, err = loadConfig(configFile) + if isoConfigFile != "" { + config, err = loadConfig(isoConfigFile) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot load config: %w", err) } } else { config = &BuildConfig{} @@ -351,7 +356,7 @@ func cmdBuild(cmd *cobra.Command, args []string) error { fmt.Printf("Generating manifest %s\n", manifest_fname) mf, err := manifestFromCobra(cmd, args) if err != nil { - panic(err) + return err } fmt.Print("DONE\n") @@ -468,7 +473,7 @@ func run() error { } rootCmd.AddCommand(manifestCmd) manifestCmd.Flags().Bool("tls-verify", true, "require HTTPS and verify certificates when contacting registries") - manifestCmd.Flags().String("config", "", "build config file") + manifestCmd.Flags().String("iso-config", "", "build config file for the iso") manifestCmd.Flags().String("rpmmd", "/rpmmd", "rpm metadata cache directory") manifestCmd.Flags().String("target-arch", "", "build for the given target architecture (experimental)") manifestCmd.Flags().StringArray("type", []string{"qcow2"}, fmt.Sprintf("image types to build [%s]", allImageTypesString())) @@ -492,7 +497,7 @@ func run() error { return err } } - if err := buildCmd.MarkFlagFilename("config"); err != nil { + if err := buildCmd.MarkFlagFilename("iso-config"); err != nil { return err } buildCmd.MarkFlagsRequiredTogether("aws-region", "aws-bucket", "aws-ami-name") diff --git a/test/test_opts.py b/test/test_opts.py index 5e3159a3..8c1b224a 100644 --- a/test/test_opts.py +++ b/test/test_opts.py @@ -1,4 +1,5 @@ import subprocess +import sys import pytest @@ -27,3 +28,41 @@ def test_bib_chown_opts(tmp_path, build_fake_container, chown_opt, expected_uid_ assert p.exists() assert p.stat().st_uid == expected_uid_gid[0] assert p.stat().st_gid == expected_uid_gid[1] + + +def test_bib_config_errors_for_default(tmp_path, build_fake_container): + output_path = tmp_path / "output" + output_path.mkdir(exist_ok=True) + + ret = subprocess.run([ + "podman", "run", "--rm", + "--privileged", + "--security-opt", "label=type:unconfined_t", + "-v", f"{output_path}:/output", + build_fake_container, + "--iso-config", "/some/random/config", + "quay.io/centos-bootc/centos-bootc:stream9", + ], check=False, encoding="utf8", stdout=sys.stdout, stderr=subprocess.PIPE) + assert ret.returncode != 0 + assert "the --iso-config switch is only supported for ISO images" in ret.stderr + + +def test_bib_iso_config_is_parsed(tmp_path, build_fake_container): + output_path = tmp_path / "output" + output_path.mkdir(exist_ok=True) + + # check that config.json is tried to be loaded + (tmp_path / "config.json").write_text("invalid-json", encoding="utf8") + ret = subprocess.run([ + "podman", "run", "--rm", + "--privileged", + "--security-opt", "label=type:unconfined_t", + "-v", f"{output_path}:/output", + "-v", f"{tmp_path}/config.json:/config.json", + build_fake_container, + "--iso-config", "/config.json", + "--type", "anaconda-iso", + "quay.io/centos-bootc/centos-bootc:stream9", + ], check=False, encoding="utf8", stdout=sys.stdout, stderr=subprocess.PIPE) + assert ret.returncode != 0 + assert "cannot load config: invalid character" in ret.stderr