Search in sources :

Example 6 with Container

use of com.yahoo.vespa.hosted.dockerapi.Container in project vespa by vespa-engine.

the class AclMaintainerTest method configures_container_acl.

@Test
public void configures_container_acl() {
    Container container = makeContainer("container-1");
    List<ContainerAclSpec> aclSpecs = makeAclSpecs(3, container.name);
    when(nodeRepository.getContainerAclSpecs(NODE_ADMIN_HOSTNAME)).thenReturn(aclSpecs);
    aclMaintainer.run();
    assertAclsApplied(container.name, aclSpecs);
}
Also used : Container(com.yahoo.vespa.hosted.dockerapi.Container) ContainerAclSpec(com.yahoo.vespa.hosted.node.admin.ContainerAclSpec) Test(org.junit.Test)

Example 7 with Container

use of com.yahoo.vespa.hosted.dockerapi.Container in project vespa by vespa-engine.

the class AclMaintainerTest method rollback_is_attempted_when_applying_acl_fail.

@Test
public void rollback_is_attempted_when_applying_acl_fail() {
    Container container = makeContainer("container-1");
    when(nodeRepository.getContainerAclSpecs(NODE_ADMIN_HOSTNAME)).thenReturn(makeAclSpecs(1, container.name));
    doThrow(new RuntimeException("iptables command failed")).doNothing().when(dockerOperations).executeCommandInNetworkNamespace(any(), anyVararg());
    aclMaintainer.run();
    verify(dockerOperations).executeCommandInNetworkNamespace(eq(container.name), eq("ip6tables"), eq("-P"), eq("INPUT"), eq("ACCEPT"));
}
Also used : Container(com.yahoo.vespa.hosted.dockerapi.Container) Test(org.junit.Test)

Example 8 with Container

use of com.yahoo.vespa.hosted.dockerapi.Container in project vespa by vespa-engine.

the class DockerOperationsImplTest method makeContainer.

private Container makeContainer(String name, Container.State state, int pid) {
    final Container container = new Container(name + ".fqdn", new DockerImage("mock"), null, new ContainerName(name), state, pid);
    when(docker.getContainer(eq(container.name))).thenReturn(Optional.of(container));
    return container;
}
Also used : Container(com.yahoo.vespa.hosted.dockerapi.Container) ContainerName(com.yahoo.vespa.hosted.dockerapi.ContainerName) DockerImage(com.yahoo.vespa.hosted.dockerapi.DockerImage)

Example 9 with Container

use of com.yahoo.vespa.hosted.dockerapi.Container in project vespa by vespa-engine.

the class AclMaintainerTest method does_not_configure_acl_if_unchanged.

@Test
public void does_not_configure_acl_if_unchanged() {
    Container container = makeContainer("container-1");
    List<ContainerAclSpec> aclSpecs = makeAclSpecs(3, container.name);
    when(nodeRepository.getContainerAclSpecs(NODE_ADMIN_HOSTNAME)).thenReturn(aclSpecs);
    // Run twice
    aclMaintainer.run();
    aclMaintainer.run();
    assertAclsApplied(container.name, aclSpecs, times(1));
}
Also used : Container(com.yahoo.vespa.hosted.dockerapi.Container) ContainerAclSpec(com.yahoo.vespa.hosted.node.admin.ContainerAclSpec) Test(org.junit.Test)

Example 10 with Container

use of com.yahoo.vespa.hosted.dockerapi.Container in project vespa by vespa-engine.

the class DockerOperationsImplTest method runsCommandInNetworkNamespace.

@Test
public void runsCommandInNetworkNamespace() {
    Container container = makeContainer("container-42", Container.State.RUNNING, 42);
    try {
        when(processExecuter.exec(aryEq(new String[] { "sudo", "nsenter", "--net=/host/proc/42/ns/net", "--", "iptables", "-nvL" }))).thenReturn(new Pair<>(0, ""));
    } catch (IOException e) {
        e.printStackTrace();
    }
    dockerOperations.executeCommandInNetworkNamespace(container.name, "iptables", "-nvL");
}
Also used : Container(com.yahoo.vespa.hosted.dockerapi.Container) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Container (com.yahoo.vespa.hosted.dockerapi.Container)12 Test (org.junit.Test)6 ContainerName (com.yahoo.vespa.hosted.dockerapi.ContainerName)4 DockerImage (com.yahoo.vespa.hosted.dockerapi.DockerImage)4 ContainerAclSpec (com.yahoo.vespa.hosted.node.admin.ContainerAclSpec)4 NodeType (com.yahoo.config.provision.NodeType)2 ContainerResources (com.yahoo.vespa.hosted.dockerapi.ContainerResources)2 Docker (com.yahoo.vespa.hosted.dockerapi.Docker)2 ProcessResult (com.yahoo.vespa.hosted.dockerapi.ProcessResult)2 ContainerNodeSpec (com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)2 Environment (com.yahoo.vespa.hosted.node.admin.component.Environment)2 PrefixLogger (com.yahoo.vespa.hosted.node.admin.util.PrefixLogger)2 IOException (java.io.IOException)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Pair (com.yahoo.collections.Pair)1 ThreadFactoryFactory (com.yahoo.concurrent.ThreadFactoryFactory)1 ProcessExecuter (com.yahoo.system.ProcessExecuter)1