Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vnic tests #1887

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions acctests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ $ source devrc
This set of environment variables and setup should allow you to run most of the acceptance tests, current failing ones or ones skipped due to missing or misconfigured environment variables will be addressed ASAP (unfortunately there had been a large amount of technical debt built up around testing).

### Please Note
As for writing a few manual steps had to be taken to privately network the nested ESXis and add them to vSphere.
As for writing a few manual steps had to be taken to privately network the nested ESXis and add them to vSphere. You will need to let the first apply fail, then perform the steps and re-apply.

1. Delete vmk1 and manually recreate it attached to the new vSwitch (which runs on vmnic1)
1. Delete vmk1 and manually recreate it attached to the new vSwitch (which runs on vmnic1), give it an IP on the private subnet
2. Visit the physical ESXi web UI (likely the vCenter IP - 1) and power off the vcsa VM
3. Attach vmnet to the vcsa VM
4. Power on the vcsa VM
Expand Down
8 changes: 4 additions & 4 deletions acctests/vsphere/for-acceptance-tests.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ resource "vsphere_resource_pool" "pool" {
}

resource "vsphere_nas_datastore" "ds" {
name = var.VSPHERE_NFS_DS_NAME
name = var.VSPHERE_NFS_DS_NAME
host_system_ids = [vsphere_host.host1.id] // TODO: needs to be networked privately for nested ESXIs to connect to it
type = "NFS"
remote_hosts = [var.VSPHERE_NAS_HOST]
remote_path = "/nfs"
type = "NFS"
remote_hosts = [var.VSPHERE_NAS_HOST]
remote_path = "/nfs"
}

resource "vsphere_virtual_machine" "template" {
Expand Down
3 changes: 2 additions & 1 deletion acctests/vsphere/nested-esxi-template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resource "vsphere_vmfs_datastore" "nested-esxi" {
}

resource "vsphere_host_virtual_switch" "switch" {
name = "terraform-test" #
name = "terraform-test"
host_system_id = vsphere_host.host1.id

network_adapters = [var.VSPHERE_ESXI_TRUNK_NIC]
Expand Down Expand Up @@ -62,5 +62,6 @@ data "vsphere_ovf_vm_template" "nested-esxi" {
remote_ovf_url = "https://download3.vmware.com/software/vmw-tools/nested-esxi/Nested_ESXi7.0u3_Appliance_Template_v1.ova"
ovf_network_map = {
"${vsphere_host_port_group.pg.name}" = data.vsphere_network.pg.id
"VM Network" = data.vsphere_network.pg.id # second NIC for testing
}
}
27 changes: 7 additions & 20 deletions vsphere/resource_vsphere_vnic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func generateSteps(cfgFunc genTfConfig, netstack string) []resource.TestStep {
return out
}

func TestAccResourceVSphereVNic_dvs(t *testing.T) {
func TestAccResourceVSphereVNic_dvs_default(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
RunSweepers()
Expand All @@ -67,7 +67,7 @@ func TestAccResourceVSphereVNic_dvs_vmotion(t *testing.T) {
})
}

func TestAccResourceVSphereVNic_hvs(t *testing.T) {
func TestAccResourceVSphereVNic_hvs_default(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
RunSweepers()
Expand Down Expand Up @@ -201,7 +201,7 @@ func testAccVsphereVNicNetworkSettings(name, ipv4State, ipv6State, netstack stri
for _, ipv6addr := range vnic.Spec.Ip.IpV6Config.IpV6Address {
if strings.EqualFold(ipv6addr.IpAddress, ip) {
if ipv6addr.PrefixLength != int32(prefix) ||
strings.EqualFold(routeConfig.IpV6DefaultGateway, gw) {
!strings.EqualFold(routeConfig.IpV6DefaultGateway, gw) {
return fmt.Errorf(
"ipv6 network error, static config mismatch. prefix length %d vs %d, gw %s vs %s",
prefix, ipv6addr.PrefixLength,
Expand Down Expand Up @@ -272,18 +272,9 @@ func testaccvspherevnicconfigHvs(netConfig string) string {
datacenter_id = data.vsphere_datacenter.rootdc1.id
}


resource "vsphere_host_virtual_switch" "hvs1" {
name = "hashi-dc_HPG0"
host_system_id = data.vsphere_host.h1.id
network_adapters = ["%s", "%s"]
active_nics = ["%s"]
standby_nics = ["%s"]
}

resource "vsphere_host_port_group" "p1" {
name = "ko-pg"
virtual_switch_name = vsphere_host_virtual_switch.hvs1.name
virtual_switch_name = "vSwitch0"
host_system_id = data.vsphere_host.h1.id
}

Expand All @@ -294,10 +285,6 @@ func testaccvspherevnicconfigHvs(netConfig string) string {
}
`, testhelper.CombineConfigs(testhelper.ConfigDataRootDC1(), testhelper.ConfigDataRootPortGroup1()),
os.Getenv("TF_VAR_VSPHERE_ESXI3"),
os.Getenv("TF_VAR_VSPHERE_HOST_NIC0"),
os.Getenv("TF_VAR_VSPHERE_HOST_NIC1"),
os.Getenv("TF_VAR_VSPHERE_HOST_NIC0"),
os.Getenv("TF_VAR_VSPHERE_HOST_NIC1"),
netConfig)
}

Expand All @@ -309,7 +296,7 @@ func testaccvspherevnicconfigDvs(netConfig string) string {
name = "hashi-dc_DVPG0"
datacenter_id = data.vsphere_datacenter.rootdc1.id
host {
host_system_id = data.vsphere_host.roothost1.id
host_system_id = data.vsphere_host.roothost2.id
devices = ["%s"]
}
}
Expand All @@ -321,14 +308,14 @@ func testaccvspherevnicconfigDvs(netConfig string) string {
}

resource "vsphere_vnic" "v1" {
host = data.vsphere_host.roothost1.id
host = data.vsphere_host.roothost2.id
distributed_switch_port = vsphere_distributed_virtual_switch.d1.id
distributed_port_group = vsphere_distributed_port_group.p1.id
%s
}
`, testhelper.CombineConfigs(
testhelper.ConfigDataRootDC1(),
testhelper.ConfigDataRootHost1(),
testhelper.ConfigDataRootHost2(),
),
os.Getenv("TF_VAR_VSPHERE_HOST_NIC1"),
netConfig)
Expand Down