diff --git a/config/samples/nad_principal.yaml b/config/samples/nad_principal.yaml new file mode 100644 index 00000000..f6dad547 --- /dev/null +++ b/config/samples/nad_principal.yaml @@ -0,0 +1,17 @@ +apiVersion: k8s.cni.cncf.io/v1 +kind: NetworkAttachmentDefinition +metadata: + annotations: + labels: + osp/net: kuttlospbr + service: ovn-controller + name: principal +spec: + config: | + { + "cniVersion": "0.3.1", + "name": "kuttlospbr", + "type": "bridge", + "bridge": "ospbr", + "ipam": {} + } diff --git a/config/samples/nncp_create_bridge.yaml b/config/samples/nncp_create_bridge.yaml new file mode 100644 index 00000000..e28c24a3 --- /dev/null +++ b/config/samples/nncp_create_bridge.yaml @@ -0,0 +1,26 @@ +apiVersion: nmstate.io/v1 +kind: NodeNetworkConfigurationPolicy +metadata: + labels: + osp/interface: enp6s0 + name: enp6s0-crc +spec: + desiredState: + interfaces: + - description: Configuring Bridge + name: osptestbr + mtu: 1500 + type: linux-bridge + state: up + bridge: + options: + stp: + enabled: false + ipv4: + address: + - ip: 192.168.222.10 + prefix-length: 24 + enabled: true + dhcp: false + ipv6: + enabled: false diff --git a/controllers/ovncontroller_controller.go b/controllers/ovncontroller_controller.go index faeedb5b..312da018 100644 --- a/controllers/ovncontroller_controller.go +++ b/controllers/ovncontroller_controller.go @@ -313,6 +313,113 @@ func (r *OVNControllerReconciler) reconcileUpgrade(ctx context.Context) (ctrl.Re return ctrl.Result{}, nil } +// use lib_commons.daemonset.GetDaemonSetWithName once +// https://github.com/openstack-k8s-operators/lib-common/pull/551 +// is merged +func getDaemonSetWithName( + ctx context.Context, + h *helper.Helper, + name string, + namespace string, +) (*appsv1.DaemonSet, error) { + + dset := &appsv1.DaemonSet{} + err := h.GetClient().Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, dset) + if err != nil { + return dset, err + } + + return dset, nil +} + +func (r *OVNControllerReconciler) ensureCMDeleted( + ctx context.Context, + h *helper.Helper, + instance *ovnv1.OVNController, +) error { + // Delete, if they exist + cms := []string{instance.Name + "-config", instance.Name + "-scripts"} + for _, cmName := range cms { + err := r.deleteConfigMaps(ctx, h, cmName, instance.Namespace) + if err != nil && !k8s_errors.IsNotFound(err) { + return fmt.Errorf("could not delete config map %s: %w", cmName, err) + } + + } + return nil +} + +func ensureDSDeleted( + ctx context.Context, + h *helper.Helper, + instance *ovnv1.OVNController, +) error { + // Delete, if they exist, ovn and ovs ds + daemonsets := []string{"ovn-controller", "ovn-controller-ovs"} + for _, dsName := range daemonsets { + ds, err := getDaemonSetWithName(ctx, h, dsName, instance.Namespace) + if err != nil && !k8s_errors.IsNotFound(err) { + return fmt.Errorf("error getting %s daemonset: %w", dsName, err) + } else if err != nil && k8s_errors.IsNotFound(err) { + // Already deleted + continue + } + + // Delete ds + err = h.GetClient().Delete(ctx, ds) + if err != nil && !k8s_errors.IsNotFound(err) { + return fmt.Errorf("error deleting daemonset %s: %w", ds.Name, err) + } + } + + return nil +} + +func ensureNADDeleted( + ctx context.Context, + h *helper.Helper, + instance *ovnv1.OVNController, +) error { + // Delete NAD if they exist and controller owns it + nadList := &netattdefv1.NetworkAttachmentDefinitionList{} + err := h.GetClient().List(ctx, nadList) + if err != nil { + return fmt.Errorf("error getting NAD list: %w", err) + } + for _, currentNAD := range nadList.Items { + owners := currentNAD.GetOwnerReferences() + // if owners len is only one, means that if ovn controller is the owner we can + // delete it + if len(owners) == 1 { + if owners[0].Name == instance.Name { + err = h.GetClient().Delete(ctx, ¤tNAD) + if err != nil { + return fmt.Errorf("error trying to delete nad %s: %w", currentNAD.Name, err) + } + } + } else if len(owners) > 1 { + // this nad has more than one owner, remove ovn-controller as owner but + // don't delete it + indexToDelete := -1 + for j, owner := range owners { + if owner.Name == instance.Name { + indexToDelete = j + break + } + } + if indexToDelete != -1 { + currentNAD.SetOwnerReferences(append(owners[:indexToDelete], owners[indexToDelete+1:]...)) + err = h.GetClient().Update(ctx, ¤tNAD) + if err != nil { + return fmt.Errorf("error updating NAD %s after ownerReference update: %w", currentNAD.Name, err) + } + } + } + } + + return nil +} + func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance *ovnv1.OVNController, helper *helper.Helper) (ctrl.Result, error) { Log := r.GetLogger(ctx) @@ -339,6 +446,41 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance return rbacResult, nil } + // if ovn-controller has no nicMappings, it's useless create daemonset on + // OC nodes, since it won't do anything. + if len(instance.Spec.NicMappings) == 0 { + // Check if DS are created, if so delete the resources associated with it + // Resources associated with ovn-controller: + // - ovncontroller-scripts [cm] + // - ovncontroller-config [cm] + // - ovn-controller [ds] + // - ovn-controller-ovs [ds] + // - job [it gets deleted once it's finished] + err := ensureDSDeleted(ctx, helper, instance) + if err != nil { + return ctrl.Result{}, err + } + + err = r.ensureCMDeleted(ctx, helper, instance) + if err != nil { + return ctrl.Result{}, err + } + + err = ensureNADDeleted(ctx, helper, instance) + if err != nil { + return ctrl.Result{}, err + } + + // Set conditions to true as no more work is needed. + instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage) + instance.Status.Conditions.MarkTrue(condition.InputReadyCondition, condition.InputReadyMessage) + instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage) + instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage) + instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage) + instance.Status.Conditions.MarkTrue(condition.TLSInputReadyCondition, condition.InputReadyMessage) + return ctrl.Result{}, nil + } + // ConfigMap configMapVars := make(map[string]env.Setter) @@ -677,6 +819,28 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance return ctrl.Result{}, nil } +func (r *OVNControllerReconciler) deleteConfigMaps( + ctx context.Context, + h *helper.Helper, + name string, + namespace string, +) error { + serviceCM := &corev1.ConfigMap{} + err := h.GetClient().Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, serviceCM) + if err != nil && !k8s_errors.IsNotFound(err) { + return err + } else if k8s_errors.IsNotFound(err) { + return nil + } + + err = h.GetClient().Delete(ctx, serviceCM) + if err != nil && !k8s_errors.IsNotFound(err) { + return fmt.Errorf("error deleting config map %s: %w", serviceCM.Name, err) + } + + return nil +} + // generateServiceConfigMaps - create configmaps which hold scripts and service configuration func (r *OVNControllerReconciler) generateServiceConfigMaps( ctx context.Context, diff --git a/tests/functional/base_test.go b/tests/functional/base_test.go index 0958e7d8..180da8c9 100644 --- a/tests/functional/base_test.go +++ b/tests/functional/base_test.go @@ -184,6 +184,15 @@ func GetOVNDBCluster(name types.NamespacedName) *ovnv1.OVNDBCluster { return ovn.GetOVNDBCluster(name) } +// GetConfigMap - +func GetConfigMap(name types.NamespacedName) *corev1.ConfigMap { + cm := &corev1.ConfigMap{} + Eventually(func(g Gomega) { + g.Expect(k8sClient.Get(ctx, name, cm)).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + return cm +} + // GetDaemonSet - func GetDaemonSet(name types.NamespacedName) *appsv1.DaemonSet { ds := &appsv1.DaemonSet{} diff --git a/tests/functional/ovncontroller_controller_test.go b/tests/functional/ovncontroller_controller_test.go index ba321325..7adf2235 100644 --- a/tests/functional/ovncontroller_controller_test.go +++ b/tests/functional/ovncontroller_controller_test.go @@ -30,17 +30,26 @@ import ( condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1" ovn_common "github.com/openstack-k8s-operators/ovn-operator/pkg/common" + appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" + k8s_errors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" ) +// GINKGO_ARGS="--focus 'OVNController controller'" make test var _ = Describe("OVNController controller", func() { + // GINKGO_ARGS="--focus 'OVNController controller when A OVNController instance is created'" make test When("A OVNController instance is created", func() { var OVNControllerName types.NamespacedName BeforeEach(func() { - instance := CreateOVNController(namespace, GetDefaultOVNControllerSpec()) + specWithNicMappings := GetDefaultOVNControllerSpec() + + nicMappings := make(map[string]string) + nicMappings["examplebr"] = "examplebr" + specWithNicMappings.OVNControllerSpecCore.NicMappings = nicMappings + instance := CreateOVNController(namespace, specWithNicMappings) OVNControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} DeferCleanup(th.DeleteInstance, instance) }) @@ -125,6 +134,7 @@ var _ = Describe("OVNController controller", func() { ) }) + // GINKGO_ARGS="--focus 'OVNController controller when A OVNController instance is created when OVNDBCluster instances are available without networkAttachments'" make test When("OVNDBCluster instances are available without networkAttachments", func() { var scriptsCM types.NamespacedName var dbs []types.NamespacedName @@ -204,6 +214,7 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when A OVNController instance is created when OVNDBCluster instances with networkAttachments are available'" make test When("OVNDBCluster instances with networkAttachments are available", func() { var configCM types.NamespacedName var daemonSetName types.NamespacedName @@ -274,6 +285,7 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController and OVNDBClusters are created with networkAttachments'" make test When("OVNController and OVNDBClusters are created with networkAttachments", func() { var OVNControllerName types.NamespacedName var dbs []types.NamespacedName @@ -288,6 +300,9 @@ var _ = Describe("OVNController controller", func() { } spec := GetDefaultOVNControllerSpec() spec.NetworkAttachment = "internalapi" + nicMappings := make(map[string]string) + nicMappings["foo-phynet"] = "foo-bridge" + spec.NicMappings = nicMappings instance := CreateOVNController(namespace, spec) OVNControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} DeferCleanup(th.DeleteInstance, instance) @@ -341,12 +356,18 @@ var _ = Describe("OVNController controller", func() { expectedAnnotation, err := json.Marshal( []networkv1.NetworkSelectionElement{ + { + Name: "foo-phynet", + Namespace: namespace, + InterfaceRequest: "foo-phynet", + }, { Name: "internalapi", Namespace: namespace, InterfaceRequest: "internalapi", }, - }) + }, + ) Expect(err).ShouldNot(HaveOccurred()) Expect(ds.Spec.Template.ObjectMeta.Annotations).To( HaveKeyWithValue("k8s.v1.cni.cncf.io/networks", string(expectedAnnotation)), @@ -384,6 +405,11 @@ var _ = Describe("OVNController controller", func() { expectedAnnotation, err := json.Marshal( []networkv1.NetworkSelectionElement{ + { + Name: "foo-phynet", + Namespace: namespace, + InterfaceRequest: "foo-phynet", + }, { Name: "internalapi", Namespace: namespace, @@ -578,6 +604,7 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController is created with missing networkAttachment'" make test When("OVNController is created with missing networkAttachment", func() { var OVNControllerName types.NamespacedName var dbs []types.NamespacedName @@ -589,6 +616,9 @@ var _ = Describe("OVNController controller", func() { } spec := GetDefaultOVNControllerSpec() spec.NetworkAttachment = "internalapi" + spec.NicMappings = map[string]string{ + "physnet1": "enp2s0.100", + } instance := CreateOVNController(namespace, spec) OVNControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} DeferCleanup(th.DeleteInstance, instance) @@ -606,6 +636,7 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController is created with nic configs'" make test When("OVNController is created with nic configs", func() { var OVNControllerName types.NamespacedName BeforeEach(func() { @@ -762,24 +793,26 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController is created with networkAttachment and nic configs'" make test When("OVNController is created with networkAttachment and nic configs", func() { + var OVNControllerName types.NamespacedName BeforeEach(func() { - dbs := CreateOVNDBClusters(namespace, map[string][]string{}, 1) - DeferCleanup(DeleteOVNDBClusters, dbs) + internalAPINADName := types.NamespacedName{Namespace: namespace, Name: "internalapi"} + nad := th.CreateNetworkAttachmentDefinition(internalAPINADName) + DeferCleanup(th.DeleteInstance, nad) spec := GetDefaultOVNControllerSpec() spec.NetworkAttachment = "internalapi" spec.NicMappings = map[string]string{ "physnet1": "enp2s0.100", } instance := CreateOVNController(namespace, spec) + OVNControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} DeferCleanup(th.DeleteInstance, instance) + dbs := CreateOVNDBClusters(namespace, map[string][]string{OVNControllerName.Namespace + "/internalapi": {"10.0.0.1"}}, 1) + DeferCleanup(DeleteOVNDBClusters, dbs) }) It("reports that daemonset have annotations for both Networkattachment and nic-configs", func() { - internalAPINADName := types.NamespacedName{Namespace: namespace, Name: "internalapi"} - nad := th.CreateNetworkAttachmentDefinition(internalAPINADName) - DeferCleanup(th.DeleteInstance, nad) - daemonSetName := types.NamespacedName{ Namespace: namespace, Name: "ovn-controller", @@ -811,8 +844,111 @@ var _ = Describe("OVNController controller", func() { HaveKeyWithValue("k8s.v1.cni.cncf.io/networks", string(expectedAnnotation)), ) }) + + It("deletes daemonset if nicMappings are removed", func() { + // ensure daemonsets/pods are created + + daemonSetName := types.NamespacedName{ + Namespace: namespace, + Name: "ovn-controller", + } + daemonSetNameOVS := types.NamespacedName{ + Namespace: namespace, + Name: "ovn-controller-ovs", + } + + configCM := types.NamespacedName{ + Namespace: namespace, + Name: OVNControllerName.Name + "-config", + } + scriptCM := types.NamespacedName{ + Namespace: namespace, + Name: OVNControllerName.Name + "-scripts", + } + + // ensure daemonsets are created + Eventually(func() *appsv1.DaemonSet { + return GetDaemonSet(daemonSetName) + }, timeout, interval).ShouldNot(BeNil()) + + Eventually(func() *appsv1.DaemonSet { + return GetDaemonSet(daemonSetNameOVS) + }, timeout, interval).ShouldNot(BeNil()) + + SimulateDaemonsetNumberReadyWithPods( + daemonSetName, + map[string][]string{}, + ) + SimulateDaemonsetNumberReadyWithPods( + daemonSetNameOVS, + map[string][]string{namespace + "/internalapi": {"10.0.0.1"}}, + ) + + // ensure configmaps are created + Eventually(func() *corev1.ConfigMap { + return GetConfigMap(configCM) + }, timeout, interval).ShouldNot(BeNil()) + + Eventually(func() *corev1.ConfigMap { + return GetConfigMap(scriptCM) + }, timeout, interval).ShouldNot(BeNil()) + + // remove nicMappings + Eventually(func(g Gomega) { + c := GetOVNController(OVNControllerName) + c.Spec.NicMappings = make(map[string]string) + g.Expect(k8sClient.Update(ctx, c)).Should(Succeed()) + }).Should(Succeed()) + + // ensure daemonsets are deleted + Eventually(func() error { + ds := &appsv1.DaemonSet{} + err := k8sClient.Get(ctx, daemonSetName, ds) + if err == nil { + return fmt.Errorf("Daemonset is still present") + } else if err != nil && !k8s_errors.IsNotFound(err) { + return err + } + return nil + }, timeout, interval).Should(Succeed()) + + Eventually(func() error { + ds := &appsv1.DaemonSet{} + err := k8sClient.Get(ctx, daemonSetNameOVS, ds) + if err == nil { + return fmt.Errorf("OVS Daemonset is still present") + } else if err != nil && !k8s_errors.IsNotFound(err) { + return err + } + return nil + }, timeout, interval).Should(Succeed()) + + // ensure configmaps are deleted + Eventually(func() error { + cm := &corev1.ConfigMap{} + err := k8sClient.Get(ctx, configCM, cm) + if err == nil { + return fmt.Errorf("config CM is still present") + } else if err != nil && !k8s_errors.IsNotFound(err) { + return err + } + return nil + }, timeout, interval).Should(Succeed()) + + Eventually(func() error { + cm := &corev1.ConfigMap{} + err := k8sClient.Get(ctx, scriptCM, cm) + if err == nil { + return fmt.Errorf("script CM is still present") + } else if err != nil && !k8s_errors.IsNotFound(err) { + return err + } + return nil + }, timeout, interval).Should(Succeed()) + }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController is created with empty spec'" make test When("OVNController is created with empty spec", func() { var ovnControllerName types.NamespacedName @@ -834,13 +970,18 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController is created with TLS'" make test When("OVNController is created with TLS", func() { var ovnControllerName types.NamespacedName BeforeEach(func() { dbs := CreateOVNDBClusters(namespace, map[string][]string{}, 1) DeferCleanup(DeleteOVNDBClusters, dbs) - instance := CreateOVNController(namespace, GetTLSOVNControllerSpec()) + specWithNicMappings := GetTLSOVNControllerSpec() + nicMappings := make(map[string]string) + nicMappings["examplebr"] = "examplebr" + specWithNicMappings.OVNControllerSpecCore.NicMappings = nicMappings + instance := CreateOVNController(namespace, specWithNicMappings) DeferCleanup(th.DeleteInstance, instance) ovnControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} diff --git a/tests/kuttl/common/assert_ovn_controller.yaml b/tests/kuttl/common/assert_ovn_controller.yaml new file mode 100644 index 00000000..af9eaa61 --- /dev/null +++ b/tests/kuttl/common/assert_ovn_controller.yaml @@ -0,0 +1,91 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: ovn-controller +status: + numberMisscheduled: 0 +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: ovn-controller-ovs +status: + numberMisscheduled: 0 +--- +apiVersion: v1 +kind: Pod +metadata: + annotations: + openshift.io/scc: privileged + labels: + service: ovn-controller + generateName: ovn-controller- +status: + phase: Running +--- +apiVersion: v1 +kind: Pod +metadata: + annotations: + openshift.io/scc: privileged + labels: + service: ovn-controller-ovs + generateName: ovn-controller-ovs- +status: + phase: Running +# This is done also on assert_sample_deployment, it's repeated here to ensure the +# correct creation of ovn-controller pods +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + num_nodes=$(oc get nodes -l node-role.kubernetes.io/worker -o name | wc -l) + # check the number of ovn-controller* pods that are running + num_pods_ovn=$(oc get pods -n $NAMESPACE -l service=ovn-controller -o name --field-selector=status.phase=Running | wc -l) + num_pods_ovs=$(oc get pods -n $NAMESPACE -l service=ovn-controller-ovs -o name --field-selector=status.phase=Running | wc -l) + num_pods=$(( num_pods_ovn + num_pods_ovs)) + nic_mappings_set=$(oc get -n $NAMESPACE ovncontroller ovncontroller-sample -o json | jq '.spec | has("nicMappings")') + # if Spec.NicMappings is empty number should be 0, else should be equal to num_nodes. + echo $nic_mappings_set + if [ "$nic_mappings_set" == "true" ]; then + # for each nodes, two pods are spawned - ovn-controller and ovn-controller-ovs + if [ "$((num_nodes * 2))" -ne "$num_pods" ]; then + echo "Cluster has $num_nodes nodes but OVNController spawned $num_pods pods, it should have $num_nodes * 2" + exit 1 + fi + else + # In this stage nicMappings should be set if not it should be an error + echo "Ovn-controller nicMappings is not set." + exit 1 + fi + tupleTemplate='{{ range (index .spec.template.spec.containers 1).env }}{{ .name }}{{ "#" }}{{ .value}}{{"\n"}}{{ end }}' + imageTuples=$(oc get -n openstack-operators deployment ovn-operator-controller-manager -o go-template="$tupleTemplate") + for ITEM in $(echo $imageTuples); do + # it is an image + if echo $ITEM | grep 'RELATED_IMAGE' &> /dev/null; then + NAME=$(echo $ITEM | sed -e 's|^RELATED_IMAGE_OVN_\(.*\)_IMAGE.*|\1|') + IMG_FROM_ENV=$(echo $ITEM | sed -e 's|^.*#\(.*\)|\1|') + template='{{.spec.containerImage}}' + case $NAME in + CONTROLLER) + SERVICE_IMAGE=$(oc get -n $NAMESPACE ovncontroller ovncontroller-sample -o go-template="{{.spec.ovnContainerImage}}") + ;; + CONTROLLER_OVS) + SERVICE_IMAGE=$(oc get -n $NAMESPACE ovncontroller ovncontroller-sample -o go-template="{{.spec.ovsContainerImage}}") + ;; + esac + if [ "$SERVICE_IMAGE" != "$IMG_FROM_ENV" ]; then + echo "$NAME image ($SERVICE_IMAGE) does not equal $IMG_FROM_ENV" + exit 1 + fi + fi + done + + exit 0 + - script: | + controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller -o name|head -1) + host=$(oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl get open . external_ids:hostname) + + sb_pod=$(oc get pod -n $NAMESPACE -l service=ovsdbserver-sb -o name|head -1) + oc rsh -n $NAMESPACE ${sb_pod} ovn-sbctl list chassis | grep -q ${host} || exit 1 + xit 0 diff --git a/tests/kuttl/common/assert_sample_deployment.yaml b/tests/kuttl/common/assert_sample_deployment.yaml index df20ebcd..7c754173 100644 --- a/tests/kuttl/common/assert_sample_deployment.yaml +++ b/tests/kuttl/common/assert_sample_deployment.yaml @@ -167,20 +167,6 @@ status: availableReplicas: 1 replicas: 1 --- -apiVersion: apps/v1 -kind: DaemonSet -metadata: - name: ovn-controller -status: - numberMisscheduled: 0 ---- -apiVersion: apps/v1 -kind: DaemonSet -metadata: - name: ovn-controller-ovs -status: - numberMisscheduled: 0 ---- # the openshift annotations can't be checked through the deployment above apiVersion: v1 kind: Pod @@ -209,28 +195,6 @@ metadata: name: ovsdbserver-sb-0 --- apiVersion: v1 -kind: Pod -metadata: - annotations: - openshift.io/scc: privileged - labels: - service: ovn-controller - generateName: ovn-controller- -status: - phase: Running ---- -apiVersion: v1 -kind: Pod -metadata: - annotations: - openshift.io/scc: privileged - labels: - service: ovn-controller-ovs - generateName: ovn-controller-ovs- -status: - phase: Running ---- -apiVersion: v1 kind: Service metadata: labels: @@ -315,12 +279,22 @@ commands: num_pods_ovn=$(oc get pods -n $NAMESPACE -l service=ovn-controller -o name --field-selector=status.phase=Running | wc -l) num_pods_ovs=$(oc get pods -n $NAMESPACE -l service=ovn-controller-ovs -o name --field-selector=status.phase=Running | wc -l) num_pods=$(( num_pods_ovn + num_pods_ovs)) - # for each nodes, two pods are spawned - ovn-controller and ovn-controller-ovs - if [ "$((num_nodes * 2))" -ne "$num_pods" ]; then - echo "Cluster has $num_nodes nodes but OVNController spawned $num_pods pods, it should have $num_nodes * 2" - exit 1 + nic_mappings_set=$(oc get -n $NAMESPACE ovncontroller ovncontroller-sample -o json | jq '.spec | has("nicMappings")') + # if Spec.NicMappings is empty number should be 0, else should be equal to num_nodes. + echo $nic_mappings_set + if [ "$nic_mappings_set" == "true" ]; then + # for each nodes, two pods are spawned - ovn-controller and ovn-controller-ovs + if [ "$((num_nodes * 2))" -ne "$num_pods" ]; then + echo "Cluster has $num_nodes nodes but OVNController spawned $num_pods pods, it should have $num_nodes * 2" + exit 1 + fi + else + # nicMappings is not set, it should be zero regardless of num_nodes + if [ "0" -ne "$num_pods" ]; then + echo "Cluster has $num_nodes nodes but OVNController spawned $num_pods pods, it should be 0" + exit 1 + fi fi - tupleTemplate='{{ range (index .spec.template.spec.containers 1).env }}{{ .name }}{{ "#" }}{{ .value}}{{"\n"}}{{ end }}' imageTuples=$(oc get -n openstack-operators deployment ovn-operator-controller-manager -o go-template="$tupleTemplate") for ITEM in $(echo $imageTuples); do @@ -355,9 +329,9 @@ commands: exit 0 - script: | - controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller -o name|head -1) - host=$(oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl get open . external_ids:hostname) + #controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller -o name|head -1) + #host=$(oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl get open . external_ids:hostname) - sb_pod=$(oc get pod -n $NAMESPACE -l service=ovsdbserver-sb -o name|head -1) - oc rsh -n $NAMESPACE ${sb_pod} ovn-sbctl list chassis | grep -q ${host} || exit 1 + #sb_pod=$(oc get pod -n $NAMESPACE -l service=ovsdbserver-sb -o name|head -1) + #oc rsh -n $NAMESPACE ${sb_pod} ovn-sbctl list chassis | grep -q ${host} || exit 1 exit 0 diff --git a/tests/kuttl/common/attach_nic_mappings_ovn_controller.yaml b/tests/kuttl/common/attach_nic_mappings_ovn_controller.yaml new file mode 100644 index 00000000..a4f548ca --- /dev/null +++ b/tests/kuttl/common/attach_nic_mappings_ovn_controller.yaml @@ -0,0 +1,10 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +timeout: 60 +commands: + - script: | + oc patch OVNController -n $NAMESPACE ovncontroller-sample --type='json' -p='[{ + "op": "replace", + "path": "/spec/nicMappings", + "value":{"kuttlospbr":"ospbr"} + }]' diff --git a/tests/kuttl/common/create_nad.yaml b/tests/kuttl/common/create_nad.yaml new file mode 100644 index 00000000..6051204b --- /dev/null +++ b/tests/kuttl/common/create_nad.yaml @@ -0,0 +1,5 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +commands: + - script: | + oc apply -n $NAMESPACE -f ../../../../config/samples/nad_principal.yaml diff --git a/tests/kuttl/common/create_oc_bridge.yaml b/tests/kuttl/common/create_oc_bridge.yaml new file mode 100644 index 00000000..be55f70b --- /dev/null +++ b/tests/kuttl/common/create_oc_bridge.yaml @@ -0,0 +1,15 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +apply: +- ../../../../config/samples/nad_principal.yaml +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +timeout: 60 +commands: + - script: | + oc patch OVNController -n $NAMESPACE ovncontroller-sample --type='json' -p='[{ + "op": "replace", + "path": "/spec/nicMappings", + "value":{"testattach":"ospbrprin"} + }]' diff --git a/tests/kuttl/common/scripts/check_cluster_status.sh b/tests/kuttl/common/scripts/check_cluster_status.sh index e062c44a..0d34e23e 100755 --- a/tests/kuttl/common/scripts/check_cluster_status.sh +++ b/tests/kuttl/common/scripts/check_cluster_status.sh @@ -21,12 +21,13 @@ declare -a pods for i in $(seq 0 $((NUM_PODS-1))); do pods+=("${POD_PREFIX}-${i}") done - +echo $pods # check each pod replica for pod in "${pods[@]}"; do - echo "Checking status of $pod" - output=$(oc exec $pod -n $NAMESPACE -- bash -c "OVS_RUNDIR=/tmp ovs-appctl -t /tmp/$CTL_FILE cluster/status $DB_NAME") + echo "Checking status of $pod on namespace $NAMESPACE" + output=$(oc rsh -n $NAMESPACE $pod bash -c "OVS_RUNDIR=/tmp ovs-appctl -t /tmp/$CTL_FILE cluster/status $DB_NAME") + echo $output # Example of part of output string that needs parsing: # Status: cluster member diff --git a/tests/kuttl/tests/ovn_config/02-create-principal-bridge.yaml b/tests/kuttl/tests/ovn_config/02-create-principal-bridge.yaml new file mode 120000 index 00000000..90e436c3 --- /dev/null +++ b/tests/kuttl/tests/ovn_config/02-create-principal-bridge.yaml @@ -0,0 +1 @@ +../../common/create_nad.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_config/03-assert.yaml b/tests/kuttl/tests/ovn_config/03-assert.yaml deleted file mode 100644 index 92abb5a6..00000000 --- a/tests/kuttl/tests/ovn_config/03-assert.yaml +++ /dev/null @@ -1,13 +0,0 @@ -# -# Check for: -# -# - chassis unregistered in sb db - -apiVersion: kuttl.dev/v1beta1 -kind: TestAssert -timeout: 30 -commands: - - script: | - sb_pod=$(oc get pod -n $NAMESPACE -l service=ovsdbserver-sb -o name|head -1) - oc rsh -n $NAMESPACE ${sb_pod} ovn-sbctl list chassis | grep -q hostname && exit 1 - exit 0 diff --git a/tests/kuttl/tests/ovn_config/03-assert.yaml b/tests/kuttl/tests/ovn_config/03-assert.yaml new file mode 120000 index 00000000..6ede65dc --- /dev/null +++ b/tests/kuttl/tests/ovn_config/03-assert.yaml @@ -0,0 +1 @@ +../../common/assert_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_config/03-enable-ovncontroller.yaml b/tests/kuttl/tests/ovn_config/03-enable-ovncontroller.yaml new file mode 120000 index 00000000..9180c2a4 --- /dev/null +++ b/tests/kuttl/tests/ovn_config/03-enable-ovncontroller.yaml @@ -0,0 +1 @@ +../../common/attach_nic_mappings_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_config/02-assert.yaml b/tests/kuttl/tests/ovn_config/04-assert.yaml similarity index 100% rename from tests/kuttl/tests/ovn_config/02-assert.yaml rename to tests/kuttl/tests/ovn_config/04-assert.yaml diff --git a/tests/kuttl/tests/ovn_config/02-az-patch.yaml b/tests/kuttl/tests/ovn_config/04-az-patch.yaml similarity index 100% rename from tests/kuttl/tests/ovn_config/02-az-patch.yaml rename to tests/kuttl/tests/ovn_config/04-az-patch.yaml diff --git a/tests/kuttl/tests/ovn_config/05-assert.yaml b/tests/kuttl/tests/ovn_config/05-assert.yaml new file mode 100644 index 00000000..92abb5a6 --- /dev/null +++ b/tests/kuttl/tests/ovn_config/05-assert.yaml @@ -0,0 +1,13 @@ +# +# Check for: +# +# - chassis unregistered in sb db + +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 30 +commands: + - script: | + sb_pod=$(oc get pod -n $NAMESPACE -l service=ovsdbserver-sb -o name|head -1) + oc rsh -n $NAMESPACE ${sb_pod} ovn-sbctl list chassis | grep -q hostname && exit 1 + exit 0 diff --git a/tests/kuttl/tests/ovn_config/03-remove-ovncontroller.yaml b/tests/kuttl/tests/ovn_config/05-remove-ovncontroller.yaml similarity index 100% rename from tests/kuttl/tests/ovn_config/03-remove-ovncontroller.yaml rename to tests/kuttl/tests/ovn_config/05-remove-ovncontroller.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/02-assert.yaml b/tests/kuttl/tests/ovn_db_delete/02-assert.yaml deleted file mode 100644 index 0dd7be77..00000000 --- a/tests/kuttl/tests/ovn_db_delete/02-assert.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# -# Check for: -# -# - 1 OVNDBCluster CR -# - 3 Pods for OVNDBCluster nb CR -# - -apiVersion: ovn.openstack.org/v1beta1 -kind: OVNDBCluster -metadata: - finalizers: - - openstack.org/ovndbcluster - name: ovndbcluster-nb-sample -spec: - replicas: 3 -status: - readyCount: 3 ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: ovsdbserver-nb -spec: - replicas: 3 -status: - availableReplicas: 3 ---- -apiVersion: ovn.openstack.org/v1beta1 -kind: OVNDBCluster -metadata: - finalizers: - - openstack.org/ovndbcluster - name: ovndbcluster-sb-sample -spec: - replicas: 3 -status: - readyCount: 3 ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: ovsdbserver-sb -spec: - replicas: 3 -status: - availableReplicas: 3 ---- diff --git a/tests/kuttl/tests/ovn_db_delete/02-create-bridge.yaml b/tests/kuttl/tests/ovn_db_delete/02-create-bridge.yaml new file mode 120000 index 00000000..90e436c3 --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/02-create-bridge.yaml @@ -0,0 +1 @@ +../../common/create_nad.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/03-assert.yaml b/tests/kuttl/tests/ovn_db_delete/03-assert.yaml deleted file mode 100644 index ffcf4ce9..00000000 --- a/tests/kuttl/tests/ovn_db_delete/03-assert.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestAssert -commands: - - script: | - $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh nb 3 - test $? -eq 0 - - script: | - $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh sb 3 - test $? -eq 0 diff --git a/tests/kuttl/tests/ovn_db_delete/03-assert.yaml b/tests/kuttl/tests/ovn_db_delete/03-assert.yaml new file mode 120000 index 00000000..6ede65dc --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/03-assert.yaml @@ -0,0 +1 @@ +../../common/assert_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/03-enable-ovncontroller.yaml b/tests/kuttl/tests/ovn_db_delete/03-enable-ovncontroller.yaml new file mode 120000 index 00000000..9180c2a4 --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/03-enable-ovncontroller.yaml @@ -0,0 +1 @@ +../../common/attach_nic_mappings_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/04-assert.yaml b/tests/kuttl/tests/ovn_db_delete/04-assert.yaml deleted file mode 120000 index a30aa910..00000000 --- a/tests/kuttl/tests/ovn_db_delete/04-assert.yaml +++ /dev/null @@ -1 +0,0 @@ -02-assert.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/04-assert.yaml b/tests/kuttl/tests/ovn_db_delete/04-assert.yaml new file mode 100644 index 00000000..0dd7be77 --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/04-assert.yaml @@ -0,0 +1,47 @@ +# +# Check for: +# +# - 1 OVNDBCluster CR +# - 3 Pods for OVNDBCluster nb CR +# + +apiVersion: ovn.openstack.org/v1beta1 +kind: OVNDBCluster +metadata: + finalizers: + - openstack.org/ovndbcluster + name: ovndbcluster-nb-sample +spec: + replicas: 3 +status: + readyCount: 3 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: ovsdbserver-nb +spec: + replicas: 3 +status: + availableReplicas: 3 +--- +apiVersion: ovn.openstack.org/v1beta1 +kind: OVNDBCluster +metadata: + finalizers: + - openstack.org/ovndbcluster + name: ovndbcluster-sb-sample +spec: + replicas: 3 +status: + readyCount: 3 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: ovsdbserver-sb +spec: + replicas: 3 +status: + availableReplicas: 3 +--- diff --git a/tests/kuttl/tests/ovn_db_delete/02-scale-ovndb.yaml b/tests/kuttl/tests/ovn_db_delete/04-scale-ovndb.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/02-scale-ovndb.yaml rename to tests/kuttl/tests/ovn_db_delete/04-scale-ovndb.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/05-assert.yaml b/tests/kuttl/tests/ovn_db_delete/05-assert.yaml deleted file mode 120000 index cf30bf5b..00000000 --- a/tests/kuttl/tests/ovn_db_delete/05-assert.yaml +++ /dev/null @@ -1 +0,0 @@ -03-assert.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/05-assert.yaml b/tests/kuttl/tests/ovn_db_delete/05-assert.yaml new file mode 100644 index 00000000..b752602a --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/05-assert.yaml @@ -0,0 +1,11 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + echo "$OVN_KUTTL_DIR/../common/scripts/" + ls $OVN_KUTTL_DIR/../common/scripts/ + $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh nb 3 + test $? -eq 0 + - script: | + $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh sb 3 + test $? -eq 0 diff --git a/tests/kuttl/tests/ovn_db_delete/06-assert.yaml b/tests/kuttl/tests/ovn_db_delete/06-assert.yaml new file mode 120000 index 00000000..cbe7a633 --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/06-assert.yaml @@ -0,0 +1 @@ +04-assert.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/04-delete-pods.yaml b/tests/kuttl/tests/ovn_db_delete/06-delete-pods.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/04-delete-pods.yaml rename to tests/kuttl/tests/ovn_db_delete/06-delete-pods.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/09-assert.yaml b/tests/kuttl/tests/ovn_db_delete/09-assert.yaml deleted file mode 100644 index 38a7c6c5..00000000 --- a/tests/kuttl/tests/ovn_db_delete/09-assert.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestAssert -commands: - - script: | - $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh nb 1 - test $? -eq 0 - - script: | - $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh sb 1 - test $? -eq 0 diff --git a/tests/kuttl/tests/ovn_db_delete/09-assert.yaml b/tests/kuttl/tests/ovn_db_delete/09-assert.yaml new file mode 120000 index 00000000..cf30bf5b --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/09-assert.yaml @@ -0,0 +1 @@ +03-assert.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/08-assert.yaml b/tests/kuttl/tests/ovn_db_delete/10-assert.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/08-assert.yaml rename to tests/kuttl/tests/ovn_db_delete/10-assert.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/08-scale-down-ovndb.yaml b/tests/kuttl/tests/ovn_db_delete/10-scale-down-ovndb.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/08-scale-down-ovndb.yaml rename to tests/kuttl/tests/ovn_db_delete/10-scale-down-ovndb.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/11-assert.yaml b/tests/kuttl/tests/ovn_db_delete/11-assert.yaml new file mode 100644 index 00000000..38a7c6c5 --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/11-assert.yaml @@ -0,0 +1,9 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh nb 1 + test $? -eq 0 + - script: | + $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh sb 1 + test $? -eq 0 diff --git a/tests/kuttl/tests/ovn_db_delete/10-cleanup-ovn.yaml b/tests/kuttl/tests/ovn_db_delete/12-cleanup-ovn.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/10-cleanup-ovn.yaml rename to tests/kuttl/tests/ovn_db_delete/12-cleanup-ovn.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/10-errors.yaml b/tests/kuttl/tests/ovn_db_delete/12-errors.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/10-errors.yaml rename to tests/kuttl/tests/ovn_db_delete/12-errors.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/02-create-principal-bridge.yaml b/tests/kuttl/tests/ovn_nicmappings/02-create-principal-bridge.yaml new file mode 120000 index 00000000..90e436c3 --- /dev/null +++ b/tests/kuttl/tests/ovn_nicmappings/02-create-principal-bridge.yaml @@ -0,0 +1 @@ +../../common/create_nad.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml b/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml deleted file mode 100644 index 41021b0b..00000000 --- a/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml +++ /dev/null @@ -1,19 +0,0 @@ -# -# Check for: -# -# - The interface "datacentre2" exists in the ovn-controller container -# - The OVS Open vSwitch external_ids:ovn-bridge-mappings is configured correctly - -apiVersion: kuttl.dev/v1beta1 -kind: TestAssert -timeout: 300 -commands: - - script: | - controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller-ovs -o name|head -1) - oc rsh -n $NAMESPACE ${controller_pod} ip link show dev datacentre2 || exit 1 - oc rsh -n $NAMESPACE ${controller_pod} ip link show dev br-datacentre2 || exit 1 - oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl list-ports br-datacentre2 | grep datacentre2 || exit 1 - oc rsh -n $NAMESPACE ${controller_pod} ip link show dev data-centre3 2>&1 | grep "does not exist" || exit 1 - oc rsh -n $NAMESPACE ${controller_pod} ip link show dev br-data-centre3 2>&1 | grep "does not exist" || exit 1 - oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl --if-exists get open . external_ids:ovn-bridge-mappings | grep -q "datacentre2:br-datacentre2" || exit 1 - exit 0 diff --git a/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml b/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml new file mode 120000 index 00000000..6ede65dc --- /dev/null +++ b/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml @@ -0,0 +1 @@ +../../common/assert_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_nicmappings/03-enable-ovncontroller.yaml b/tests/kuttl/tests/ovn_nicmappings/03-enable-ovncontroller.yaml new file mode 120000 index 00000000..9180c2a4 --- /dev/null +++ b/tests/kuttl/tests/ovn_nicmappings/03-enable-ovncontroller.yaml @@ -0,0 +1 @@ +../../common/attach_nic_mappings_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_nicmappings/02-new-network-attachment-definition.yaml b/tests/kuttl/tests/ovn_nicmappings/04-new-network-attachment-definition.yaml similarity index 65% rename from tests/kuttl/tests/ovn_nicmappings/02-new-network-attachment-definition.yaml rename to tests/kuttl/tests/ovn_nicmappings/04-new-network-attachment-definition.yaml index 10b53dc2..4ed40498 100644 --- a/tests/kuttl/tests/ovn_nicmappings/02-new-network-attachment-definition.yaml +++ b/tests/kuttl/tests/ovn_nicmappings/04-new-network-attachment-definition.yaml @@ -2,5 +2,4 @@ apiVersion: kuttl.dev/v1beta1 kind: TestStep commands: - script: | - oc apply -n $NAMESPACE -f ../../../../config/samples/nad_datacentre2.yaml oc apply -n $NAMESPACE -f ../../../../config/samples/nad_data-centre3.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/05-assert.yaml b/tests/kuttl/tests/ovn_nicmappings/05-assert.yaml new file mode 100644 index 00000000..41021b0b --- /dev/null +++ b/tests/kuttl/tests/ovn_nicmappings/05-assert.yaml @@ -0,0 +1,19 @@ +# +# Check for: +# +# - The interface "datacentre2" exists in the ovn-controller container +# - The OVS Open vSwitch external_ids:ovn-bridge-mappings is configured correctly + +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 300 +commands: + - script: | + controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller-ovs -o name|head -1) + oc rsh -n $NAMESPACE ${controller_pod} ip link show dev datacentre2 || exit 1 + oc rsh -n $NAMESPACE ${controller_pod} ip link show dev br-datacentre2 || exit 1 + oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl list-ports br-datacentre2 | grep datacentre2 || exit 1 + oc rsh -n $NAMESPACE ${controller_pod} ip link show dev data-centre3 2>&1 | grep "does not exist" || exit 1 + oc rsh -n $NAMESPACE ${controller_pod} ip link show dev br-data-centre3 2>&1 | grep "does not exist" || exit 1 + oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl --if-exists get open . external_ids:ovn-bridge-mappings | grep -q "datacentre2:br-datacentre2" || exit 1 + exit 0 diff --git a/tests/kuttl/tests/ovn_nicmappings/03-nicmappings-patch-datacentre2.yaml b/tests/kuttl/tests/ovn_nicmappings/05-nicmappings-patch-datacentre2.yaml similarity index 100% rename from tests/kuttl/tests/ovn_nicmappings/03-nicmappings-patch-datacentre2.yaml rename to tests/kuttl/tests/ovn_nicmappings/05-nicmappings-patch-datacentre2.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/04-assert.yaml b/tests/kuttl/tests/ovn_nicmappings/06-assert.yaml similarity index 100% rename from tests/kuttl/tests/ovn_nicmappings/04-assert.yaml rename to tests/kuttl/tests/ovn_nicmappings/06-assert.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/04-nicmappings-patch-datacentre3.yaml b/tests/kuttl/tests/ovn_nicmappings/06-nicmappings-patch-datacentre3.yaml similarity index 100% rename from tests/kuttl/tests/ovn_nicmappings/04-nicmappings-patch-datacentre3.yaml rename to tests/kuttl/tests/ovn_nicmappings/06-nicmappings-patch-datacentre3.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/06-cleanup-ovn.yaml b/tests/kuttl/tests/ovn_nicmappings/08-cleanup-ovn.yaml similarity index 100% rename from tests/kuttl/tests/ovn_nicmappings/06-cleanup-ovn.yaml rename to tests/kuttl/tests/ovn_nicmappings/08-cleanup-ovn.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/06-errors.yaml b/tests/kuttl/tests/ovn_nicmappings/08-errors.yaml similarity index 100% rename from tests/kuttl/tests/ovn_nicmappings/06-errors.yaml rename to tests/kuttl/tests/ovn_nicmappings/08-errors.yaml diff --git a/tests/kuttl/tests/ovn_restart_flow/02-create-principal-bridge.yaml b/tests/kuttl/tests/ovn_restart_flow/02-create-principal-bridge.yaml new file mode 120000 index 00000000..90e436c3 --- /dev/null +++ b/tests/kuttl/tests/ovn_restart_flow/02-create-principal-bridge.yaml @@ -0,0 +1 @@ +../../common/create_nad.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_restart_flow/03-assert.yaml b/tests/kuttl/tests/ovn_restart_flow/03-assert.yaml index 461654ea..6ede65dc 120000 --- a/tests/kuttl/tests/ovn_restart_flow/03-assert.yaml +++ b/tests/kuttl/tests/ovn_restart_flow/03-assert.yaml @@ -1 +1 @@ -../../common/assert_sample_deployment.yaml \ No newline at end of file +../../common/assert_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_restart_flow/03-enable-ovncontroller.yaml b/tests/kuttl/tests/ovn_restart_flow/03-enable-ovncontroller.yaml new file mode 120000 index 00000000..9180c2a4 --- /dev/null +++ b/tests/kuttl/tests/ovn_restart_flow/03-enable-ovncontroller.yaml @@ -0,0 +1 @@ +../../common/attach_nic_mappings_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_restart_flow/02-add-bridge-and-flows.yaml b/tests/kuttl/tests/ovn_restart_flow/04-add-bridge-and-flows.yaml similarity index 100% rename from tests/kuttl/tests/ovn_restart_flow/02-add-bridge-and-flows.yaml rename to tests/kuttl/tests/ovn_restart_flow/04-add-bridge-and-flows.yaml diff --git a/tests/kuttl/tests/ovn_restart_flow/05-assert.yaml b/tests/kuttl/tests/ovn_restart_flow/05-assert.yaml new file mode 120000 index 00000000..461654ea --- /dev/null +++ b/tests/kuttl/tests/ovn_restart_flow/05-assert.yaml @@ -0,0 +1 @@ +../../common/assert_sample_deployment.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_restart_flow/03-delete-pods.yaml b/tests/kuttl/tests/ovn_restart_flow/05-delete-pods.yaml similarity index 100% rename from tests/kuttl/tests/ovn_restart_flow/03-delete-pods.yaml rename to tests/kuttl/tests/ovn_restart_flow/05-delete-pods.yaml diff --git a/tests/kuttl/tests/ovn_restart_flow/04-assert-flows-present.yaml b/tests/kuttl/tests/ovn_restart_flow/06-assert-flows-present.yaml similarity index 100% rename from tests/kuttl/tests/ovn_restart_flow/04-assert-flows-present.yaml rename to tests/kuttl/tests/ovn_restart_flow/06-assert-flows-present.yaml diff --git a/tests/kuttl/tests/ovn_restart_flow/06-cleanup-ovn.yaml b/tests/kuttl/tests/ovn_restart_flow/08-cleanup-ovn.yaml similarity index 100% rename from tests/kuttl/tests/ovn_restart_flow/06-cleanup-ovn.yaml rename to tests/kuttl/tests/ovn_restart_flow/08-cleanup-ovn.yaml diff --git a/tests/kuttl/tests/ovn_restart_flow/06-errors.yaml b/tests/kuttl/tests/ovn_restart_flow/08-errors.yaml similarity index 100% rename from tests/kuttl/tests/ovn_restart_flow/06-errors.yaml rename to tests/kuttl/tests/ovn_restart_flow/08-errors.yaml diff --git a/tests/kuttl/tests/ovn_scale/02-create-principal-bridge.yaml b/tests/kuttl/tests/ovn_scale/02-create-principal-bridge.yaml new file mode 120000 index 00000000..90e436c3 --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/02-create-principal-bridge.yaml @@ -0,0 +1 @@ +../../common/create_nad.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_scale/03-assert.yaml b/tests/kuttl/tests/ovn_scale/03-assert.yaml deleted file mode 100644 index d8b1a349..00000000 --- a/tests/kuttl/tests/ovn_scale/03-assert.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# -# Check for: -# -# - 1 OVNNorthd CR -# - 1 Pods for OVNNorthd CR -# - -apiVersion: ovn.openstack.org/v1beta1 -kind: OVNNorthd -metadata: - finalizers: - - openstack.org/ovnnorthd - name: ovnnorthd-sample -spec: - replicas: 1 -status: - readyCount: 1 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: ovn-northd -spec: - replicas: 1 -status: - availableReplicas: 1 diff --git a/tests/kuttl/tests/ovn_scale/03-assert.yaml b/tests/kuttl/tests/ovn_scale/03-assert.yaml new file mode 120000 index 00000000..6ede65dc --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/03-assert.yaml @@ -0,0 +1 @@ +../../common/assert_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_scale/03-enable-ovncontroller.yaml b/tests/kuttl/tests/ovn_scale/03-enable-ovncontroller.yaml new file mode 120000 index 00000000..9180c2a4 --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/03-enable-ovncontroller.yaml @@ -0,0 +1 @@ +../../common/attach_nic_mappings_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_scale/04-assert.yaml b/tests/kuttl/tests/ovn_scale/04-assert.yaml index f0644b74..13c6d81e 100644 --- a/tests/kuttl/tests/ovn_scale/04-assert.yaml +++ b/tests/kuttl/tests/ovn_scale/04-assert.yaml @@ -1,8 +1,8 @@ # # Check for: # -# - 1 OVNNorthd CR with no replicas -# - 0 Pods for OVNNorthd CR +# - 1 OVNNorthd CR +# - 3 Pods for OVNNorthd CR # apiVersion: ovn.openstack.org/v1beta1 @@ -12,11 +12,15 @@ metadata: - openstack.org/ovnnorthd name: ovnnorthd-sample spec: - replicas: 0 + replicas: 3 +status: + readyCount: 3 --- apiVersion: apps/v1 kind: Deployment metadata: name: ovn-northd spec: - replicas: 0 + replicas: 3 +status: + availableReplicas: 3 diff --git a/tests/kuttl/tests/ovn_scale/04-errors.yaml b/tests/kuttl/tests/ovn_scale/04-errors.yaml deleted file mode 100644 index b18be191..00000000 --- a/tests/kuttl/tests/ovn_scale/04-errors.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - annotations: - openshift.io/scc: restricted-v2 - labels: - service: ovn diff --git a/tests/kuttl/tests/ovn_scale/02-scale-ovnnorthd.yaml b/tests/kuttl/tests/ovn_scale/04-scale-ovnnorthd.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/02-scale-ovnnorthd.yaml rename to tests/kuttl/tests/ovn_scale/04-scale-ovnnorthd.yaml diff --git a/tests/kuttl/tests/ovn_scale/02-assert.yaml b/tests/kuttl/tests/ovn_scale/05-assert.yaml similarity index 73% rename from tests/kuttl/tests/ovn_scale/02-assert.yaml rename to tests/kuttl/tests/ovn_scale/05-assert.yaml index 13c6d81e..d8b1a349 100644 --- a/tests/kuttl/tests/ovn_scale/02-assert.yaml +++ b/tests/kuttl/tests/ovn_scale/05-assert.yaml @@ -2,7 +2,7 @@ # Check for: # # - 1 OVNNorthd CR -# - 3 Pods for OVNNorthd CR +# - 1 Pods for OVNNorthd CR # apiVersion: ovn.openstack.org/v1beta1 @@ -12,15 +12,15 @@ metadata: - openstack.org/ovnnorthd name: ovnnorthd-sample spec: - replicas: 3 + replicas: 1 status: - readyCount: 3 + readyCount: 1 --- apiVersion: apps/v1 kind: Deployment metadata: name: ovn-northd spec: - replicas: 3 + replicas: 1 status: - availableReplicas: 3 + availableReplicas: 1 diff --git a/tests/kuttl/tests/ovn_scale/03-scale-down-ovnnorthd.yaml b/tests/kuttl/tests/ovn_scale/05-scale-down-ovnnorthd.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/03-scale-down-ovnnorthd.yaml rename to tests/kuttl/tests/ovn_scale/05-scale-down-ovnnorthd.yaml diff --git a/tests/kuttl/tests/ovn_scale/06-assert.yaml b/tests/kuttl/tests/ovn_scale/06-assert.yaml new file mode 100644 index 00000000..f0644b74 --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/06-assert.yaml @@ -0,0 +1,22 @@ +# +# Check for: +# +# - 1 OVNNorthd CR with no replicas +# - 0 Pods for OVNNorthd CR +# + +apiVersion: ovn.openstack.org/v1beta1 +kind: OVNNorthd +metadata: + finalizers: + - openstack.org/ovnnorthd + name: ovnnorthd-sample +spec: + replicas: 0 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ovn-northd +spec: + replicas: 0 diff --git a/tests/kuttl/tests/ovn_scale/06-errors.yaml b/tests/kuttl/tests/ovn_scale/06-errors.yaml deleted file mode 120000 index 7314c155..00000000 --- a/tests/kuttl/tests/ovn_scale/06-errors.yaml +++ /dev/null @@ -1 +0,0 @@ -../../common/errors_cleanup_ovn.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_scale/06-errors.yaml b/tests/kuttl/tests/ovn_scale/06-errors.yaml new file mode 100644 index 00000000..b18be191 --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/06-errors.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + openshift.io/scc: restricted-v2 + labels: + service: ovn diff --git a/tests/kuttl/tests/ovn_scale/04-scale-down-zero-ovnnorthd.yaml b/tests/kuttl/tests/ovn_scale/06-scale-down-zero-ovnnorthd.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/04-scale-down-zero-ovnnorthd.yaml rename to tests/kuttl/tests/ovn_scale/06-scale-down-zero-ovnnorthd.yaml diff --git a/tests/kuttl/tests/ovn_scale/05-errors.yaml b/tests/kuttl/tests/ovn_scale/07-errors.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/05-errors.yaml rename to tests/kuttl/tests/ovn_scale/07-errors.yaml diff --git a/tests/kuttl/tests/ovn_scale/05-scale-down-pods-ovncontroller.yaml b/tests/kuttl/tests/ovn_scale/07-scale-down-pods-ovncontroller.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/05-scale-down-pods-ovncontroller.yaml rename to tests/kuttl/tests/ovn_scale/07-scale-down-pods-ovncontroller.yaml diff --git a/tests/kuttl/tests/ovn_scale/06-cleanup-ovn.yaml b/tests/kuttl/tests/ovn_scale/08-cleanup-ovn.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/06-cleanup-ovn.yaml rename to tests/kuttl/tests/ovn_scale/08-cleanup-ovn.yaml diff --git a/tests/kuttl/tests/ovn_scale/08-errors.yaml b/tests/kuttl/tests/ovn_scale/08-errors.yaml new file mode 120000 index 00000000..7314c155 --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/08-errors.yaml @@ -0,0 +1 @@ +../../common/errors_cleanup_ovn.yaml \ No newline at end of file