private void addContainerToMockAdapter(String hostLink, String containerId, String containerName, String containerImage, List<String> tenantLinks) throws Throwable { addContainerToMockAdapter(hostLink, containerId, containerName, containerImage, PowerState.UNKNOWN, tenantLinks); }
@Test public void testStoppedContainer() throws Throwable { String image = "image:ver"; ContainerDescription containerDesc = new ContainerDescription(); containerDesc.image = image; containerDesc = doPost(containerDesc, ContainerDescriptionService.FACTORY_LINK); ContainerState cs = new ContainerState(); cs.id = UUID.randomUUID().toString(); cs.names = new ArrayList<>(Collections.singletonList("name_" + cs.id)); cs.parentLink = COMPUTE_HOST_LINK; cs.powerState = ContainerState.PowerState.RUNNING; cs.image = image; cs.adapterManagementReference = UriUtils.buildUri(ManagementUriParts.ADAPTER_DOCKER); cs.descriptionLink = containerDesc.documentSelfLink; cs = doPost(cs, ContainerFactoryService.SELF_LINK); // add system container to the adapter service because it already exists on host addContainerToMockAdapter(COMPUTE_HOST_LINK, cs.id, cs.names.get(0), image, PowerState.STOPPED, computeState.tenantLinks); // run data collection on preexisting system container with old version startAndWaitHostContainerListDataCollection(); cs = getDocument(ContainerState.class, cs.documentSelfLink); assertEquals(PowerState.STOPPED, cs.powerState); }
@Test public void testProvisionSystemContainerWhenDoesNotExistsOnHost() throws Throwable { // add preexisting container to the adapter service addContainerToMockAdapter(COMPUTE_HOST_LINK, TEST_PREEXISTING_CONTAINER_ID, TEST_PREEXISTING_CONTAINER_ID, "TestName", computeState.tenantLinks); // run data collection on preexisting container startAndWaitHostContainerListDataCollection(); ContainerState systemContainer = waitForContainer(systemContainerLink, image, null, null); assertNotNull("System container not created or can't be retrieved.", systemContainer); assertEquals(systemContainerLink, systemContainer.documentSelfLink); assertEquals(SystemContainerDescriptions.AGENT_CONTAINER_NAME, systemContainer.names.get(0)); assertNotNull("System container not provisioned", systemContainer.id); assertEquals(SystemContainerDescriptions.AGENT_CONTAINER_DESCRIPTION_LINK, systemContainer.descriptionLink); assertEquals(Boolean.TRUE, systemContainer.system); assertEquals(TENANT_LINKS, systemContainer.tenantLinks); }
@Test public void testProvisionSystemContainerWhenOlderVersionExistsOnHost() throws Throwable { String systemContainerId = extractId(systemContainerLink); // deploy an old version of the system container String oldImage = String.format("%s:%s", SystemContainerDescriptions.AGENT_IMAGE_NAME, "0.0.0"); // add system container to the adapter service because it already exists on host addContainerToMockAdapter(COMPUTE_HOST_LINK, systemContainerId, SystemContainerDescriptions.AGENT_CONTAINER_NAME, oldImage, computeState.tenantLinks); // run data collection on preexisting system container with old version startAndWaitHostContainerListDataCollection(); // wait for the system container with the updated image ContainerState systemContainer = waitForContainer(systemContainerLink, image, null, null); assertNotNull("System container not created or can't be retrieved.", systemContainer); assertEquals(systemContainerLink, systemContainer.documentSelfLink); assertEquals(SystemContainerDescriptions.AGENT_CONTAINER_NAME, systemContainer.names.get(0)); assertNotNull("System container volumes should not be empty", systemContainer.volumes); assertNotNull("System container not recreated", systemContainer.id); assertEquals(SystemContainerDescriptions.AGENT_CONTAINER_DESCRIPTION_LINK, systemContainer.descriptionLink); assertEquals(image, systemContainer.image); assertEquals(Boolean.TRUE, systemContainer.system); assertEquals(TENANT_LINKS, systemContainer.tenantLinks); }
@Test public void testProvisionSystemContainerWhenVersionIsWrong() throws Throwable { String systemContainerId = extractId(systemContainerLink); // deploy an old version of the system container String oldImage = String.format("%s:%s", "test", "abcdefg"); // add system container to the adapter service because it already exists on host addContainerToMockAdapter(COMPUTE_HOST_LINK, systemContainerId, SystemContainerDescriptions.AGENT_CONTAINER_NAME, oldImage, computeState.tenantLinks); // run data collection on preexisting system container with old version startAndWaitHostContainerListDataCollection(); // wait for the system container with the updated image ContainerState systemContainer = waitForContainer(systemContainerLink, image, null, null); assertNotNull("System container not created or can't be retrieved.", systemContainer); assertEquals(systemContainerLink, systemContainer.documentSelfLink); assertEquals(SystemContainerDescriptions.AGENT_CONTAINER_NAME, systemContainer.names.get(0)); assertNotNull("System container volumes should not be empty", systemContainer.volumes); assertNotNull("System container not recreated", systemContainer.id); assertEquals(SystemContainerDescriptions.AGENT_CONTAINER_DESCRIPTION_LINK, systemContainer.descriptionLink); assertEquals(image, systemContainer.image); assertEquals(Boolean.TRUE, systemContainer.system); assertEquals(TENANT_LINKS, systemContainer.tenantLinks); }
private void testStateStuckInProvisioning(boolean isSystemContainerMissingOnHost) throws Throwable { String systemContainerId = extractId(systemContainerLink); addContainerToMockAdapter(COMPUTE_HOST_LINK, systemContainerId, SystemContainerDescriptions.AGENT_CONTAINER_NAME, image, computeState.tenantLinks); startAndWaitHostContainerListDataCollection(); waitForContainer(systemContainerLink, image, PowerState.RUNNING, "System container state should be running after regular data collection."); ContainerState cs = new ContainerState(); cs.powerState = PowerState.PROVISIONING; doPatch(cs, systemContainerLink); waitForContainer(systemContainerLink, image, PowerState.PROVISIONING, "System container state should be provisioning after patching it to provisioning."); startAndWaitHostContainerListDataCollection(); waitForContainer(systemContainerLink, image, PowerState.RUNNING, "System container state should be running after the second data collection when the" + " state was provisioning."); }
@Test public void testProvisionSystemContainerWhenExistsOnHost() throws Throwable { String systemContainerId = extractId(systemContainerLink); // add system container to the adapter service because it already exists on host addContainerToMockAdapter(COMPUTE_HOST_LINK, systemContainerId, SystemContainerDescriptions.AGENT_CONTAINER_NAME, image, computeState.tenantLinks); // run data collection on preexisting system container startAndWaitHostContainerListDataCollection(); ContainerState systemContainer = waitForContainer(systemContainerLink, image, null, null); assertNotNull("System container not created or can't be retrieved.", systemContainer); assertEquals(systemContainerLink, systemContainer.documentSelfLink); assertEquals(SystemContainerDescriptions.AGENT_CONTAINER_NAME, systemContainer.names.get(0)); assertNotNull("System container not discovered", systemContainer.id); assertEquals(SystemContainerDescriptions.AGENT_CONTAINER_DESCRIPTION_LINK, systemContainer.descriptionLink); assertEquals(image, systemContainer.image); assertEquals(Boolean.TRUE, systemContainer.system); assertEquals(TENANT_LINKS, systemContainer.tenantLinks); }