-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from afaranha/functional_tests
Add functional tests
- Loading branch information
Showing
13 changed files
with
577 additions
and
62 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ import sys | |
from barbican.cmd.keystone_listener import main | ||
if __name__ == "__main__": | ||
sys.exit(main()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ import sys | |
from barbican.cmd.worker import main | ||
if __name__ == "__main__": | ||
sys.exit(main()) | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,3 @@ else: | |
with app_lock: | ||
if application is None: | ||
application = get_api_wsgi_script() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.