Skip to content

Commit

Permalink
Merge pull request #3488 from erimerdal/issue-3485
Browse files Browse the repository at this point in the history
vcsim: Add support for DRS automation levels
  • Loading branch information
erimerdal authored Jul 6, 2024
2 parents 769897c + a463e54 commit fb9679e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions simulator/cluster_compute_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func (c *ClusterComputeResource) update(cfg *types.ClusterConfigInfoEx, cspec *t
if val := cspec.DrsConfig.Enabled; val != nil {
cfg.DrsConfig.Enabled = val
}
if val := cspec.DrsConfig.DefaultVmBehavior; val != "" {
cfg.DrsConfig.DefaultVmBehavior = val
}
}

return nil
Expand Down
33 changes: 33 additions & 0 deletions simulator/cluster_compute_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ package simulator

import (
"context"
"path"
"testing"

"github.com/stretchr/testify/require"

"github.com/vmware/govmomi"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/simulator/esx"
"github.com/vmware/govmomi/simulator/vpx"
Expand Down Expand Up @@ -83,6 +87,35 @@ func TestClusterVC(t *testing.T) {
t.Fatal(err)
}

// Enable DRS and HA for the cluster
clusterSpec := types.ClusterConfigSpecEx{
DrsConfig: &types.ClusterDrsConfigInfo{
Enabled: types.NewBool(true),
DefaultVmBehavior: types.DrsBehaviorFullyAutomated, // Set DRS to fully automated
},
DasConfig: &types.ClusterDasConfigInfo{
Enabled: types.NewBool(true),
},
}

task, err := cluster.Reconfigure(ctx, &clusterSpec, true)
require.NoError(t, err)
err = task.Wait(ctx)
require.NoError(t, err)

// Check if DRS and HA is set

finder := find.NewFinder(c.Client, false).SetDatacenter(dc)
pathname := path.Join(dc.InventoryPath, "host", "cluster1")
clusterComputeResource, err := finder.ClusterComputeResource(ctx, pathname)
require.NoError(t, err)
clusterComputeInfo, err := clusterComputeResource.Configuration(ctx)
require.NoError(t, err)
require.NotNil(t, clusterComputeInfo.DrsConfig.Enabled)
require.NotNil(t, clusterComputeInfo.DasConfig.Enabled)
require.True(t, *clusterComputeInfo.DrsConfig.Enabled)
require.True(t, *clusterComputeInfo.DasConfig.Enabled)
require.True(t, clusterComputeInfo.DrsConfig.DefaultVmBehavior == types.DrsBehaviorFullyAutomated)
_, err = folders.HostFolder.CreateCluster(ctx, "cluster1", types.ClusterConfigSpecEx{})
if err == nil {
t.Error("expected DuplicateName error")
Expand Down

0 comments on commit fb9679e

Please sign in to comment.