github.com/vmware/govmomi@v0.43.0/object/host_system_test.go (about) 1 /* 2 Copyright (c) 2019-2024 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package object_test 18 19 import ( 20 "bytes" 21 "context" 22 "encoding/pem" 23 "testing" 24 25 "github.com/vmware/govmomi/find" 26 "github.com/vmware/govmomi/simulator" 27 "github.com/vmware/govmomi/simulator/esx" 28 "github.com/vmware/govmomi/vim25" 29 "github.com/vmware/govmomi/vim25/mo" 30 ) 31 32 func TestHostSystemManagementIPs(t *testing.T) { 33 simulator.Test(func(ctx context.Context, c *vim25.Client) { 34 host, err := find.NewFinder(c).HostSystem(ctx, "DC0_C0_H0") 35 if err != nil { 36 t.Fatal(err) 37 } 38 39 ips, err := host.ManagementIPs(ctx) 40 if err != nil { 41 t.Fatal(err) 42 } 43 if len(ips) != 1 { 44 t.Fatal("no mgmt ip found") 45 } 46 if ips[0].String() != "127.0.0.1" { 47 t.Fatalf("Expected management ip %s, got %s", "127.0.0.1", ips[0].String()) 48 } 49 50 // These fields can be nil while ESX is being upgraded 51 hs := simulator.Map.Get(host.Reference()).(*simulator.HostSystem) 52 tests := []func(){ 53 func() { hs.Config.VirtualNicManagerInfo = nil }, 54 func() { hs.Config = nil }, 55 } 56 57 for _, f := range tests { 58 f() 59 ips, err = host.ManagementIPs(ctx) 60 if err != nil { 61 t.Fatal(err) 62 } 63 if len(ips) != 0 { 64 t.Fatal("expected zero ips") 65 } 66 } 67 }) 68 } 69 70 func TestHostSystemConfig(t *testing.T) { 71 simulator.Test(func(ctx context.Context, c *vim25.Client) { 72 host, err := find.NewFinder(c).HostSystem(ctx, "DC0_C0_H0") 73 if err != nil { 74 t.Fatal(err) 75 } 76 77 var props mo.HostSystem 78 if err := host.Properties(ctx, host.Reference(), []string{"config"}, &props); err != nil { 79 t.Fatal(err) 80 } 81 82 if !bytes.Equal(props.Config.Certificate, esx.HostConfigInfo.Certificate) { 83 t.Errorf("certificate=%s", string(props.Config.Certificate)) 84 } 85 86 b, _ := pem.Decode(props.Config.Certificate) 87 if b == nil { 88 t.Error("failed to parse certificate") 89 } 90 }) 91 }