VOLAPI-49 DELETE should delete

This commit is contained in:
Josh Wilsdon 2017-05-29 09:36:30 -07:00
parent 471ea6f3fe
commit ebffea1a88
5 changed files with 16 additions and 67 deletions

View File

@ -19,55 +19,6 @@ var distractions = require('../distractions');
var errors = require('../errors'); var errors = require('../errors');
function deleteVolume(volumeName, opts, cb) {
assert.string(volumeName, 'volumeName');
assert.object(opts, 'opts');
assert.object(opts.tritonapi, 'opts.tritonapi');
assert.func(cb, 'cb');
var tritonapi = opts.tritonapi;
vasync.pipeline({funcs: [
function getVolume(ctx, next) {
tritonapi.getVolume(volumeName,
function onGetVolume(getVolErr, volume) {
if (!getVolErr) {
ctx.volume = volume;
}
next(getVolErr);
});
},
function doDeleteVolume(ctx, next) {
assert.object(ctx.volume, 'ctx.volume');
tritonapi.cloudapi.deleteVolume(ctx.volume.id,
next);
},
function waitForVolumeStates(ctx, next) {
assert.object(ctx.volume, 'ctx.volume');
var distraction;
var volumeId = ctx.volume.id;
if (!opts.wait) {
next();
return;
}
distraction = distractions.createDistraction(opts.wait.length);
tritonapi.cloudapi.waitForVolumeStates({
id: volumeId,
states: ['deleted', 'failed']
}, function onWaitDone(waitErr, volume) {
distraction.destroy();
next(waitErr);
});
}
], arg: {}}, cb);
}
function do_delete(subcmd, opts, args, cb) { function do_delete(subcmd, opts, args, cb) {
var self = this; var self = this;

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright 2016 Joyent, Inc. * Copyright 2017 Joyent, Inc.
* *
* `triton volume list ...` * `triton volume list ...`
*/ */
@ -66,12 +66,7 @@ function do_list(subcmd, opts, args, callback) {
} }
if (jsprim.deepEqual(filterPredicate, {})) { if (jsprim.deepEqual(filterPredicate, {})) {
filterPredicate = { filterPredicate = { ne: ['state', 'failed'] };
and: [
{ ne: ['state', 'deleted']},
{ ne: ['state', 'failed']}
]
};
} }
if (filterPredicate) { if (filterPredicate) {

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright 2016 Joyent, Inc. * Copyright 2017 Joyent, Inc.
*/ */
/* BEGIN JSSTYLED */ /* BEGIN JSSTYLED */
@ -122,6 +122,7 @@ var restifyBunyanSerializers =
require('restify-clients/lib/helpers/bunyan').serializers; require('restify-clients/lib/helpers/bunyan').serializers;
var tabula = require('tabula'); var tabula = require('tabula');
var vasync = require('vasync'); var vasync = require('vasync');
var verror = require('verror');
var sshpk = require('sshpk'); var sshpk = require('sshpk');
var cloudapi = require('./cloudapi2'); var cloudapi = require('./cloudapi2');
@ -2645,12 +2646,7 @@ TritonApi.prototype.getVolume = function getVolume(name, cb) {
}); });
} else { } else {
this.cloudapi.listVolumes({ this.cloudapi.listVolumes({
predicate: JSON.stringify({ predicate: JSON.stringify({ ne: ['state', 'failed']})
and: [
{ ne: ['state', 'deleted']},
{ ne: ['state', 'failed']}
]
})
}, function (err, volumes) { }, function (err, volumes) {
if (err) { if (err) {
return cb(err); return cb(err);
@ -2729,9 +2725,16 @@ TritonApi.prototype.deleteVolume = function deleteVolume(opts, cb) {
} }
self.cloudapi.waitForVolumeStates({ self.cloudapi.waitForVolumeStates({
id: arg.volId, id: arg.volId,
states: ['deleted', 'failed'], states: ['failed'],
timeout: opts.waitTimeout timeout: opts.waitTimeout
}, next); }, function onVolumeStateReached(err) {
if (verror.hasCauseWithName(err, 'VOLUME_NOT_FOUNDError')) {
// volume is gone, that's not an error
next();
return;
}
next(err);
});
} }
]}, function onDeletionComplete(err) { ]}, function onDeletionComplete(err) {
cb(err, null, res); cb(err, null, res);

View File

@ -27,7 +27,7 @@
"strsplit": "1.0.0", "strsplit": "1.0.0",
"tabula": "1.9.0", "tabula": "1.9.0",
"vasync": "1.6.3", "vasync": "1.6.3",
"verror": "1.6.0", "verror": "1.10.0",
"which": "1.2.4", "which": "1.2.4",
"wordwrap": "1.0.0" "wordwrap": "1.0.0"
}, },

View File

@ -170,7 +170,7 @@ test('triton volume create ...', testOpts, function (tt) {
function onGetVolume(getVolErr, stdout, stderr) { function onGetVolume(getVolErr, stdout, stderr) {
t.ok(getVolErr, t.ok(getVolErr,
'Getting volume ' + validVolumeName + 'after deleting it ' + 'Getting volume ' + validVolumeName + 'after deleting it ' +
'should errorr'); 'should error');
t.notEqual(stderr.indexOf('ResourceNotFound'), -1, t.notEqual(stderr.indexOf('ResourceNotFound'), -1,
'Getting volume ' + validVolumeName + 'should not find it'); 'Getting volume ' + validVolumeName + 'should not find it');
t.end(); t.end();