Repository: vmware/govmomi
Pull request #2868 (2022-06-01 21:52:20)

Fix: use correct controlflag for vslm SetControlFlags API test
## Description

`FCD_KEEP_AFTER_DELETE_VM` is not correct control flag.
correcting test to use correct control flag VslmVStorageObjectControlFlagKeepAfterDeleteVm with value `keepAfterDeleteVm` 

## Type of change

Please mark options that are relevant:
Bug fix (non-breaking change which fixes an issue)

## How Has This Been Tested?
Validated control flag in this PR - https://github.com/kubernetes-sigs/vsphere-csi-driver/pull/1762 


cc: @chethanv28 @bandyopadhyays-vmware


Patch:
diff --git a/govc/USAGE.md b/govc/USAGE.md
index 15257b83..c5a094f1 100644
--- a/govc/USAGE.md
+++ b/govc/USAGE.md
@@ -5905,7 +5905,6 @@ Options:
   -host=                     Host system [GOVC_HOST]
   -pool=                     Resource pool [GOVC_RESOURCE_POOL]
   -priority=defaultPriority  The task priority
-  -vm=                       Virtual machine [GOVC_VM]
 ```
 
 ## vm.network.add
diff --git a/govc/vm/migrate.go b/govc/vm/migrate.go
index cf133e86..a43c4da2 100644
--- a/govc/vm/migrate.go
+++ b/govc/vm/migrate.go
@@ -32,7 +32,7 @@ type migrate struct {
 	*flags.ResourcePoolFlag
 	*flags.HostSystemFlag
 	*flags.DatastoreFlag
-	*flags.VirtualMachineFlag
+	*flags.SearchFlag
 
 	priority types.VirtualMachineMovePriority
 	spec     types.VirtualMachineRelocateSpec
@@ -46,8 +46,8 @@ func (cmd *migrate) Register(ctx context.Context, f *flag.FlagSet) {
 	cmd.FolderFlag, ctx = flags.NewFolderFlag(ctx)
 	cmd.FolderFlag.Register(ctx, f)
 
-	cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
-	cmd.VirtualMachineFlag.Register(ctx, f)
+	cmd.SearchFlag, ctx = flags.NewSearchFlag(ctx, flags.SearchVirtualMachines)
+	cmd.SearchFlag.Register(ctx, f)
 
 	cmd.ResourcePoolFlag, ctx = flags.NewResourcePoolFlag(ctx)
 	cmd.ResourcePoolFlag.Register(ctx, f)
@@ -65,9 +65,6 @@ func (cmd *migrate) Process(ctx context.Context) error {
 	if err := cmd.FolderFlag.Process(ctx); err != nil {
 		return err
 	}
-	if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
-		return err
-	}
 	if err := cmd.ResourcePoolFlag.Process(ctx); err != nil {
 		return err
 	}
@@ -112,7 +109,7 @@ func (cmd *migrate) relocate(ctx context.Context, vm *object.VirtualMachine) err
 }
 
 func (cmd *migrate) Run(ctx context.Context, f *flag.FlagSet) error {
-	vms, err := cmd.VirtualMachineFlag.VirtualMachines(f.Args())
+	vms, err := cmd.VirtualMachines(f.Args())
 	if err != nil {
 		return err
 	}


Test patch:
diff --git a/govc/test/vm.bats b/govc/test/vm.bats
index a1c26bc9..7b2fb77b 100755
--- a/govc/test/vm.bats
+++ b/govc/test/vm.bats
@@ -770,7 +770,7 @@ load test_helper
   vm="DC0_H0_VM0"
   clone=$(new_id)
 
-  run govc vm.clone -vm "$vm" -host.ipath /DC0/host/DC0_C0/DC0_C0_H0 -annotation $$ "$clone"
+  run govc vm.clone -vm "$vm" -annotation $$ "$clone"
   assert_success
 
   backing=$(govc device.info -json -vm "$clone" disk-* | jq .Devices[].Backing)
diff --git a/vslm/client_test.go b/vslm/client_test.go
index 60898958..4555b7c1 100644
--- a/vslm/client_test.go
+++ b/vslm/client_test.go
@@ -119,7 +119,8 @@ func TestClient(t *testing.T) {
 	t.Logf("volumeCreateResult %+v", volumeCreateResult)
 	t.Logf("Volume created sucessfully. volumeId: %s", volumeId)
 
-	err = globalObjectManager.SetControlFlags(ctx, types.ID{Id: volumeId}, []string{"FCD_KEEP_AFTER_DELETE_VM"})
+	err = globalObjectManager.SetControlFlags(ctx, types.ID{Id: volumeId}, []string{
+		string(types.VslmVStorageObjectControlFlagKeepAfterDeleteVm)})
 	if err != nil {
 		t.Fatal(err)
 	}