Skip to content

Commit 16b76b7

Browse files
committed
Update functional tests for ansible lib
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]>
1 parent df03103 commit 16b76b7

File tree

3 files changed

+44
-35
lines changed

3 files changed

+44
-35
lines changed

tests/functional/dataplane/base_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
. "github.com/onsi/gomega" //revive:disable:dot-imports
77
"gopkg.in/yaml.v3"
8+
batchv1 "k8s.io/api/batch/v1"
89
corev1 "k8s.io/api/core/v1"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -13,7 +14,6 @@ import (
1314

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

@@ -590,8 +590,8 @@ func DataplaneDeploymentConditionGetter(name types.NamespacedName) condition.Con
590590
return instance.Status.Conditions
591591
}
592592

593-
func GetAnsibleee(name types.NamespacedName) *v1beta1.OpenStackAnsibleEE {
594-
instance := &v1beta1.OpenStackAnsibleEE{}
593+
func GetAnsibleee(name types.NamespacedName) *batchv1.Job {
594+
instance := &batchv1.Job{}
595595
Eventually(func(g Gomega) {
596596
g.Expect(k8sClient.Get(ctx, name, instance)).Should(Succeed())
597597
}, timeout, interval).Should(Succeed())
@@ -620,3 +620,12 @@ func getCtlPlaneIP(secret *corev1.Secret) string {
620620
}
621621
return inv.EdpmComputeNodeset.Hosts.Node.CtlPlaneIP
622622
}
623+
624+
func findEnvVar(envVars []corev1.EnvVar) corev1.EnvVar {
625+
for _, envVar := range envVars {
626+
if envVar.Name == "RUNNER_EXTRA_VARS" {
627+
return envVar
628+
}
629+
}
630+
return corev1.EnvVar{}
631+
}

tests/functional/dataplane/openstackdataplanedeployment_controller_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
//revive:disable-next-line:dot-imports
1414
. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
15-
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
1615
baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1"
1716
corev1 "k8s.io/api/core/v1"
1817
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -134,7 +133,8 @@ var _ = Describe("Dataplane Deployment Test", func() {
134133
CreateDataplaneService(dataplaneGlobalServiceName, true)
135134
// with EDPMServiceType set
136135
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, map[string]interface{}{
137-
"EDPMServiceType": "foo-service"})
136+
"edpmServiceType": "foo-update-service",
137+
"openStackAnsibleEERunnerImage": "foo-image:latest"})
138138

139139
DeferCleanup(th.DeleteService, dataplaneServiceName)
140140
DeferCleanup(th.DeleteService, dataplaneGlobalServiceName)
@@ -210,25 +210,22 @@ var _ = Describe("Dataplane Deployment Test", func() {
210210
Name: aeeName,
211211
Namespace: dataplaneDeploymentName.Namespace,
212212
}
213-
ansibleEE := &ansibleeev1.OpenStackAnsibleEE{
214-
ObjectMeta: metav1.ObjectMeta{
215-
Name: ansibleeeName.Name,
216-
Namespace: ansibleeeName.Namespace,
217-
}}
218-
g.Expect(th.K8sClient.Get(th.Ctx, ansibleeeName, ansibleEE)).To(Succeed())
219-
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
213+
ansibleEE := GetAnsibleee(ansibleeeName)
220214

215+
ansibleEE.Status.Succeeded = 1
221216
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
222-
g.Expect(ansibleEE.Spec.ExtraVars).To(HaveKey("edpm_override_hosts"))
223217
if service.Spec.EDPMServiceType != "" {
224-
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceType)))
218+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring("edpm_service_type"))
219+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring(service.Spec.EDPMServiceType))
225220
} else {
226-
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
221+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring(serviceName))
227222
}
228223
if service.Spec.DeployOnAllNodeSets {
229-
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_override_hosts"])).To(Equal("\"all\""))
224+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring("edpm_override_hosts"))
225+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring("all"))
230226
} else {
231-
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_override_hosts"])).To(Equal(fmt.Sprintf("\"%s\"", dataplaneNodeSetName.Name)))
227+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring("edpm_override_hosts"))
228+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring(dataplaneNodeSetName.Name))
232229
}
233230
}, th.Timeout, th.Interval).Should(Succeed())
234231
}
@@ -281,7 +278,8 @@ var _ = Describe("Dataplane Deployment Test", func() {
281278
CreateDataplaneService(dataplaneServiceName, false)
282279
CreateDataplaneService(dataplaneGlobalServiceName, true)
283280
CreateDataPlaneServiceFromSpec(dataplaneUpdateServiceName, map[string]interface{}{
284-
"EDPMServiceType": "foo-service"})
281+
"edpmServiceType": "foo-update-service",
282+
"openStackAnsibleEERunnerImage": "foo-image:latest"})
285283

286284
DeferCleanup(th.DeleteService, dataplaneServiceName)
287285
DeferCleanup(th.DeleteService, dataplaneGlobalServiceName)
@@ -430,19 +428,21 @@ var _ = Describe("Dataplane Deployment Test", func() {
430428
}
431429
ansibleEE := GetAnsibleee(ansibleeeName)
432430
if service.Spec.DeployOnAllNodeSets {
433-
g.Expect(ansibleEE.Spec.ExtraMounts[0].Volumes).Should(HaveLen(4))
431+
g.Expect(ansibleEE.Spec.Template.Spec.Volumes).Should(HaveLen(4))
434432
} else {
435-
g.Expect(ansibleEE.Spec.ExtraMounts[0].Volumes).Should(HaveLen(2))
433+
g.Expect(ansibleEE.Spec.Template.Spec.Volumes).Should(HaveLen(2))
436434
}
437-
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
435+
ansibleEE.Status.Succeeded = 1
438436
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
439437
if service.Spec.EDPMServiceType != "" {
440-
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceType)))
438+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring(service.Spec.EDPMServiceType))
441439
} else {
442-
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
440+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring(serviceName))
443441
}
444442
if service.Spec.DeployOnAllNodeSets {
445-
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_override_hosts"])).To(Equal("\"all\""))
443+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring("edpm_override_hosts"))
444+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring("all"))
445+
446446
}
447447
}, th.Timeout, th.Interval).Should(Succeed())
448448
}
@@ -467,16 +467,16 @@ var _ = Describe("Dataplane Deployment Test", func() {
467467
}
468468
ansibleEE := GetAnsibleee(ansibleeeName)
469469
if service.Spec.DeployOnAllNodeSets {
470-
g.Expect(ansibleEE.Spec.ExtraMounts[0].Volumes).Should(HaveLen(4))
470+
g.Expect(ansibleEE.Spec.Template.Spec.Volumes).Should(HaveLen(4))
471471
} else {
472-
g.Expect(ansibleEE.Spec.ExtraMounts[0].Volumes).Should(HaveLen(2))
472+
g.Expect(ansibleEE.Spec.Template.Spec.Volumes).Should(HaveLen(2))
473473
}
474-
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
474+
ansibleEE.Status.Succeeded = 1
475475
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
476476
if service.Spec.EDPMServiceType != "" {
477-
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", service.Spec.EDPMServiceType)))
477+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring(service.Spec.EDPMServiceType))
478478
} else {
479-
g.Expect(string(ansibleEE.Spec.ExtraVars["edpm_service_type"])).To(Equal(fmt.Sprintf("\"%s\"", serviceName)))
479+
g.Expect(findEnvVar(ansibleEE.Spec.Template.Spec.Containers[0].Env).Value).To(ContainSubstring(serviceName))
480480
}
481481
}, th.Timeout, th.Interval).Should(Succeed())
482482
}
@@ -694,7 +694,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
694694
}
695695
Eventually(func(g Gomega) {
696696
ansibleEE := GetAnsibleee(ansibleeeName)
697-
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
697+
ansibleEE.Status.Succeeded = 1
698698
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
699699
}, th.Timeout, th.Interval).Should(Succeed())
700700

@@ -897,7 +897,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
897897
Namespace: dataplaneMultiNodesetDeploymentName.Namespace,
898898
}
899899
ansibleEE := GetAnsibleee(ansibleeeName)
900-
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
900+
ansibleEE.Status.Succeeded = 1
901901
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
902902
}, th.Timeout, th.Interval).Should(Succeed())
903903
}
@@ -922,7 +922,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
922922
Namespace: dataplaneMultiNodesetDeploymentName.Namespace,
923923
}
924924
ansibleEE := GetAnsibleee(ansibleeeName)
925-
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
925+
ansibleEE.Status.Succeeded = 1
926926
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
927927
}, th.Timeout, th.Interval).Should(Succeed())
928928
}
@@ -1023,7 +1023,7 @@ var _ = Describe("Dataplane Deployment Test", func() {
10231023
}
10241024
Eventually(func(g Gomega) {
10251025
ansibleEE := GetAnsibleee(ansibleeeName)
1026-
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
1026+
ansibleEE.Status.Succeeded = 1
10271027
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
10281028
}, th.Timeout, th.Interval).Should(Succeed())
10291029

tests/functional/dataplane/openstackdataplanenodeset_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
. "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports
2424
. "github.com/onsi/gomega" //revive:disable:dot-imports
2525
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
26-
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
2726
openstackv1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
2827
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
2928

@@ -1301,6 +1300,7 @@ var _ = Describe("Dataplane NodeSet Test", func() {
13011300
When("A DataPlaneNodeSet is created with NoNodes and a MinorUpdate OpenStackDataPlaneDeployment is created", func() {
13021301
BeforeEach(func() {
13031302

1303+
dataplanev1.SetupDefaults()
13041304
updateServiceSpec := map[string]interface{}{
13051305
"playbook": "osp.edpm.update",
13061306
}
@@ -1331,7 +1331,7 @@ var _ = Describe("Dataplane NodeSet Test", func() {
13311331
Namespace: namespace,
13321332
}
13331333
ansibleEE := GetAnsibleee(ansibleeeName)
1334-
ansibleEE.Status.JobStatus = ansibleeev1.JobStatusSucceeded
1334+
ansibleEE.Status.Succeeded = 1
13351335
g.Expect(th.K8sClient.Status().Update(th.Ctx, ansibleEE)).To(Succeed())
13361336
}, th.Timeout, th.Interval).Should(Succeed())
13371337

0 commit comments

Comments
 (0)