44 "strings"
55 "testing"
66
7- "github.com/sirupsen/logrus"
87 "github.com/stretchr/testify/assert"
98 v1 "k8s.io/api/core/v1"
109 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -547,7 +546,6 @@ func TestCreateHostNetworkConfig(t *testing.T) {
547546 validator := NewHostNetworkConfigValidator (nadCache , cnCache , hncCache , vcCache , vsCache , nodeCache , vmCache )
548547
549548 err := validator .Create (nil , tc .newHostNetworkConfig )
550- logrus .Infof ("test case %s returned error: %v" , tc .name , err )
551549 assert .True (t , tc .returnErr == (err != nil ))
552550 if tc .returnErr {
553551 assert .NotNil (t , err )
@@ -932,7 +930,6 @@ func TestUpdateHostNetworkConfig(t *testing.T) {
932930 validator := NewHostNetworkConfigValidator (nadCache , cnCache , hncCache , vcCache , vsCache , nodeCache , vmCache )
933931
934932 err := validator .Update (nil , tc .currentHostNetworkConfig , tc .newHostNetworkConfig )
935- logrus .Infof ("test case %s returned error: %v" , tc .name , err )
936933 assert .True (t , tc .returnErr == (err != nil ))
937934 if tc .returnErr {
938935 assert .NotNil (t , err )
@@ -947,13 +944,10 @@ func TestDeleteHostNetworkConfig(t *testing.T) {
947944 name string
948945 returnErr bool
949946 errKey string
950- currentCN * networkv1.ClusterNetwork
951- currentNAD * cniv1.NetworkAttachmentDefinition
952947 currentHostNetworkConfig * networkv1.HostNetworkConfig
953- currentVM * kubevirtv1.VirtualMachine
954948 }{
955949 {
956- name : "delete hostnetworkconfig successfully when not used by any overlay VMs " ,
950+ name : "delete hostnetworkconfig successfully" ,
957951 returnErr : false ,
958952 errKey : "" ,
959953 currentHostNetworkConfig : & networkv1.HostNetworkConfig {
@@ -962,62 +956,15 @@ func TestDeleteHostNetworkConfig(t *testing.T) {
962956 VlanID : 2012 ,
963957 Mode : "static" ,
964958 HostIPs : map [string ]networkv1.IPAddr {"node1" : "192.168.1.100/24" },
965- Underlay : true ,
959+ Underlay : false ,
966960 },
967961 },
968962 },
969963 {
970- name : "cannot delete hostnetworkconfig when used by overlay VMs " ,
964+ name : "cannot delete hostnetworkconfig when underlay is enabled " ,
971965 returnErr : true ,
972- errKey : "it's still used by VM(s)" ,
973- currentCN : & networkv1.ClusterNetwork {
974- ObjectMeta : metav1.ObjectMeta {
975- Name : testCnName ,
976- Annotations : map [string ]string {"test" : "test" },
977- },
978- },
979- currentNAD : & cniv1.NetworkAttachmentDefinition {
980- ObjectMeta : metav1.ObjectMeta {
981- Name : testNadName ,
982- Namespace : testNamespace ,
983- Annotations : map [string ]string {"test" : "test" },
984- Labels : map [string ]string {utils .KeyClusterNetworkLabel : testCnName , utils .KeyNetworkType : string (utils .OverlayNetwork )},
985- },
986- Spec : cniv1.NetworkAttachmentDefinitionSpec {
987- Config : testNadConfig ,
988- },
989- },
990- currentVM : & kubevirtv1.VirtualMachine {
991- ObjectMeta : metav1.ObjectMeta {
992- Name : testVMName ,
993- Namespace : testNamespace ,
994- },
995- Spec : kubevirtv1.VirtualMachineSpec {
996- Template : & kubevirtv1.VirtualMachineInstanceTemplateSpec {
997- Spec : kubevirtv1.VirtualMachineInstanceSpec {
998- Networks : []kubevirtv1.Network {
999- {
1000- Name : "nic-1" ,
1001- NetworkSource : kubevirtv1.NetworkSource {
1002- Multus : & kubevirtv1.MultusNetwork {
1003- NetworkName : testNamespace + "/" + testNadName , // same with nad namesapce
1004- },
1005- },
1006- },
1007- },
1008- Domain : kubevirtv1.DomainSpec {
1009- Devices : kubevirtv1.Devices {
1010- Interfaces : []kubevirtv1.Interface {
1011- {
1012- Name : "nic-1" ,
1013- },
1014- },
1015- },
1016- },
1017- }, // vmi.spec
1018- },
1019- },
1020- },
966+ errKey : "disable underlay first" ,
967+
1021968 currentHostNetworkConfig : & networkv1.HostNetworkConfig {
1022969 Spec : networkv1.HostNetworkConfigSpec {
1023970 ClusterNetwork : testCnName ,
@@ -1044,33 +991,10 @@ func TestDeleteHostNetworkConfig(t *testing.T) {
1044991
1045992 // client to inject test data
1046993 cnCache := fakeclients .ClusterNetworkCache (nchclientset .NetworkV1beta1 ().ClusterNetworks )
1047- cnClient := fakeclients .ClusterNetworkClient (nchclientset .NetworkV1beta1 ().ClusterNetworks )
1048994 vcCache := fakeclients .VlanConfigCache (nchclientset .NetworkV1beta1 ().VlanConfigs )
1049995 vsCache := fakeclients .VlanStatusCache (nchclientset .NetworkV1beta1 ().VlanStatuses )
1050996 nodeCache := fakeclients .NodeCache (nchclientset .CoreV1 ().Nodes )
1051997
1052- if tc .currentVM != nil {
1053- err := nchclientset .Tracker ().Add (tc .currentVM )
1054- assert .Nil (t , err , "mock resource vm should add into fake controller tracker" )
1055- }
1056-
1057- if tc .currentCN != nil {
1058- _ , err := cnClient .Create (tc .currentCN )
1059- assert .NoError (t , err )
1060- }
1061-
1062- if tc .currentNAD != nil {
1063- nadGvr := schema.GroupVersionResource {
1064- Group : "k8s.cni.cncf.io" ,
1065- Version : "v1" ,
1066- Resource : "network-attachment-definitions" ,
1067- }
1068-
1069- if err := nchclientset .Tracker ().Create (nadGvr , tc .currentNAD .DeepCopy (), tc .currentNAD .Namespace ); err != nil {
1070- t .Fatalf ("failed to add nad %+v" , tc .currentNAD )
1071- }
1072- }
1073-
1074998 if tc .currentHostNetworkConfig != nil {
1075999 hncClient := fakeclients .HostNetworkConfigClient (nchclientset .NetworkV1beta1 ().HostNetworkConfigs )
10761000 _ , err := hncClient .Create (tc .currentHostNetworkConfig )
0 commit comments