Skip to content

Commit

Permalink
Add more functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
afaranha committed Dec 8, 2023
1 parent 7ac9165 commit 55f24c9
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 58 deletions.
174 changes: 124 additions & 50 deletions tests/functional/barbican_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
//"k8s.io/utils/ptr"
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
)

var _ = Describe("Barbican controller", func() {

var barbicanName types.NamespacedName
//var dbSyncJobName types.NamespacedName
var barbicanTransportURL types.NamespacedName
var dbSyncJobName types.NamespacedName
//var bootstrapJobName types.NamespacedName
//var deploymentName types.NamespacedName

Expand All @@ -26,11 +27,15 @@ var _ = Describe("Barbican controller", func() {
Name: "barbican",
Namespace: namespace,
}
barbicanTransportURL = types.NamespacedName{
Name: "barbican-barbican-transport",
Namespace: namespace,
}
dbSyncJobName = types.NamespacedName{
Name: "barbican-db-sync",
Namespace: namespace,
}
/*
dbSyncJobName = types.NamespacedName{
Name: "keystone-db-sync",
Namespace: namespace,
}
bootstrapJobName = types.NamespacedName{
Name: "keystone-bootstrap",
Namespace: namespace,
Expand All @@ -50,65 +55,134 @@ var _ = Describe("Barbican controller", func() {
DeferCleanup(th.DeleteInstance, CreateBarbican(barbicanName, GetDefaultBarbicanSpec()))
})

/*
It("should have the Spec fields defaulted", func() {
Barbican := GetBarbican(barbicanName)
Expect(Barbican.Spec.ServiceUser).Should(Equal("barbican"))
Expect(Barbican.Spec.DatabaseInstance).Should(Equal("openstack"))
Expect(Barbican.Spec.DatabaseUser).Should(Equal("barbican"))
})
It("should have the Spec fields defaulted", func() {
Barbican := GetBarbican(barbicanName)
Expect(Barbican.Spec.ServiceUser).Should(Equal("barbican"))
Expect(Barbican.Spec.DatabaseInstance).Should(Equal("openstack"))
Expect(Barbican.Spec.DatabaseUser).Should(Equal("barbican"))
})

It("should have the Status fields initialized", func() {
Barbican := GetBarbican(barbicanName)
Expect(Barbican.Status.Hash).To(BeEmpty())
Expect(Barbican.Status.BarbicanAPIReadyCount).To(Equal(int32(0)))
Expect(Barbican.Status.BarbicanWorkerReadyCount).To(Equal(int32(0)))
Expect(Barbican.Status.BarbicanKeystoneListenerReadyCount).To(Equal(int32(0)))
Expect(Barbican.Status.TransportURLSecret).To(Equal(""))
Expect(Barbican.Status.DatabaseHostname).To(Equal(""))
})
*/
It("should have the Status fields initialized", func() {
Barbican := GetBarbican(barbicanName)
Expect(Barbican.Status.Hash).To(BeEmpty())
Expect(Barbican.Status.BarbicanAPIReadyCount).To(Equal(int32(0)))
Expect(Barbican.Status.BarbicanWorkerReadyCount).To(Equal(int32(0)))
Expect(Barbican.Status.BarbicanKeystoneListenerReadyCount).To(Equal(int32(0)))
Expect(Barbican.Status.TransportURLSecret).To(Equal(""))
Expect(Barbican.Status.DatabaseHostname).To(Equal(""))
})

It("should have input not ready and unknown Conditions initialized", func() {
/*
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.ReadyCondition,
corev1.ConditionFalse,
)

th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.InputReadyCondition,
corev1.ConditionUnknown,
)

for _, cond := range []condition.Type{
condition.ServiceConfigReadyCondition,
condition.DBReadyCondition,
condition.DBSyncReadyCondition,
//condition.BarbicanAPIReadyCondition,
//condition.BarbicanWorkerReadyCondition,
//condition.BarbicanKeystoneListenerReadyCondition,
//condition.,
//condition.ExposeServiceReadyCondition,
//condition.BootstrapReadyCondition,
//condition.DeploymentReadyCondition,
condition.NetworkAttachmentsReadyCondition,
//condition.CronJobReadyCondition,
} {
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.ReadyCondition,
corev1.ConditionFalse,
cond,
corev1.ConditionUnknown,
)
*/
}
})
It("should have a finalizer", func() {
// the reconciler loop adds the finalizer so we have to wait for
// it to run
Eventually(func() []string {
return GetBarbican(barbicanName).Finalizers
}, timeout, interval).Should(ContainElement("Barbican"))
})
})

When("Barbican DB is created", func() {
BeforeEach(func() {
DeferCleanup(k8sClient.Delete, ctx, CreateBarbicanMessageBusSecret(barbicanName.Namespace, "rabbitmq-secret"))
DeferCleanup(th.DeleteInstance, CreateBarbican(barbicanName, GetDefaultBarbicanSpec()))
DeferCleanup(
mariadb.DeleteDBService,
mariadb.CreateDBService(
namespace,
GetBarbican(barbicanName).Spec.DatabaseInstance,
corev1.ServiceSpec{
Ports: []corev1.ServicePort{{Port: 3306}},
},
),
)
infra.SimulateTransportURLReady(barbicanTransportURL)
//DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, "memcached", memcachedSpec))
/*
infra.SimulateMemcachedReady(cinderTest.CinderMemcached)
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(namespace))
*/
})
It("Should set DBReady Condition and set DatabaseHostname Status when DB is Created", func() {
mariadb.SimulateMariaDBDatabaseCompleted(barbicanName)
th.SimulateJobSuccess(dbSyncJobName)
Barbican := GetBarbican(barbicanName)
Expect(Barbican.Status.DatabaseHostname).To(Equal("hostname-for-openstack"))
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.InputReadyCondition,
corev1.ConditionTrue,
)
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.DBSyncReadyCondition,
corev1.ConditionFalse,
)
/*
for _, cond := range []condition.Type{
condition.ServiceConfigReadyCondition,
})
/*
It("Should fail if db-sync job fails when DB is Created", func() {
mariadb.SimulateMariaDBDatabaseCompleted(cinderTest.Instance)
th.SimulateJobFailure(cinderTest.CinderDBSync)
th.ExpectCondition(
cinderTest.Instance,
ConditionGetterFunc(CinderConditionGetter),
condition.DBReadyCondition,
corev1.ConditionTrue,
)
th.ExpectCondition(
cinderTest.Instance,
ConditionGetterFunc(CinderConditionGetter),
condition.DBSyncReadyCondition,
//condition.BarbicanAPIReadyCondition,
//condition.BarbicanWorkerReadyCondition,
//condition.BarbicanKeystoneListenerReadyCondition,
//condition.,
//condition.ExposeServiceReadyCondition,
//condition.BootstrapReadyCondition,
//condition.DeploymentReadyCondition,
condition.NetworkAttachmentsReadyCondition,
//condition.CronJobReadyCondition,
} {
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
cond,
corev1.ConditionUnknown,
)
}
*/
})
corev1.ConditionFalse,
)
})
It("Does not create CinderAPI", func() {
CinderAPINotExists(cinderTest.Instance)
})
It("Does not create CinderScheduler", func() {
CinderSchedulerNotExists(cinderTest.Instance)
})
It("Does not create CinderVolume", func() {
CinderVolumeNotExists(cinderTest.Instance)
})
*/
})
})
14 changes: 13 additions & 1 deletion tests/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ limitations under the License.
package functional_test

import (
"fmt"
. "github.com/onsi/gomega"

//batchv1 "k8s.io/api/batch/v1"
//corev1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -58,6 +59,17 @@ func GetBarbican(name types.NamespacedName) *barbicanv1.Barbican {
return instance
}

func CreateBarbicanMessageBusSecret(namespace string, name string) *corev1.Secret {
s := th.CreateSecret(
types.NamespacedName{Namespace: namespace, Name: name},
map[string][]byte{
"transport_url": []byte(fmt.Sprintf("rabbit://%s/fake", name)),
},
)
logger.Info("Secret created", "name", name)
return s
}

/*
func CreateKeystoneAPISecret(namespace string, name string) *corev1.Secret {
return th.CreateSecret(
Expand Down
14 changes: 7 additions & 7 deletions tests/functional/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
//memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
//keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
barbicanv1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1"
Expand Down Expand Up @@ -100,9 +100,9 @@ var _ = BeforeSuite(func() {
mariaDBCRDs, err := test.GetCRDDirFromModule(
"github.com/openstack-k8s-operators/mariadb-operator/api", "../../go.mod", "bases")
Expect(err).ShouldNot(HaveOccurred())
memcachedCRDs, err := test.GetCRDDirFromModule(
"github.com/openstack-k8s-operators/infra-operator/apis", "../../go.mod", "bases")
Expect(err).ShouldNot(HaveOccurred())
//memcachedCRDs, err := test.GetCRDDirFromModule(
// "github.com/openstack-k8s-operators/infra-operator/apis", "../../go.mod", "bases")
//Expect(err).ShouldNot(HaveOccurred())

By("bootstrapping test environment")
testEnv = &envtest.Environment{
Expand All @@ -111,7 +111,7 @@ var _ = BeforeSuite(func() {
keystoneCRDs,
rabbitmqCRDs,
mariaDBCRDs,
memcachedCRDs,
//memcachedCRDs,
},
CRDInstallOptions: envtest.CRDInstallOptions{
Paths: []string{
Expand Down Expand Up @@ -140,8 +140,8 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
err = mariadbv1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
err = memcachedv1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
//err = memcachedv1.AddToScheme(scheme.Scheme)
//Expect(err).NotTo(HaveOccurred())
err = rabbitmqv1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
err = networkv1.AddToScheme(scheme.Scheme)
Expand Down

0 comments on commit 55f24c9

Please sign in to comment.