Skip to content

Commit 68efbc1

Browse files
committed
config: copy v3_5 to v3_6_experimental
1 parent 3b0b89b commit 68efbc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+5411
-0
lines changed

config/v3_6_experimental/config.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2020 Red Hat, 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 v3_5
16+
17+
import (
18+
"github.com/coreos/ignition/v2/config/merge"
19+
"github.com/coreos/ignition/v2/config/shared/errors"
20+
"github.com/coreos/ignition/v2/config/util"
21+
prev "github.com/coreos/ignition/v2/config/v3_4"
22+
"github.com/coreos/ignition/v2/config/v3_5/translate"
23+
"github.com/coreos/ignition/v2/config/v3_5/types"
24+
"github.com/coreos/ignition/v2/config/validate"
25+
26+
"github.com/coreos/go-semver/semver"
27+
"github.com/coreos/vcontext/report"
28+
)
29+
30+
func Merge(parent, child types.Config) types.Config {
31+
res, _ := merge.MergeStructTranscribe(parent, child)
32+
return res.(types.Config)
33+
}
34+
35+
// Parse parses the raw config into a types.Config struct and generates a report of any
36+
// errors, warnings, info, and deprecations it encountered
37+
func Parse(rawConfig []byte) (types.Config, report.Report, error) {
38+
if len(rawConfig) == 0 {
39+
return types.Config{}, report.Report{}, errors.ErrEmpty
40+
}
41+
42+
var config types.Config
43+
if rpt, err := util.HandleParseErrors(rawConfig, &config); err != nil {
44+
return types.Config{}, rpt, err
45+
}
46+
47+
version, err := semver.NewVersion(config.Ignition.Version)
48+
49+
if err != nil || *version != types.MaxVersion {
50+
return types.Config{}, report.Report{}, errors.ErrUnknownVersion
51+
}
52+
53+
rpt := validate.ValidateWithContext(config, rawConfig)
54+
if rpt.IsFatal() {
55+
return types.Config{}, rpt, errors.ErrInvalid
56+
}
57+
58+
return config, rpt, nil
59+
}
60+
61+
// ParseCompatibleVersion parses the raw config of version 3.5.0 or
62+
// lesser into a 3.5 types.Config struct and generates a report of any errors,
63+
// warnings, info, and deprecations it encountered
64+
func ParseCompatibleVersion(raw []byte) (types.Config, report.Report, error) {
65+
version, rpt, err := util.GetConfigVersion(raw)
66+
if err != nil {
67+
return types.Config{}, rpt, err
68+
}
69+
70+
if version == types.MaxVersion {
71+
return Parse(raw)
72+
}
73+
prevCfg, r, err := prev.ParseCompatibleVersion(raw)
74+
if err != nil {
75+
return types.Config{}, r, err
76+
}
77+
return translate.Translate(prevCfg), r, nil
78+
}
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
// Copyright 2020 Red Hat, 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 v3_5
16+
17+
import (
18+
"testing"
19+
20+
"github.com/coreos/ignition/v2/config/shared/errors"
21+
"github.com/coreos/ignition/v2/config/v3_5/types"
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestParse(t *testing.T) {
26+
type in struct {
27+
config []byte
28+
}
29+
type out struct {
30+
config types.Config
31+
err error
32+
}
33+
34+
tests := []struct {
35+
in in
36+
out out
37+
}{
38+
{
39+
in: in{config: []byte(`{"ignitionVersion": 1}`)},
40+
out: out{err: errors.ErrUnknownVersion},
41+
},
42+
{
43+
in: in{config: []byte(`{"ignition": {"version": "1.0.0"}}`)},
44+
out: out{err: errors.ErrUnknownVersion},
45+
},
46+
{
47+
in: in{config: []byte(`{"ignition": {"version": "2.0.0"}}`)},
48+
out: out{err: errors.ErrUnknownVersion},
49+
},
50+
{
51+
in: in{config: []byte(`{"ignition": {"version": "2.1.0"}}`)},
52+
out: out{err: errors.ErrUnknownVersion},
53+
},
54+
{
55+
in: in{config: []byte(`{"ignition": {"version": "2.2.0"}}`)},
56+
out: out{err: errors.ErrUnknownVersion},
57+
},
58+
{
59+
in: in{config: []byte(`{"ignition": {"version": "2.3.0"}}`)},
60+
out: out{err: errors.ErrUnknownVersion},
61+
},
62+
{
63+
in: in{config: []byte(`{"ignition": {"version": "2.4.0"}}`)},
64+
out: out{err: errors.ErrUnknownVersion},
65+
},
66+
{
67+
in: in{config: []byte(`{"ignition": {"version": "3.0.0"}}`)},
68+
out: out{err: errors.ErrUnknownVersion},
69+
},
70+
{
71+
in: in{config: []byte(`{"ignition": {"version": "3.1.0"}}`)},
72+
out: out{err: errors.ErrUnknownVersion},
73+
},
74+
{
75+
in: in{config: []byte(`{"ignition": {"version": "3.2.0"}}`)},
76+
out: out{err: errors.ErrUnknownVersion},
77+
},
78+
{
79+
in: in{config: []byte(`{"ignition": {"version": "3.3.0"}}`)},
80+
out: out{err: errors.ErrUnknownVersion},
81+
},
82+
{
83+
in: in{config: []byte(`{"ignition": {"version": "3.4.0"}}`)},
84+
out: out{err: errors.ErrUnknownVersion},
85+
},
86+
{
87+
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}}`)},
88+
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
89+
},
90+
{
91+
in: in{config: []byte(`{"ignition": {"version": "2.0.0-experimental"}}`)},
92+
out: out{err: errors.ErrUnknownVersion},
93+
},
94+
{
95+
in: in{config: []byte(`{"ignition": {"version": "2.1.0-experimental"}}`)},
96+
out: out{err: errors.ErrUnknownVersion},
97+
},
98+
{
99+
in: in{config: []byte(`{"ignition": {"version": "2.2.0-experimental"}}`)},
100+
out: out{err: errors.ErrUnknownVersion},
101+
},
102+
{
103+
in: in{config: []byte(`{"ignition": {"version": "2.3.0-experimental"}}`)},
104+
out: out{err: errors.ErrUnknownVersion},
105+
},
106+
{
107+
in: in{config: []byte(`{"ignition": {"version": "2.4.0-experimental"}}`)},
108+
out: out{err: errors.ErrUnknownVersion},
109+
},
110+
{
111+
in: in{config: []byte(`{"ignition": {"version": "2.5.0-experimental"}}`)},
112+
out: out{err: errors.ErrUnknownVersion},
113+
},
114+
{
115+
in: in{config: []byte(`{"ignition": {"version": "3.0.0-experimental"}}`)},
116+
out: out{err: errors.ErrUnknownVersion},
117+
},
118+
{
119+
in: in{config: []byte(`{"ignition": {"version": "3.1.0-experimental"}}`)},
120+
out: out{err: errors.ErrUnknownVersion},
121+
},
122+
{
123+
in: in{config: []byte(`{"ignition": {"version": "3.2.0-experimental"}}`)},
124+
out: out{err: errors.ErrUnknownVersion},
125+
},
126+
{
127+
in: in{config: []byte(`{"ignition": {"version": "3.3.0-experimental"}}`)},
128+
out: out{err: errors.ErrUnknownVersion},
129+
},
130+
{
131+
in: in{config: []byte(`{"ignition": {"version": "3.4.0-experimental"}}`)},
132+
out: out{err: errors.ErrUnknownVersion},
133+
},
134+
{
135+
in: in{config: []byte(`{"ignition": {"version": "3.5.0-experimental"}}`)},
136+
out: out{err: errors.ErrUnknownVersion},
137+
},
138+
{
139+
in: in{config: []byte(`{"ignition": {"version": "2.0.0"},}`)},
140+
out: out{err: errors.ErrInvalid},
141+
},
142+
{
143+
in: in{config: []byte(`{"ignition": {"version": "invalid.semver"}}`)},
144+
out: out{err: errors.ErrUnknownVersion},
145+
},
146+
{
147+
in: in{config: []byte(`{}`)},
148+
out: out{err: errors.ErrUnknownVersion},
149+
},
150+
{
151+
in: in{config: []byte{}},
152+
out: out{err: errors.ErrEmpty},
153+
},
154+
{
155+
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
156+
out: out{err: errors.ErrInvalid},
157+
},
158+
}
159+
160+
testsCompt := []struct {
161+
in in
162+
out out
163+
}{
164+
{
165+
in: in{config: []byte(`{"ignition": {"version": "3.0.0"}}`)},
166+
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
167+
},
168+
{
169+
in: in{config: []byte(`{"ignition": {"version": "3.1.0"}}`)},
170+
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
171+
},
172+
{
173+
in: in{config: []byte(`{"ignition": {"version": "3.2.0"}}`)},
174+
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
175+
},
176+
{
177+
in: in{config: []byte(`{"ignition": {"version": "3.3.0"}}`)},
178+
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
179+
},
180+
{
181+
in: in{config: []byte(`{"ignition": {"version": "3.4.0"}}`)},
182+
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
183+
},
184+
{
185+
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}}`)},
186+
out: out{config: types.Config{Ignition: types.Ignition{Version: types.MaxVersion.String()}}},
187+
},
188+
{
189+
in: in{config: []byte(`{"ignition": {"version": "3.6.0-experimental"}}`)},
190+
out: out{err: errors.ErrUnknownVersion},
191+
},
192+
{
193+
in: in{config: []byte(`{"ignition": {"version": "3.7.0"}}`)},
194+
out: out{err: errors.ErrUnknownVersion},
195+
},
196+
{
197+
in: in{config: []byte{}},
198+
out: out{err: errors.ErrEmpty},
199+
},
200+
{
201+
in: in{config: []byte(`{"ignition": {"version": "3.0.0"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
202+
out: out{err: errors.ErrInvalid},
203+
},
204+
{
205+
in: in{config: []byte(`{"ignition": {"version": "3.5.0"}, "storage": {"filesystems": [{"format": "ext4", "label": "zzzzzzzzzzzzzzzzzzzzzzzzzzz"}]}}`)},
206+
out: out{err: errors.ErrInvalid},
207+
},
208+
}
209+
210+
for i, test := range tests {
211+
config, report, err := Parse(test.in.config)
212+
if test.out.err != err {
213+
t.Errorf("#%d: bad error: want %v, got %v, report: %+v", i, test.out.err, err, report)
214+
}
215+
if test.out.err == errors.ErrInvalid && len(report.Entries) == 0 {
216+
t.Errorf("#%d: expected report, got none", i)
217+
}
218+
assert.Equal(t, test.out.config, config, "#%d: bad config, report: %+v", i, report)
219+
}
220+
for i, test := range testsCompt {
221+
config, report, err := ParseCompatibleVersion(test.in.config)
222+
if test.out.err != err {
223+
t.Errorf("#%d: bad error: want %v, got %v, report: %+v", i, test.out.err, err, report)
224+
}
225+
if test.out.err == errors.ErrInvalid && len(report.Entries) == 0 {
226+
t.Errorf("#%d: expected report, got none", i)
227+
}
228+
assert.Equal(t, test.out.config, config, "#%d: bad config, report: %+v", i, report)
229+
}
230+
}

0 commit comments

Comments
 (0)