Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 3163576

Browse files
committed
Integration and contract tests use credential url for vcenter
- Since we want the stembuild user to be the user with minimal permissions for running package/construct, and the govc commands that are run in test set-up for our integration/contract tests require additional permissions, we need to provide different credentials for these test-setup commands. - We now take in a VCENTER_ADMIN_CREDENTIAL_URL string to pass to these commands - VCENTER_ADMIN_CREDENTIAL_URL is in the form of "username:password@url" - We cannot use GOVC_USERNAME/GOVC_PASSWORD or a full GOVC_URL for either the stembuild or admin users because govc will always choose these credentials if provided. [#166227545](https://www.pivotaltracker.com/story/show/166227545) [Pipeline Fix] Fix stembuild integration test permissions issue
1 parent 6b15d58 commit 3163576

File tree

6 files changed

+49
-50
lines changed

6 files changed

+49
-50
lines changed

iaas_cli/govc_cli_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var _ = Describe("GovcCli", func() {
1515
})
1616

1717
It("lists the devices for a known VCenter VM", func() {
18-
out, _, err := runner.RunWithOutput([]string{"device.ls", "-vm", targetVMPath})
18+
out, _, err := runner.RunWithOutput([]string{"device.ls", "-vm", targetVMPath, "-u", vCenterCredentialUrl})
1919
Expect(err).NotTo(HaveOccurred())
2020
Expect(out).To(Equal(
2121
`ide-200 VirtualIDEController IDE 0
@@ -38,7 +38,7 @@ ethernet-0 VirtualE1000e DVSwitch: a7 fa 3a 50 a9 72 57
3838
})
3939

4040
It("returns exit code 1, if VM doesn't exist", func() {
41-
out, exitCode, err := runner.RunWithOutput([]string{"device.ls", "-vm", "/vm/does/not/exist"})
41+
out, exitCode, err := runner.RunWithOutput([]string{"device.ls", "-vm", "/vm/does/not/exist", "-u", vCenterCredentialUrl})
4242
Expect(err).NotTo(HaveOccurred())
4343
Expect(exitCode).To(Equal(1))
4444
Expect(out).To(Equal(""))

iaas_cli/iaas_cli_suite_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ func TestIaasCli(t *testing.T) {
1515
}
1616

1717
var targetVMPath string
18+
var vCenterCredentialUrl string
1819

1920
var _ = BeforeSuite(func() {
21+
22+
vCenterCredentialUrl = os.Getenv("VCENTER_ADMIN_CREDENTIAL_URL")
23+
Expect(vCenterCredentialUrl).NotTo(Equal(""), "VCENTER_ADMIN_CREDENTIAL_URL is required")
24+
2025
vmFolder := os.Getenv("VM_FOLDER")
2126
Expect(vmFolder).NotTo(Equal(""), "VM_FOLDER is required")
2227
vmName := os.Getenv("PACKAGE_TEST_BASE_VM_NAME")
2328
Expect(vmName).NotTo(Equal(""), "PACKAGE_TEST_BASE_VM_NAME is required")
2429

2530
targetVMPath = fmt.Sprintf("%s/%s", vmFolder, vmName)
31+
2632
})

integration/construct/construct_suite_test.go

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,30 @@ func TestConstruct(t *testing.T) {
4040
}
4141

4242
const (
43-
NetworkGatewayVariable = "NETWORK_GATEWAY"
44-
SubnetMaskVariable = "SUBNET_MASK"
45-
OvaFileVariable = "OVA_FILE"
46-
VMNamePrefixVariable = "VM_NAME_PREFIX"
47-
VMFolderVariable = "VM_FOLDER"
48-
VMUsernameVariable = "VM_USERNAME"
49-
VMPasswordVariable = "VM_PASSWORD"
50-
VMNetworkVariable = "GOVC_NETWORK"
51-
ExistingVmIPVariable = "EXISTING_VM_IP"
52-
UserProvidedIPVariable = "USER_PROVIDED_IP"
53-
LockPrivateKeyVariable = "LOCK_PRIVATE_KEY"
54-
IPPoolGitURIVariable = "IP_POOL_GIT_URI"
55-
IPPoolNameVariable = "IP_POOL_NAME"
56-
OvaSourceS3RegionVariable = "OVA_SOURCE_S3_REGION"
57-
OvaSourceS3BucketVariable = "OVA_SOURCE_S3_BUCKET"
58-
OvaSourceS3FilenameVariable = "OVA_SOURCE_S3_FILENAME"
59-
AwsAccessKeyVariable = "AWS_ACCESS_KEY_ID"
60-
AwsSecretKeyVariable = "AWS_SECRET_ACCESS_KEY"
61-
SkipCleanupVariable = "SKIP_CLEANUP"
62-
vcenterFolderVariable = "VM_FOLDER"
63-
vcenterURLVariable = "GOVC_URL"
64-
vcenterAdminUsernameVariable = "VCENTER_ADMIN_USERNAME"
65-
vcenterAdminPasswordVariable = "VCENTER_ADMIN_PASSWORD"
66-
vcenterStembuildUsernameVariable = "VCENTER_STEMBUILD_USER"
67-
vcenterStembuildPasswordVariable = "VCENTER_STEMBUILD_PASSWORD"
43+
NetworkGatewayVariable = "NETWORK_GATEWAY"
44+
SubnetMaskVariable = "SUBNET_MASK"
45+
OvaFileVariable = "OVA_FILE"
46+
VMNamePrefixVariable = "VM_NAME_PREFIX"
47+
VMFolderVariable = "VM_FOLDER"
48+
VMUsernameVariable = "VM_USERNAME"
49+
VMPasswordVariable = "VM_PASSWORD"
50+
VMNetworkVariable = "GOVC_NETWORK"
51+
ExistingVmIPVariable = "EXISTING_VM_IP"
52+
UserProvidedIPVariable = "USER_PROVIDED_IP"
53+
LockPrivateKeyVariable = "LOCK_PRIVATE_KEY"
54+
IPPoolGitURIVariable = "IP_POOL_GIT_URI"
55+
IPPoolNameVariable = "IP_POOL_NAME"
56+
OvaSourceS3RegionVariable = "OVA_SOURCE_S3_REGION"
57+
OvaSourceS3BucketVariable = "OVA_SOURCE_S3_BUCKET"
58+
OvaSourceS3FilenameVariable = "OVA_SOURCE_S3_FILENAME"
59+
AwsAccessKeyVariable = "AWS_ACCESS_KEY_ID"
60+
AwsSecretKeyVariable = "AWS_SECRET_ACCESS_KEY"
61+
SkipCleanupVariable = "SKIP_CLEANUP"
62+
vcenterFolderVariable = "VM_FOLDER"
63+
vcenterAdminCredentialUrlVariable = "VCENTER_ADMIN_CREDENTIAL_URL"
64+
vcenterBaseURLVariable = "VCENTER_BASE_URL"
65+
vcenterStembuildUsernameVariable = "VCENTER_STEMBUILD_USER"
66+
vcenterStembuildPasswordVariable = "VCENTER_STEMBUILD_PASSWORD"
6867
)
6968

7069
var (
@@ -162,13 +161,10 @@ var _ = SynchronizedBeforeSuite(func() []byte {
162161
vmPassword := envMustExist(VMPasswordVariable)
163162
existingVMIP := os.Getenv(ExistingVmIPVariable)
164163
userProvidedIP := os.Getenv(UserProvidedIPVariable)
165-
vCenterUrl := envMustExist(vcenterURLVariable)
164+
vCenterUrl := envMustExist(vcenterBaseURLVariable)
166165
vcenterFolder := envMustExist(vcenterFolderVariable)
167166
vmNamePrefix := envMustExist(VMNamePrefixVariable)
168-
169-
vcenterAdminUsername := envMustExist(vcenterAdminUsernameVariable)
170-
vcenterAdminPassword := envMustExist(vcenterAdminPasswordVariable)
171-
vcenterAdminCredentialUrl = fmt.Sprintf("%s:%s@%s", vcenterAdminUsername, vcenterAdminPassword, vCenterUrl)
167+
vcenterAdminCredentialUrl = envMustExist(vcenterAdminCredentialUrlVariable)
172168

173169
vCenterStembuildUser := envMustExist(vcenterStembuildUsernameVariable)
174170
vCenterStembuildPassword := envMustExist(vcenterStembuildPasswordVariable)

integration/construct/winrm_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package construct_test
22

33
import (
4+
"path/filepath"
5+
46
. "github.com/cloudfoundry-incubator/stembuild/remotemanager"
57
. "github.com/onsi/ginkgo"
68
. "github.com/onsi/gomega"
7-
"path/filepath"
89
)
910

1011
var _ = Describe("WinRM Remote Manager", func() {

integration/package/package_test.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ import (
2626

2727
var _ = Describe("Package", func() {
2828
const (
29-
baseVMNameEnvVar = "PACKAGE_TEST_BASE_VM_NAME"
30-
mainVersion = "1803.5.3999"
31-
vcenterURLVariable = "GOVC_URL"
32-
vcenterAdminUsernameVariable = "VCENTER_ADMIN_USERNAME"
33-
vcenterAdminPasswordVariable = "VCENTER_ADMIN_PASSWORD"
34-
vcenterFolderVariable = "VM_FOLDER"
35-
existingVMVariable = "EXISTING_SOURCE_VM"
36-
vcenterStembuildUsernameVariable = "VCENTER_STEMBUILD_USER"
37-
vcenterStembuildPasswordVariable = "VCENTER_STEMBUILD_PASSWORD"
29+
baseVMNameEnvVar = "PACKAGE_TEST_BASE_VM_NAME"
30+
mainVersion = "1803.5.3999"
31+
vcenterURLVariable = "VCENTER_BASE_URL"
32+
vcenterAdminCredentialUrlVariable = "VCENTER_ADMIN_CREDENTIAL_URL"
33+
vcenterFolderVariable = "VM_FOLDER"
34+
existingVMVariable = "EXISTING_SOURCE_VM"
35+
vcenterStembuildUsernameVariable = "VCENTER_STEMBUILD_USER"
36+
vcenterStembuildPasswordVariable = "VCENTER_STEMBUILD_PASSWORD"
3837
)
3938

4039
var (
@@ -76,21 +75,17 @@ var _ = Describe("Package", func() {
7675
baseVMWithPath := fmt.Sprintf(vcenterFolder + "/" + baseVMName)
7776
vmPath = strings.Join([]string{vcenterFolder, sourceVMName}, "/")
7877

79-
vcenterAdminUsername := helpers.EnvMustExist(vcenterAdminUsernameVariable)
80-
vcenterAdminPassword := helpers.EnvMustExist(vcenterAdminPasswordVariable)
81-
82-
vcenterURL = helpers.EnvMustExist(vcenterURLVariable)
83-
84-
vcenterAdminCredentialUrl = fmt.Sprintf("%s:%s@%s", vcenterAdminUsername, vcenterAdminPassword, vcenterURL)
78+
vcenterAdminCredentialUrl = helpers.EnvMustExist(vcenterAdminCredentialUrlVariable)
8579

8680
cli.Run([]string{
8781
"vm.clone",
8882
"-vm", baseVMWithPath,
8983
"-on=false",
90-
"-u=%s", vcenterAdminCredentialUrl,
84+
"-u", vcenterAdminCredentialUrl,
9185
sourceVMName,
9286
})
9387

88+
vcenterURL = helpers.EnvMustExist(vcenterURLVariable)
9489
vcenterStembuildUsername = helpers.EnvMustExist(vcenterStembuildUsernameVariable)
9590
vcenterStembuildPassword = helpers.EnvMustExist(vcenterStembuildPasswordVariable)
9691

@@ -145,7 +140,7 @@ var _ = Describe("Package", func() {
145140
AfterEach(func() {
146141
os.RemoveAll(workingDir)
147142
if vmPath != "" {
148-
cli.Run([]string{"vm.destroy", "-vm.ipath", vmPath, "-u=%s", vcenterAdminCredentialUrl})
143+
cli.Run([]string{"vm.destroy", "-vm.ipath", vmPath, "-u", vcenterAdminCredentialUrl})
149144
}
150145
})
151146
})

integration/version_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package integration_test
22

33
import (
44
"fmt"
5+
56
"github.com/cloudfoundry-incubator/stembuild/test/helpers"
67
. "github.com/onsi/ginkgo"
78
. "github.com/onsi/gomega"

0 commit comments

Comments
 (0)