-
Notifications
You must be signed in to change notification settings - Fork 112
/
deployment.go
75 lines (63 loc) · 1.97 KB
/
deployment.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
package integration
import (
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/chef/automate/components/automate-cli/pkg/diagnostics"
"github.com/chef/automate/lib/io/fileutils"
)
type chefServerSave struct {
ChefServerEnabled bool `json:"chef_server_enabled"`
}
type versionResponse struct {
Services []serviceVersion `json:"services"`
}
type serviceVersion struct {
Name string `json:"name"`
Origin string `json:"origin"`
Version string `json:"version"`
Release string `json:"release"`
}
func CreateDeploymentDiagnostic() diagnostics.Diagnostic {
return diagnostics.Diagnostic{
Name: "deployment",
Tags: diagnostics.Tags{"deployment", "skip-for-deep-upgrade"},
Generate: func(tstCtx diagnostics.TestContext) error {
resp := versionResponse{}
err := MustJSONDecodeSuccess(
tstCtx.DoLBRequest("/api/v1/deployment/service_versions")).WithValue(&resp)
if err != nil {
return errors.Wrap(err, "could not query service_versions")
}
csEnabled := false
for _, s := range resp.Services {
if s.Name == "automate-cs-nginx" {
csEnabled = true
}
}
tstCtx.SetValue("deployment-chef-server-enabled",
chefServerSave{ChefServerEnabled: csEnabled})
return nil
},
Verify: func(tstCtx diagnostics.VerificationTestContext) {
loaded := chefServerSave{}
require.NoError(tstCtx, tstCtx.GetValue("deployment-chef-server-enabled", &loaded),
"Generated context was not found")
binlinks := []string{"/bin/chef-automate"}
if loaded.ChefServerEnabled {
binlinks = append(binlinks, "/bin/knife", "/bin/chef-server-ctl")
}
for _, p := range binlinks {
isSym, err := fileutils.IsSymlink(p)
assert.NoError(tstCtx, err, "stat failed for %s", p)
assert.True(tstCtx, isSym, "%s should be a symlink", p)
}
},
Cleanup: func(diagnostics.TestContext) error {
return nil
},
}
}
func init() {
diagnostics.RegisterDiagnostic(CreateDeploymentDiagnostic())
}