github.com/coreos/mantle@v0.13.0/cmd/kola/options.go (about) 1 // Copyright 2015 CoreOS, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "fmt" 19 "os" 20 "strings" 21 22 "github.com/coreos/mantle/auth" 23 "github.com/coreos/mantle/kola" 24 "github.com/coreos/mantle/platform" 25 "github.com/coreos/mantle/sdk" 26 ) 27 28 var ( 29 outputDir string 30 kolaPlatform string 31 defaultTargetBoard = sdk.DefaultBoard() 32 kolaArchitectures = []string{"amd64"} 33 kolaPlatforms = []string{"aws", "azure", "do", "esx", "gce", "openstack", "packet", "qemu", "qemu-unpriv"} 34 kolaDistros = []string{"cl", "fcos", "rhcos"} 35 kolaDefaultImages = map[string]string{ 36 "amd64-usr": sdk.BuildRoot() + "/images/amd64-usr/latest/coreos_production_image.bin", 37 "arm64-usr": sdk.BuildRoot() + "/images/arm64-usr/latest/coreos_production_image.bin", 38 } 39 kolaIgnitionVersionDefaults = map[string]string{ 40 "cl": "v2", 41 "fcos": "v3", 42 "rhcos": "v3", 43 } 44 45 kolaDefaultBIOS = map[string]string{ 46 "amd64-usr": "bios-256k.bin", 47 "arm64-usr": sdk.BuildRoot() + "/images/arm64-usr/latest/coreos_production_qemu_uefi_efi_code.fd", 48 } 49 ) 50 51 func init() { 52 sv := root.PersistentFlags().StringVar 53 bv := root.PersistentFlags().BoolVar 54 ss := root.PersistentFlags().StringSlice 55 56 // general options 57 sv(&outputDir, "output-dir", "", "Temporary output directory for test data and logs") 58 sv(&kola.TorcxManifestFile, "torcx-manifest", "", "Path to a torcx manifest that should be made available to tests") 59 root.PersistentFlags().StringVarP(&kolaPlatform, "platform", "p", "qemu", "VM platform: "+strings.Join(kolaPlatforms, ", ")) 60 root.PersistentFlags().StringVarP(&kola.Options.Distribution, "distro", "b", "cl", "Distribution: "+strings.Join(kolaDistros, ", ")) 61 root.PersistentFlags().IntVarP(&kola.TestParallelism, "parallel", "j", 1, "number of tests to run in parallel") 62 sv(&kola.TAPFile, "tapfile", "", "file to write TAP results to") 63 sv(&kola.Options.BaseName, "basename", "kola", "Cluster name prefix") 64 ss("debug-systemd-unit", []string{}, "full-unit-name.service to enable SYSTEMD_LOG_LEVEL=debug on. Specify multiple times for multiple units.") 65 sv(&kola.UpdatePayloadFile, "update-payload", "", "Path to an update payload that should be made available to tests") 66 sv(&kola.Options.IgnitionVersion, "ignition-version", "", "Ignition version override: v2, v3") 67 68 // rhcos-specific options 69 sv(&kola.Options.OSContainer, "oscontainer", "", "oscontainer image pullspec for pivot (RHCOS only)") 70 71 // aws-specific options 72 defaultRegion := os.Getenv("AWS_REGION") 73 if defaultRegion == "" { 74 defaultRegion = "us-west-2" 75 } 76 sv(&kola.AWSOptions.CredentialsFile, "aws-credentials-file", "", "AWS credentials file (default \"~/.aws/credentials\")") 77 sv(&kola.AWSOptions.Region, "aws-region", defaultRegion, "AWS region") 78 sv(&kola.AWSOptions.Profile, "aws-profile", "default", "AWS profile name") 79 sv(&kola.AWSOptions.AMI, "aws-ami", "alpha", `AWS AMI ID, or (alpha|beta|stable) to use the latest image`) 80 sv(&kola.AWSOptions.InstanceType, "aws-type", "m4.large", "AWS instance type") 81 sv(&kola.AWSOptions.SecurityGroup, "aws-sg", "kola", "AWS security group name") 82 sv(&kola.AWSOptions.IAMInstanceProfile, "aws-iam-profile", "kola", "AWS IAM instance profile name") 83 84 // azure-specific options 85 sv(&kola.AzureOptions.AzureProfile, "azure-profile", "", "Azure profile (default \"~/"+auth.AzureProfilePath+"\")") 86 sv(&kola.AzureOptions.AzureAuthLocation, "azure-auth", "", "Azure auth location (default \"~/"+auth.AzureAuthPath+"\")") 87 sv(&kola.AzureOptions.DiskURI, "azure-disk-uri", "", "Azure disk uri (custom images)") 88 sv(&kola.AzureOptions.Publisher, "azure-publisher", "CoreOS", "Azure image publisher (default \"CoreOS\"") 89 sv(&kola.AzureOptions.Offer, "azure-offer", "CoreOS", "Azure image offer (default \"CoreOS\"") 90 sv(&kola.AzureOptions.Sku, "azure-sku", "alpha", "Azure image sku/channel (default \"alpha\"") 91 sv(&kola.AzureOptions.Version, "azure-version", "", "Azure image version") 92 sv(&kola.AzureOptions.Location, "azure-location", "westus", "Azure location (default \"westus\"") 93 sv(&kola.AzureOptions.Size, "azure-size", "Standard_D2_v2", "Azure machine size (default \"Standard_D2_v2\")") 94 95 // do-specific options 96 sv(&kola.DOOptions.ConfigPath, "do-config-file", "", "DigitalOcean config file (default \"~/"+auth.DOConfigPath+"\")") 97 sv(&kola.DOOptions.Profile, "do-profile", "", "DigitalOcean profile (default \"default\")") 98 sv(&kola.DOOptions.AccessToken, "do-token", "", "DigitalOcean access token (overrides config file)") 99 sv(&kola.DOOptions.Region, "do-region", "sfo2", "DigitalOcean region slug") 100 sv(&kola.DOOptions.Size, "do-size", "1gb", "DigitalOcean size slug") 101 sv(&kola.DOOptions.Image, "do-image", "alpha", "DigitalOcean image ID, {alpha, beta, stable}, or user image name") 102 103 // esx-specific options 104 sv(&kola.ESXOptions.ConfigPath, "esx-config-file", "", "ESX config file (default \"~/"+auth.ESXConfigPath+"\")") 105 sv(&kola.ESXOptions.Server, "esx-server", "", "ESX server") 106 sv(&kola.ESXOptions.Profile, "esx-profile", "", "ESX profile (default \"default\")") 107 sv(&kola.ESXOptions.BaseVMName, "esx-base-vm", "", "ESX base VM name") 108 109 // gce-specific options 110 sv(&kola.GCEOptions.Image, "gce-image", "projects/coreos-cloud/global/images/family/coreos-alpha", "GCE image, full api endpoints names are accepted if resource is in a different project") 111 sv(&kola.GCEOptions.Project, "gce-project", "coreos-gce-testing", "GCE project name") 112 sv(&kola.GCEOptions.Zone, "gce-zone", "us-central1-a", "GCE zone name") 113 sv(&kola.GCEOptions.MachineType, "gce-machinetype", "n1-standard-1", "GCE machine type") 114 sv(&kola.GCEOptions.DiskType, "gce-disktype", "pd-ssd", "GCE disk type") 115 sv(&kola.GCEOptions.Network, "gce-network", "default", "GCE network") 116 bv(&kola.GCEOptions.ServiceAuth, "gce-service-auth", false, "for non-interactive auth when running within GCE") 117 sv(&kola.GCEOptions.JSONKeyFile, "gce-json-key", "", "use a service account's JSON key for authentication") 118 119 // openstack-specific options 120 sv(&kola.OpenStackOptions.ConfigPath, "openstack-config-file", "", "OpenStack config file (default \"~/"+auth.OpenStackConfigPath+"\")") 121 sv(&kola.OpenStackOptions.Profile, "openstack-profile", "", "OpenStack profile (default \"default\")") 122 sv(&kola.OpenStackOptions.Region, "openstack-region", "", "OpenStack region") 123 sv(&kola.OpenStackOptions.Image, "openstack-image", "", "OpenStack image ref") 124 sv(&kola.OpenStackOptions.Flavor, "openstack-flavor", "1", "OpenStack flavor ref") 125 sv(&kola.OpenStackOptions.Network, "openstack-network", "", "OpenStack network") 126 sv(&kola.OpenStackOptions.Domain, "openstack-domain", "", "OpenStack domain ID") 127 sv(&kola.OpenStackOptions.FloatingIPPool, "openstack-floating-ip-pool", "", "OpenStack floating IP pool for Compute v2 networking") 128 129 // packet-specific options 130 sv(&kola.PacketOptions.ConfigPath, "packet-config-file", "", "Packet config file (default \"~/"+auth.PacketConfigPath+"\")") 131 sv(&kola.PacketOptions.Profile, "packet-profile", "", "Packet profile (default \"default\")") 132 sv(&kola.PacketOptions.ApiKey, "packet-api-key", "", "Packet API key (overrides config file)") 133 sv(&kola.PacketOptions.Project, "packet-project", "", "Packet project UUID (overrides config file)") 134 sv(&kola.PacketOptions.Facility, "packet-facility", "sjc1", "Packet facility code") 135 sv(&kola.PacketOptions.Plan, "packet-plan", "", "Packet plan slug (default board-dependent, e.g. \"baremetal_0\")") 136 sv(&kola.PacketOptions.InstallerImageBaseURL, "packet-installer-image-base-url", "", "Packet installer image base URL, non-https (default board-dependent, e.g. \"http://stable.release.core-os.net/amd64-usr/current\")") 137 sv(&kola.PacketOptions.ImageURL, "packet-image-url", "", "Packet image URL (default board-dependent, e.g. \"https://alpha.release.core-os.net/amd64-usr/current/coreos_production_packet_image.bin.bz2\")") 138 sv(&kola.PacketOptions.StorageURL, "packet-storage-url", "gs://users.developer.core-os.net/"+os.Getenv("USER")+"/mantle", "Google Storage base URL for temporary uploads") 139 140 // QEMU-specific options 141 sv(&kola.QEMUOptions.Board, "board", defaultTargetBoard, "target board") 142 sv(&kola.QEMUOptions.DiskImage, "qemu-image", "", "path to CoreOS disk image") 143 sv(&kola.QEMUOptions.BIOSImage, "qemu-bios", "", "BIOS to use for QEMU vm") 144 bv(&kola.QEMUOptions.UseVanillaImage, "qemu-skip-mangle", false, "don't modify CL disk image to capture console log") 145 } 146 147 // Sync up the command line options if there is dependency 148 func syncOptions() error { 149 kola.PacketOptions.Board = kola.QEMUOptions.Board 150 kola.PacketOptions.GSOptions = &kola.GCEOptions 151 152 validateOption := func(name, item string, valid []string) error { 153 for _, v := range valid { 154 if v == item { 155 return nil 156 } 157 } 158 return fmt.Errorf("unsupported %v %q", name, item) 159 } 160 161 if err := validateOption("platform", kolaPlatform, kolaPlatforms); err != nil { 162 return err 163 } 164 165 if err := validateOption("distro", kola.Options.Distribution, kolaDistros); err != nil { 166 return err 167 } 168 169 image, ok := kolaDefaultImages[kola.QEMUOptions.Board] 170 if !ok { 171 return fmt.Errorf("unsupport board %q", kola.QEMUOptions.Board) 172 } 173 174 if kola.QEMUOptions.DiskImage == "" { 175 kola.QEMUOptions.DiskImage = image 176 } 177 178 if kola.QEMUOptions.BIOSImage == "" { 179 kola.QEMUOptions.BIOSImage = kolaDefaultBIOS[kola.QEMUOptions.Board] 180 } 181 units, _ := root.PersistentFlags().GetStringSlice("debug-systemd-units") 182 for _, unit := range units { 183 kola.Options.SystemdDropins = append(kola.Options.SystemdDropins, platform.SystemdDropin{ 184 Unit: unit, 185 Name: "10-debug.conf", 186 Contents: "[Service]\nEnvironment=SYSTEMD_LOG_LEVEL=debug", 187 }) 188 } 189 190 if kola.Options.OSContainer != "" && kola.Options.Distribution != "rhcos" { 191 return fmt.Errorf("oscontainer is only supported on rhcos") 192 } 193 194 if kola.Options.IgnitionVersion == "" { 195 kola.Options.IgnitionVersion, ok = kolaIgnitionVersionDefaults[kola.Options.Distribution] 196 if !ok { 197 return fmt.Errorf("Distribution %q has no default Ignition version", kola.Options.Distribution) 198 } 199 } 200 201 return nil 202 }