Permalink
Browse files

OS-4664 vmadm and dockerinit should know about log drivers

  • Loading branch information...
joshwilsdon committed Aug 22, 2015
1 parent 4690126 commit 72fa211e6427445f55eb9c3bfa9de69355237756
Showing with 124 additions and 12 deletions.
  1. +2 −2 Makefile
  2. +2 −1 src/dockerinit/src/docker-common.h
  3. +36 −0 src/dockerinit/src/dockerinit.c
  4. +50 −9 src/vm/node_modules/VM.js
  5. +34 −0 src/vm/tests/test-docker.js
View
@@ -13,8 +13,10 @@ MCPROTO = $(ROOT)/mancheck.conf.d
# On Darwin/OS X we support running 'make check'
ifeq ($(shell uname -s),Darwin)
PATH = /bin:/usr/bin:/usr/sbin:/sbin:/opt/local/bin
NATIVE_CC = gcc
else
PATH = /usr/bin:/usr/sbin:/sbin:/opt/local/bin
NATIVE_CC = /opt/local/bin/gcc
endif
#
@@ -49,8 +51,6 @@ CTFBINDIR = \
CTFMERGE = $(CTFBINDIR)/ctfmerge
CTFCONVERT = $(CTFBINDIR)/ctfconvert
NATIVE_CC = /opt/local/bin/gcc
SUBDIR_DEFS = \
CTFMERGE=$(CTFMERGE) \
CTFCONVERT=$(CTFCONVERT) \
@@ -93,7 +93,8 @@ typedef enum {
ERR_MDATA_TOO_OLD,
ERR_UNLINK_MTAB,
ERR_NO_MEMORY,
ERR_MKDIR
ERR_MKDIR,
ERR_UNKNOWN_LOG_DRIVER
} dockerinit_err_t;
typedef enum {
@@ -180,6 +180,8 @@ setupTerminal(void)
int _stdin, _stdout, _stderr;
boolean_t ctty = B_FALSE;
char *data;
char *log_config = "{}";
char *log_driver = "json-file";
boolean_t open_stdin = getStdinStatus();
if ((data = mdataGet("docker:tty")) != NULL) {
@@ -189,6 +191,29 @@ setupTerminal(void)
free(data);
}
if ((data = mdataGet("docker:logdriver")) != NULL) {
if (strcmp("json-file", data) != 0) {
log_driver = strdup(data);
if (log_driver == NULL) {
fatal(ERR_STRDUP, "unable to strdup() logdriver: %s\n",
strerror(errno));
}
}
free(data);
}
if ((data = mdataGet("docker:logconfig")) != NULL) {
log_config = strdup(data);
if (log_config == NULL) {
fatal(ERR_STRDUP, "unable to strdup() logconfig: %s\n",
strerror(errno));
}
free(data);
}
dlog("INFO logdriver %s\n", log_driver);
dlog("INFO logconfig %s\n", log_config);
dlog("SWITCHING TO /dev/zfd/*\n");
/*
@@ -215,6 +240,17 @@ setupTerminal(void)
}
}
/*
* When we're not using json-file, we want to fork a logger child to handle
* the logging driver.
*/
if (strcmp("json-file", log_driver) != 0
&& strcmp("none", log_driver) != 0) {
fatal(ERR_UNKNOWN_LOG_DRIVER, "unsupported log driver: '%s'\n",
log_driver);
}
if (close(1) == -1) {
fatal(ERR_CLOSE, "failed to close(1): %s\n", strerror(errno));
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -29,6 +29,12 @@ var common_payload = {
max_swap: 1024
};
var image_uuid = vmtest.CURRENT_SMARTOS_UUID;
var log_modes = {
'interactive': {'docker:tty': true, 'docker:logdriver': 'json-file'},
'nlinteractive': {'docker:tty': true, 'docker:logdriver': 'none'},
'logging': {'docker:tty': false, 'docker:logdriver': 'json-file'},
'nologging': {'docker:tty': false, 'docker:logdriver': 'none'}
};
function writeInit(uuid, contents, callback) {
var filename = '/zones/' + uuid + '/root/root/init';
@@ -707,3 +713,31 @@ test('test docker VM with paths in /tmp', function (t) {
}
]);
});
Object.keys(log_modes).forEach(function (mode) {
console.log('mode: ' + mode);
test('test docker VM with log mode ' + mode, function (t) {
var payload = JSON.parse(JSON.stringify(common_payload));
var state = {brand: payload.brand};
payload.docker = true;
payload.internal_metadata = log_modes[mode];
vmtest.on_new_vm(t, image_uuid, payload, state, [
function (cb) {
VM.load(state.uuid, function (err, obj) {
t.ok(!err, 'loading obj for new VM');
if (err) {
cb(err);
return;
}
t.equal(obj.zlog_mode, mode, 'zlog_mode set correctly for '
+ JSON.stringify(log_modes[mode]));
cb();
});
}
]);
});
});

0 comments on commit 72fa211

Please sign in to comment.