Skip to content

Commit

Permalink
Update functional tests for ansible lib
Browse files Browse the repository at this point in the history
This change updates the functional tests to work with the changes
from Ansibleeev1 to the new lib-common AnsibleEE library.

Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed Aug 1, 2024
1 parent daa9aac commit eb2fb61
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
15 changes: 12 additions & 3 deletions tests/functional/dataplane/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (

. "github.com/onsi/gomega" //revive:disable:dot-imports
"gopkg.in/yaml.v3"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"

infrav1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
)

Expand Down Expand Up @@ -466,8 +466,8 @@ func DataplaneDeploymentConditionGetter(name types.NamespacedName) condition.Con
return instance.Status.Conditions
}

func GetAnsibleee(name types.NamespacedName) *v1beta1.OpenStackAnsibleEE {
instance := &v1beta1.OpenStackAnsibleEE{}
func GetAnsibleee(name types.NamespacedName) *batchv1.Job {
instance := &batchv1.Job{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, name, instance)).Should(Succeed())
}, timeout, interval).Should(Succeed())
Expand Down Expand Up @@ -496,3 +496,12 @@ func getCtlPlaneIP(secret *corev1.Secret) string {
}
return inv.EdpmComputeNodeset.Hosts.Node.CtlPlaneIP
}

func findEnvVar(envVars []corev1.EnvVar, name string) corev1.EnvVar {
for _, envVar := range envVars {
if envVar.Name == name {
return envVar
}
}
return corev1.EnvVar{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

//revive:disable-next-line:dot-imports
. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -128,7 +128,8 @@ var _ = Describe("Dataplane Deployment Test", func() {
CreateDataplaneService(dataplaneGlobalServiceName, true)
// with EDPMServiceType set
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, map[string]interface{}{
"EDPMServiceType": "foo-service"})
"EDPMServiceType": "foo-service",
"OpenStackAnsibleEERunnerImage": "foo-image:latest"})

DeferCleanup(th.DeleteService, dataplaneServiceName)
DeferCleanup(th.DeleteService, dataplaneGlobalServiceName)
Expand Down Expand Up @@ -204,25 +205,24 @@ var _ = Describe("Dataplane Deployment Test", func() {
Name: aeeName,
Namespace: dataplaneDeploymentName.Namespace,
}
ansibleEE := &ansibleeev1.OpenStackAnsibleEE{
ansibleEE := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: ansibleeeName.Name,
Namespace: ansibleeeName.Namespace,
}}
g.Expect(th.K8sClient.Get(th.Ctx, ansibleeeName, ansibleEE)).To(Succeed())
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded

g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
g.Expect(ansibleEE.Spec.ExtraVars).To(HaveKey("edpm_override_hosts"))
g.Expect(ansibleEE.Spec.Template.Spec.Containers[0].Env).To(HaveKey("edpm_override_hosts"))
if service.Spec.EDPMServiceType != "" {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceType)))
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env, "edpm_service_type").Value).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceType)))
} else {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env, "edpm_service_type").Value).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
}
if service.Spec.DeployOnAllNodeSets {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_override_hosts"])).To(Equal("\"all\""))
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env, "edpm_override_hosts").Value).To(Equal("\"all\""))
} else {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_override_hosts"])).To(Equal(fmt.Sprintf("\"%s\"", dataplaneNodeSetName.Name)))
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env, "edpm_override_hosts").Value).To(Equal(fmt.Sprintf("\"%s\"", dataplaneNodeSetName.Name)))
}
}, th.Timeout, th.Interval).Should(Succeed())
}
Expand Down Expand Up @@ -275,7 +275,8 @@ var _ = Describe("Dataplane Deployment Test", func() {
CreateDataplaneService(dataplaneServiceName, false)
CreateDataplaneService(dataplaneGlobalServiceName, true)
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, map[string]interface{}{
"EDPMServiceType": "foo-service"})
"EDPMServiceType": "foo-service",
"OpenStackAnsibleEERunnerImage": "foo-image:latest"})

DeferCleanup(th.DeleteService, dataplaneServiceName)
DeferCleanup(th.DeleteService, dataplaneGlobalServiceName)
Expand Down Expand Up @@ -424,19 +425,19 @@ var _ = Describe("Dataplane Deployment Test", func() {
}
ansibleEE := GetAnsibleee(ansibleeeName)
if service.Spec.DeployOnAllNodeSets {
g.Expect(ansibleEE.Spec.ExtraMounts[0].Volumes).Should(HaveLen(4))
g.Expect(ansibleEE.Spec.Template.Spec.Volumes).Should(HaveLen(4))
} else {
g.Expect(ansibleEE.Spec.ExtraMounts[0].Volumes).Should(HaveLen(2))
g.Expect(ansibleEE.Spec.Template.Spec.Volumes).Should(HaveLen(2))
}
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
ansibleEE.Status.Succeeded = 1
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
if service.Spec.EDPMServiceType != "" {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceType)))
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env, "edpm_service_type").Value).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceType)))
} else {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env, "edpm_service_type").Value).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
}
if service.Spec.DeployOnAllNodeSets {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_override_hosts"])).To(Equal("\"all\""))
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env, "edpm_override_hosts").Value).To(Equal("\"all\""))
}
}, th.Timeout, th.Interval).Should(Succeed())
}
Expand All @@ -461,16 +462,16 @@ var _ = Describe("Dataplane Deployment Test", func() {
}
ansibleEE := GetAnsibleee(ansibleeeName)
if service.Spec.DeployOnAllNodeSets {
g.Expect(ansibleEE.Spec.ExtraMounts[0].Volumes).Should(HaveLen(4))
g.Expect(ansibleEE.Spec.Template.Spec.Volumes).Should(HaveLen(4))
} else {
g.Expect(ansibleEE.Spec.ExtraMounts[0].Volumes).Should(HaveLen(2))
g.Expect(ansibleEE.Spec.Template.Spec.Volumes).Should(HaveLen(2))
}
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
ansibleEE.Status.Succeeded = 1
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
if service.Spec.EDPMServiceType != "" {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceType)))
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env, "edpm_service_type").Value).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceType)))
} else {
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env, "edpm_service_type").Value).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
}
}, th.Timeout, th.Interval).Should(Succeed())
}
Expand Down Expand Up @@ -688,7 +689,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
}
Eventually(func(g Gomega) {
ansibleEE := GetAnsibleee(ansibleeeName)
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
ansibleEE.Status.Succeeded = 1
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
}, th.Timeout, th.Interval).Should(Succeed())

Expand Down Expand Up @@ -787,7 +788,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
}
Eventually(func(g Gomega) {
ansibleEE := GetAnsibleee(ansibleeeName)
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
ansibleEE.Status.Succeeded = 1
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
}, th.Timeout, th.Interval).Should(Succeed())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
. "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports
. "github.com/onsi/gomega" //revive:disable:dot-imports
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
openstackv1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"

Expand Down Expand Up @@ -1331,7 +1330,7 @@ var _ = Describe("Dataplane NodeSet Test", func() {
Namespace: namespace,
}
ansibleEE := GetAnsibleee(ansibleeeName)
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
ansibleEE.Status.Succeeded = 1
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
}, th.Timeout, th.Interval).Should(Succeed())

Expand Down

0 comments on commit eb2fb61

Please sign in to comment.