Permalink
Browse files

OS-1865 keep output from zonecfg/zoneadm commands so we can track fai…

…lures coming from brand scripts.
  • Loading branch information...
1 parent eb8bd16 commit 4a0967e0e01cf6f229c08fd5dd22293582f7cd23 @joshwilsdon joshwilsdon committed Mar 7, 2013
Showing with 123 additions and 47 deletions.
  1. +118 −46 src/vm/node_modules/VM.js
  2. +5 −0 src/vm/tests/test-required-nic-props.js
  3. +0 −1 src/vm/tests/test-update-kvm.js
View
164 src/vm/node_modules/VM.js
@@ -3698,8 +3698,8 @@ function cleanupMessyDataset(zonepath, brand, log, callback)
command = command + '&& touch ' + zoneroot + '/var/adm/wtmpx';
log.debug(command);
exec(command, function (error, stdout, stderr) {
- log.debug('stdout: ' + stdout);
- log.debug('stderr: ' + stderr);
+ log.debug({err: error, stdout: stdout, stderr: stderr},
+ 'returned from cleaning up dataset');
callback(error);
});
} else {
@@ -3851,7 +3851,6 @@ function zonecfg(args, log, callback)
log.debug(cmd + ' ' + args.join(' '));
execFile(cmd, args, function (error, stdout, stderr) {
if (error) {
- // TODO log here.
callback(error, {'stdout': stdout, 'stderr': stderr});
} else {
callback(null, {'stdout': stdout, 'stderr': stderr});
@@ -5195,10 +5194,13 @@ function createDelegatedDataset(payload, log, callback)
zcfg = zcfg + 'add dataset; set name=' + ds + '; end\n';
zonecfg(['-u', payload.uuid, zcfg], log, function (e, fds) {
if (e) {
- log.error({'err': e, 'stderr': fds.stderr},
- 'unable to add delegated dataset to ' + payload.uuid);
+ log.error({'err': e, stdout: fds.stdout,
+ stderr: fds.stderr}, 'unable to add delegated dataset '
+ + ds + ' to ' + payload.uuid);
callback(e);
} else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'added delegated dataset ' + ds);
callback();
}
});
@@ -5540,8 +5542,8 @@ function buildZonecfgUpdate(vmobj, payload, log)
assert(log, 'no logger passed to buildZonecfgUpdate()');
- log.debug('vmobj:\n' + JSON.stringify(vmobj, null, 2));
- log.debug('payload:\n' + JSON.stringify(payload, null, 2));
+ log.debug({vmobj: vmobj, payload: payload},
+ 'parameters to buildZonecfgUpdate()');
if (vmobj && vmobj.hasOwnProperty('brand')) {
brand = vmobj.brand;
@@ -6006,13 +6008,15 @@ exports.markVMFailure = function (m, options, cb)
zcfg = 'add attr; set name=failed; set value="provisioning"; '
+ 'set type=string; end';
- zonecfg(['-u', m.uuid, zcfg], log, function (zonecfg_err) {
+ zonecfg(['-u', m.uuid, zcfg], log, function (zonecfg_err, fds) {
if (zonecfg_err) {
- log.error(zonecfg_err, 'Unable to set failure flag on '
+ log.error({err: zonecfg_err, stdout: fds.stdout,
+ stderr: fds.stderr}, 'Unable to set failure flag on '
+ m.uuid + ': ' + zonecfg_err.message);
} else {
- log.debug('set failure flag on ' + m.uuid);
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'set failure flag on ' + m.uuid);
}
// attempt to remove transition
@@ -6268,11 +6272,13 @@ function installZone(payload, log, callback)
zoneadm(args, log, function (err, fds) {
if (err) {
- log.error({'err': err, 'stdout': fds.stdout,
- 'stderr': fds.stderr}, 'zoneadm failed to install: '
+ log.error({err: err, stdout: fds.stdout,
+ stderr: fds.stderr}, 'zoneadm failed to install: '
+ err.message);
cb(err);
} else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'zoneadm installed zone');
cb();
}
});
@@ -6809,8 +6815,12 @@ function createZone(payload, log, callback)
// this will create the zone.
zonecfgFile(zcfg, ['-z', payload.zonename], log, function (err, fds) {
if (err || payload.create_only) {
+ log.error({err: err, zcfg: zcfg, stdout: fds.stdout,
+ stderr: fds.stderr}, 'failed to modify zonecfg');
callback(err);
} else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'modified zonecfg');
installZone(payload, log, callback);
}
});
@@ -7170,20 +7180,27 @@ exports.unsetTransition = function (m, options, callback)
if (err) {
// log at info because this might be because already removed
- log.info(err, 'unable to remove transition for zone '
- + m.uuid + ' stderr: ' + fds.stderr);
+ log.info({err: err, stdout: fds.stdout, stderr: fds.stderr},
+ 'unable to remove transition for zone ' + m.uuid);
+ } else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'removed transition for zone ' + m.uuid);
}
zonecfg(['-u', m.uuid, 'info attr name=transition'], log,
function (info_err, info_fds) {
if (info_err) {
- log.err(info_err, 'failed to confirm transition removal');
+ log.error({err: info_err, stdout: info_fds.stdout,
+ stderr: info_fds.stderr},
+ 'failed to confirm transition removal');
callback(info_err);
return;
}
if (info_fds.stdout !== 'No such attr resource.\n') {
+ log.error({stdout: info_fds.stdout, stderr: info_fds.stderr},
+ 'unknown error checking transition after removal');
callback(new Error('transition does not appear to have been '
+ 'removed zonecfg said: ' + JSON.stringify(info_fds)));
return;
@@ -7227,13 +7244,17 @@ function setTransition(m, transition, target, timeout, log, callback)
var zcfg;
zcfg = buildTransitionZonecfg(transition, target, timeout);
- zonecfg(['-u', m.uuid, zcfg], log, function () {
- // TODO: handle errors
-
- log.debug('setting transition=' + transition
- + ' for vm ' + m.uuid);
+ zonecfg(['-u', m.uuid, zcfg], log, function (err, fds) {
+ if (err) {
+ log.err({err: err, stdout: fds.stdout, stderr: fds.stderr},
+ 'failed to set transition=' + transition + ' for VM '
+ + m.uuid);
+ } else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'set transition=' + transition + ' for vm ' + m.uuid);
+ }
- cb();
+ cb(err);
});
}
], function (error) {
@@ -7930,28 +7951,40 @@ function deleteZone(uuid, log, callback)
zoneobj = obj;
cb();
});
+ // TODO: replace these next two with VM.stop(..{force: true} ?
}, function (cb) {
log.debug('setting autoboot=false');
- zonecfg(['-u', uuid, 'set autoboot=false'], log, function (e) {
+ zonecfg(['-u', uuid, 'set autoboot=false'], log, function (e, fds) {
if (e) {
- log.warn(e, 'Error setting autoboot=false: '
- + e.message);
+ log.warn({err: e, stdout: fds.stdout, stderr: fds.stderr},
+ 'Error setting autoboot=false');
+ } else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'set autoboot=false');
}
cb();
});
}, function (cb) {
log.debug('halting zone');
- zoneadm(['-u', uuid, 'halt', '-X'], log, function (e) {
+ zoneadm(['-u', uuid, 'halt', '-X'], log, function (e, fds) {
if (e) {
- log.warn(e, 'Error halting zone: ' + e.message);
+ log.warn({err: e, stdout: fds.stdout, stderr: fds.stderr},
+ 'Error halting zone');
+ } else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'halted zone');
}
cb();
});
}, function (cb) {
log.debug('uninstalling zone');
- zoneadm(['-u', uuid, 'uninstall', '-F'], log, function (e) {
+ zoneadm(['-u', uuid, 'uninstall', '-F'], log, function (e, fds) {
if (e) {
- log.warn(e, 'Error uninstalling zone: ' + e.message);
+ log.warn({err: e, stdout: fds.stdout, stderr: fds.stderr},
+ 'Error uninstalling zone: ' + e.message);
+ } else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'uninstalled zone');
}
cb();
});
@@ -7984,10 +8017,14 @@ function deleteZone(uuid, log, callback)
log.debug('deleting zone');
// XXX for some reason -u <uuid> doesn't work with delete
zonecfg(['-z', zoneobj.zonename, 'delete', '-F'], log,
- function (e) {
+ function (e, fds) {
if (e) {
- log.warn(e, 'Error deleting VM: ' + e.message);
+ log.warn({err: e, stdout: fds.stdout,
+ stderr: fds.stderr}, 'Error deleting VM');
+ } else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'deleted VM ' + uuid);
}
cb();
});
@@ -8115,7 +8152,12 @@ function startZone(zoneobj, log, callback)
// do the booting
zoneadm(['-u', uuid, 'boot', '-X'], log, function (err, boot_fds) {
if (err) {
- log.error(err);
+ log.error({err: err, stdout: boot_fds.stdout,
+ stderr: boot_fds.stderr}, 'zoneadm failed to boot '
+ + 'VM');
+ } else {
+ log.debug({stdout: boot_fds.stdout,
+ stderr: boot_fds.stderr}, 'zoneadm booted VM');
}
cb(err);
});
@@ -8145,8 +8187,12 @@ function startZone(zoneobj, log, callback)
if (err) {
// The vm is running at this point, erroring out here would
// do no good, so we just log it.
- log.error(err, 'startZone(): Failed to ' + set_autoboot
- + ' for ' + uuid + ': ' + err.message);
+ log.error({err: err, stdout: autoboot_fds.stdout,
+ stderr: autoboot_fds.stderr}, 'startZone(): Failed to '
+ + set_autoboot + ' for ' + uuid);
+ } else {
+ log.debug({stdout: autoboot_fds.stdout,
+ stderr: autoboot_fds.stderr}, 'set autoboot');
}
cb(err);
});
@@ -8159,8 +8205,13 @@ function startZone(zoneobj, log, callback)
function (err, neverbooted_fds) {
// Ignore errors here, because we're started.
if (err) {
- log.warn(err, 'failed to remove never-booted '
- + 'flag for ' + uuid + ': ' + err.message);
+ log.warn({err: err, stdout: neverbooted_fds.stdout,
+ stderr: neverbooted_fds.stderr}, 'failed to remove '
+ + 'never-booted flag');
+ } else {
+ log.debug({stdout: neverbooted_fds.stdout,
+ stderr: neverbooted_fds.stderr}, 'removed '
+ + 'never-booted flag');
}
cb();
}
@@ -9672,6 +9723,13 @@ exports.update = function (uuid, payload, options, callback)
// the zone.
zcfg = buildZonecfgUpdate(vmobj, payload, log);
zonecfgFile(zcfg, ['-u', uuid], log, function (e, fds) {
+ if (e) {
+ log.error({err: e, stdout: fds.stdout, stderr: fds.stderr},
+ 'unable to update zonecfg');
+ } else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'updated zonecfg');
+ }
cb(e);
});
}, function (cb) {
@@ -9734,17 +9792,24 @@ function kill(uuid, log, callback)
callback(new_err);
});
} else if (e) {
- log.error(e, 'failed to kill ' + uuid + ': ' + fds.stderr);
+ log.error({err: e, stdout: fds.stdout, stderr: fds.stderr},
+ 'failed to halt VM ' + uuid);
callback(err, msg);
} else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'zoneadm halted VM ' + uuid);
zonecfg(['-u', uuid, unset_autoboot], log,
function (error, unset_fds) {
if (error) {
// The vm is dead at this point, erroring out here would
// do no good, so we just log it.
- log.error('killVM(): Failed to '
- + unset_autoboot + ' for ' + uuid);
+ log.error({err: error, stdout: unset_fds.stdout,
+ stderr: unset_fds.stderr}, 'killVM(): Failed to '
+ + unset_autoboot);
+ } else {
+ log.debug({stdout: unset_fds.stdout,
+ stderr: unset_fds.stderr}, 'unset autoboot flag');
}
if (obj.state === 'stopping') {
// remove transition marker
@@ -9892,11 +9957,13 @@ exports.stop = function (uuid, options, callback)
if (err) {
// The vm is dead at this point, failing
// here would do no good, so we just log it.
- log.error(err, 'stop(): Failed to '
- + unset_autoboot + ' for ' + uuid + ': '
- + err.message);
+ log.error({err: err, stdout: fds.stdout,
+ stderr: fds.stderr}, 'stop(): Failed to'
+ + ' ' + unset_autoboot + ' for ' + uuid
+ + ': ' + err.message);
} else {
- log.info('Stopped ' + uuid);
+ log.info({stdout: fds.stdout,
+ stderr: fds.stderr}, 'Stopped ' + uuid);
}
callbk();
}
@@ -9942,11 +10009,12 @@ exports.stop = function (uuid, options, callback)
if (err) {
// The vm is dead at this point, failing
// do no good, so we just log it.
- log.warn(err, 'Failed to '
- + unset_autoboot + ' for ' + uuid + ': '
- + err.message);
+ log.warn({err: err, stdout: fds.stdout,
+ stderr: fds.stderr}, 'Failed to '
+ + unset_autoboot + ' for ' + uuid);
} else {
- log.info('Stopped ' + uuid);
+ log.info({stdout: fds.stdout,
+ stderr: fds.stderr}, 'Stopped ' + uuid);
}
callbk();
}
@@ -10090,8 +10158,12 @@ function reset(uuid, log, callback)
} else {
zoneadm(['-u', obj.uuid, 'reboot', '-X'], log, function (e, fds) {
if (e) {
+ log.warn({err: e, stdout: fds.stdout, stderr: fds.stderr},
+ 'zoneadm failed to reboot VM ' + obj.uuid);
callback(new Error(rtrim(fds.stderr)));
} else {
+ log.debug({stdout: fds.stdout, stderr: fds.stderr},
+ 'zoneadm rebooted VM ' + obj.uuid);
callback();
}
});
View
5 src/vm/tests/test-required-nic-props.js
@@ -73,6 +73,7 @@ var payload_kvm_missing_netmask = {
'vcpus': 1,
'ram': 256,
'alias': 'autotest-' + process.pid,
+ 'do_not_inventory': true,
'autoboot': false,
'disks': [
{
@@ -99,6 +100,7 @@ var payload_kvm_missing_model = {
'vcpus': 1,
'ram': 256,
'autoboot': false,
+ 'do_not_inventory': true,
'alias': 'autotest-' + process.pid,
'disks': [
{
@@ -125,6 +127,7 @@ var payload_kvm_missing_model_but_have_driver = {
'vcpus': 1,
'ram': 256,
'autoboot': false,
+ 'do_not_inventory': true,
'alias': 'autotest-' + process.pid,
'nic_driver': 'virtio',
'disks': [
@@ -152,6 +155,7 @@ var payload_kvm_good = {
'vcpus': 1,
'ram': 256,
'alias': 'autotest-' + process.pid,
+ 'do_not_inventory': true,
'autoboot': false,
'disks': [
{
@@ -181,6 +185,7 @@ var payload_kvm_good_dhcp = {
'vcpus': 1,
'ram': 256,
'alias': 'autotest-' + process.pid,
+ 'do_not_inventory': true,
'autoboot': false,
'disks': [
{
View
1 src/vm/tests/test-update-kvm.js
@@ -131,7 +131,6 @@ test('boot zone', function(t) {
});
test('add net0', {'timeout': 60000}, function(t) {
- console.log('boarg');
VM.update(vm_uuid, PAYLOADS.add_net0, function (err) {
if (err) {
t.ok(false, 'error updating VM: ' + err.message);

0 comments on commit 4a0967e

Please sign in to comment.