github.com/vmware/govmomi@v0.51.0/object/host_system_test.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package object_test
     6  
     7  import (
     8  	"bytes"
     9  	"context"
    10  	"encoding/pem"
    11  	"testing"
    12  
    13  	"github.com/vmware/govmomi/find"
    14  	"github.com/vmware/govmomi/simulator"
    15  	"github.com/vmware/govmomi/simulator/esx"
    16  	"github.com/vmware/govmomi/vim25"
    17  	"github.com/vmware/govmomi/vim25/mo"
    18  )
    19  
    20  func TestHostSystemManagementIPs(t *testing.T) {
    21  	simulator.Test(func(ctx context.Context, c *vim25.Client) {
    22  		host, err := find.NewFinder(c).HostSystem(ctx, "DC0_C0_H0")
    23  		if err != nil {
    24  			t.Fatal(err)
    25  		}
    26  
    27  		ips, err := host.ManagementIPs(ctx)
    28  		if err != nil {
    29  			t.Fatal(err)
    30  		}
    31  		if len(ips) != 1 {
    32  			t.Fatal("no mgmt ip found")
    33  		}
    34  		if ips[0].String() != "127.0.0.1" {
    35  			t.Fatalf("Expected management ip %s, got %s", "127.0.0.1", ips[0].String())
    36  		}
    37  
    38  		// These fields can be nil while ESX is being upgraded
    39  		hs := simulator.Map(ctx).Get(host.Reference()).(*simulator.HostSystem)
    40  		tests := []func(){
    41  			func() { hs.Config.VirtualNicManagerInfo = nil },
    42  			func() { hs.Config = nil },
    43  		}
    44  
    45  		for _, f := range tests {
    46  			f()
    47  			ips, err = host.ManagementIPs(ctx)
    48  			if err != nil {
    49  				t.Fatal(err)
    50  			}
    51  			if len(ips) != 0 {
    52  				t.Fatal("expected zero ips")
    53  			}
    54  		}
    55  	})
    56  }
    57  
    58  func TestHostSystemConfig(t *testing.T) {
    59  	simulator.Test(func(ctx context.Context, c *vim25.Client) {
    60  		host, err := find.NewFinder(c).HostSystem(ctx, "DC0_C0_H0")
    61  		if err != nil {
    62  			t.Fatal(err)
    63  		}
    64  
    65  		var props mo.HostSystem
    66  		if err := host.Properties(ctx, host.Reference(), []string{"config"}, &props); err != nil {
    67  			t.Fatal(err)
    68  		}
    69  
    70  		if !bytes.Equal(props.Config.Certificate, esx.HostConfigInfo.Certificate) {
    71  			t.Errorf("certificate=%s", string(props.Config.Certificate))
    72  		}
    73  
    74  		b, _ := pem.Decode(props.Config.Certificate)
    75  		if b == nil {
    76  			t.Error("failed to parse certificate")
    77  		}
    78  	})
    79  }