github.com/coreos/mantle@v0.13.0/kola/register/register.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 register 16 17 import ( 18 "fmt" 19 20 "github.com/coreos/go-semver/semver" 21 22 "github.com/coreos/mantle/kola/cluster" 23 "github.com/coreos/mantle/platform/conf" 24 ) 25 26 type Flag int 27 28 const ( 29 NoSSHKeyInUserData Flag = iota // don't inject SSH key into Ignition/cloud-config 30 NoSSHKeyInMetadata // don't add SSH key to platform metadata 31 NoEmergencyShellCheck // don't check console output for emergency shell invocation 32 NoEnableSelinux // don't enable selinux when starting or rebooting a machine 33 RequiresInternetAccess // run the test only if the platform supports Internet access 34 ) 35 36 var ( 37 // platforms that have no Internet access 38 PlatformsNoInternet = []string{ 39 "qemu", 40 "qemu-unpriv", 41 } 42 ) 43 44 // Test provides the main test abstraction for kola. The run function is 45 // the actual testing function while the other fields provide ways to 46 // statically declare state of the platform.TestCluster before the test 47 // function is run. 48 type Test struct { 49 Name string // should be unique 50 Run func(cluster.TestCluster) 51 NativeFuncs map[string]func() error 52 UserData *conf.UserData 53 UserDataV3 *conf.UserData 54 ClusterSize int 55 Platforms []string // whitelist of platforms to run test against -- defaults to all 56 ExcludePlatforms []string // blacklist of platforms to ignore -- defaults to none 57 Distros []string // whitelist of distributions to run test against -- defaults to all 58 ExcludeDistros []string // blacklist of distributions to ignore -- defaults to none 59 Architectures []string // whitelist of machine architectures supported -- defaults to all 60 Flags []Flag // special-case options for this test 61 62 // FailFast skips any sub-test that occurs after a sub-test has 63 // failed. 64 FailFast bool 65 66 // MinVersion prevents the test from executing on CoreOS machines 67 // less than MinVersion. This will be ignored if the name fully 68 // matches without globbing. 69 MinVersion semver.Version 70 71 // EndVersion prevents the test from executing on CoreOS machines 72 // greater than or equal to EndVersion. This will be ignored if 73 // the name fully matches without globbing. 74 EndVersion semver.Version 75 } 76 77 // Registered tests live here. Mapping of names to tests. 78 var Tests = map[string]*Test{} 79 80 // Register is usually called in init() functions and is how kola test 81 // harnesses knows which tests it can choose from. Panics if existing 82 // name is registered 83 func Register(t *Test) { 84 _, ok := Tests[t.Name] 85 if ok { 86 panic(fmt.Sprintf("test %v already registered", t.Name)) 87 } 88 89 if (t.EndVersion != semver.Version{}) && !t.MinVersion.LessThan(t.EndVersion) { 90 panic(fmt.Sprintf("test %v has an invalid version range", t.Name)) 91 } 92 93 Tests[t.Name] = t 94 } 95 96 func (t *Test) HasFlag(flag Flag) bool { 97 for _, f := range t.Flags { 98 if f == flag { 99 return true 100 } 101 } 102 return false 103 }