2016-02-04 15:39:50 +02:00
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016, Joyent, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-02-16 15:13:29 +02:00
|
|
|
* Integration tests for `triton instance snapshot ...`
|
2016-02-04 15:39:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
var h = require('./helpers');
|
2016-02-16 15:13:29 +02:00
|
|
|
var f = require('util').format;
|
|
|
|
var os = require('os');
|
2016-02-04 15:39:50 +02:00
|
|
|
var test = require('tape');
|
|
|
|
|
|
|
|
// --- Globals
|
|
|
|
|
|
|
|
var SNAP_NAME = 'test-snapshot';
|
2016-03-02 02:46:06 +02:00
|
|
|
var INST_ALIAS = f('nodetritontest-snapshots-%s', os.hostname());
|
2016-02-04 15:39:50 +02:00
|
|
|
var INST;
|
2016-02-16 15:13:29 +02:00
|
|
|
var OPTS = {
|
|
|
|
skip: !h.CONFIG.allowWriteActions
|
|
|
|
};
|
2016-02-04 15:39:50 +02:00
|
|
|
|
|
|
|
// --- Tests
|
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
if (OPTS.skip) {
|
|
|
|
console.error('** skipping %s tests', __filename);
|
|
|
|
console.error('** set "allowWriteActions" in test config to enable');
|
|
|
|
}
|
|
|
|
|
|
|
|
test('triton instance snapshot', OPTS, function (tt) {
|
|
|
|
h.printConfig(tt);
|
2016-02-04 15:39:50 +02:00
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
tt.test(' cleanup existing inst with alias ' + INST_ALIAS, function (t) {
|
|
|
|
h.deleteTestInst(t, INST_ALIAS, function (err) {
|
|
|
|
t.ifErr(err);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
2016-02-04 15:39:50 +02:00
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
tt.test(' setup: triton instance create', function (t) {
|
|
|
|
h.createTestInst(t, INST_ALIAS, function onInst(err2, instId) {
|
|
|
|
if (h.ifErr(t, err2, 'triton instance create'))
|
2016-02-07 15:50:47 +02:00
|
|
|
return t.end();
|
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
INST = instId.match(/^(.+?)-/)[1]; // convert to short ID
|
2016-02-07 15:50:47 +02:00
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
t.end();
|
2016-02-04 15:39:50 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
tt.test(' triton instance snapshot create', function (t) {
|
|
|
|
var cmd = 'instance snapshot create -w -n ' + SNAP_NAME + ' ' + INST;
|
2016-02-04 15:39:50 +02:00
|
|
|
|
|
|
|
h.triton(cmd, function (err, stdout, stderr) {
|
2016-02-16 15:13:29 +02:00
|
|
|
if (h.ifErr(t, err, 'triton instance snapshot create'))
|
2016-02-04 15:39:50 +02:00
|
|
|
return t.end();
|
|
|
|
|
|
|
|
t.ok(stdout.match('Created snapshot "' + SNAP_NAME + '" in \\d+'),
|
|
|
|
'snapshot made');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
tt.test(' triton instance snapshot get', function (t) {
|
|
|
|
var cmd = 'instance snapshot get ' + INST + ' ' + SNAP_NAME;
|
2016-02-04 15:39:50 +02:00
|
|
|
|
|
|
|
h.triton(cmd, function (err, stdout, stderr) {
|
2016-02-16 15:13:29 +02:00
|
|
|
if (h.ifErr(t, err, 'triton instance snapshot get'))
|
2016-02-04 15:39:50 +02:00
|
|
|
return t.end();
|
|
|
|
|
|
|
|
var obj = JSON.parse(stdout);
|
|
|
|
t.equal(obj.name, SNAP_NAME, 'snapshot name is correct');
|
|
|
|
t.equal(obj.state, 'created', 'snapshot was properly created');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
tt.test(' triton instance snapshot list', function (t) {
|
|
|
|
var cmd = 'instance snapshot list ' + INST;
|
|
|
|
|
|
|
|
h.triton(cmd, function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err, 'triton instance snapshot list'))
|
2016-02-04 15:39:50 +02:00
|
|
|
return t.end();
|
|
|
|
|
|
|
|
var snaps = stdout.split('\n');
|
2016-02-16 15:13:29 +02:00
|
|
|
t.ok(snaps[0].match(/NAME\s+STATE\s+CREATED/));
|
2016-02-04 15:39:50 +02:00
|
|
|
snaps.shift();
|
|
|
|
|
|
|
|
t.ok(snaps.length >= 1, 'triton snap list expected snap num');
|
|
|
|
|
|
|
|
var testSnaps = snaps.filter(function (snap) {
|
|
|
|
return snap.match(SNAP_NAME);
|
|
|
|
});
|
|
|
|
|
|
|
|
t.equal(testSnaps.length, 1, 'triton snap list test snap found');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
tt.test(' triton instance start --snapshot', function (t) {
|
2016-02-05 14:54:13 +02:00
|
|
|
var cmd = 'instance start ' + INST + ' -w --snapshot=' + SNAP_NAME;
|
|
|
|
|
|
|
|
h.triton(cmd, function (err, stdout, stderr) {
|
|
|
|
if (h.ifErr(t, err, 'triton instance start --snapshot'))
|
|
|
|
return t.end();
|
|
|
|
|
|
|
|
t.ok(stdout.match('Start instance ' + INST));
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
tt.test(' triton instance snapshot delete', function (t) {
|
|
|
|
var cmd = 'instance snapshot delete -w --force ' + INST + ' ' +
|
|
|
|
SNAP_NAME;
|
|
|
|
|
2016-02-04 15:39:50 +02:00
|
|
|
h.triton(cmd, function (err, stdout, stderr) {
|
2016-02-16 15:13:29 +02:00
|
|
|
if (h.ifErr(t, err, 'triton instance snapshot delete'))
|
2016-02-04 15:39:50 +02:00
|
|
|
return t.end();
|
|
|
|
|
|
|
|
t.ok(stdout.match('Deleting snapshot "' + SNAP_NAME + '"',
|
|
|
|
'deleting snapshot'));
|
|
|
|
t.ok(stdout.match('Deleted snapshot "' + SNAP_NAME + '" in \\d+s',
|
|
|
|
'deleted snapshot'));
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
2016-02-07 15:50:47 +02:00
|
|
|
|
2016-02-16 15:13:29 +02:00
|
|
|
/*
|
|
|
|
* Use a timeout, because '-w' on delete doesn't have a way to know if the
|
|
|
|
* attempt failed or if it is just taking a really long time.
|
|
|
|
*/
|
|
|
|
tt.test(' cleanup: triton instance rm INST', {timeout: 10 * 60 * 1000},
|
|
|
|
function (t) {
|
|
|
|
h.deleteTestInst(t, INST_ALIAS, function () {
|
2016-02-07 15:50:47 +02:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
2016-02-04 15:39:50 +02:00
|
|
|
});
|