Skip to content

Commit 625e847

Browse files
committed
Add tests for database and distributed architecture
Signed-off-by: Dmitry Tantsur <[email protected]>
1 parent 52689b1 commit 625e847

File tree

2 files changed

+78
-15
lines changed

2 files changed

+78
-15
lines changed

test/functional.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ make install deploy IMG="${IMG}"
2929

3030
kubectl wait --for=condition=Available --timeout=60s \
3131
-n ironic-standalone-operator-system deployment/ironic-standalone-operator-controller-manager
32-
cd test && go test
32+
cd test && go test -timeout 30m

test/suite_test.go

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
. "github.com/onsi/gomega"
3030

3131
corev1 "k8s.io/api/core/v1"
32+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
3233
"k8s.io/apimachinery/pkg/api/meta"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3435
"k8s.io/apimachinery/pkg/types"
@@ -82,6 +83,39 @@ var _ = BeforeSuite(func() {
8283

8384
})
8485

86+
func WaitForIronic(name types.NamespacedName) *metal3api.Ironic {
87+
GinkgoHelper()
88+
89+
ironic := &metal3api.Ironic{}
90+
91+
By("waiting for Ironic deployment")
92+
93+
Eventually(func() bool {
94+
err := k8sClient.Get(ctx, name, ironic)
95+
Expect(err).NotTo(HaveOccurred())
96+
97+
cond := meta.FindStatusCondition(ironic.Status.Conditions, string(metal3api.IronicStatusAvailable))
98+
if cond != nil && cond.Status == metav1.ConditionTrue {
99+
return true
100+
}
101+
102+
GinkgoWriter.Printf("Current status of Ironic: %+v\n", ironic)
103+
return false
104+
}).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(BeTrue())
105+
106+
return ironic
107+
}
108+
109+
func VerifyIronic(ironic *metal3api.Ironic) {
110+
GinkgoHelper()
111+
112+
By("checking the service")
113+
114+
svc, err := clientset.CoreV1().Services(ironic.Namespace).Get(ctx, ironic.Name, metav1.GetOptions{})
115+
GinkgoWriter.Printf("Ironic service: %+v\n", svc)
116+
Expect(err).NotTo(HaveOccurred())
117+
}
118+
85119
var _ = Describe("Ironic object tests", func() {
86120
var namespace string
87121

@@ -93,6 +127,15 @@ var _ = Describe("Ironic object tests", func() {
93127
Expect(err).NotTo(HaveOccurred())
94128
DeferCleanup(func() {
95129
_ = clientset.CoreV1().Namespaces().Delete(ctx, namespace, metav1.DeleteOptions{})
130+
Eventually(func() bool {
131+
_, err := clientset.CoreV1().Namespaces().Get(ctx, namespace, metav1.GetOptions{})
132+
if err != nil && k8serrors.IsNotFound(err) {
133+
return true
134+
}
135+
GinkgoWriter.Println("Namespace", namespace, "not deleted yet, error is", err)
136+
Expect(err).NotTo(HaveOccurred())
137+
return false
138+
}).WithTimeout(2 * time.Minute).WithPolling(5 * time.Second).Should(BeTrue())
96139
})
97140
})
98141

@@ -102,33 +145,53 @@ var _ = Describe("Ironic object tests", func() {
102145
Namespace: namespace,
103146
}
104147

105-
ironic := metal3api.Ironic{
148+
ironic := &metal3api.Ironic{
106149
ObjectMeta: metav1.ObjectMeta{
107150
Name: name.Name,
108151
Namespace: name.Namespace,
109152
},
110153
}
111-
err := k8sClient.Create(ctx, &ironic)
154+
err := k8sClient.Create(ctx, ironic)
112155
Expect(err).NotTo(HaveOccurred())
113156

114-
var cond *metav1.Condition
115-
for attempt := 0; attempt < 10; attempt += 1 {
116-
err = k8sClient.Get(ctx, name, &ironic)
117-
Expect(err).NotTo(HaveOccurred())
157+
ironic = WaitForIronic(name)
158+
VerifyIronic(ironic)
159+
})
118160

119-
cond = meta.FindStatusCondition(ironic.Status.Conditions, string(metal3api.IronicStatusAvailable))
120-
if cond != nil && cond.Status == metav1.ConditionTrue {
121-
break
122-
}
161+
It("creates distributed Ironic", func() {
162+
name := types.NamespacedName{
163+
Name: "test-ironic",
164+
Namespace: namespace,
165+
}
123166

124-
time.Sleep(5 * time.Second)
167+
ironicDb := &metal3api.IronicDatabase{
168+
ObjectMeta: metav1.ObjectMeta{
169+
Name: fmt.Sprintf("%s-db", name.Name),
170+
Namespace: name.Namespace,
171+
},
125172
}
126173

127-
if cond == nil || cond.Status != metav1.ConditionTrue {
128-
Fail("Ironic deployment never succeded")
174+
err := k8sClient.Create(ctx, ironicDb)
175+
Expect(err).NotTo(HaveOccurred())
176+
177+
ironic := &metal3api.Ironic{
178+
ObjectMeta: metav1.ObjectMeta{
179+
Name: name.Name,
180+
Namespace: name.Namespace,
181+
},
182+
Spec: metal3api.IronicSpec{
183+
DatabaseRef: corev1.LocalObjectReference{
184+
Name: ironicDb.Name,
185+
},
186+
Distributed: true,
187+
},
129188
}
130-
})
189+
err = k8sClient.Create(ctx, ironic)
190+
Expect(err).NotTo(HaveOccurred())
131191

192+
ironic = WaitForIronic(name)
193+
VerifyIronic(ironic)
194+
})
132195
})
133196

134197
var _ = AfterSuite(func() {

0 commit comments

Comments
 (0)