@@ -97,9 +97,7 @@ var _ = Describe("[rfe_id:3503][crit:medium][vendor:cnv-qe@redhat.com][level:com
9797 Expect (err ).ToNot (HaveOccurred (), "Should succeed getting the mutating webhook opt-mode" )
9898
9999 if vmWebhookOptMode == optInMode {
100- By ("opting in the namespace" )
101- err := addLabelsToNamespace (TestNamespace , map [string ]string {vmNamespaceOptInLabel : "allocate" })
102- Expect (err ).ToNot (HaveOccurred (), "should be able to add the namespace labels" )
100+ optInNamespaceForVMs (TestNamespace )
103101 }
104102 })
105103
@@ -671,14 +669,12 @@ var _ = Describe("[rfe_id:3503][crit:medium][vendor:cnv-qe@redhat.com][level:com
671669 })
672670 Context ("and another vm is created in an opted-in namespace" , func () {
673671 BeforeEach (func () {
674- By (fmt .Sprintf ("opting in the %s namespace" , managedNamespace ))
675- err := addLabelsToNamespace (managedNamespace , map [string ]string {vmNamespaceOptInLabel : "allocate" })
676- Expect (err ).ToNot (HaveOccurred (), "should be able to add the namespace labels" )
672+ optInNamespaceForVMs (managedNamespace )
677673
678674 By ("creating a vm in the opted-in namespace" )
679675 managedVM := CreateVMObject (managedNamespace , []kubevirtv1.Interface {newInterface ("br" , "" )},
680676 []kubevirtv1.Network {newNetwork ("br" )})
681- err = testClient .CRClient .Create (context .TODO (), managedVM )
677+ err : = testClient .CRClient .Create (context .TODO (), managedVM )
682678 Expect (err ).ToNot (HaveOccurred (), "Should succeed creating the vm" )
683679 allocatedMac = managedVM .Spec .Template .Spec .Domain .Devices .Interfaces [0 ].MacAddress
684680 })
@@ -732,19 +728,15 @@ var _ = Describe("[rfe_id:3503][crit:medium][vendor:cnv-qe@redhat.com][level:com
732728
733729 Context ("and kubemacpool is opted-out on a namespace" , func () {
734730 BeforeEach (func () {
735- By ("opting out the namespace" )
736- err := addLabelsToNamespace (TestNamespace , map [string ]string {vmNamespaceOptInLabel : "ignore" })
737- Expect (err ).ToNot (HaveOccurred (), "should be able to add the namespace labels" )
731+ optOutNamespaceForVMs (TestNamespace )
738732 })
739733 It ("should create a VM object without a MAC assigned" , func () {
740- var err error
741734 vm := CreateVMObject (TestNamespace , []kubevirtv1.Interface {newInterface ("br" , "" )},
742735 []kubevirtv1.Network {newNetwork ("br" )})
743-
744- err = testClient .CRClient .Create (context .TODO (), vm )
736+ err := testClient .CRClient .Create (context .TODO (), vm )
745737 Expect (err ).ToNot (HaveOccurred (), "Should succeed creating the vm" )
746738 Expect (vm .Spec .Template .Spec .Domain .Devices .Interfaces [0 ].MacAddress ).Should (Equal ("" ),
747- "should not allocated a mac to the opted-out vm" )
739+ "should not allocate a mac to the opted-out vm" )
748740 })
749741 })
750742
@@ -775,20 +767,12 @@ var _ = Describe("[rfe_id:3503][crit:medium][vendor:cnv-qe@redhat.com][level:com
775767 })
776768 Context ("and then when we opt-out the namespace" , func () {
777769 BeforeEach (func () {
778- By ("Adding namespace opt-out label to mark it as opted-out" )
779- err := addLabelsToNamespace (TestNamespace , map [string ]string {vmNamespaceOptInLabel : "ignore" })
780- Expect (err ).ToNot (HaveOccurred (), "should be able to add the namespace labels" )
781-
782- By ("Wait 5 seconds for namespace label clean-up to be propagated at server" )
783- time .Sleep (5 * time .Second )
770+ optOutNamespaceForVMs (TestNamespace )
784771 })
785772 AfterEach (func () {
786- By ("Removing namespace opt-out label to get kmp service again " )
773+ By ("Removing namespace opt-out label" )
787774 err := cleanNamespaceLabels (TestNamespace )
788775 Expect (err ).ToNot (HaveOccurred (), "should be able to remove the namespace labels" )
789-
790- By ("Wait 5 seconds for opt-in label at namespace to be propagated at server" )
791- time .Sleep (5 * time .Second )
792776 })
793777 It ("should able to be deleted" , func () {
794778 By ("Delete the VM after opt-out the namespace" )
@@ -841,8 +825,7 @@ var _ = Describe("[rfe_id:3503][crit:medium][vendor:cnv-qe@redhat.com][level:com
841825 Expect (net .ParseMAC (vm1 .Spec .Template .Spec .Domain .Devices .Interfaces [0 ].MacAddress )).ToNot (BeEmpty (),
842826 "Should successfully parse mac address" )
843827
844- err = addLabelsToNamespace (OtherTestNamespace , map [string ]string {vmNamespaceOptInLabel : "ignore" })
845- Expect (err ).ToNot (HaveOccurred (), "should be able to add the namespace labels" )
828+ optOutNamespaceForVMs (OtherTestNamespace )
846829
847830 By (fmt .Sprintf ("Adding a vm with the same Mac Address %s on the unmanaged namespace" , macAddress ))
848831 conflictingVM = CreateVMObject (OtherTestNamespace ,
@@ -899,27 +882,6 @@ var _ = Describe("[rfe_id:3503][crit:medium][vendor:cnv-qe@redhat.com][level:com
899882 })
900883})
901884
902- func newInterface (name , macAddress string ) kubevirtv1.Interface {
903- return kubevirtv1.Interface {
904- Name : name ,
905- InterfaceBindingMethod : kubevirtv1.InterfaceBindingMethod {
906- Bridge : & kubevirtv1.InterfaceBridge {},
907- },
908- MacAddress : macAddress ,
909- }
910- }
911-
912- func newNetwork (name string ) kubevirtv1.Network {
913- return kubevirtv1.Network {
914- Name : name ,
915- NetworkSource : kubevirtv1.NetworkSource {
916- Multus : & kubevirtv1.MultusNetwork {
917- NetworkName : name ,
918- },
919- },
920- }
921- }
922-
923885func deleteVMI (vm * kubevirtv1.VirtualMachine ) {
924886 By (fmt .Sprintf ("Delete vm %s/%s" , vm .Namespace , vm .Name ))
925887 err := testClient .CRClient .Delete (context .TODO (), vm )
0 commit comments