@Test public void testMissingContainer() throws Throwable { 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 = doPost(cs, ContainerFactoryService.SELF_LINK); // run data collection on preexisting system container with old version startAndWaitHostContainerListDataCollection(); cs = getDocument(ContainerState.class, cs.documentSelfLink); assertEquals(PowerState.RETIRED, cs.powerState); }
@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); }
private void addContainerToMockAdapter(String hostLink, String containerId, String containerName, String containerImage, PowerState powerState, List<String> tenantLinks) throws Throwable { MockDockerContainerToHostState mockContainerToHostState = new MockDockerContainerToHostState(); mockContainerToHostState.documentSelfLink = UriUtils.buildUriPath( MockDockerContainerToHostService.FACTORY_LINK, UUID.randomUUID().toString()); mockContainerToHostState.parentLink = hostLink; mockContainerToHostState.id = containerId; mockContainerToHostState.name = containerName; mockContainerToHostState.image = containerImage; mockContainerToHostState.powerState = powerState; mockContainerToHostState.tenantLinks = tenantLinks; host.sendRequest(Operation.createPost(host, MockDockerContainerToHostService.FACTORY_LINK) .setBody(mockContainerToHostState) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e != null) { host.log("Cannot create mock container to host state. Error: %s", e.getMessage()); } })); // wait until container to host is created in the mock adapter waitFor(() -> { getDocument(MockDockerContainerToHostState.class, mockContainerToHostState.documentSelfLink); return true; }); } }