From a64e73332c2e7cdaeba9bffef839d2d610d79ae9 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 12 Dec 2019 13:54:44 +0000 Subject: [PATCH] the rest of the tosca tests now fixed note these need e72175d4b0746cd640740a5cf2c48d1d964731fe in A4C (Cloudsoft branch) --- .../tosca/a4c/brooklyn/Alien4CloudFacade.java | 17 ++++------ .../RuntimeEnvironmentModifierSpecTest.java | 32 ++++++++++++------- .../templates/mysql-topology.tosca.yaml | 5 ++- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/brooklyn-tosca-transformer/src/main/java/io/cloudsoft/tosca/a4c/brooklyn/Alien4CloudFacade.java b/brooklyn-tosca-transformer/src/main/java/io/cloudsoft/tosca/a4c/brooklyn/Alien4CloudFacade.java index 93e2311..14e96bd 100644 --- a/brooklyn-tosca-transformer/src/main/java/io/cloudsoft/tosca/a4c/brooklyn/Alien4CloudFacade.java +++ b/brooklyn-tosca-transformer/src/main/java/io/cloudsoft/tosca/a4c/brooklyn/Alien4CloudFacade.java @@ -322,25 +322,20 @@ private Optional getArtifact(String nodeId, Alien4CloudAppli return Optional.fromNullable(getArtifactsMap(nodeId, toscaApplication).get().get(artifactId)); } + private static final List validInterfaceNames = ImmutableList.of("tosca.interfaces.node.lifecycle.Standard", "Standard", "standard"); private Map getStandardInterfaceOperationsMap(String nodeId, Alien4CloudApplication toscaApplication) { - Map operations = MutableMap.of(); NodeTemplate nodeTemplate = toscaApplication.getNodeTemplate(nodeId); + // or could getIndexedNodeTemplate(nodeId, toscaApplication) -- but above seems easier -// IndexedArtifactToscaElement indexedNodeTemplate = getIndexedNodeTemplate(nodeId, toscaApplication); - List validInterfaceNames = ImmutableList.of("tosca.interfaces.node.lifecycle.Standard", "Standard", "standard"); -// operations.putAll(getInterfaceOperationsMap(indexedNodeTemplate, validInterfaceNames)); - - // returns from the type not the node Optional optionalNodeTemplateInterface = NodeTemplates.findInterfaceOfNodeTemplate( nodeTemplate.getInterfaces(), validInterfaceNames); if (optionalNodeTemplateInterface.isPresent()) { - // merge is now done at build time (though possibly that's not ideal?) -// operations.putAll(optionalNodeTemplateInterface.get().getOperations()); + // merge is now done at build time so we no longer need to look at node types return optionalNodeTemplateInterface.get().getOperations(); } - // return empty default - return operations; + + return MutableMap.of(); } private Map getConfigureInterfaceOperationsMap(Alien4CloudApplication toscaApplication, ToscaApplication.Relationship relationship) { @@ -567,7 +562,7 @@ public Optional getArtifactPath(String nodeId, Alien4CloudApplication tosc DeploymentArtifact artifact = optionalArtifact.get(); Optional csarPath = getCsarPath(artifact); if (!csarPath.isPresent()) { - LOG.warn("CSAR " + artifactId + ":" + artifact.getArchiveVersion() + " does not exist"); + LOG.warn("CSAR " + artifact.getArchiveName() + ":" + artifact.getArchiveVersion() + " for artifact "+artifactId+" does not exist"); return Optional.absent(); } else { return Optional.of(Paths.get(csarPath.get().getParent().toAbsolutePath().toString(), "expanded", artifact.getArtifactRef())); diff --git a/brooklyn-tosca-transformer/src/test/java/io/cloudsoft/tosca/a4c/brooklyn/spec/RuntimeEnvironmentModifierSpecTest.java b/brooklyn-tosca-transformer/src/test/java/io/cloudsoft/tosca/a4c/brooklyn/spec/RuntimeEnvironmentModifierSpecTest.java index 2695dda..bfb81c0 100644 --- a/brooklyn-tosca-transformer/src/test/java/io/cloudsoft/tosca/a4c/brooklyn/spec/RuntimeEnvironmentModifierSpecTest.java +++ b/brooklyn-tosca-transformer/src/test/java/io/cloudsoft/tosca/a4c/brooklyn/spec/RuntimeEnvironmentModifierSpecTest.java @@ -5,20 +5,25 @@ import static org.mockito.Mockito.when; import static org.testng.Assert.assertEquals; -import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; import java.util.Map; +import java.util.regex.Pattern; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.BrooklynDslCommon; import org.apache.brooklyn.core.test.entity.TestEntity; import org.apache.brooklyn.entity.software.base.SoftwareProcess; +import org.apache.brooklyn.test.Asserts; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import alien4cloud.component.repository.exception.CSARVersionNotFoundException; @@ -30,6 +35,8 @@ public class RuntimeEnvironmentModifierSpecTest extends Alien4CloudToscaTest { + private static final Logger log = LoggerFactory.getLogger(RuntimeEnvironmentModifierSpecTest.class); + @Mock private ToscaFacade alien4CloudFacade; @Mock @@ -48,6 +55,10 @@ public void initMocks(){ MockitoAnnotations.initMocks(this); } + private static String escapeLiteralForRegex(String in) { + return in.replaceAll("[-\\[\\]{}()*+?.,\\\\\\\\^$|#\\s]", "\\\\$0"); + } + @Test public void testArtifactLocationsAreConfiguredAsShellVariables() throws CSARVersionNotFoundException { final String artifactName = "artifactName"; @@ -61,19 +72,18 @@ public void testArtifactLocationsAreConfiguredAsShellVariables() throws CSARVers Map artifacts = ImmutableMap.of(artifactKey, artifact); when(alien4CloudFacade.getArtifacts(anyString(), any(ToscaApplication.class))).thenReturn(artifacts.keySet()); - when(alien4CloudFacade.getArtifactPath(anyString(), any(ToscaApplication.class), anyString())).thenReturn(Optional.of(Paths.get("/tmp"))); + when(alien4CloudFacade.getArtifactRef(anyString(), any(ToscaApplication.class), ArgumentMatchers.eq(artifactKey))).thenReturn("http://foo"); + + //when(alien4CloudFacade.getArtifactPath(anyString(), any(ToscaApplication.class), anyString())).thenReturn(Optional.of(Paths.get("/tmp"))); EntitySpec spec = EntitySpec.create(TestEntity.class); RuntimeEnvironmentModifier modifier = new RuntimeEnvironmentModifier(mgmt, alien4CloudFacade); modifier.apply(spec, "", toscaApplication); - String actual = spec.getConfig().get(SoftwareProcess.SHELL_ENVIRONMENT.subKey(artifactKey)).toString(); - String expected = BrooklynDslCommon.formatString("%s/%s/%s", BrooklynDslCommon.attributeWhenReady("install.dir"),"RANDOM", artifactKey).toString(); - String[] actualParts = actual.split("install.dir"); - String[] expectedParts = expected.split("install.dir"); - assertEquals(actualParts.length, expectedParts.length); - assertEquals(actualParts[0], expectedParts[0]); - // remove the random string for comparison, since we can't seed the Random object - assertEquals(actualParts[1].substring(11), expectedParts[1].substring(11), "full-actual="+actual+"; full-expected="+expected); + + Asserts.assertStringMatchesRegex( + spec.getConfig().get(SoftwareProcess.SHELL_ENVIRONMENT.subKey(artifactKey)).toString(), + escapeLiteralForRegex(BrooklynDslCommon.formatString("%s/%s/%s", BrooklynDslCommon.attributeWhenReady("install.dir"), "__ANYTHING__", artifactKey).toString()) + .replace("__ANYTHING__", ".*")); } } diff --git a/brooklyn-tosca-transformer/src/test/resources/templates/mysql-topology.tosca.yaml b/brooklyn-tosca-transformer/src/test/resources/templates/mysql-topology.tosca.yaml index a53fc28..4de1738 100644 --- a/brooklyn-tosca-transformer/src/test/resources/templates/mysql-topology.tosca.yaml +++ b/brooklyn-tosca-transformer/src/test/resources/templates/mysql-topology.tosca.yaml @@ -52,4 +52,7 @@ topology_template: configs: implementation: configs type: tosca.artifacts.File - description: configs \ No newline at end of file + description: configs + # added to explicitly specify since it might be coming from imports + archive_name: mysql-type + archive_version: 2.0.0-SNAPSHOT