Repository: vmware/govmomi
Pull request #2709 (2022-01-18 15:35:08)

Update CONTRIBUTING.md file
Closes: #2708

## Description

Please include a summary of the change and which issue is fixed. Please also
include relevant motivation and context. List any dependencies that are required
for this change.

Closes: #(issue-number)

## Type of change

Please mark options that are relevant:

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to
  not work as expected)
- [ ] This change requires a documentation update
- [ ] Build related change

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. If applicable, please also list any relevant
details for your test configuration.

Not Applicable, this is markdown file change
## Checklist:

- [x] My code follows the CONTRIBUTION [guidelines](./../CONTRIBUTING.md) of
  this project
- [ ] I have commented on my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

vmwclabot: @pradeep288, you must sign our contributor license agreement before your changes are merged. Click [here](https://cla.vmware.com/cla/f30f3181f98d4f51a254ac75fd583b7d) to sign the agreement. If you are a VMware employee, read [this](https://cla.vmware.com/employee) for further instruction.
vmwclabot: @pradeep288, VMware has rejected your signed contributor license agreement. The merge can not proceed until the agreement has been resigned. Click [here](https://cla.vmware.com/cla/f30f3181f98d4f51a254ac75fd583b7d) to resign the agreement.
embano1: Something seems wrong with the commit.

Please also note that:

- There's a typo in the commit title
- Please use the `docs: ` prefix in the commit title for proper CHANGELOG rendering.

Patch:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 40537e9d..37d679b2 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -58,6 +58,8 @@ $ git add <files>
 $ git commit -m "govc: Add feature ..." -m "Closes: #<issue-number>"
 $ git push $USER issue-<number>
 ```
+**Note**:  
+To register the new `govc` command package, add a blank `_` import to `govmomi/govc/main.go`.
 
 ### Example 4 - Fix a Bug in `vcsim`
 
diff --git a/go.mod b/go.mod
index fa79755a..1722e0f5 100644
--- a/go.mod
+++ b/go.mod
@@ -14,4 +14,4 @@ require (
 	github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728
 )
 
-require	github.com/kr/text v0.1.0 // indirect
+require github.com/kr/text v0.1.0 // indirect
diff --git a/simulator/custom_fields_manager.go b/simulator/custom_fields_manager.go
index 4aac583f..049a3ed3 100644
--- a/simulator/custom_fields_manager.go
+++ b/simulator/custom_fields_manager.go
@@ -188,30 +188,8 @@ func (c *CustomFieldsManager) SetField(ctx *Context, req *types.SetField) soap.H
 		Value:            req.Value,
 	}
 
-	removeIndex := func(s []types.BaseCustomFieldValue, i int) []types.BaseCustomFieldValue {
-		new := make([]types.BaseCustomFieldValue, 0)
-		new = append(new, s[:i]...)
-		return append(new, s[i+1:]...)
-	}
-
-	removeExistingValues := func(s []types.BaseCustomFieldValue) []types.BaseCustomFieldValue {
-		for i := 0; i < len(s); {
-			if s[i].GetCustomFieldValue().Key == newValue.GetCustomFieldValue().Key {
-				s = removeIndex(s, i)
-			}
-			i++
-		}
-		return s
-	}
-
 	entity := ctx.Map.Get(req.Entity).(mo.Entity).Entity()
-
 	ctx.WithLock(entity, func() {
-		// Check if custom value and value are already set. If so, remove them.
-		entity.CustomValue = removeExistingValues(entity.CustomValue)
-		entity.Value = removeExistingValues(entity.Value)
-
-		// Add the new value
 		entity.CustomValue = append(entity.CustomValue, newValue)
 		entity.Value = append(entity.Value, newValue)
 	})
diff --git a/simulator/virtual_machine.go b/simulator/virtual_machine.go
index 158ded82..42ecfd04 100644
--- a/simulator/virtual_machine.go
+++ b/simulator/virtual_machine.go
@@ -1769,15 +1769,6 @@ type vmFolder interface {
 	CreateVMTask(ctx *Context, c *types.CreateVM_Task) soap.HasFault
 }
 
-func (vm *VirtualMachine) cloneDevice() []types.BaseVirtualDevice {
-	src := types.ArrayOfVirtualDevice{
-		VirtualDevice: vm.Config.Hardware.Device,
-	}
-	dst := types.ArrayOfVirtualDevice{}
-	deepCopy(src, &dst)
-	return dst.VirtualDevice
-}
-
 func (vm *VirtualMachine) CloneVMTask(ctx *Context, req *types.CloneVM_Task) soap.HasFault {
 	pool := req.Spec.Location.Pool
 	if pool == nil {
@@ -1836,8 +1827,7 @@ func (vm *VirtualMachine) CloneVMTask(ctx *Context, req *types.CloneVM_Task) soa
 		config.VirtualSMCPresent = vm.Config.Hardware.VirtualSMCPresent
 
 		defaultDevices := object.VirtualDeviceList(esx.VirtualDevice)
-		devices := vm.cloneDevice()
-
+		devices := vm.Config.Hardware.Device
 		for _, device := range devices {
 			var fop types.VirtualDeviceConfigSpecFileOperation
 
diff --git a/sts/signer.go b/sts/signer.go
index 78cf2046..399ed7fd 100644
--- a/sts/signer.go
+++ b/sts/signer.go
@@ -30,7 +30,6 @@ import (
 	"io"
 	"io/ioutil"
 	mrand "math/rand"
-	"net"
 	"net/http"
 	"net/url"
 	"strings"
@@ -275,18 +274,11 @@ func (s *Signer) SignRequest(req *http.Request) error {
 		}
 
 		var buf bytes.Buffer
-		host := req.URL.Hostname()
-
-		// Check if the host IP is in IPv6 format. If yes, add the opening and closing square brackets.
-		if isIPv6(host) {
-			host = fmt.Sprintf("%s%s%s", "[", host, "]")
-		}
-
 		msg := []string{
 			nonce,
 			req.Method,
 			req.URL.Path,
-			strings.ToLower(host),
+			strings.ToLower(req.URL.Hostname()),
 			port,
 		}
 		for i := range msg {
@@ -337,11 +329,3 @@ func (s *Signer) NewRequest() TokenRequest {
 		KeyID:       s.keyID,
 	}
 }
-
-func isIPv6(s string) bool {
-	ip := net.ParseIP(s)
-	if ip == nil {
-		return false
-	}
-	return len(ip) == net.IPv6len
-}


Test patch:
diff --git a/govc/test/vm.bats b/govc/test/vm.bats
index d16cfe67..38799ceb 100755
--- a/govc/test/vm.bats
+++ b/govc/test/vm.bats
@@ -818,16 +818,6 @@ load test_helper
   backing=$(govc device.info -json -vm "$clone" disk-* | jq .Devices[].Backing)
   assert_equal true "$(jq .EagerlyScrub <<<"$backing")"
   assert_equal false "$(jq .ThinProvisioned <<<"$backing")"
-
-  # test that each vm has a unique vmdk path
-  for item in FileName Uuid;  do
-    items=$(govc object.collect -json -type m / config.hardware.device | \
-              jq ".ChangeSet[].Val.VirtualDevice[].Backing.$item | select(. != null)")
-
-    nitems=$(wc -l <<<"$items")
-    uitems=$(sort -u <<<"$items" | wc -l)
-    assert_equal "$nitems" "$uitems"
-  done
 }
 
 @test "vm.clone change resources" {
diff --git a/simulator/object_test.go b/simulator/object_test.go
index a7758fb8..5ae4bafd 100644
--- a/simulator/object_test.go
+++ b/simulator/object_test.go
@@ -54,7 +54,6 @@ func TestObjectCustomFields(t *testing.T) {
 
 	fieldName := "testField"
 	fieldValue := "12345"
-	updatedFieldValue := "67890"
 
 	// Test that field is not created
 	err = vmm.SetCustomValue(ctx, fieldName, fieldValue)
@@ -114,47 +113,37 @@ func TestObjectCustomFields(t *testing.T) {
 		t.Fatalf("len(vm.AvailableField) expected 2, got %d", len(vm.AvailableField))
 	}
 
-	testFieldValues := func(want string) {
-		if len(vm.CustomValue) != 1 {
-			t.Fatalf("len(vm.CustomValue) expected 1, got %d", len(vm.CustomValue))
-		}
-
-		if len(vm.Value) != 1 {
-			t.Fatalf("len(vm.Value) expected 1, got %d", len(vm.Value))
-		}
-
-		if vm.CustomValue[0].(*types.CustomFieldStringValue).Key != field.Key {
-			t.Fatalf("vm.CustomValue[0].Key expected %d, got %d",
-				field.Key, vm.CustomValue[0].(*types.CustomFieldStringValue).Key)
-		}
-		if vm.CustomValue[0].(*types.CustomFieldStringValue).Value != want {
-			t.Fatalf("vm.CustomValue[0].Value expected %s, got %s",
-				want, vm.CustomValue[0].(*types.CustomFieldStringValue).Value)
-		}
-
-		if vm.Value[0].(*types.CustomFieldStringValue).Key != field.Key {
-			t.Fatalf("vm.Value[0].Key expected %d, got %d",
-				field.Key, vm.Value[0].(*types.CustomFieldStringValue).Key)
-		}
-		if vm.Value[0].(*types.CustomFieldStringValue).Value != want {
-			t.Fatalf("vm.Value[0].Value expected %s, got %s",
-				want, vm.Value[0].(*types.CustomFieldStringValue).Value)
-		}
-	}
-
 	// Set field
 	err = vmm.SetCustomValue(ctx, fieldName, fieldValue)
 	if err != nil {
 		t.Fatal(err)
 	}
-	testFieldValues(fieldValue)
 
-	// Update field
-	err = vmm.SetCustomValue(ctx, fieldName, updatedFieldValue)
-	if err != nil {
-		t.Fatal(err)
+	if len(vm.CustomValue) != 1 {
+		t.Fatalf("len(vm.CustomValue) expected 1, got %d", len(vm.CustomValue))
+	}
+
+	if len(vm.Value) != 1 {
+		t.Fatalf("len(vm.Value) expected 1, got %d", len(vm.Value))
+	}
+
+	if vm.CustomValue[0].(*types.CustomFieldStringValue).Key != field.Key {
+		t.Fatalf("vm.CustomValue[0].Key expected %d, got %d",
+			field.Key, vm.CustomValue[0].(*types.CustomFieldStringValue).Key)
+	}
+	if vm.CustomValue[0].(*types.CustomFieldStringValue).Value != fieldValue {
+		t.Fatalf("vm.CustomValue[0].Value expected %s, got %s",
+			fieldValue, vm.CustomValue[0].(*types.CustomFieldStringValue).Value)
+	}
+
+	if vm.Value[0].(*types.CustomFieldStringValue).Key != field.Key {
+		t.Fatalf("vm.Value[0].Key expected %d, got %d",
+			field.Key, vm.Value[0].(*types.CustomFieldStringValue).Key)
+	}
+	if vm.Value[0].(*types.CustomFieldStringValue).Value != fieldValue {
+		t.Fatalf("vm.Value[0].Value expected %s, got %s",
+			fieldValue, vm.Value[0].(*types.CustomFieldStringValue).Value)
 	}
-	testFieldValues(updatedFieldValue)
 
 	// Rename field
 	newName := field.Name + "_renamed"
diff --git a/sts/signer_test.go b/sts/signer_test.go
index f857b612..81e16adf 100644
--- a/sts/signer_test.go
+++ b/sts/signer_test.go
@@ -133,10 +133,4 @@ func TestSigner(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
-
-	req, _ = http.NewRequest(http.MethodPost, "https://[0:0:0:0:0:0:0:1]", nil)
-	err = s.SignRequest(req)
-	if err != nil {
-		t.Fatal(err)
-	}
 }