-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup_test.go
147 lines (133 loc) · 4.3 KB
/
setup_test.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
package dctest
import (
"context"
"fmt"
"os"
"time"
"github.com/cybozu-go/log"
"github.com/cybozu-go/neco"
"github.com/cybozu-go/well"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
// testSetup tests "neco setup"
func testSetup() {
// kubectl caches the results, but it takes time to write
// To speed up this caching, mount the directory to be cached by tmpfs.
It("should create mount service", func() {
mountUnit := `
[Unit]
Description=mount ,kube directory by tmpfs
Wants=network-online.target
After=network-online.target
[Mount]
What=tmpfs
Where=/home/cybozu/.kube
DirectoryMode=0777
Type=tmpfs
Options=strictatime,nosuid,nodev
[Install]
WantedBy=multi-user.target`
mountServicePath := "/lib/systemd/system/home-cybozu-.kube.mount"
for _, v := range bootServers {
stdout, stderr, err := execAtWithInput(v, []byte(mountUnit), "sudo", "tee", mountServicePath)
Expect(err).NotTo(HaveOccurred(), "host=%s, stdout=%s, stderr=%s, err=%v", v, stdout, stderr, err)
execSafeAt(v, "test", "-f", mountServicePath)
execSafeAt(v, "sudo", "systemctl", "enable", "home-cybozu-.kube.mount")
execSafeAt(v, "sudo", "systemctl", "start", "home-cybozu-.kube.mount")
execSafeAt(v, "systemctl", "-q", "is-active", "home-cybozu-.kube.mount")
}
})
It("should complete on all boot servers", func() {
env := well.NewEnvironment(context.Background())
env.Go(func(ctx context.Context) error {
stdout, stderr, err := execAtWithInput(
bootServers[0], []byte(os.Getenv("GITHUB_TOKEN")), "sudo", "neco", "setup", "--no-revoke",
"--proxy="+proxy, "0", "1", "2")
if err != nil {
log.Error("neco setup failed", map[string]interface{}{
"host": "boot-0",
"stdout": string(stdout),
"stderr": string(stderr),
})
return err
}
return nil
})
env.Go(func(ctx context.Context) error {
stdout, stderr, err := execAtWithInput(
bootServers[1], []byte(os.Getenv("GITHUB_TOKEN")), "sudo", "neco", "setup", "--no-revoke",
"--proxy="+proxy, "0", "1", "2")
if err != nil {
log.Error("neco setup failed", map[string]interface{}{
"host": "boot-1",
"stdout": string(stdout),
"stderr": string(stderr),
})
return err
}
return nil
})
env.Go(func(ctx context.Context) error {
stdout, stderr, err := execAtWithInput(
bootServers[2], []byte(os.Getenv("GITHUB_TOKEN")), "sudo", "neco", "setup", "--no-revoke",
"--proxy="+proxy, "0", "1", "2")
if err != nil {
log.Error("neco setup failed", map[string]interface{}{
"host": "boot-2",
"stdout": string(stdout),
"stderr": string(stderr),
})
return err
}
return nil
})
env.Stop()
Expect(env.Wait()).NotTo(HaveOccurred())
})
It("should install files", func() {
for _, h := range bootServers {
execSafeAt(h, "test", "-f", neco.NecoConfFile)
execSafeAt(h, "test", "-f", neco.NecoCertFile)
execSafeAt(h, "test", "-f", neco.NecoKeyFile)
execSafeAt(h, "test", "-f", neco.EtcdBackupCertFile)
execSafeAt(h, "test", "-f", neco.EtcdBackupKeyFile)
execSafeAt(h, "test", "-f", neco.TimerFile("etcd-backup"))
execSafeAt(h, "test", "-f", neco.ServiceFile("etcd-backup"))
execSafeAt(h, "test", "-f", "/lib/systemd/system/neco-updater.service")
execSafeAt(h, "test", "-f", "/lib/systemd/system/neco-worker.service")
execSafeAt(h, "test", "-f", "/lib/systemd/system/node-exporter.service")
execSafeAt(h, "test", "-f", "/lib/systemd/system/sabakan-state-setter.service")
}
})
It("should run services", func() {
services := []string{
"neco-updater.service",
"neco-worker.service",
"node-exporter.service",
"etcd-backup.timer",
neco.EtcdService + ".service",
neco.VaultService + ".service",
}
Eventually(func() error {
for _, h := range bootServers {
for _, svc := range services {
_, stderr, err := execAt(h, "systemctl", "-q", "is-active", svc)
if err != nil {
return fmt.Errorf("err: %v, stderr: %s", err, stderr)
}
}
}
return nil
}, 1*time.Minute).Should(Succeed())
})
It("should complete updates", func() {
By("Waiting for request to complete")
waitRequestComplete("")
By("Installing sshd_config and sudoers")
for _, h := range bootServers {
execSafeAt(h, "test", "-f", "/etc/ssh/sshd_config.d/neco.conf")
execSafeAt(h, "sudo", "test", "-f", "/etc/sudoers.d/cybozu")
}
})
}