Skip to content

Commit fffc191

Browse files
committed
Add tests for novncproxy certs and routes cleanup
1 parent b628e5e commit fffc191

2 files changed

Lines changed: 244 additions & 48 deletions

File tree

tests/functional/ctlplane/base_test.go

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,50 @@ import (
4444
)
4545

4646
type Names struct {
47-
Namespace string
48-
OpenStackControlplaneName types.NamespacedName
49-
OpenStackVersionName types.NamespacedName
50-
KeystoneAPIName types.NamespacedName
51-
MemcachedName types.NamespacedName
52-
MemcachedCertName types.NamespacedName
53-
CinderName types.NamespacedName
54-
ManilaName types.NamespacedName
55-
GlanceName types.NamespacedName
56-
NeutronName types.NamespacedName
57-
HorizonName types.NamespacedName
58-
HeatName types.NamespacedName
59-
TelemetryName types.NamespacedName
60-
DBName types.NamespacedName
61-
DBCertName types.NamespacedName
62-
DBCell1Name types.NamespacedName
63-
DBCell1CertName types.NamespacedName
64-
RabbitMQName types.NamespacedName
65-
RabbitMQCertName types.NamespacedName
66-
RabbitMQCell1Name types.NamespacedName
67-
RabbitMQCell1CertName types.NamespacedName
68-
ServiceAccountName types.NamespacedName
69-
RoleName types.NamespacedName
70-
RoleBindingName types.NamespacedName
71-
RootCAPublicName types.NamespacedName
72-
RootCAInternalName types.NamespacedName
73-
RootCAOvnName types.NamespacedName
74-
RootCALibvirtName types.NamespacedName
75-
SelfSignedIssuerName types.NamespacedName
76-
CustomIssuerName types.NamespacedName
77-
CustomServiceCertSecretName types.NamespacedName
78-
CABundleName types.NamespacedName
79-
OpenStackClientName types.NamespacedName
80-
OVNNorthdName types.NamespacedName
81-
OVNNorthdCertName types.NamespacedName
82-
OVNControllerName types.NamespacedName
83-
OVNControllerCertName types.NamespacedName
84-
OVNDbServerNBName types.NamespacedName
85-
OVNDbServerSBName types.NamespacedName
86-
NeutronOVNCertName types.NamespacedName
87-
OpenStackTopology []types.NamespacedName
47+
Namespace string
48+
OpenStackControlplaneName types.NamespacedName
49+
OpenStackVersionName types.NamespacedName
50+
KeystoneAPIName types.NamespacedName
51+
MemcachedName types.NamespacedName
52+
MemcachedCertName types.NamespacedName
53+
CinderName types.NamespacedName
54+
ManilaName types.NamespacedName
55+
GlanceName types.NamespacedName
56+
NeutronName types.NamespacedName
57+
HorizonName types.NamespacedName
58+
HeatName types.NamespacedName
59+
TelemetryName types.NamespacedName
60+
DBName types.NamespacedName
61+
DBCertName types.NamespacedName
62+
DBCell1Name types.NamespacedName
63+
DBCell1CertName types.NamespacedName
64+
RabbitMQName types.NamespacedName
65+
RabbitMQCertName types.NamespacedName
66+
RabbitMQCell1Name types.NamespacedName
67+
RabbitMQCell1CertName types.NamespacedName
68+
NoVNCProxyCell1CertPublicRouteName types.NamespacedName
69+
NoVNCProxyCell1CertPublicSvcName types.NamespacedName
70+
NoVNCProxyCell1CertVencryptName types.NamespacedName
71+
ServiceAccountName types.NamespacedName
72+
RoleName types.NamespacedName
73+
RoleBindingName types.NamespacedName
74+
RootCAPublicName types.NamespacedName
75+
RootCAInternalName types.NamespacedName
76+
RootCAOvnName types.NamespacedName
77+
RootCALibvirtName types.NamespacedName
78+
SelfSignedIssuerName types.NamespacedName
79+
CustomIssuerName types.NamespacedName
80+
CustomServiceCertSecretName types.NamespacedName
81+
CABundleName types.NamespacedName
82+
OpenStackClientName types.NamespacedName
83+
OVNNorthdName types.NamespacedName
84+
OVNNorthdCertName types.NamespacedName
85+
OVNControllerName types.NamespacedName
86+
OVNControllerCertName types.NamespacedName
87+
OVNDbServerNBName types.NamespacedName
88+
OVNDbServerSBName types.NamespacedName
89+
NeutronOVNCertName types.NamespacedName
90+
OpenStackTopology []types.NamespacedName
8891
}
8992

9093
func CreateNames(openstackControlplaneName types.NamespacedName) Names {
@@ -200,6 +203,18 @@ func CreateNames(openstackControlplaneName types.NamespacedName) Names {
200203
Namespace: openstackControlplaneName.Namespace,
201204
Name: "cert-rabbitmq-cell1-svc",
202205
},
206+
NoVNCProxyCell1CertPublicRouteName: types.NamespacedName{
207+
Name: "cert-nova-novncproxy-cell1-public-route",
208+
Namespace: openstackControlplaneName.Namespace,
209+
},
210+
NoVNCProxyCell1CertPublicSvcName: types.NamespacedName{
211+
Name: "cert-nova-novncproxy-cell1-public-svc",
212+
Namespace: openstackControlplaneName.Namespace,
213+
},
214+
NoVNCProxyCell1CertVencryptName: types.NamespacedName{
215+
Name: "cert-nova-novncproxy-cell1-vencrypt",
216+
Namespace: openstackControlplaneName.Namespace,
217+
},
203218
OpenStackClientName: types.NamespacedName{
204219
Namespace: openstackControlplaneName.Namespace,
205220
Name: "openstackclient",

tests/functional/ctlplane/openstackoperator_controller_test.go

Lines changed: 188 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ import (
4545
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
4646
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
4747
manilav1 "github.com/openstack-k8s-operators/manila-operator/api/v1beta1"
48+
novav1 "github.com/openstack-k8s-operators/nova-operator/api/v1beta1"
4849
clientv1 "github.com/openstack-k8s-operators/openstack-operator/apis/client/v1beta1"
4950
corev1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
5051
ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1"
52+
placementv1 "github.com/openstack-k8s-operators/placement-operator/api/v1beta1"
5153
)
5254

5355
var _ = Describe("OpenStackOperator controller", func() {
@@ -2931,6 +2933,14 @@ var _ = Describe("OpenStackOperator controller galera and rabbitmq", func() {
29312933
th.CreateCertSecret(names.RabbitMQCertName)
29322934
th.CreateCertSecret(names.RabbitMQCell1CertName)
29332935

2936+
// create cert secrets for ovn instance
2937+
DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.OVNNorthdCertName))
2938+
DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.OVNControllerCertName))
2939+
DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.NeutronOVNCertName))
2940+
2941+
// create cert secrets for memcached instance
2942+
DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.MemcachedCertName))
2943+
29342944
extGalera := CreateGaleraConfig(namespace, GetDefaultGaleraSpec())
29352945
extGaleraName.Name = extGalera.GetName()
29362946
extGaleraName.Namespace = extGalera.GetNamespace()
@@ -2949,6 +2959,13 @@ var _ = Describe("OpenStackOperator controller galera and rabbitmq", func() {
29492959
th.DeleteInstance,
29502960
CreateOpenStackControlPlane(names.OpenStackControlplaneName, spec),
29512961
)
2962+
2963+
// enable TLS
2964+
Eventually(func(g Gomega) {
2965+
OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName)
2966+
OSCtlplane.Spec.TLS.PodLevel.Enabled = true
2967+
g.Expect(k8sClient.Update(ctx, OSCtlplane)).Should(Succeed())
2968+
}, timeout, interval).Should(Succeed())
29522969
})
29532970

29542971
It("cell1 galera should be deleted from CR", func() {
@@ -3031,13 +3048,6 @@ var _ = Describe("OpenStackOperator controller galera and rabbitmq", func() {
30313048
var secretName types.NamespacedName
30323049
var certName types.NamespacedName
30333050

3034-
// enable TLS
3035-
Eventually(func(g Gomega) {
3036-
OSCtlplane = GetOpenStackControlPlane(names.OpenStackControlplaneName)
3037-
OSCtlplane.Spec.TLS.PodLevel.Enabled = true
3038-
g.Expect(k8sClient.Update(ctx, OSCtlplane)).Should(Succeed())
3039-
}, timeout, interval).Should(Succeed())
3040-
30413051
// rabbitmq exists
30423052
Eventually(func(g Gomega) {
30433053
rabbitmq := GetRabbitMQCluster(names.RabbitMQCell1Name)
@@ -3102,6 +3112,177 @@ var _ = Describe("OpenStackOperator controller galera and rabbitmq", func() {
31023112

31033113
})
31043114

3115+
When("The novncproxy k8s service is created for cell1", func() {
3116+
/*
3117+
- generate certs and routes for novncproxy
3118+
- enable nova and dependencies
3119+
- create novncproxy service
3120+
- find and verify certs and routes are created
3121+
- reproduce cell1 deletion
3122+
- delete novnc service
3123+
- verify if there are no residue certs and routes
3124+
*/
3125+
3126+
BeforeEach(func() {
3127+
// enable Nova and dependencies
3128+
Eventually(func(g Gomega) {
3129+
OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName)
3130+
OSCtlplane.Spec.Nova.Enabled = true
3131+
OSCtlplane.Spec.Nova.Template = &novav1.NovaSpecCore{}
3132+
// enable "Galera, Memcached, RabbitMQ, Keystone, Glance, Neutron, Placement" too
3133+
3134+
OSCtlplane.Spec.Keystone.Enabled = true
3135+
OSCtlplane.Spec.Glance.Enabled = true
3136+
OSCtlplane.Spec.Neutron.Enabled = true
3137+
OSCtlplane.Spec.Placement.Enabled = true
3138+
3139+
if OSCtlplane.Spec.Placement.Template == nil {
3140+
OSCtlplane.Spec.Placement.Template = &placementv1.PlacementAPISpecCore{}
3141+
OSCtlplane.Spec.Placement.Template.APITimeout = 10
3142+
}
3143+
g.Expect(k8sClient.Update(ctx, OSCtlplane)).Should(Succeed())
3144+
}, timeout, interval).Should(Succeed())
3145+
3146+
// logger.Info("XXX OpenStackControlPlane updated")
3147+
// OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName)
3148+
// th.Logger.Info("", "XXX OSCtlplane", OSCtlplane)
3149+
3150+
// nova-novncproxy-cell1-public
3151+
novncProxyPublicSvcName := types.NamespacedName{
3152+
Name: "nova-novncproxy-cell1-public",
3153+
Namespace: namespace}
3154+
3155+
th.CreateService(
3156+
novncProxyPublicSvcName,
3157+
map[string]string{
3158+
"osctlplane-service": "nova-novncproxy",
3159+
"osctlplane": "",
3160+
"cell": "cell1",
3161+
},
3162+
k8s_corev1.ServiceSpec{
3163+
Ports: []k8s_corev1.ServicePort{
3164+
{
3165+
Name: "nova-novncproxy-cell1-public",
3166+
Port: int32(6080),
3167+
Protocol: k8s_corev1.ProtocolTCP,
3168+
},
3169+
},
3170+
})
3171+
3172+
novncProxySvc := th.GetService(novncProxyPublicSvcName)
3173+
3174+
if novncProxySvc.Annotations == nil {
3175+
novncProxySvc.Annotations = map[string]string{}
3176+
}
3177+
3178+
novncProxySvc.Annotations[service.AnnotationIngressCreateKey] = "true"
3179+
novncProxySvc.Annotations[service.AnnotationEndpointKey] = "public"
3180+
3181+
Expect(th.K8sClient.Status().Update(th.Ctx, novncProxySvc)).To(Succeed())
3182+
// novncProxySvc = th.GetService(novncProxyPublicSvcName)
3183+
// logger.Info("", "XXX novncproxy labels", novncProxySvc.Labels)
3184+
3185+
// vnproxy certs
3186+
DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.NoVNCProxyCell1CertPublicRouteName))
3187+
DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.NoVNCProxyCell1CertPublicSvcName))
3188+
DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(names.NoVNCProxyCell1CertVencryptName))
3189+
3190+
})
3191+
3192+
It("cell1 novncproxy certs should be deleted", func() {
3193+
3194+
nova := &novav1.Nova{}
3195+
novaNamespace := types.NamespacedName{Name: "nova", Namespace: namespace}
3196+
// Eventually(func(g Gomega) {
3197+
// g.Expect(k8sClient.Get(ctx, novaNamespace, nova)).Should(Succeed())
3198+
// }, timeout, interval).Should(Succeed())
3199+
3200+
// th.Logger.Info("", "XXX nova", nova)
3201+
3202+
certNames := []types.NamespacedName{
3203+
{Name: "nova-novncproxy-cell1-public-route", Namespace: namespace},
3204+
{Name: "nova-novncproxy-cell1-public-svc", Namespace: namespace},
3205+
{Name: "nova-novncproxy-cell1-vencrypt", Namespace: namespace},
3206+
}
3207+
3208+
// verify all certs for novncproxy exists
3209+
Eventually(func(g Gomega) {
3210+
for _, certName := range certNames {
3211+
cert := crtmgr.GetCert(certName)
3212+
g.Expect(cert).NotTo(BeNil())
3213+
}
3214+
}, timeout, interval).Should(Succeed())
3215+
3216+
// verify route is present
3217+
Eventually(func(g Gomega) {
3218+
novncproxyRouteName := types.NamespacedName{Name: "nova-novncproxy-cell1-public", Namespace: namespace}
3219+
novncproxyRoute := &routev1.Route{}
3220+
3221+
g.Expect(th.K8sClient.Get(th.Ctx, novncproxyRouteName, novncproxyRoute)).Should(Succeed())
3222+
g.Expect(novncproxyRoute.Spec.TLS.Certificate).Should(Not(BeEmpty()))
3223+
g.Expect(novncproxyRoute.Spec.TLS.Key).Should(Not(BeEmpty()))
3224+
g.Expect(novncproxyRoute.Spec.TLS.CACertificate).Should(Not(BeEmpty()))
3225+
}, timeout, interval).Should(Succeed())
3226+
3227+
novncProxyPublicSvcName := types.NamespacedName{
3228+
Name: "nova-novncproxy-cell1-public",
3229+
Namespace: namespace}
3230+
3231+
th.DeleteService(novncProxyPublicSvcName)
3232+
3233+
// simulate cell1 deletion jobsuccess !!
3234+
3235+
// remove cell1 from nova
3236+
Eventually(func(g Gomega) {
3237+
g.Expect(k8sClient.Get(ctx, novaNamespace, nova)).Should(Succeed())
3238+
delete(nova.Spec.CellTemplates, "cell1")
3239+
g.Expect(k8sClient.Update(ctx, nova)).To(Succeed())
3240+
}, timeout, interval).Should(Succeed())
3241+
3242+
// Eventually(func(g Gomega) {
3243+
// g.Expect(k8sClient.Get(ctx, novaNamespace, nova)).Should(Succeed())
3244+
// }, timeout, interval).Should(Succeed())
3245+
3246+
// th.Logger.Info("", "XXX nova 1", nova)
3247+
3248+
// remove from oscp
3249+
Eventually(func(g Gomega) {
3250+
OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName)
3251+
delete(OSCtlplane.Spec.Nova.Template.CellTemplates, "cell1")
3252+
g.Expect(k8sClient.Update(ctx, OSCtlplane)).Should(Succeed())
3253+
}, timeout, interval).Should(Succeed())
3254+
3255+
// OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName)
3256+
// th.Logger.Info("", "XXX oscp", OSCtlplane)
3257+
3258+
// // verify all certs for novncproxy
3259+
// Eventually(func(g Gomega) {
3260+
// for _, certName := range certNames {
3261+
// cert := crtmgr.GetCert(certName)
3262+
// g.Expect(cert).To(BeNil())
3263+
// }
3264+
// }, timeout, interval).Should(Succeed())
3265+
3266+
certs := crtmgr.GetCerts(namespace)
3267+
for _, cert := range certs.Items {
3268+
th.Logger.Info("XXX---", "", cert.Name)
3269+
3270+
}
3271+
3272+
// Eventually(func(g Gomega) {
3273+
// novncproxyRouteName := types.NamespacedName{Name: "nova-novncproxy-cell1-public", Namespace: namespace}
3274+
// novncproxyRoute := &routev1.Route{}
3275+
3276+
// g.Expect(th.K8sClient.Get(th.Ctx, novncproxyRouteName, novncproxyRoute)).Should(Succeed())
3277+
// g.Expect(novncproxyRoute.Spec.TLS.Certificate).Should(Not(BeEmpty()))
3278+
// g.Expect(novncproxyRoute.Spec.TLS.Key).Should(Not(BeEmpty()))
3279+
// g.Expect(novncproxyRoute.Spec.TLS.CACertificate).Should(Not(BeEmpty()))
3280+
// }, timeout, interval).Should(Succeed())
3281+
3282+
})
3283+
3284+
})
3285+
31053286
})
31063287

31073288
})

0 commit comments

Comments
 (0)