Skip to content

Commit 45d6178

Browse files
chore: adding more end-to-end tests (#34)
adding more end-to-end tests.
1 parent e0ac224 commit 45d6178

File tree

5 files changed

+143
-19
lines changed

5 files changed

+143
-19
lines changed

.github/workflows/e2e.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ jobs:
1313
- TestMultiNodeInstallation
1414
- TestSingleNodeInstallation
1515
- TestTokenBasedMultiNodeInstallation
16+
- TestSingleNodeInstallationRockyLinux8
17+
- TestSingleNodeInstallationDebian12
18+
- TestSingleNodeInstallationCentos8Stream
1619
steps:
1720
- name: Move Docker aside
1821
run: |

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ e2e-test: helmvm-linux-amd64
143143
mkdir -p output/tmp
144144
rm -rf output/tmp/id_rsa*
145145
ssh-keygen -t rsa -N "" -C "Integration Test Key" -f output/tmp/id_rsa
146-
go test -timeout 10m -v ./e2e -run $(TEST_NAME)
146+
go test -timeout 10m -v ./e2e -run $(TEST_NAME)$
147147

148148
.PHONY: create-e2e-workflows
149149
create-e2e-workflows:

e2e/cluster/cluster.go

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ lxc.cap.drop=
2424
lxc.cgroup.devices.allow=a
2525
lxc.mount.auto=proc:rw sys:rw
2626
lxc.mount.entry = /dev/kmsg dev/kmsg none defaults,bind,create=file`
27+
const checkInternet = `#!/bin/bash
28+
timeout 5 bash -c 'cat < /dev/null > /dev/tcp/www.replicated.com/80'
29+
if [ $? == 0 ]; then
30+
echo "Internet connectivity is up"
31+
exit 0
32+
fi
33+
echo "Internet connectivity is down"
34+
exit 1
35+
`
2736

2837
func init() {
2938
networkaddr = make(chan string, 255)
@@ -214,20 +223,28 @@ func CopyFilesToNode(in *Input, node string) {
214223
})
215224
}
216225
for _, file := range files {
217-
fp, err := os.Open(file.SourcePath)
218-
if err != nil {
219-
in.T.Fatalf("Failed to open file %s: %v", file.SourcePath, err)
220-
}
221-
defer fp.Close()
222-
req = lxd.ContainerFileArgs{
223-
Content: fp,
224-
Mode: file.Mode,
225-
Type: "file",
226-
}
227-
err = client.CreateContainerFile(node, file.DestPath, req)
228-
if err != nil {
229-
in.T.Fatalf("Failed to copy file %s: %v", file.SourcePath, err)
230-
}
226+
CopyFileToNode(in, node, file)
227+
}
228+
}
229+
230+
// CopyFileToNode copies a single file to a node.
231+
func CopyFileToNode(in *Input, node string, file File) {
232+
client, err := lxd.ConnectLXDUnix(lxdSocket, nil)
233+
if err != nil {
234+
in.T.Fatalf("Failed to connect to LXD: %v", err)
235+
}
236+
fp, err := os.Open(file.SourcePath)
237+
if err != nil {
238+
in.T.Fatalf("Failed to open file %s: %v", file.SourcePath, err)
239+
}
240+
defer fp.Close()
241+
req := lxd.ContainerFileArgs{
242+
Content: fp,
243+
Mode: file.Mode,
244+
Type: "file",
245+
}
246+
if err := client.CreateContainerFile(node, file.DestPath, req); err != nil {
247+
in.T.Fatalf("Failed to copy file %s: %v", file.SourcePath, err)
231248
}
232249
}
233250

@@ -247,13 +264,28 @@ func CreateNodes(in *Input) []string {
247264
// pinging google.com.
248265
func NodeHasInternet(in *Input, node string) {
249266
in.T.Logf("Testing if node %s can reach the internet", node)
267+
fp, err := os.CreateTemp("/tmp", "internet-XXXXX.sh")
268+
if err != nil {
269+
in.T.Fatalf("Failed to create temporary file: %v", err)
270+
}
271+
fp.Close()
272+
defer func() {
273+
os.RemoveAll(fp.Name())
274+
}()
275+
if err := os.WriteFile(fp.Name(), []byte(checkInternet), 0755); err != nil {
276+
in.T.Fatalf("Failed to write script: %v", err)
277+
}
278+
file := File{
279+
SourcePath: fp.Name(),
280+
DestPath: "/usr/local/bin/check_internet.sh",
281+
Mode: 0755,
282+
}
283+
CopyFileToNode(in, node, file)
250284
cmd := Command{
251285
Node: node,
252286
Stdout: os.Stdout,
253287
Stderr: os.Stderr,
254-
Line: []string{
255-
"nc", "-w", "2", "-zv", "www.replicated.com", "80",
256-
},
288+
Line: []string{"/usr/local/bin/check_internet.sh"},
257289
}
258290
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
259291
defer cancel()
@@ -317,7 +349,7 @@ func CreateNode(in *Input, i int) string {
317349
state := &api.InstanceState{}
318350
for state.Status != "Running" {
319351
time.Sleep(5 * time.Second)
320-
in.T.Logf("Waiting for node %s to run", name)
352+
in.T.Logf("Waiting for node %s to start (running)", name)
321353
if state, _, err = client.GetInstanceState(name); err != nil {
322354
in.T.Fatalf("Failed to get node state %s: %v", name, err)
323355
}

e2e/install_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,80 @@ func TestMultiNodeInstallation(t *testing.T) {
9696
t.Fatalf("fail to install helmvm from node 00: %v", err)
9797
}
9898
}
99+
100+
func TestSingleNodeInstallationRockyLinux8(t *testing.T) {
101+
t.Parallel()
102+
tc := cluster.NewTestCluster(&cluster.Input{
103+
T: t,
104+
Nodes: 1,
105+
Image: "rockylinux/8",
106+
SSHPublicKey: "../output/tmp/id_rsa.pub",
107+
SSHPrivateKey: "../output/tmp/id_rsa",
108+
HelmVMPath: "../output/bin/helmvm",
109+
})
110+
defer tc.Destroy()
111+
t.Log("installing ssh on node 0")
112+
commands := [][]string{
113+
{"dnf", "install", "-y", "openssh-server"},
114+
{"systemctl", "enable", "sshd"},
115+
{"systemctl", "start", "sshd"},
116+
}
117+
if err := RunCommandsOnNode(t, tc, 0, commands); err != nil {
118+
t.Fatalf("fail to install ssh on node %s: %v", tc.Nodes[0], err)
119+
}
120+
t.Log("installing helmvm on node 0")
121+
line := []string{"single-node-install.sh"}
122+
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
123+
t.Fatalf("fail to install helmvm on node %s: %v", tc.Nodes[0], err)
124+
}
125+
}
126+
127+
func TestSingleNodeInstallationDebian12(t *testing.T) {
128+
t.Parallel()
129+
tc := cluster.NewTestCluster(&cluster.Input{
130+
T: t,
131+
Nodes: 1,
132+
Image: "debian/12",
133+
SSHPublicKey: "../output/tmp/id_rsa.pub",
134+
SSHPrivateKey: "../output/tmp/id_rsa",
135+
HelmVMPath: "../output/bin/helmvm",
136+
})
137+
defer tc.Destroy()
138+
t.Log("installing ssh on node 0")
139+
line := []string{"apt", "install", "openssh-server", "-y"}
140+
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
141+
t.Fatalf("fail to install ssh on node 0: %v", err)
142+
}
143+
t.Log("installing helmvm on node 0")
144+
line = []string{"single-node-install.sh"}
145+
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
146+
t.Fatalf("fail to install helmvm on node %s: %v", tc.Nodes[0], err)
147+
}
148+
}
149+
150+
func TestSingleNodeInstallationCentos8Stream(t *testing.T) {
151+
t.Parallel()
152+
tc := cluster.NewTestCluster(&cluster.Input{
153+
T: t,
154+
Nodes: 1,
155+
Image: "centos/8-Stream",
156+
SSHPublicKey: "../output/tmp/id_rsa.pub",
157+
SSHPrivateKey: "../output/tmp/id_rsa",
158+
HelmVMPath: "../output/bin/helmvm",
159+
})
160+
defer tc.Destroy()
161+
t.Log("installing ssh on node 0")
162+
commands := [][]string{
163+
{"dnf", "install", "-y", "openssh-server"},
164+
{"systemctl", "enable", "sshd"},
165+
{"systemctl", "start", "sshd"},
166+
}
167+
if err := RunCommandsOnNode(t, tc, 0, commands); err != nil {
168+
t.Fatalf("fail to install ssh on node %s: %v", tc.Nodes[0], err)
169+
}
170+
t.Log("installing helmvm on node 0")
171+
line := []string{"single-node-install.sh"}
172+
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
173+
t.Fatalf("fail to install helmvm on node %s: %v", tc.Nodes[0], err)
174+
}
175+
}

e2e/utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package e2e
33
import (
44
"bytes"
55
"context"
6+
"strings"
67
"testing"
78
"time"
89

@@ -17,6 +18,17 @@ func (b *buffer) Close() error {
1718
return nil
1819
}
1920

21+
func RunCommandsOnNode(t *testing.T, cl *cluster.Output, node int, cmds [][]string) error {
22+
for _, cmd := range cmds {
23+
cmdstr := strings.Join(cmd, " ")
24+
t.Logf("running `%s` node %d", cmdstr, node)
25+
if _, _, err := RunCommandOnNode(t, cl, node, cmd); err != nil {
26+
return err
27+
}
28+
}
29+
return nil
30+
}
31+
2032
func RunCommandOnNode(t *testing.T, cl *cluster.Output, node int, line []string) (string, string, error) {
2133
stdout := &buffer{bytes.NewBuffer(nil)}
2234
stderr := &buffer{bytes.NewBuffer(nil)}

0 commit comments

Comments
 (0)