From 0a65be8239468ad9514de768500c486d867a3a63 Mon Sep 17 00:00:00 2001 From: Josh Wilsdon Date: Wed, 24 May 2017 15:24:35 -0700 Subject: [PATCH] VOLAPI-49 DELETE should delete (add support in node-triton) --- lib/do_volume/do_delete.js | 49 ---------------------------- lib/do_volume/do_list.js | 9 ++--- lib/tritonapi.js | 21 +++++++----- package.json | 2 +- test/integration/cli-volumes.test.js | 2 +- 5 files changed, 16 insertions(+), 67 deletions(-) diff --git a/lib/do_volume/do_delete.js b/lib/do_volume/do_delete.js index 4ac15d6..53fc1cf 100644 --- a/lib/do_volume/do_delete.js +++ b/lib/do_volume/do_delete.js @@ -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; diff --git a/lib/do_volume/do_list.js b/lib/do_volume/do_list.js index 51e040d..9a20c90 100644 --- a/lib/do_volume/do_list.js +++ b/lib/do_volume/do_list.js @@ -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) { diff --git a/lib/tritonapi.js b/lib/tritonapi.js index 6355c06..949560e 100644 --- a/lib/tritonapi.js +++ b/lib/tritonapi.js @@ -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); diff --git a/package.json b/package.json index 8427e06..49259e7 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/integration/cli-volumes.test.js b/test/integration/cli-volumes.test.js index 18fed4e..6a4c987 100644 --- a/test/integration/cli-volumes.test.js +++ b/test/integration/cli-volumes.test.js @@ -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();