From b955bcfe82dce47b8523b274dfe96dea0324a3b0 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 15 Jan 2020 21:53:21 +0000 Subject: [PATCH] kola: Add a --cosa-build argument This starts the ball rolling on having mantle understand cosa, which is key for long-term dedup of the projects. The main motivation for this right now is that by decoding the JSON into a Go struct, we are effectively doing a schema validation. After this lands I'll make a separate PR to flesh out the struct entirely, then change the decoder to error on unknown keys. This also removes some CL cruft around the default disk image. --- cmd/kola/options.go | 45 +++++++++++++++++++++++++++++------------- cosa/build.go | 47 ++++++++++++++++++++++++++++++++++++++++++++ platform/platform.go | 2 ++ 3 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 cosa/build.go diff --git a/cmd/kola/options.go b/cmd/kola/options.go index b7d73ac984..6ff2a6c096 100644 --- a/cmd/kola/options.go +++ b/cmd/kola/options.go @@ -15,27 +15,26 @@ package main import ( + "encoding/json" "fmt" "os" + "path/filepath" "strings" "github.com/coreos/mantle/auth" + "github.com/coreos/mantle/cosa" "github.com/coreos/mantle/kola" "github.com/coreos/mantle/platform" "github.com/coreos/mantle/sdk" ) var ( - outputDir string - kolaPlatform string - defaultTargetBoard = sdk.DefaultBoard() - kolaArchitectures = []string{"amd64"} - kolaPlatforms = []string{"aws", "azure", "do", "esx", "gce", "openstack", "packet", "qemu", "qemu-unpriv"} - kolaDistros = []string{"fcos", "rhcos"} - kolaDefaultImages = map[string]string{ - "amd64-usr": sdk.BuildRoot() + "/images/amd64-usr/latest/coreos_production_image.bin", - "arm64-usr": sdk.BuildRoot() + "/images/arm64-usr/latest/coreos_production_image.bin", - } + outputDir string + kolaPlatform string + defaultTargetBoard = sdk.DefaultBoard() + kolaArchitectures = []string{"amd64"} + kolaPlatforms = []string{"aws", "azure", "do", "esx", "gce", "openstack", "packet", "qemu", "qemu-unpriv"} + kolaDistros = []string{"fcos", "rhcos"} kolaIgnitionVersionDefaults = map[string]string{ "cl": "v2", "fcos": "v3", @@ -62,6 +61,7 @@ func init() { sv(&kola.Options.IgnitionVersion, "ignition-version", "", "Ignition version override: v2, v3") ssv(&kola.BlacklistedTests, "blacklist-test", []string{}, "List of tests to blacklist") bv(&kola.Options.SSHOnTestFailure, "ssh-on-test-failure", false, "SSH into a machine when tests fail") + sv(&kola.Options.CosaBuild, "cosa-build", "", "File path for coreos-assembler meta.json") // rhcos-specific options sv(&kola.Options.OSContainer, "oscontainer", "", "oscontainer image pullspec for pivot (RHCOS only)") @@ -171,13 +171,29 @@ func syncOptions() error { return err } - image, ok := kolaDefaultImages[kola.QEMUOptions.Board] - if kola.QEMUOptions.Distribution == "cl" && !ok { - return fmt.Errorf("unsupport board %q", kola.QEMUOptions.Board) + var cosaBuild *cosa.Build + if kola.Options.CosaBuild != "" { + f, err := os.Open(kola.Options.CosaBuild) + if err != nil { + return err + } + defer f.Close() + dec := json.NewDecoder(f) + // FIXME enable this to prevent schema regressions https://github.com/coreos/coreos-assembler/pull/1059 + // dec.DisallowUnknownFields() + var tmpBuild cosa.Build + if err := dec.Decode(&tmpBuild); err != nil { + return err + } + cosaBuild = &tmpBuild } if kola.QEMUOptions.DiskImage == "" { - kola.QEMUOptions.DiskImage = image + if cosaBuild != nil { + kola.QEMUOptions.DiskImage = filepath.Join(filepath.Dir(kola.Options.CosaBuild), cosaBuild.Images.QEMU.Path) + } else { + return fmt.Errorf("No --qemu-image or --cosa-build provided") + } } units, _ := root.PersistentFlags().GetStringSlice("debug-systemd-units") @@ -194,6 +210,7 @@ func syncOptions() error { } if kola.Options.IgnitionVersion == "" { + var ok bool kola.Options.IgnitionVersion, ok = kolaIgnitionVersionDefaults[kola.Options.Distribution] if !ok { return fmt.Errorf("Distribution %q has no default Ignition version", kola.Options.Distribution) diff --git a/cosa/build.go b/cosa/build.go new file mode 100644 index 0000000000..922e5b1413 --- /dev/null +++ b/cosa/build.go @@ -0,0 +1,47 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cosa + +// Build is the coreos-assembler `meta.json` which defines a build. +// This code was copied from openshift-installer's +// https://github.com/openshift/installer/blob/a0350404997b0493d7bb16aa2875e5c42879b069/pkg/rhcos/builds.go +// For now, copy-paste updates there. Later, maybe consider making this a public API? +type Build struct { + AMIs map[string]struct { + HVM string `json:"hvm"` + } `json:"amis"` + Azure struct { + Image string `json:"image"` + URL string `json:"url"` + } + GCP struct { + Image string `json:"image"` + URL string `json:"url"` + } + BaseURI string `json:"baseURI"` + Images struct { + QEMU struct { + Path string `json:"path"` + SHA256 string `json:"sha256"` + UncompressedSHA256 string `json:"uncompressed-sha256"` + } `json:"qemu"` + OpenStack struct { + Path string `json:"path"` + SHA256 string `json:"sha256"` + UncompressedSHA256 string `json:"uncompressed-sha256"` + } `json:"openstack"` + } `json:"images"` + OSTreeVersion string `json:"ostree-version"` +} diff --git a/platform/platform.go b/platform/platform.go index 6e5aaeed47..c8d31ba03b 100644 --- a/platform/platform.go +++ b/platform/platform.go @@ -158,6 +158,8 @@ type Options struct { IgnitionVersion string SystemdDropins []SystemdDropin + CosaBuild string + NoTestExitError bool // OSContainer is an image pull spec that can be given to the pivot service