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');
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) {
var self = this;

View File

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

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright 2016 Joyent, Inc.
* Copyright 2017 Joyent, Inc.
*/
/* BEGIN JSSTYLED */
@ -122,6 +122,7 @@ var restifyBunyanSerializers =
require('restify-clients/lib/helpers/bunyan').serializers;
var tabula = require('tabula');
var vasync = require('vasync');
var verror = require('verror');
var sshpk = require('sshpk');
var cloudapi = require('./cloudapi2');
@ -2645,12 +2646,7 @@ TritonApi.prototype.getVolume = function getVolume(name, cb) {
});
} else {
this.cloudapi.listVolumes({
predicate: JSON.stringify({
and: [
{ ne: ['state', 'deleted']},
{ ne: ['state', 'failed']}
]
})
predicate: JSON.stringify({ ne: ['state', 'failed']})
}, function (err, volumes) {
if (err) {
return cb(err);
@ -2729,9 +2725,16 @@ TritonApi.prototype.deleteVolume = function deleteVolume(opts, cb) {
}
self.cloudapi.waitForVolumeStates({
id: arg.volId,
states: ['deleted', 'failed'],
states: ['failed'],
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) {
cb(err, null, res);

View File

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

View File

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