This repository has been archived by the owner on May 7, 2021. It is now read-only.
/
torcx_manifest_pkgs.go
169 lines (149 loc) · 4.66 KB
/
torcx_manifest_pkgs.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// 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 docker
import (
"encoding/json"
"fmt"
"strings"
ignition "github.com/coreos/ignition/config/v2_1/types"
"github.com/coreos/mantle/kola"
"github.com/coreos/mantle/kola/cluster"
"github.com/coreos/mantle/kola/register"
"github.com/coreos/mantle/kola/torcx"
"github.com/coreos/mantle/platform"
"github.com/coreos/mantle/platform/conf"
)
func init() {
register.Register(®ister.Test{
Run: dockerTorcxManifestPkgs,
ClusterSize: 0,
Name: "docker.torcx-manifest-pkgs",
Flags: []register.Flag{register.RequiresInternetAccess}, // Downloads torcx packages
// https://github.com/coreos/bugs/issues/2205 for DO
ExcludePlatforms: []string{"do"},
Distros: []string{"cl"},
})
}
func dockerTorcxManifestPkgs(c cluster.TestCluster) {
if kola.TorcxManifest == nil {
c.Skip("no torcx manifest provided")
return
}
var dockerPkgs *torcx.Package
for _, pkg := range kola.TorcxManifest.Packages {
pkg := pkg
if pkg.Name == "docker" {
dockerPkgs = &pkg
break
}
}
if dockerPkgs == nil {
c.Fatalf("torcx manifest provided, but didn't include docker packages: %+v", kola.TorcxManifest)
}
// Generate an ignition config that downloads all of the docker torcx packages referenced
ignitionConfig := ignition.Config{
Ignition: ignition.Ignition{
Version: "2.1.0",
},
Storage: ignition.Storage{
Files: []ignition.File{},
},
}
for _, version := range dockerPkgs.Versions {
version := version
var url string
for _, loc := range version.Locations {
if loc.URL != nil {
url = *loc.URL
}
}
if url == "" {
c.Fatalf("not all docker versions had a remote location available: %+v", kola.TorcxManifest)
}
ignitionConfig.Storage.Files = append(ignitionConfig.Storage.Files, ignition.File{
Node: ignition.Node{
Filesystem: "root",
Path: fmt.Sprintf("/var/lib/torcx/store/docker:%s.torcx.tgz", version.Version),
},
FileEmbedded1: ignition.FileEmbedded1{
Contents: ignition.FileContents{
Source: url,
Verification: ignition.Verification{
Hash: &version.Hash,
},
},
Mode: 0644,
},
})
}
ignitionBytes, err := json.Marshal(ignitionConfig)
if err != nil {
c.Fatalf("marshal err: %v", err)
}
m, err := c.NewMachine(conf.Ignition(string(ignitionBytes)))
if err != nil {
c.Fatalf("could not boot machine: %v", err)
}
// Make sure the default torcx config was fine
c.MustSSH(m, `docker version`)
// And now swap in a profile for each package and make sure it works
for _, version := range dockerPkgs.Versions {
version := version.Version
c.Run("torcx-pkg-"+version, func(c cluster.TestCluster) {
testPackageVersion(m, c, version)
})
}
}
func testPackageVersion(m platform.Machine, c cluster.TestCluster, version string) {
c.Run("install-torcx-profile", func(c cluster.TestCluster) {
c.MustSSH(m, fmt.Sprintf(`sudo tee /etc/torcx/profiles/docker.json <<EOF
{
"kind": "profile-manifest-v0",
"value": {
"images": [
{
"name": "docker",
"reference": "%s"
}
]
}
}
EOF
echo "docker" | sudo tee /etc/torcx/next-profile
`, version))
if err := m.Reboot(); err != nil {
c.Fatalf("could not reboot: %v", err)
}
c.MustSSH(m, `sudo rm -rf /var/lib/docker`)
currentVersion := getTorcxDockerReference(c, m)
if currentVersion != version {
c.Fatalf("expected version to be %s, was %s", version, currentVersion)
}
serverVersion := getDockerServerVersion(c, m)
// torcx packages have truncated docker versions, e.g. 1.12.6 has a torcx
// package of 1.12
if !strings.HasPrefix(serverVersion, version) {
c.Fatalf("expected a version similar to %v, was %v", version, serverVersion)
}
})
dockerBaseTests(c)
}
func getTorcxDockerReference(c cluster.TestCluster, m platform.Machine) string {
ver := c.MustSSH(m, `jq -r '.value.images[] | select(.name == "docker").reference' /run/torcx/profile.json`)
return string(ver)
}
func getDockerServerVersion(c cluster.TestCluster, m platform.Machine) string {
ver := c.MustSSH(m, `curl -s --unix-socket /var/run/docker.sock http://docker/v1.24/info | jq -r '.ServerVersion'`)
return string(ver)
}