Search in sources :

Example 6 with ContainerTester

use of com.yahoo.vespa.hosted.controller.restapi.ContainerTester in project vespa by vespa-engine.

the class ApplicationApiTest method deployment_fails_on_illegal_domain_in_deployment_spec.

@Test
public void deployment_fails_on_illegal_domain_in_deployment_spec() throws IOException {
    ContainerControllerTester controllerTester = new ContainerControllerTester(container, responseFiles);
    ContainerTester tester = controllerTester.containerTester();
    ApplicationPackage applicationPackage = new ApplicationPackageBuilder().upgradePolicy("default").athenzIdentity(com.yahoo.config.provision.AthenzDomain.from("invalid.domain"), com.yahoo.config.provision.AthenzService.from("service")).environment(Environment.prod).region("us-west-1").build();
    long screwdriverProjectId = 123;
    createAthenzDomainWithAdmin(ATHENZ_TENANT_DOMAIN, USER_ID);
    Application application = controllerTester.createApplication(ATHENZ_TENANT_DOMAIN.getName(), "tenant1", "application1");
    ScrewdriverId screwdriverId = new ScrewdriverId(Long.toString(screwdriverProjectId));
    controllerTester.authorize(ATHENZ_TENANT_DOMAIN, screwdriverId, ApplicationAction.deploy, application);
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/test/region/us-east-1/instance/default/", POST).data(createApplicationDeployData(applicationPackage, Optional.of(screwdriverProjectId))).screwdriverIdentity(screwdriverId), "{\"error-code\":\"FORBIDDEN\",\"message\":\"Athenz domain in deployment.xml: [invalid.domain] must match tenant domain: [domain1]\"}", 403);
}
Also used : ContainerControllerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester) ScrewdriverId(com.yahoo.vespa.hosted.controller.api.identifiers.ScrewdriverId) ApplicationPackageBuilder(com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder) ContainerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerTester) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) Application(com.yahoo.vespa.hosted.controller.Application) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Example 7 with ContainerTester

use of com.yahoo.vespa.hosted.controller.restapi.ContainerTester in project vespa by vespa-engine.

the class ApplicationApiTest method testDeployDirectly.

@Test
public void testDeployDirectly() throws Exception {
    // Setup
    ContainerControllerTester controllerTester = new ContainerControllerTester(container, responseFiles);
    ContainerTester tester = controllerTester.containerTester();
    tester.updateSystemVersion();
    createAthenzDomainWithAdmin(ATHENZ_TENANT_DOMAIN, USER_ID);
    // Create tenant
    tester.assertResponse(request("/application/v4/tenant/tenant1", POST).userIdentity(USER_ID).data("{\"athensDomain\":\"domain1\", \"property\":\"property1\"}").nToken(N_TOKEN), new File("tenant-without-applications.json"));
    // Create application
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", POST).userIdentity(USER_ID).nToken(N_TOKEN), new File("application-reference.json"));
    // Grant deploy access
    addScrewdriverUserToDeployRole(SCREWDRIVER_ID, ATHENZ_TENANT_DOMAIN, new com.yahoo.vespa.hosted.controller.api.identifiers.ApplicationId("application1"));
    // POST (deploy) an application to a prod zone - allowed when project ID is not specified
    HttpEntity entity = createApplicationDeployData(applicationPackage, Optional.empty());
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/prod/region/corp-us-east-1/instance/default/deploy", POST).data(entity).screwdriverIdentity(SCREWDRIVER_ID), new File("deploy-result.json"));
}
Also used : ContainerControllerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester) HttpEntity(org.apache.http.HttpEntity) ContainerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerTester) File(java.io.File) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Example 8 with ContainerTester

use of com.yahoo.vespa.hosted.controller.restapi.ContainerTester in project vespa by vespa-engine.

the class ApplicationApiTest method testErrorResponses.

@Test
public void testErrorResponses() throws Exception {
    ContainerTester tester = new ContainerTester(container, responseFiles);
    tester.updateSystemVersion();
    createAthenzDomainWithAdmin(ATHENZ_TENANT_DOMAIN, USER_ID);
    // PUT (update) non-existing tenant
    tester.assertResponse(request("/application/v4/tenant/tenant1", PUT).userIdentity(USER_ID).data("{\"athensDomain\":\"domain1\", \"property\":\"property1\"}"), "{\"error-code\":\"NOT_FOUND\",\"message\":\"Tenant 'tenant1' does not exist\"}", 404);
    // GET non-existing tenant
    tester.assertResponse(request("/application/v4/tenant/tenant1", GET).userIdentity(USER_ID), "{\"error-code\":\"NOT_FOUND\",\"message\":\"Tenant 'tenant1' does not exist\"}", 404);
    // GET non-existing application
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", GET).userIdentity(USER_ID), "{\"error-code\":\"NOT_FOUND\",\"message\":\"tenant1.application1 not found\"}", 404);
    // GET non-existing deployment
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/prod/region/us-east/instance/default", GET).userIdentity(USER_ID), "{\"error-code\":\"NOT_FOUND\",\"message\":\"tenant1.application1 not found\"}", 404);
    // POST (add) a tenant
    tester.assertResponse(request("/application/v4/tenant/tenant1", POST).userIdentity(USER_ID).data("{\"athensDomain\":\"domain1\", \"property\":\"property1\"}").nToken(N_TOKEN), new File("tenant-without-applications.json"));
    // POST (add) another tenant under the same domain
    tester.assertResponse(request("/application/v4/tenant/tenant2", POST).userIdentity(USER_ID).data("{\"athensDomain\":\"domain1\", \"property\":\"property1\"}").nToken(N_TOKEN), "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not create tenant 'tenant2': The Athens domain 'domain1' is already connected to tenant 'tenant1'\"}", 400);
    // Add the same tenant again
    tester.assertResponse(request("/application/v4/tenant/tenant1", POST).userIdentity(USER_ID).nToken(N_TOKEN).data("{\"athensDomain\":\"domain1\", \"property\":\"property1\"}"), "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Tenant 'tenant1' already exists\"}", 400);
    // POST (create) an (empty) application
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", POST).userIdentity(USER_ID).nToken(N_TOKEN), new File("application-reference.json"));
    // Create the same application again
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", POST).userIdentity(USER_ID), "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not create 'tenant1.application1': Application already exists\"}", 400);
    ConfigServerClientMock configServer = (ConfigServerClientMock) container.components().getComponent("com.yahoo.vespa.hosted.controller.ConfigServerClientMock");
    configServer.throwOnNextPrepare(new ConfigServerException(new URI("server-url"), "Failed to prepare application", ConfigServerException.ErrorCode.INVALID_APPLICATION_PACKAGE, null));
    // POST (deploy) an application with an invalid application package
    HttpEntity entity = createApplicationDeployData(applicationPackage, Optional.empty());
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/dev/region/us-west-1/instance/default/deploy", POST).data(entity).userIdentity(USER_ID), new File("deploy-failure.json"), 400);
    // POST (deploy) an application without available capacity
    configServer.throwOnNextPrepare(new ConfigServerException(new URI("server-url"), "Failed to prepare application", ConfigServerException.ErrorCode.OUT_OF_CAPACITY, null));
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/dev/region/us-west-1/instance/default/deploy", POST).data(entity).userIdentity(USER_ID), new File("deploy-out-of-capacity.json"), 400);
    // POST (deploy) an application where activation fails
    configServer.throwOnNextPrepare(new ConfigServerException(new URI("server-url"), "Failed to activate application", ConfigServerException.ErrorCode.ACTIVATION_CONFLICT, null));
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/dev/region/us-west-1/instance/default/deploy", POST).data(entity).userIdentity(USER_ID), new File("deploy-activation-conflict.json"), 409);
    // POST (deploy) an application where we get an internal server error
    configServer.throwOnNextPrepare(new ConfigServerException(new URI("server-url"), "Internal server error", ConfigServerException.ErrorCode.INTERNAL_SERVER_ERROR, null));
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1/environment/dev/region/us-west-1/instance/default/deploy", POST).data(entity).userIdentity(USER_ID), new File("deploy-internal-server-error.json"), 500);
    // DELETE tenant which has an application
    tester.assertResponse(request("/application/v4/tenant/tenant1", DELETE).userIdentity(USER_ID), "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not delete tenant 'tenant1': This tenant has active applications\"}", 400);
    // DELETE application
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", DELETE).userIdentity(USER_ID).nToken(N_TOKEN), "");
    // DELETE application again - should produce 404
    tester.assertResponse(request("/application/v4/tenant/tenant1/application/application1", DELETE).userIdentity(USER_ID), "{\"error-code\":\"NOT_FOUND\",\"message\":\"Could not delete application 'tenant1.application1': Application not found\"}", 404);
    // DELETE tenant
    tester.assertResponse(request("/application/v4/tenant/tenant1", DELETE).userIdentity(USER_ID).nToken(N_TOKEN), new File("tenant-without-applications.json"));
    // DELETE tenant again - should produce 404
    tester.assertResponse(request("/application/v4/tenant/tenant1", DELETE).userIdentity(USER_ID), "{\"error-code\":\"NOT_FOUND\",\"message\":\"Could not delete tenant 'tenant1': Tenant not found\"}", 404);
    // Promote application chef env for nonexistent tenant/application
    tester.assertResponse(request("/application/v4/tenant/dontexist/application/dontexist/environment/prod/region/us-west-1/instance/default/promote", POST).userIdentity(USER_ID), "{\"error-code\":\"INTERNAL_SERVER_ERROR\",\"message\":\"Unable to promote Chef environments for application\"}", 500);
}
Also used : HttpEntity(org.apache.http.HttpEntity) ContainerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerTester) ConfigServerException(com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException) File(java.io.File) URI(java.net.URI) ConfigServerClientMock(com.yahoo.vespa.hosted.controller.ConfigServerClientMock) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Aggregations

ContainerTester (com.yahoo.vespa.hosted.controller.restapi.ContainerTester)8 ControllerContainerTest (com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest)7 File (java.io.File)7 Test (org.junit.Test)7 ContainerControllerTester (com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester)5 HttpEntity (org.apache.http.HttpEntity)5 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)3 ApplicationPackageBuilder (com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder)3 ApplicationId (com.yahoo.config.provision.ApplicationId)2 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)2 Application (com.yahoo.vespa.hosted.controller.Application)2 ScrewdriverId (com.yahoo.vespa.hosted.controller.api.identifiers.ScrewdriverId)2 UserId (com.yahoo.vespa.hosted.controller.api.identifiers.UserId)2 ConfigServerClientMock (com.yahoo.vespa.hosted.controller.ConfigServerClientMock)1 ConfigServerException (com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException)1 URI (java.net.URI)1