github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/importable_dvpg_test.go (about)

     1  //go:build network || nsxt || functional || openapi || ALL
     2  
     3  /*
     4   * Copyright 2023 VMware, Inc.  All rights reserved.  Licensed under the Apache v2 License.
     5   */
     6  
     7  package govcd
     8  
     9  import (
    10  	"fmt"
    11  	. "gopkg.in/check.v1"
    12  	"strings"
    13  )
    14  
    15  func (vcd *TestVCD) Test_VcenterImportableDvpg(check *C) {
    16  	if vcd.skipAdminTests {
    17  		check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
    18  	}
    19  	skipNoNsxtConfiguration(vcd, check)
    20  
    21  	if vcd.config.VCD.Nsxt.NsxtDvpg == "" {
    22  		check.Skip("No NSX-T Dvpg provided")
    23  	}
    24  
    25  	// Get all DVPGs
    26  	dvpgs, err := vcd.client.GetAllVcenterImportableDvpgs(nil)
    27  	check.Assert(err, IsNil)
    28  	check.Assert(len(dvpgs) > 0, Equals, true)
    29  
    30  	var compatibleDVPG []*VcenterImportableDvpg
    31  	for _, dvpg := range dvpgs {
    32  		// make a list of the port groups created with 'count' during the VCD configuration
    33  		if strings.HasPrefix(dvpg.VcenterImportableDvpg.BackingRef.Name, vcd.config.VCD.Nsxt.NsxtDvpg) {
    34  			compatibleDVPG = append(compatibleDVPG, dvpg)
    35  		}
    36  	}
    37  
    38  	// Get DVPG by name
    39  	dvpgByName, err := vcd.client.GetVcenterImportableDvpgByName(vcd.config.VCD.Nsxt.NsxtDvpg)
    40  	check.Assert(err, IsNil)
    41  	check.Assert(dvpgByName, NotNil)
    42  	check.Assert(dvpgByName.VcenterImportableDvpg.BackingRef.Name, Equals, vcd.config.VCD.Nsxt.NsxtDvpg)
    43  
    44  	// Get all DVPGs withing NSX-T VDC
    45  	nsxtVdc, err := vcd.org.GetVDCByName(vcd.config.VCD.Nsxt.Vdc, false)
    46  	check.Assert(err, IsNil)
    47  	check.Assert(nsxtVdc, NotNil)
    48  
    49  	allDvpgsWithingVdc, err := nsxtVdc.GetAllVcenterImportableDvpgs(nil)
    50  	check.Assert(err, IsNil)
    51  	check.Assert(len(allDvpgsWithingVdc) > 0, Equals, true)
    52  
    53  	// Get DVPG by name within NSX-T VDC
    54  	dvpgByNameWithinVdc, err := nsxtVdc.GetVcenterImportableDvpgByName(vcd.config.VCD.Nsxt.NsxtDvpg)
    55  	check.Assert(err, IsNil)
    56  	check.Assert(dvpgByNameWithinVdc, NotNil)
    57  	check.Assert(dvpgByNameWithinVdc.VcenterImportableDvpg.BackingRef.Name, Equals, vcd.config.VCD.Nsxt.NsxtDvpg)
    58  
    59  	check.Assert(len(compatibleDVPG) > 1, Equals, true,
    60  		Commentf("The VCD %s was not configured with multiple vsphere_distributed_port_group", vcd.config.Provider.Url))
    61  	// test that port group created with the same switch ID are compatible
    62  	foundSameParent := false
    63  	for _, dvpg := range dvpgs {
    64  		for _, other := range dvpgs {
    65  			if other == dvpg {
    66  				continue
    67  			}
    68  			if dvpg.Parent().ID == other.Parent().ID {
    69  				foundSameParent = true
    70  				break
    71  			}
    72  		}
    73  		if foundSameParent {
    74  			break
    75  		}
    76  	}
    77  	check.Assert(foundSameParent, Equals, true)
    78  	foundCompatible := false
    79  	for _, dvpg := range dvpgs {
    80  		if dvpg.UsableWith(compatibleDVPG...) {
    81  			foundCompatible = true
    82  			break
    83  		}
    84  	}
    85  	check.Assert(len(compatibleDVPG), Equals, 3)
    86  	check.Assert(foundCompatible, Equals, true)
    87  }