Skip to content

Commit

Permalink
Create Barbican Secret on functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
afaranha committed Dec 18, 2023
1 parent 04d403d commit c6a5fdd
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
8 changes: 8 additions & 0 deletions controllers/barbican_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ func (r *BarbicanReconciler) reconcileInit(
return rbacResult, nil
}

Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB"))
//
// create service DB instance
//
Expand All @@ -755,6 +756,7 @@ func (r *BarbicanReconciler) reconcileInit(
helper,
)
if err != nil {
Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB ERROR"))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DBReadyCondition,
condition.ErrorReason,
Expand All @@ -763,6 +765,7 @@ func (r *BarbicanReconciler) reconcileInit(
err.Error()))
return ctrl.Result{}, err
}
Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB WORKS"))
if (ctrlResult != ctrl.Result{}) {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DBReadyCondition,
Expand All @@ -774,6 +777,7 @@ func (r *BarbicanReconciler) reconcileInit(
// wait for the DB to be setup
ctrlResult, err = db.WaitForDBCreated(ctx, helper)
if err != nil {
Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB CREATION ERROR"))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DBReadyCondition,
condition.ErrorReason,
Expand All @@ -782,17 +786,21 @@ func (r *BarbicanReconciler) reconcileInit(
err.Error()))
return ctrlResult, err
}
Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB CREATED"))
if (ctrlResult != ctrl.Result{}) {
Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB RESULT ERROR"))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DBReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.DBReadyRunningMessage))
return ctrlResult, nil
}
Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB MARK AS TRUE"))
// update Status.DatabaseHostname, used to config the service
instance.Status.DatabaseHostname = db.GetDatabaseHostname()
instance.Status.Conditions.MarkTrue(condition.DBReadyCondition, condition.DBReadyMessage)
Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB MARKED AS TRUE"))
// create service DB - end

//
Expand Down
71 changes: 71 additions & 0 deletions tests/functional/barbican_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
//rabbit //"k8s.io/utils/ptr"
barbicanv1beta1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1"
)

var _ = Describe("Barbican controller", func() {
Expand Down Expand Up @@ -203,4 +204,74 @@ var _ = Describe("Barbican controller", 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(th.DeleteInstance, keystone.CreateKeystoneAPI(barbicanName.Namespace))
DeferCleanup(k8sClient.Delete, ctx, CreateKeystoneAPISecret(namespace, SecretName))

DeferCleanup(
k8sClient.Delete, ctx, CreateBarbicanSecret(barbicanName.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))
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,
)
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.ExposeServiceReadyCondition,
corev1.ConditionTrue,
)
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.BootstrapReadyCondition,
corev1.ConditionFalse,
)
*/
th.ExpectCondition(
barbicanName,
ConditionGetterFunc(BarbicanConditionGetter),
condition.NetworkAttachmentsReadyCondition,
corev1.ConditionUnknown,
)
})
})
})
10 changes: 10 additions & 0 deletions tests/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ func CreateBarbicanMessageBusSecret(namespace string, name string) *corev1.Secre
return s
}

func CreateBarbicanSecret(namespace string, name string) *corev1.Secret {
return th.CreateSecret(
types.NamespacedName{Namespace: namespace, Name: name},
map[string][]byte{
"BarbicanDatabasePassword": []byte("12345678"),
"BarbicanPassword": []byte("12345678"),
},
)
}

/*
func CreateKeystoneAPISecret(namespace string, name string) *corev1.Secret {
return th.CreateSecret(
Expand Down

0 comments on commit c6a5fdd

Please sign in to comment.