fix(provider/cf): cloning across CF foundations fails
spinnaker/spinnaker#3730
MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/converters/DeployCloudFoundryServerGroupAtomicOperationConverter.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/converters/DeployCloudFoundryServerGroupAtomicOperationConverter.java
@@ -87,13 +87,13 @@ public class DeployCloudFoundryServerGroupAtomicOperationConverter extends Abstr
converted.setArtifact(convertToArtifact(artifactCredentials, artifactSource.get("reference").toString()));
converted.setArtifactCredentials(artifactCredentials);
} else if ("package".equals(artifactSource.get("type"))) {
- CloudFoundryCredentials accountCredentials = getCredentialsObject(artifactSource.get("account").toString());
- converted.setArtifactCredentials(new PackageArtifactCredentials(credentials.getClient()));
+ CloudFoundryCredentials artifactCredentials = getCredentialsObject(artifactSource.get("account").toString());
+ converted.setArtifactCredentials(new PackageArtifactCredentials(artifactCredentials.getClient()));
Artifact artifact = new Artifact();
artifact.setType("package");
artifact.setReference(getServerGroupId(artifactSource.get("serverGroupName").toString(),
- artifactSource.get("region").toString(), accountCredentials.getClient()));
+ artifactSource.get("region").toString(), artifactCredentials.getClient()));
converted.setArtifact(artifact);
}

MODIFY
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/converters/DeployCloudFoundryServerGroupAtomicOperationConverterTest.java
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/converters/DeployCloudFoundryServerGroupAtomicOperationConverterTest.java
@@ -19,6 +19,7 @@ package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.converters;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.clouddriver.artifacts.ArtifactCredentialsRepository;
import com.netflix.spinnaker.clouddriver.cloudfoundry.artifacts.ArtifactCredentialsFromString;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.artifacts.PackageArtifactCredentials;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.*;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.DeployCloudFoundryServerGroupDescription;
import com.netflix.spinnaker.clouddriver.cloudfoundry.model.CloudFoundryOrganization;
@@ -34,6 +35,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.stubbing.Answer;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
@@ -43,7 +45,8 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
class DeployCloudFoundryServerGroupAtomicOperationConverterTest {
- private final CloudFoundryClient cloudFoundryClient = new MockCloudFoundryClient();
+ private static CloudFoundryCredentials createCredentials(String name) {
+ CloudFoundryClient cloudFoundryClient = new MockCloudFoundryClient();
{
when(cloudFoundryClient.getOrganizations().findByName(any()))
.thenAnswer((Answer<Optional<CloudFoundryOrganization>>) invocation -> {
@@ -60,25 +63,27 @@ class DeployCloudFoundryServerGroupAtomicOperationConverterTest {
});
}
- private final CloudFoundryCredentials cloudFoundryCredentials = new CloudFoundryCredentials(
- "test", "", "", "", "", "", "") {
+ return new CloudFoundryCredentials(name, "", "", "", "", "", "")
+ {
public CloudFoundryClient getClient() {
return cloudFoundryClient;
}
};
+ }
+ private List<String> accounts = List.of("test", "sourceAccount", "destinationAccount");
private final ArtifactCredentialsRepository artifactCredentialsRepository = new ArtifactCredentialsRepository();
{
- artifactCredentialsRepository.save(new ArtifactCredentialsFromString(
- "test",
+ accounts.toStream().forEach(account -> artifactCredentialsRepository.save(new ArtifactCredentialsFromString(
+ account,
List.of("a").asJava(),
"applications: [{instances: 42}]"
- ));
+ )));
}
private final AccountCredentialsRepository accountCredentialsRepository = new MapBackedAccountCredentialsRepository();
{
- accountCredentialsRepository.update("test", cloudFoundryCredentials);
+ accounts.toStream().forEach(account -> accountCredentialsRepository.update(account, createCredentials(account)));
}
private final AccountCredentialsProvider accountCredentialsProvider =
new DefaultAccountCredentialsProvider(accountCredentialsRepository);
@@ -95,11 +100,11 @@ class DeployCloudFoundryServerGroupAtomicOperationConverterTest {
@Test
void convertDescriptionWithPackageArtifactSourceAndDownloadedManifest() {
final Map input = HashMap.of(
- "credentials", "test",
+ "credentials", "destinationAccount",
"region", "org > space",
"artifact", HashMap.of(
"type", "package",
- "account", "test",
+ "account", "sourceAccount",
"serverGroupName", "serverGroupName1",
"region", "org > space"
).toJavaMap(),
@@ -112,7 +117,10 @@ class DeployCloudFoundryServerGroupAtomicOperationConverterTest {
final DeployCloudFoundryServerGroupDescription result = converter.convertDescription(input);
- assertThat(result.getAccountName()).isEqualTo("test");
+ CloudFoundryCredentials sourceCredentials = converter.getCredentialsObject("sourceAccount");
+ assertThat(result.getAccountName()).isEqualTo("destinationAccount");
+ assertThat(result.getArtifactCredentials())
+ .isEqualToComparingFieldByFieldRecursively(new PackageArtifactCredentials(sourceCredentials.getClient()));
assertThat(result.getSpace()).isEqualToComparingFieldByFieldRecursively(
CloudFoundrySpace.builder().id("spaceID").name("space").organization(
CloudFoundryOrganization.builder().id("orgID").name("org").build()).build());

fix(provider/cf): cloning across CF foundations fails (#3226)

spinnaker/spinnaker#3730

Co-Authored-By: Stu Pollock <spollock@pivotal.io>
Signed-off-by: Jammy Louie <jlouie@pivotal.io>