-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
longhorn_int_test.go
154 lines (142 loc) · 5.11 KB
/
longhorn_int_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
148
149
150
151
152
153
154
package longhorn
import (
"fmt"
"os/exec"
"strings"
"testing"
testutil "github.com/k3s-io/k3s/tests/integration"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var server *testutil.K3sServer
var serverArgs = []string{"--cluster-init"}
var testLock int
var _ = BeforeSuite(func() {
if _, err := exec.LookPath("iscsiadm"); err != nil {
Skip("Test needs open-iscsi to be installed")
} else if !testutil.IsExistingServer() {
var err error
testLock, err = testutil.K3sTestLock()
Expect(err).ToNot(HaveOccurred())
server, err = testutil.K3sStartServer(serverArgs...)
Expect(err).ToNot(HaveOccurred())
}
})
var _ = Describe("longhorn", Ordered, func() {
BeforeEach(func() {
if testutil.IsExistingServer() && !testutil.ServerArgsPresent(serverArgs) {
Skip("Test needs k3s server with: " + strings.Join(serverArgs, " "))
}
})
When("a new cluster is created", func() {
It("starts up with no problems", func() {
Eventually(func() error {
return testutil.K3sDefaultDeployments()
}, "120s", "5s").Should(Succeed())
})
})
When("longhorn is installed", func() {
It("installs components into the longhorn-system namespace", func() {
result, err := testutil.K3sCmd("kubectl apply -f ./testdata/longhorn.yaml")
Expect(err).NotTo(HaveOccurred())
Expect(result).To(ContainSubstring("namespace/longhorn-system created"))
Expect(result).To(ContainSubstring("daemonset.apps/longhorn-manager created"))
Expect(result).To(ContainSubstring("deployment.apps/longhorn-driver-deployer created"))
Expect(result).To(ContainSubstring("deployment.apps/longhorn-recovery-backend created"))
Expect(result).To(ContainSubstring("deployment.apps/longhorn-ui created"))
Expect(result).To(ContainSubstring("deployment.apps/longhorn-conversion-webhook created"))
Expect(result).To(ContainSubstring("deployment.apps/longhorn-admission-webhook created"))
})
It("starts the longhorn pods with no problems", func() {
Eventually(func() error {
pods, err := testutil.ParsePods("longhorn-system", metav1.ListOptions{})
if err != nil {
return err
}
for _, pod := range pods {
if pod.Status.Phase != "Running" && pod.Status.Phase != "Succeeded" {
return fmt.Errorf("pod %s failing", pod.Name)
}
}
return nil
}, "120s", "5s").Should(Succeed())
})
})
When("persistent volume claim is created", func() {
It("creates the pv and pvc", func() {
result, err := testutil.K3sCmd("kubectl create -f ./testdata/pvc.yaml")
Expect(err).NotTo(HaveOccurred())
Expect(result).To(ContainSubstring("persistentvolumeclaim/longhorn-volv-pvc created"))
Eventually(func() error {
pvc, err := testutil.GetPersistentVolumeClaim("default", "longhorn-volv-pvc")
if err != nil {
return fmt.Errorf("failed to get pvc longhorn-volv-pvc")
}
if pvc.Status.Phase != "Bound" {
return fmt.Errorf("pvc longhorn-volv-pvc not bound")
}
pv, err := testutil.GetPersistentVolume(pvc.Spec.VolumeName)
if err != nil {
return fmt.Errorf("failed to get pv %s", pvc.Spec.VolumeName)
}
if pv.Status.Phase != "Bound" {
return fmt.Errorf("pv %s not bound", pv.Name)
}
return nil
}, "300s", "5s").Should(Succeed())
})
It("creates a pod with the pvc", func() {
result, err := testutil.K3sCmd("kubectl create -f ./testdata/pod.yaml")
Expect(err).NotTo(HaveOccurred())
Expect(result).To(ContainSubstring("pod/volume-test created"))
Eventually(func() error {
pod, err := testutil.GetPod("default", "volume-test")
if err != nil {
return fmt.Errorf("failed to get pod volume-test")
}
if pod.Status.Phase != "Running" {
return fmt.Errorf("pod volume-test \"%s\" reason: \"%s\" message \"%s\"", pod.Status.Phase, pod.Status.Reason, pod.Status.Message)
}
return nil
}, "60s", "5s").Should(Succeed())
})
})
When("the pvc is deleted", func() {
It("the pv is deleted according to the default reclaim policy", func() {
result, err := testutil.K3sCmd("kubectl delete pod volume-test")
Expect(err).NotTo(HaveOccurred())
Expect(result).To(ContainSubstring("pod \"volume-test\" deleted"))
result, err = testutil.K3sCmd("kubectl delete pvc longhorn-volv-pvc")
Expect(err).NotTo(HaveOccurred())
Expect(result).To(ContainSubstring("persistentvolumeclaim \"longhorn-volv-pvc\" deleted"))
Eventually(func() error {
result, err = testutil.K3sCmd("kubectl get pv")
if err != nil {
return fmt.Errorf("failed get persistent volumes")
}
if !strings.Contains(result, "No resources found") {
return fmt.Errorf("persistent volumes still exist")
}
return nil
}, "60s", "5s").Should(Succeed())
})
})
})
var failed bool
var _ = AfterEach(func() {
failed = failed || CurrentSpecReport().Failed()
})
var _ = AfterSuite(func() {
if !testutil.IsExistingServer() && server != nil {
if failed {
testutil.K3sSaveLog(server, false)
}
Expect(testutil.K3sKillServer(server)).To(Succeed())
Expect(testutil.K3sCleanup(testLock, "")).To(Succeed())
}
})
func Test_IntegrationLonghorn(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Longhorn Suite")
}