Skip to content

Commit

Permalink
Merge pull request #52 from afaranha/functional_tests
Browse files Browse the repository at this point in the history
Add functional tests
  • Loading branch information
openshift-merge-bot[bot] authored Jan 16, 2024
2 parents 1ddabbd + b7b2ef8 commit de33896
Show file tree
Hide file tree
Showing 13 changed files with 577 additions and 62 deletions.
55 changes: 0 additions & 55 deletions .github/workflows/golangci-lint.yaml

This file was deleted.

13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ tidy: ## Run go mod tidy on every mod file in the repo
go mod tidy
cd ./api && go mod tidy

PROCS?=$(shell expr $(shell nproc --ignore 2) / 2)
PROC_CMD = --procs ${PROCS}

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
test: manifests generate fmt vet envtest ginkgo ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) --trace --cover --coverpkg=../../pkg/barbican,../../controllers,../../api/v1beta1 --coverprofile cover.out --covermode=atomic ${PROC_CMD} $(GINKGO_ARGS) ./tests/...

##@ Build

Expand Down Expand Up @@ -192,6 +195,7 @@ $(LOCALBIN):
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
GINKGO ?= $(LOCALBIN)/ginkgo

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
Expand All @@ -218,6 +222,11 @@ envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
$(GINKGO): $(LOCALBIN)
test -s $(LOCALBIN)/ginkgo || GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo

.PHONY: operator-sdk
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
Expand Down
2 changes: 1 addition & 1 deletion config/certmanager/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This configuration is for teaching kustomize how to update name ref and var substitution
# This configuration is for teaching kustomize how to update name ref and var substitution
nameReference:
- kind: Issuer
group: cert-manager.io
Expand Down
1 change: 0 additions & 1 deletion config/default/manager_default_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ spec:
value: quay.io/podified-antelope-centos9/openstack-barbican-worker:current-podified
- name: RELATED_IMAGE_BARBICAN_KEYSTONE_LISTENER_IMAGE_URL_DEFAULT
value: quay.io/podified-antelope-centos9/openstack-barbican-keystone-listener:current-podified

1 change: 1 addition & 0 deletions controllers/barbican_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ func (r *BarbicanReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&barbicanv1beta1.BarbicanAPI{}).
Owns(&barbicanv1beta1.BarbicanWorker{}).
Owns(&barbicanv1beta1.BarbicanKeystoneListener{}).
Owns(&rabbitmqv1.TransportURL{}).
Owns(&mariadbv1.MariaDBDatabase{}).
Owns(&keystonev1.KeystoneService{}).
Owns(&corev1.ServiceAccount{}).
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
1 change: 0 additions & 1 deletion templates/barbican/config/barbican-keystone-listener
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ import sys
from barbican.cmd.keystone_listener import main
if __name__ == "__main__":
sys.exit(main())

1 change: 0 additions & 1 deletion templates/barbican/config/barbican-worker
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ import sys
from barbican.cmd.worker import main
if __name__ == "__main__":
sys.exit(main())

Empty file modified templates/barbican/config/kolla_extend_start
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion templates/barbican/config/main
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ else:
with app_lock:
if application is None:
application = get_api_wsgi_script()

223 changes: 223 additions & 0 deletions tests/functional/barbican_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
package functional_test

import (
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
barbicanv1beta1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1"
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"
)

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

var barbicanName types.NamespacedName
var barbicanTransportURL types.NamespacedName
var dbSyncJobName types.NamespacedName
var barbicanConfigMapData types.NamespacedName

BeforeEach(func() {

barbicanName = types.NamespacedName{
Name: "barbican",
Namespace: namespace,
}
barbicanTransportURL = types.NamespacedName{
Name: "barbican-barbican-transport",
Namespace: namespace,
}
dbSyncJobName = types.NamespacedName{
Name: "barbican-db-sync",
Namespace: namespace,
}
barbicanConfigMapData = types.NamespacedName{
Name: "barbican-config-data",
Namespace: namespace,
}

err := os.Setenv("OPERATOR_TEMPLATES", "../../templates")
Expect(err).NotTo(HaveOccurred())

})

When("A Barbican instance is created", func() {
BeforeEach(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 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.NetworkAttachmentsReadyCondition,
} {
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
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"))
})
It("should not create a config map", func() {
Eventually(func() []corev1.ConfigMap {
return th.ListConfigMaps(barbicanConfigMapData.Name).Items
}, timeout, interval).Should(BeEmpty())
})
})

When("Barbican DB is created", func() {
BeforeEach(func() {
DeferCleanup(k8sClient.Delete, ctx, CreateBarbicanMessageBusSecret(barbicanName.Namespace, "rabbitmq-secret"))
DeferCleanup(th.DeleteInstance, CreateBarbican(barbicanName, GetDefaultBarbicanSpec()))
DeferCleanup(k8sClient.Delete, ctx, CreateKeystoneAPISecret(namespace, SecretName))
DeferCleanup(
mariadb.DeleteDBService,
mariadb.CreateDBService(
namespace,
GetBarbican(barbicanName).Spec.DatabaseInstance,
corev1.ServiceSpec{
Ports: []corev1.ServicePort{{Port: 3306}},
},
),
)
infra.SimulateTransportURLReady(barbicanTransportURL)
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(barbicanName.Namespace))
//DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, "memcached", memcachedSpec))
})
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,
)
})
It("Should fail if db-sync job fails when DB is Created", func() {
mariadb.SimulateMariaDBDatabaseCompleted(barbicanName)
th.SimulateJobFailure(dbSyncJobName)
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.DBReadyCondition,
corev1.ConditionTrue,
)
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.DBSyncReadyCondition,
corev1.ConditionFalse,
)
})
It("Does not create BarbicanAPI", func() {
BarbicanAPINotExists(barbicanName)
})
It("Does not create BarbicanWorker", func() {
BarbicanWorkerNotExists(barbicanName)
})
It("Does not create BarbicanKeystoneListener", func() {
BarbicanKeystoneListenerNotExists(barbicanName)
})
})

When("DB sync is completed", func() {
BeforeEach(func() {
DeferCleanup(k8sClient.Delete, ctx, CreateBarbicanMessageBusSecret(barbicanName.Namespace, "rabbitmq-secret"))
DeferCleanup(th.DeleteInstance, CreateBarbican(barbicanName, GetDefaultBarbicanSpec()))
DeferCleanup(k8sClient.Delete, ctx, CreateKeystoneAPISecret(namespace, SecretName))

DeferCleanup(
k8sClient.Delete, ctx, CreateBarbicanSecret(barbicanName.Namespace, "test-osp-secret-berbican"))

DeferCleanup(
mariadb.DeleteDBService,
mariadb.CreateDBService(
namespace,
GetBarbican(barbicanName).Spec.DatabaseInstance,
corev1.ServiceSpec{
Ports: []corev1.ServicePort{{Port: 3306}},
},
),
)
infra.SimulateTransportURLReady(barbicanTransportURL)
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(barbicanName.Namespace))
mariadb.SimulateMariaDBDatabaseCompleted(barbicanName)
th.SimulateJobSuccess(dbSyncJobName)
})

It("should have db sync ready condition", func() {
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.ReadyCondition,
corev1.ConditionFalse,
)

th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
barbicanv1beta1.BarbicanRabbitMQTransportURLReadyCondition,
corev1.ConditionTrue,
)

th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.DBSyncReadyCondition,
corev1.ConditionTrue,
)
})
})
})
Loading

0 comments on commit de33896

Please sign in to comment.