diff options
author | Harald Musum <musum@yahoo-inc.com> | 2016-12-08 21:07:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-08 21:07:19 +0100 |
commit | b8024c275e9d5bab661910d7360f69422d96557b (patch) | |
tree | 0600f124ae8228d6aabf4ae36186bc325560ed00 /configserver | |
parent | eaed14310982d37fba4da1bbde6c386226626768 (diff) |
Revert "Revert "Skeleton for testing deployment with docker image specified in request""
Diffstat (limited to 'configserver')
-rw-r--r-- | configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java | 71 | ||||
-rw-r--r-- | configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java | 42 |
2 files changed, 97 insertions, 16 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java index bb7560e3740..8b4b7237662 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java @@ -1,5 +1,7 @@ package com.yahoo.vespa.config.server.deploy; +import com.google.common.io.Files; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.model.NullConfigModelRegistry; import com.yahoo.config.model.api.HostProvisioner; @@ -17,6 +19,7 @@ import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.HostFilter; import com.yahoo.config.provision.HostSpec; import com.yahoo.config.provision.InstanceName; +import com.yahoo.config.provision.ProvisionInfo; import com.yahoo.config.provision.ProvisionLogger; import com.yahoo.config.provision.Provisioner; import com.yahoo.config.provision.Version; @@ -40,7 +43,6 @@ import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.VespaModelFactory; import java.io.File; -import java.io.IOException; import java.time.Clock; import java.time.Duration; import java.time.Instant; @@ -68,17 +70,24 @@ public class DeployTester { } public DeployTester(String appPath, List<ModelFactory> modelFactories) { + this(appPath, modelFactories, new ConfigserverConfig(new ConfigserverConfig.Builder() + .configServerDBDir(Files.createTempDir() + .getAbsolutePath()))); + } + + public DeployTester(String appPath, ConfigserverConfig configserverConfig) { + this(appPath, + Collections.singletonList(createDefaultModelFactory(Clock.systemUTC())), + configserverConfig); + } + + public DeployTester(String appPath, List<ModelFactory> modelFactories, ConfigserverConfig configserverConfig) { + Metrics metrics = Metrics.createTestMetrics(); + this.curator = new MockCurator(); + TestComponentRegistry componentRegistry = createComponentRegistry(curator, metrics, modelFactories, configserverConfig); try { - this.curator = new MockCurator(); this.testApp = new File(appPath); - ModelFactoryRegistry modelFactoryRegistry = new ModelFactoryRegistry(modelFactories); - final Metrics metrics = Metrics.createTestMetrics(); - this.tenants = new Tenants(new TestComponentRegistry.Builder() - .curator(curator) - .modelFactoryRegistry(modelFactoryRegistry) - .metrics(metrics) - .build(), - metrics); + this.tenants = new Tenants(componentRegistry, metrics); } catch (Exception e) { throw new IllegalArgumentException(e); @@ -96,12 +105,23 @@ public class DeployTester { /** * Do the initial "deploy" with the existing API-less code as the deploy API doesn't support first deploys yet. */ - public ApplicationId deployApp(String appName) { + public ApplicationId deployApp(String appName){ + return deployApp(appName, Optional.empty()); + } + + /** + * Do the initial "deploy" with the existing API-less code as the deploy API doesn't support first deploys yet. + */ + public ApplicationId deployApp(String appName, Optional<String> dockerVespaImageVersion) { final Tenant tenant = tenant(); LocalSession session = tenant.getSessionFactory().createSession(testApp, appName, new TimeoutBudget(Clock.systemUTC(), Duration.ofSeconds(60))); ApplicationId id = ApplicationId.from(tenant.getName(), ApplicationName.from(appName), InstanceName.defaultName()); + PrepareParams.Builder paramsBuilder = new PrepareParams.Builder() + .applicationId(id); + if (dockerVespaImageVersion.isPresent()) + paramsBuilder.dockerVespaImageVersion(dockerVespaImageVersion.get()); session.prepare(new SilentDeployLogger(), - new PrepareParams.Builder().applicationId(id).build(), + paramsBuilder.build(), Optional.empty(), tenant.getPath()); session.createActivateTransaction().commit(); @@ -109,7 +129,14 @@ public class DeployTester { this.id = id; return id; } - + + public ProvisionInfo getProvisionInfoFromDeployedApp(ApplicationId applicationId) { + final Tenant tenant = tenant(); + LocalSession session = tenant.getLocalSessionRepo().getSession(tenant.getApplicationRepo() + .getSessionIdForApplication(applicationId)); + return session.getProvisionInfo(); + } + public ApplicationId applicationId() { return id; } public Optional<com.yahoo.config.provision.Deployment> redeployFromLocalActive() { @@ -127,7 +154,23 @@ public class DeployTester { } private Provisioner createHostProvisioner() { - return new ProvisionerAdapter(new InMemoryProvisioner(true, "host0", "host1", "host2")); + return new ProvisionerAdapter(new InMemoryProvisioner(true, "host0", "host1", "host2", "host3", "host4", "host5")); + } + + private TestComponentRegistry createComponentRegistry(Curator curator, Metrics metrics, + List<ModelFactory> modelFactories, + ConfigserverConfig configserverConfig) { + TestComponentRegistry.Builder builder = new TestComponentRegistry.Builder(); + + if (configserverConfig.hostedVespa()) { + builder.provisioner(createHostProvisioner()); + } + + builder.configServerConfig(configserverConfig) + .curator(curator) + .modelFactoryRegistry(new ModelFactoryRegistry(modelFactories)) + .metrics(metrics); + return builder.build(); } private static class ProvisionerAdapter implements Provisioner { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java index 25efbc77a17..1578bacf429 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java @@ -1,9 +1,13 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.deploy; +import com.google.common.io.Files; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.model.api.ModelFactory; +import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Version; import com.yahoo.test.ManualClock; +import org.junit.Ignore; import org.junit.Test; import java.io.IOException; @@ -12,6 +16,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -19,10 +24,21 @@ import static org.junit.Assert.fail; * @author bratseth */ public class HostedDeployTest { + private static final String dockerRegistry = "foo.com:4443"; + private static final String dockerVespaBaseImage = "/vespa/ci"; + private static final ConfigserverConfig config = new ConfigserverConfig(new ConfigserverConfig.Builder() + .configServerDBDir(Files.createTempDir() + .getAbsolutePath()) + .dockerRegistry(dockerRegistry) + .dockerVespaBaseImage(dockerVespaBaseImage) + .configServerDBDir(Files.createTempDir() + .getAbsolutePath()) + .hostedVespa(true) + .multitenant(true)); @Test public void testRedeploy() throws InterruptedException, IOException { - DeployTester tester = new DeployTester("src/test/apps/hosted/"); + DeployTester tester = new DeployTester("src/test/apps/hosted/", config); tester.deployApp("myApp"); Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive(); @@ -38,7 +54,7 @@ public class HostedDeployTest { List<ModelFactory> modelFactories = new ArrayList<>(); modelFactories.add(DeployTester.createDefaultModelFactory(clock)); modelFactories.add(DeployTester.createFailingModelFactory(Version.fromIntValues(1, 0, 0))); // older than default - DeployTester tester = new DeployTester("src/test/apps/validationOverride/", modelFactories); + DeployTester tester = new DeployTester("src/test/apps/validationOverride/", modelFactories, config); tester.deployApp("myApp"); // Redeployment from local active works @@ -71,4 +87,26 @@ public class HostedDeployTest { } } + @Test + @Ignore //WIP + public void testDeployWithDockerImage() throws InterruptedException, IOException { + final String vespaVersion = "6.51.1"; + DeployTester tester = new DeployTester("src/test/apps/hosted/", config); + ApplicationId applicationId = tester.deployApp("myApp", Optional.of(vespaVersion)); + assertProvisionInfo(vespaVersion, tester, applicationId); + + System.out.println("Redeploy"); + Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive(); + assertTrue(deployment.isPresent()); + deployment.get().prepare(); + deployment.get().activate(); + //assertProvisionInfo(vespaVersion, tester, applicationId); + } + + private void assertProvisionInfo(String vespaVersion, DeployTester tester, ApplicationId applicationId) { + tester.getProvisionInfoFromDeployedApp(applicationId).getHosts().stream() + .forEach(h -> assertEquals(dockerRegistry + dockerVespaBaseImage + ":" + vespaVersion, + h.membership().get().cluster().dockerImage().get())); + } + } |