From 0102c826ca95225dad70aafbbef87ddff8e2905a Mon Sep 17 00:00:00 2001 From: Levente Kale Date: Tue, 30 Jul 2019 22:41:04 +0200 Subject: [PATCH] Added new test cases toround about all the negative validation cases reg allocation pool, and TNet API. --- pkg/admit/validators.go | 4 +- test/uts/admit_tests/netadmit_test.go | 53 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/pkg/admit/validators.go b/pkg/admit/validators.go index 88aceb4d..79e103d8 100644 --- a/pkg/admit/validators.go +++ b/pkg/admit/validators.go @@ -120,14 +120,14 @@ func validateTenantNetRules(oldManifest, newManifest *danmtypes.DanmNet, opType if opType == admissionv1.Create && (newManifest.Spec.Options.Vxlan != 0 || newManifest.Spec.Options.Vlan != 0) { - return errors.New("Manually configuring vlan, or vxlan attributes is not allowed for TenantNetworks!") + return errors.New("Manually configuring Spec.Options.vlan, or Spec.Options.vxlan attributes is not allowed for TenantNetworks!") } if opType == admissionv1.Update && (newManifest.Spec.Options.Device != oldManifest.Spec.Options.Device || newManifest.Spec.Options.DevicePool != oldManifest.Spec.Options.DevicePool || newManifest.Spec.Options.Vxlan != oldManifest.Spec.Options.Vxlan || newManifest.Spec.Options.Vlan != oldManifest.Spec.Options.Vlan) { - return errors.New("Manually changing any one of host_device, vlan, or vxlan attributes is not allowed for TenantNetworks!") + return errors.New("Manually changing any one of Spec.Options. host_device, devie_pool, vlan, or vxlan attributes is not allowed for TenantNetworks!") } return nil } diff --git a/test/uts/admit_tests/netadmit_test.go b/test/uts/admit_tests/netadmit_test.go index 852c9c6f..e9916eaa 100644 --- a/test/uts/admit_tests/netadmit_test.go +++ b/test/uts/admit_tests/netadmit_test.go @@ -73,6 +73,27 @@ var validateNetworkTcs = []struct { {"IpvlanWithDevicePlusDpDNet", "", "ipvlan-with-dp-and-device", DnetType, "", nil, true, "empty", 0}, {"IpvlanWithDevicePlusDpTNet", "", "ipvlan-with-dp-and-device", TnetType, "", nil, true, "empty", 0}, {"IpvlanWithDevicePlusDpCNet", "", "ipvlan-with-dp-and-device", CnetType, "", nil, true, "empty", 0}, + {"AllocDuringCreateDNet", "", "alloc-without-cidr", DnetType, v1beta1.Create, nil, true, "empty", 0}, + {"AllocDuringCreateTNet", "", "alloc-without-cidr", TnetType, v1beta1.Create, nil, true, "empty", 0}, + {"AllocDuringCreateCNet", "", "alloc-without-cidr", CnetType, v1beta1.Create, nil, true, "empty", 0}, + {"AllocationPoolWithoutCidrDNet", "", "alloc-without-cidr", DnetType, v1beta1.Update, nil, true, "empty", 0}, + {"AllocationPoolWithoutCidrTNet", "", "alloc-without-cidr", TnetType, v1beta1.Update, nil, true, "empty", 0}, + {"AllocationPoolWithoutCidrCNet", "", "alloc-without-cidr", CnetType, v1beta1.Update, nil, true, "empty", 0}, + {"AllocationPoolStartOutsideCidrDNet", "", "allocstart-outside-cidr", DnetType, "", nil, true, "empty", 0}, + {"AllocationPoolStartOutsideCidrTNet", "", "allocstart-outside-cidr", TnetType, "", nil, true, "empty", 0}, + {"AllocationPoolStartOutsideCidrCNet", "", "allocstart-outside-cidr", CnetType, "", nil, true, "empty", 0}, + {"AllocationPoolEndOutsideCidrDNet", "", "allocend-outside-cidr", DnetType, "", nil, true, "empty", 0}, + {"AllocationPoolEndOutsideCidrTNet", "", "allocend-outside-cidr", TnetType, "", nil, true, "empty", 0}, + {"AllocationPoolEndOutsideCidrCNet", "", "allocend-outside-cidr", CnetType, "", nil, true, "empty", 0}, + {"AllocationPoolWithoutAnyIpDNet", "", "no-free-ip", DnetType, "", nil, true, "empty", 0}, + {"AllocationPoolWithoutAnyIpTNet", "", "no-free-ip", TnetType, "", nil, true, "empty", 0}, + {"AllocationPoolWithoutAnyIpCNet", "", "no-free-ip", CnetType, "", nil, true, "empty", 0}, + {"CreateWithVlanTNet", "", "tnet-vlan", TnetType, v1beta1.Create, nil, true, "empty", 0}, + {"CreateWithVxlanTNet", "", "tnet-vxlan", TnetType, v1beta1.Create, nil, true, "empty", 0}, + {"UpdateWithVlanTNet", "", "tnet-vlan", TnetType, v1beta1.Update, nil, true, "empty", 0}, + {"UpdateWithVxlanTNet", "", "tnet-vxlan", TnetType, v1beta1.Update, nil, true, "empty", 0}, + {"UpdateWithDeviceTNet", "", "tnet-device", TnetType, v1beta1.Update, nil, true, "empty", 0}, + {"UpdateWithDevicePoolTNet", "", "tnet-dp", TnetType, v1beta1.Update, nil, true, "empty", 0}, } var ( @@ -140,6 +161,38 @@ var ( ObjectMeta: meta_v1.ObjectMeta {Name: "ipvlan-with-dp-and-device"}, Spec: danmtypes.DanmNetSpec{NetworkType: "ipvlan", NetworkID: "nanomsg", Options: danmtypes.DanmNetOption{DevicePool: "nokia.k8s.io/sriov_ens1f1", Device: "ens1f1"}}, }, + danmtypes.DanmNet { + ObjectMeta: meta_v1.ObjectMeta {Name: "alloc-without-cidr"}, + Spec: danmtypes.DanmNetSpec{NetworkType: "ipvlan", NetworkID: "nanomsg", Options: danmtypes.DanmNetOption{Alloc: "gAAAAAAAAAAAAAAE", Pool: danmtypes.IP4Pool{Start: "192.168.1.1"}}}, + }, + danmtypes.DanmNet { + ObjectMeta: meta_v1.ObjectMeta {Name: "allocstart-outside-cidr"}, + Spec: danmtypes.DanmNetSpec{NetworkType: "ipvlan", NetworkID: "nanomsg", Options: danmtypes.DanmNetOption{Pool: danmtypes.IP4Pool{Start: "192.168.1.63"}, Cidr: "192.168.1.64/26"}}, + }, + danmtypes.DanmNet { + ObjectMeta: meta_v1.ObjectMeta {Name: "allocend-outside-cidr"}, + Spec: danmtypes.DanmNetSpec{NetworkType: "ipvlan", NetworkID: "nanomsg", Options: danmtypes.DanmNetOption{Pool: danmtypes.IP4Pool{End: "192.168.1.128"}, Cidr: "192.168.1.64/26"}}, + }, + danmtypes.DanmNet { + ObjectMeta: meta_v1.ObjectMeta {Name: "no-free-ip"}, + Spec: danmtypes.DanmNetSpec{NetworkType: "ipvlan", NetworkID: "nanomsg", Options: danmtypes.DanmNetOption{Pool: danmtypes.IP4Pool{Start: "192.168.1.127", End: "192.168.1.127"}, Cidr: "192.168.1.64/26"}}, + }, + danmtypes.DanmNet { + ObjectMeta: meta_v1.ObjectMeta {Name: "tnet-vlan"}, + Spec: danmtypes.DanmNetSpec{NetworkType: "ipvlan", NetworkID: "nanomsg", Options: danmtypes.DanmNetOption{Vlan: 50}}, + }, + danmtypes.DanmNet { + ObjectMeta: meta_v1.ObjectMeta {Name: "tnet-vxlan"}, + Spec: danmtypes.DanmNetSpec{NetworkType: "ipvlan", NetworkID: "nanomsg", Options: danmtypes.DanmNetOption{Vxlan: 50}}, + }, + danmtypes.DanmNet { + ObjectMeta: meta_v1.ObjectMeta {Name: "tnet-device"}, + Spec: danmtypes.DanmNetSpec{NetworkType: "ipvlan", NetworkID: "nanomsg", Options: danmtypes.DanmNetOption{Device: "ens3"}}, + }, + danmtypes.DanmNet { + ObjectMeta: meta_v1.ObjectMeta {Name: "tnet-dp"}, + Spec: danmtypes.DanmNetSpec{NetworkType: "ipvlan", NetworkID: "nanomsg", Options: danmtypes.DanmNetOption{DevicePool: "nokia.k8s.io/sriov_ens1f0"}}, + }, } )