Skip to content

Commit

Permalink
Add tests for database and distributed architecture
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Tantsur <[email protected]>
  • Loading branch information
dtantsur committed Mar 25, 2024
1 parent 85c92b8 commit ce48e8a
Showing 1 changed file with 77 additions and 14 deletions.
91 changes: 77 additions & 14 deletions test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -82,6 +83,39 @@ var _ = BeforeSuite(func() {

})

func WaitForIronic(name types.NamespacedName) *metal3api.Ironic {
GinkgoHelper()

ironic := &metal3api.Ironic{}

By("waiting for Ironic deployment")

Eventually(func() bool {
err := k8sClient.Get(ctx, name, ironic)
Expect(err).NotTo(HaveOccurred())

cond := meta.FindStatusCondition(ironic.Status.Conditions, string(metal3api.IronicStatusAvailable))
if cond != nil && cond.Status == metav1.ConditionTrue {
return true
}

GinkgoWriter.Printf("Current status of Ironic: %+v\n", ironic)
return false
}).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(BeTrue())

return ironic
}

func VerifyIronic(ironic *metal3api.Ironic) {
GinkgoHelper()

By("checking the service")

svc, err := clientset.CoreV1().Services(ironic.Namespace).Get(ctx, ironic.Name, metav1.GetOptions{})
GinkgoWriter.Printf("Ironic service: %+v\n", svc)
Expect(err).NotTo(HaveOccurred())
}

var _ = Describe("Ironic object tests", func() {
var namespace string

Expand All @@ -93,6 +127,15 @@ var _ = Describe("Ironic object tests", func() {
Expect(err).NotTo(HaveOccurred())
DeferCleanup(func() {
_ = clientset.CoreV1().Namespaces().Delete(ctx, namespace, metav1.DeleteOptions{})
Eventually(func() bool {
_, err := clientset.CoreV1().Namespaces().Get(ctx, namespace, metav1.GetOptions{})
if err != nil && k8serrors.IsNotFound(err) {
return true
}
GinkgoWriter.Println("Namespace", namespace, "not deleted yet, error is", err)
Expect(err).NotTo(HaveOccurred())
return false
}).WithTimeout(2 * time.Minute).WithPolling(5 * time.Second).Should(BeTrue())
})
})

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

ironic := metal3api.Ironic{
ironic := &metal3api.Ironic{
ObjectMeta: metav1.ObjectMeta{
Name: name.Name,
Namespace: name.Namespace,
},
}
err := k8sClient.Create(ctx, &ironic)
err := k8sClient.Create(ctx, ironic)
Expect(err).NotTo(HaveOccurred())

var cond *metav1.Condition
for attempt := 0; attempt < 10; attempt += 1 {
err = k8sClient.Get(ctx, name, &ironic)
Expect(err).NotTo(HaveOccurred())
ironic = WaitForIronic(name)
VerifyIronic(ironic)
})

cond = meta.FindStatusCondition(ironic.Status.Conditions, string(metal3api.IronicStatusAvailable))
if cond != nil && cond.Status == metav1.ConditionTrue {
break
}
It("creates distributed Ironic", func() {
name := types.NamespacedName{
Name: "test-ironic",
Namespace: namespace,
}

time.Sleep(5 * time.Second)
ironicDb := &metal3api.IronicDatabase{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-db", name.Name),
Namespace: name.Namespace,
},
}

if cond == nil || cond.Status != metav1.ConditionTrue {
Fail("Ironic deployment never succeded")
err := k8sClient.Create(ctx, ironicDb)
Expect(err).NotTo(HaveOccurred())

ironic := &metal3api.Ironic{
ObjectMeta: metav1.ObjectMeta{
Name: name.Name,
Namespace: name.Namespace,
},
Spec: metal3api.IronicSpec{
DatabaseRef: corev1.LocalObjectReference{
Name: ironicDb.Name,
},
Distributed: true,
},
}
})
err = k8sClient.Create(ctx, ironic)
Expect(err).NotTo(HaveOccurred())

ironic = WaitForIronic(name)
VerifyIronic(ironic)
})
})

var _ = AfterSuite(func() {
Expand Down

0 comments on commit ce48e8a

Please sign in to comment.