use of com.spotify.docker.client.LogStream in project helios by spotify.
the class EnvironmentVariableTest method test.
@Test
public void test() throws Exception {
startDefaultMaster();
startDefaultAgent(testHost(), "--env", "SPOTIFY_POD=PODNAME", "SPOTIFY_ROLE=ROLENAME", "BAR=badfood");
awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Wait for the agent to report environment vars
Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<Object>() {
@Override
public Object call() throws Exception {
final Map<String, HostStatus> status = Json.read(cli("hosts", testHost(), "--json"), new TypeReference<Map<String, HostStatus>>() {
});
return status.get(testHost()).getEnvironment();
}
});
try (final DockerClient dockerClient = getNewDockerClient()) {
final List<String> command = asList("sh", "-c", "echo pod: $SPOTIFY_POD; " + "echo role: $SPOTIFY_ROLE; " + "echo foo: $FOO; " + "echo bar: $BAR");
// Create job
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, command, ImmutableMap.of("FOO", "4711", "BAR", "deadbeef"));
// deploy
deployJob(jobId, testHost());
final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED);
final LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout(), stderr());
final String log = logs.readFully();
assertThat(log, containsString("pod: PODNAME"));
assertThat(log, containsString("role: ROLENAME"));
assertThat(log, containsString("foo: 4711"));
// Verify that the the BAR environment variable in the job overrode the agent config
assertThat(log, containsString("bar: deadbeef"));
final Map<String, HostStatus> status = Json.read(cli("hosts", testHost(), "--json"), new TypeReference<Map<String, HostStatus>>() {
});
assertEquals(ImmutableMap.of("SPOTIFY_POD", "PODNAME", "SPOTIFY_ROLE", "ROLENAME", "BAR", "badfood"), status.get(testHost()).getEnvironment());
assertEquals(ImmutableMap.of("SPOTIFY_POD", "PODNAME", "SPOTIFY_ROLE", "ROLENAME", "BAR", "deadbeef", "FOO", "4711"), status.get(testHost()).getStatuses().get(jobId).getEnv());
}
}
use of com.spotify.docker.client.LogStream in project helios by spotify.
the class ContainerHostNameTest method testValidHostname.
@Test
public void testValidHostname() throws Exception {
startDefaultMaster();
startDefaultAgent(testHost());
awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
try (final DockerClient dockerClient = getNewDockerClient()) {
final List<String> command = asList("hostname", "-f");
// Create job
final JobId jobId = createJob(Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setHostname(testHost()).setCommand(command).build());
// deploy
deployJob(jobId, testHost());
final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED);
final String log;
try (final LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout(), stderr())) {
log = logs.readFully();
}
assertThat(log, containsString(testHost()));
}
}
use of com.spotify.docker.client.LogStream in project helios by spotify.
the class ExecHealthCheckerTest method setUp.
@Before
public void setUp() throws Exception {
final ExecHealthCheck healthCheck = ExecHealthCheck.of("exit 0");
final Info info = mock(Info.class);
when(info.executionDriver()).thenReturn("native-0.2");
final Version version = mock(Version.class);
when(version.apiVersion()).thenReturn("1.18");
final ExecState execState = mock(ExecState.class);
when(execState.exitCode()).thenReturn(0);
final LogStream log = mock(LogStream.class);
when(log.readFully()).thenReturn("");
docker = mock(DockerClient.class);
when(docker.info()).thenReturn(info);
when(docker.version()).thenReturn(version);
when(docker.execCreate(eq(CONTAINER_ID), any(String[].class), (DockerClient.ExecCreateParam) anyVararg())).thenReturn(ExecCreation.create(EXEC_ID, emptyList()));
when(docker.execStart(eq(EXEC_ID), (ExecStartParameter) anyVararg())).thenReturn(log);
when(docker.execInspect(EXEC_ID)).thenReturn(execState);
checker = new ExecHealthChecker(healthCheck, docker);
}
use of com.spotify.docker.client.LogStream in project helios by spotify.
the class BindVolumeTest method test.
@Test
public void test() throws Exception {
try (final DockerClient docker = getNewDockerClient()) {
// Start Helios agent, configured to bind host /etc/hostname into container /mnt/hostname
startDefaultMaster();
startDefaultAgent(testHost(), "--bind", "/etc/hostname:/mnt/hostname:ro");
awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Figure out the host kernel version
final String hostname = docker.info().name();
// Run a job that cat's /mnt/hostname, which should be the host's name
final List<String> command = ImmutableList.of("cat", "/mnt/hostname");
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, command);
deployJob(jobId, testHost());
final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED);
final String log;
try (LogStream logs = docker.logs(taskStatus.getContainerId(), stdout(), stderr())) {
log = logs.readFully();
}
// the kernel version from the host should be in the log
assertThat(log, containsString(hostname));
}
}
use of com.spotify.docker.client.LogStream in project helios by spotify.
the class TerminationTest method testTermOnExit.
@Test
public void testTermOnExit() throws Exception {
startDefaultMaster();
final String host = testHost();
startDefaultAgent(host);
final HeliosClient client = defaultClient();
awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);
// Note: signal 15 is SIGTERM
final Job jobToInterrupt = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(asList("/bin/sh", "-c", "trap handle 15; handle() { echo term; exit 0; }; " + "while true; do sleep 1; done")).build();
final JobId jobId = createJob(jobToInterrupt);
deployJob(jobId, host);
awaitTaskState(jobId, host, RUNNING);
client.setGoal(new Deployment(jobId, Goal.STOP, Deployment.EMTPY_DEPLOYER_USER, Deployment.EMPTY_DEPLOYER_MASTER, Deployment.EMPTY_DEPLOYMENT_GROUP_NAME), host);
final TaskStatus taskStatus = awaitTaskState(jobId, host, STOPPED);
final String log;
try (final DockerClient dockerClient = getNewDockerClient();
LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout())) {
log = logs.readFully();
}
// Message expected, because the SIGTERM handler in the script should have run
assertEquals("term\n", log);
}
Aggregations