Skip to content

Commit

Permalink
Update govmomi
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Jul 9, 2024
1 parent c828218 commit 7de1359
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 117 deletions.
42 changes: 20 additions & 22 deletions esx/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
package esx

import (
"context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/vmware/govmomi/object"
Expand All @@ -33,7 +31,7 @@ const HostSystemName string = "DC0_H0"
var _ = Describe("CheckForMaintenance", func() {
var vCenters *VCenters

BeforeEach(func() {
BeforeEach(func(ctx SpecContext) {
vCenters = &VCenters{
Template: TemplateURL,
Credentials: map[string]Credential{
Expand All @@ -45,56 +43,56 @@ var _ = Describe("CheckForMaintenance", func() {
}

// set host out of maintenance
client, err := vCenters.Client(context.Background(), vcServer.URL.Host)
client, err := vCenters.Client(ctx, vcServer.URL.Host)
Expect(err).To(Succeed())
host := object.NewHostSystem(client.Client, types.ManagedObjectReference{
Type: "HostSystem",
Value: "host-20",
Value: esxRef,
})
task, err := host.ExitMaintenanceMode(context.Background(), 1000)
task, err := host.ExitMaintenanceMode(ctx, 1000)
Expect(err).To(Succeed())
err = task.WaitEx(context.Background())
err = task.WaitEx(ctx)
Expect(err).To(Succeed())
})

AfterEach(func() {
AfterEach(func(ctx SpecContext) {
// set host out of maintenance
client, err := vCenters.Client(context.Background(), vcServer.URL.Host)
client, err := vCenters.Client(ctx, vcServer.URL.Host)
Expect(err).To(Succeed())
host := object.NewHostSystem(client.Client, types.ManagedObjectReference{
Type: "HostSystem",
Value: "host-20",
Value: esxRef,
})
task, err := host.ExitMaintenanceMode(context.Background(), 1000)
task, err := host.ExitMaintenanceMode(ctx, 1000)
Expect(err).To(Succeed())
err = task.WaitEx(context.Background())
err = task.WaitEx(ctx)
Expect(err).To(Succeed())
})

It("should return NoMaintenance if the host is not in maintenance", func() {
result, err := CheckForMaintenance(context.Background(), CheckParameters{vCenters, HostInfo{
It("should return NoMaintenance if the host is not in maintenance", func(ctx SpecContext) {
result, err := CheckForMaintenance(ctx, CheckParameters{vCenters, HostInfo{
AvailabilityZone: vcServer.URL.Host,
Name: HostSystemName,
}, GinkgoLogr})
Expect(err).To(Succeed())
Expect(result).To(Equal(NoMaintenance))
})

It("should return InMaintenance if the host is in maintenance", func() {
client, err := vCenters.Client(context.Background(), vcServer.URL.Host)
It("should return InMaintenance if the host is in maintenance", func(ctx SpecContext) {
client, err := vCenters.Client(ctx, vcServer.URL.Host)
Expect(err).To(Succeed())

// set host in maintenance
host := object.NewHostSystem(client.Client, types.ManagedObjectReference{
Type: "HostSystem",
Value: "host-20",
Value: esxRef,
})
task, err := host.EnterMaintenanceMode(context.Background(), 1000, false, &types.HostMaintenanceSpec{})
task, err := host.EnterMaintenanceMode(ctx, 1000, false, &types.HostMaintenanceSpec{})
Expect(err).To(Succeed())
err = task.WaitEx(context.Background())
err = task.WaitEx(ctx)
Expect(err).To(Succeed())

result, err := CheckForMaintenance(context.Background(), CheckParameters{vCenters, HostInfo{
result, err := CheckForMaintenance(ctx, CheckParameters{vCenters, HostInfo{
AvailabilityZone: vcServer.URL.Host,
Name: HostSystemName,
}, GinkgoLogr})
Expand All @@ -119,8 +117,8 @@ var _ = Describe("FetchVersion", func() {
}
})

It("should return the version", func() {
version, err := FetchVersion(context.Background(), CheckParameters{vCenters, HostInfo{
It("should return the version", func(ctx SpecContext) {
version, err := FetchVersion(ctx, CheckParameters{vCenters, HostInfo{
AvailabilityZone: vcServer.URL.Host,
Name: HostSystemName,
}, GinkgoLogr})
Expand Down
Loading

0 comments on commit 7de1359

Please sign in to comment.