forked from coreos/ignition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preemption.go
129 lines (118 loc) · 3.59 KB
/
preemption.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2017 CoreOS, 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 general
import (
"fmt"
"strings"
"github.com/coreos/ignition/tests/register"
"github.com/coreos/ignition/tests/types"
)
func init() {
// Default config is applied
register.Register(register.PositiveTest, makePreemptTest("D"))
// Base and default configs are both applied
register.Register(register.PositiveTest, makePreemptTest("BD"))
// Base and provider configs are both applied
register.Register(register.PositiveTest, makePreemptTest("BP"))
// Provider config is applied; default config is ignored
register.Register(register.PositiveTest, makePreemptTest("dP"))
// Base and user configs are applied; provider and default
// configs are ignored
register.Register(register.PositiveTest, makePreemptTest("BdUp"))
// No configs provided; Ignition should still run successfully
register.Register(register.PositiveTest, makePreemptTest(""))
}
// makePreemptTest returns a config preemption test that executes some
// combination of "b"ase, "d"efault, "u"ser (user.ign), and "p"rovider
// (IGNITION_CONFIG_FILE) configs. Capital letters indicate configs that
// Ignition should apply.
func makePreemptTest(components string) types.Test {
longnames := map[string]string{
"b": "base",
"d": "default",
"u": "user",
"p": "provider",
}
makeConfig := func(component string) string {
return fmt.Sprintf(`{
"ignition": {"version": "2.1.0"},
"storage": {
"files": [{
"filesystem": "root",
"path": "/ignition/%s",
"contents": {"source": "data:,%s"}
}]}
}`, longnames[component], component)
}
enabled := func(component string) bool {
return strings.Contains(strings.ToLower(components), component)
}
var longnameList []string
for _, component := range strings.Split(strings.ToLower(components), "") {
longnameList = append(longnameList, longnames[component])
}
if len(longnameList) == 0 {
longnameList = append(longnameList, "no")
}
name := "Preemption with " + strings.Join(longnameList, ", ") + " config"
in := types.GetBaseDisk()
out := types.GetBaseDisk()
var config string
if enabled("p") {
config = makeConfig("p")
}
var systemFiles []types.File
for _, component := range []string{"b", "d", "u"} {
if enabled(component) {
systemFiles = append(systemFiles, types.File{
Node: types.Node{
Name: longnames[component] + ".ign",
},
Contents: makeConfig(component),
})
}
}
for component, longname := range longnames {
in[0].Partitions.AddFiles("ROOT", []types.File{
{
Node: types.Node{
Name: longname,
Directory: "ignition",
},
Contents: "unset",
},
})
result := "unset"
if strings.Contains(components, strings.ToUpper(component)) {
result = component
}
out[0].Partitions.AddFiles("ROOT", []types.File{
{
Node: types.Node{
Name: longname,
Directory: "ignition",
},
Contents: result,
},
})
}
return types.Test{
Name: name,
In: in,
Out: out,
Config: config,
SystemDirFiles: systemFiles,
ConfigShouldBeBad: true,
}
}