Skip to content

Commit

Permalink
e2e: add spidermultusconfig e2e for spiderpool (#2222)
Browse files Browse the repository at this point in the history
Signed-off-by: ty-dc <[email protected]>
  • Loading branch information
ty-dc authored Aug 25, 2023
1 parent a695eef commit 422ce64
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 11 deletions.
22 changes: 11 additions & 11 deletions test/doc/spidermultus.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
| Case ID | Title | Priority | Smoke | Status | Other |
| ------- | ------------------------------------------------------------ | -------- | ----- | ------ | ----- |
| M00001 | testing creating spiderMultusConfig with cniType: macvlan and checking the net-attach-conf config if works | p1 | smoke | done | |
| M00002 | testing creating spiderMultusConfig with cniType: ipvlan and checking the net-attach-conf config if works | p1 | smoke | | |
| M00003 | testing creating spiderMultusConfig with cniType: sriov and checking the net-attach-conf config if works | p1 | smoke | | |
| M00004 | testing creating spiderMultusConfig with cniType: custom and checking the net-attach-conf config if works | p1 | smoke | | |
| M00005 | testing creating spiderMultusConfig with cniType: custom and invalid json config, expect error happened | p2 | | | |
| M00002 | testing creating spiderMultusConfig with cniType: ipvlan and checking the net-attach-conf config if works | p1 | smoke | done | |
| M00003 | testing creating spiderMultusConfig with cniType: sriov and checking the net-attach-conf config if works | p1 | smoke | done | |
| M00004 | testing creating spiderMultusConfig with cniType: custom and checking the net-attach-conf config if works | p1 | smoke | done | |
| M00005 | testing creating spiderMultusConfig with cniType: custom and invalid json config, expect error happened | p2 | | done | |
| M00006 | testing creating spiderMultusConfig with cniType: macvlan with vlanId with one master and checking the net-attach-conf config if works | p1 | smoke | | |
| M00007 | testing creating spiderMultusConfig with cniType: macvlan with vlanId with two master with bond config and checking the net-attach-conf config if works | p1 | smoke | | |
| M00008 | testing creating spiderMultusConfig with cniType: ovs with vlanId with and checking the net-attach-conf config if works | p1 | smoke | | |
Expand All @@ -16,12 +16,12 @@
| M00012 | Update spidermultusConfig, the corresponding multus net-attach-conf will also be updated | p2 | | | |
| M00013 | Update spidermultusConfig: add new bond config | p1 | smoke | | |
| M00014 | Manually delete the net-attach-conf of multus, it will be created automatically | p1 | | done | |
| M00015 | Customize net-attach-conf name via annotation multus.spidernet.io/cr-name | p2 | | | |
| M00016 | webhook validation for multus.spidernet.io/cr-name | p3 | | | |
| M00017 | Change net-attach-conf version via annotation multus.spidernet.io/cni-version | p2 | | | |
| M00018 | webhook validation for multus.spidernet.io/cni-version | p3 | | | |
| M00015 | Customize net-attach-conf name via annotation multus.spidernet.io/cr-name | p2 | | done | |
| M00016 | webhook validation for multus.spidernet.io/cr-name | p3 | | done | |
| M00017 | Change net-attach-conf version via annotation multus.spidernet.io/cni-version | p2 | | done | |
| M00018 | webhook validation for multus.spidernet.io/cni-version | p3 | | done | |
| M00019 | Set enableCoordinator to false, multus cr will not generate coordinator configuration | p3 | | | |
| M00020 | Already have multus cr, spidermultus should take care of it | p3 | | | |
| M00020 | Already have multus cr, spidermultus should take care of it | p3 | | done | |
| M00021 | Multiple annotations of spidermultus should be inherited by multus CR | p3 | | | |
| M00022 | The value of webhook verification cniType is inconsistent with cniConf | p3 | | | |
| M00023 | vlan is not in the range of 0-4094 and will not be created | p3 | | | |
| M00022 | The value of webhook verification cniType is inconsistent with cniConf | p3 | | done | |
| M00023 | vlan is not in the range of 0-4094 and will not be created | p3 | | done | |
113 changes: 113 additions & 0 deletions test/e2e/spidermultus/spidermultus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package spidermultus_test

import (
"encoding/json"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
api_errors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -12,6 +14,7 @@ import (

v1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
"github.com/spidernet-io/spiderpool/pkg/constant"
"github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1"
spiderpoolv2beta1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1"
"github.com/spidernet-io/spiderpool/test/e2e/common"
)
Expand Down Expand Up @@ -319,4 +322,114 @@ var _ = Describe("test spidermultus", Label("spiderMultus", "overlay"), func() {
GinkgoWriter.Printf("should fail to create, the error is: %v \n", err.Error())
Expect(err).To(HaveOccurred())
})

It("testing creating spiderMultusConfig with cniType: ipvlan and checking the net-attach-conf config if works", Label("M00002"), func() {
var smcName string = "ipvlan-" + common.GenerateString(10, true)

// Define Spidermultus cr with ipvlan
smc := &spiderpoolv2beta1.SpiderMultusConfig{
ObjectMeta: metav1.ObjectMeta{
Name: smcName,
Namespace: namespace,
},
Spec: spiderpoolv2beta1.MultusCNIConfigSpec{
CniType: "ipvlan",
IPVlanConfig: &spiderpoolv2beta1.SpiderIPvlanCniConfig{
Master: []string{common.NIC3},
},
},
}
GinkgoWriter.Printf("spidermultus cr with ipvlan: %+v \n", smc)
Expect(frame.CreateSpiderMultusInstance(smc)).NotTo(HaveOccurred())

Eventually(func() bool {
ipvlanMultusConfig, err := frame.GetMultusInstance(smcName, namespace)
GinkgoWriter.Printf("auto-generated ipvlan nad configuration %+v \n", ipvlanMultusConfig)
if api_errors.IsNotFound(err) {
return false
}
// The automatically generated multus configuration should be associated with spidermultus
if ipvlanMultusConfig.ObjectMeta.OwnerReferences[0].Kind != constant.KindSpiderMultusConfig {
return false
}
return true
}, common.SpiderSyncMultusTime, common.ForcedWaitingTime).Should(BeTrue())
})

It("testing creating spiderMultusConfig with cniType: sriov and checking the net-attach-conf config if works", Label("M00003"), func() {
var smcName string = "sriov-" + common.GenerateString(10, true)

// Define Spidermultus cr with sriov
smc := &spiderpoolv2beta1.SpiderMultusConfig{
ObjectMeta: metav1.ObjectMeta{
Name: smcName,
Namespace: namespace,
},
Spec: spiderpoolv2beta1.MultusCNIConfigSpec{
CniType: "sriov",
SriovConfig: &spiderpoolv2beta1.SpiderSRIOVCniConfig{
ResourceName: "sriov-test",
},
},
}
GinkgoWriter.Printf("spidermultus cr with sriov: %+v \n", smc)
Expect(frame.CreateSpiderMultusInstance(smc)).NotTo(HaveOccurred())

Eventually(func() bool {
sriovMultusConfig, err := frame.GetMultusInstance(smcName, namespace)
GinkgoWriter.Printf("auto-generated sriov nad configuration %+v \n", sriovMultusConfig)
if api_errors.IsNotFound(err) {
return false
}
// The automatically generated multus configuration should be associated with spidermultus
if sriovMultusConfig.ObjectMeta.OwnerReferences[0].Kind != constant.KindSpiderMultusConfig {
return false
}
return true
}, common.SpiderSyncMultusTime, common.ForcedWaitingTime).Should(BeTrue())
})

It("testing creating spiderMultusConfig with cniType: custom and invalid/valid json config", Label("M00005", "M00004"), func() {
var smcName string = "custom-multus" + common.GenerateString(10, true)

invalidJson := `{ "invalid" }`
// Define Spidermultus cr with invalid json config
smc := &spiderpoolv2beta1.SpiderMultusConfig{
ObjectMeta: metav1.ObjectMeta{
Name: smcName,
Namespace: namespace,
},
Spec: v2beta1.MultusCNIConfigSpec{
CniType: "custom",
CustomCNIConfig: &invalidJson,
},
}

GinkgoWriter.Printf("spidermultus cr with invalid json config: %+v \n", smc)
err := frame.CreateSpiderMultusInstance(smc)
GinkgoWriter.Printf("failed to create spidermultusconfig with invalid json config, error is %v", err)
Expect(err).To(HaveOccurred())

// Define valid json config
validString := `{"cniVersion":"0.3.1","name":"macvlan-conf","plugins":[{"type":"macvlan","master":"eth0","mode":"bridge","ipam":{"type":"spiderpool",{"mode":"auto","type":"coordinator"}]}`
validJson, err := json.Marshal(validString)
Expect(err).NotTo(HaveOccurred())
validJsonString := string(validJson)
smc.Spec.CustomCNIConfig = &validJsonString
GinkgoWriter.Printf("spidermultus cr with invalid json config: %+v \n", smc)
Expect(frame.CreateSpiderMultusInstance(smc)).NotTo(HaveOccurred(), "failed to create spidermultusconfig with valid json config, error is %v", err)

Eventually(func() bool {
customMultusConfig, err := frame.GetMultusInstance(smcName, namespace)
GinkgoWriter.Printf("auto-generated custom nad configuration %+v \n", customMultusConfig)
if api_errors.IsNotFound(err) {
return false
}
// The automatically generated multus configuration should be associated with spidermultus
if customMultusConfig.ObjectMeta.OwnerReferences[0].Kind != constant.KindSpiderMultusConfig {
return false
}
return true
}, common.SpiderSyncMultusTime, common.ForcedWaitingTime).Should(BeTrue())
})
})

0 comments on commit 422ce64

Please sign in to comment.