PUBAPI-1376 Create volume errors out when the network parameter is passed
Reviewed By: Julien Gilli <julien.gilli@joyent.com>
This commit is contained in:
parent
348db1ebcc
commit
471ea6f3fe
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2015 Joyent, Inc.
|
* Copyright 2017 Joyent, Inc.
|
||||||
*
|
*
|
||||||
* Client library for the SmartDataCenter Cloud API (cloudapi).
|
* Client library for the SmartDataCenter Cloud API (cloudapi).
|
||||||
* http://apidocs.joyent.com/cloudapi/
|
* http://apidocs.joyent.com/cloudapi/
|
||||||
@ -2308,8 +2308,8 @@ CloudApi.prototype.listVolumes = function listVolumes(options, cb) {
|
|||||||
* - name {String} Optional: the name of the volume to be created
|
* - name {String} Optional: the name of the volume to be created
|
||||||
* - size {Number} Optional: a number representing the size of the volume
|
* - size {Number} Optional: a number representing the size of the volume
|
||||||
* to be created in mebibytes.
|
* to be created in mebibytes.
|
||||||
* - networks {Array} Optional: an array that contains all the networks
|
* - networks {Array} Optional: an array that contains the uuids of all the
|
||||||
* that should be reachable from the newly created volume
|
* networks that should be reachable from the newly created volume
|
||||||
* - type {String}: the type of the volume. Currently, only "tritonnfs" is
|
* - type {String}: the type of the volume. Currently, only "tritonnfs" is
|
||||||
* supported.
|
* supported.
|
||||||
* @param {Function} callback - called like `function (err, volume, res)`
|
* @param {Function} callback - called like `function (err, volume, res)`
|
||||||
@ -2328,7 +2328,7 @@ CloudApi.prototype.createVolume = function createVolume(options, cb) {
|
|||||||
data: {
|
data: {
|
||||||
name: options.name,
|
name: options.name,
|
||||||
size: options.size,
|
size: options.size,
|
||||||
networks: options.networks,
|
networks: (options.networks ? options.networks : undefined),
|
||||||
type: options.type
|
type: options.type
|
||||||
}
|
}
|
||||||
}, function (err, req, res, body) {
|
}, function (err, req, res, body) {
|
||||||
|
@ -62,7 +62,7 @@ function do_create(subcmd, opts, args, cb) {
|
|||||||
self.top.tritonapi.getNetwork(networkName,
|
self.top.tritonapi.getNetwork(networkName,
|
||||||
function onGetNetwork(getNetErr, net) {
|
function onGetNetwork(getNetErr, net) {
|
||||||
if (net) {
|
if (net) {
|
||||||
ctx.networks.push(net);
|
ctx.networks.push(net.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
nextNet(getNetErr);
|
nextNet(getNetErr);
|
||||||
|
@ -20,11 +20,15 @@ var vasync = require('vasync');
|
|||||||
var common = require('../../lib/common');
|
var common = require('../../lib/common');
|
||||||
var h = require('./helpers');
|
var h = require('./helpers');
|
||||||
|
|
||||||
|
var FABRIC_NETWORKS = [];
|
||||||
|
|
||||||
var testOpts = {
|
var testOpts = {
|
||||||
skip: !h.CONFIG.allowWriteActions
|
skip: !h.CONFIG.allowWriteActions
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
test('triton volume create ...', testOpts, function (tt) {
|
test('triton volume create ...', testOpts, function (tt) {
|
||||||
|
var currentVolume;
|
||||||
var validVolumeName =
|
var validVolumeName =
|
||||||
h.makeResourceName('node-triton-test-volume-create-default');
|
h.makeResourceName('node-triton-test-volume-create-default');
|
||||||
|
|
||||||
@ -37,6 +41,8 @@ test('triton volume create ...', testOpts, function (tt) {
|
|||||||
tt.test(' cleanup leftover resources', function (t) {
|
tt.test(' cleanup leftover resources', function (t) {
|
||||||
h.triton(['volume', 'delete', '-y', '-w', validVolumeName].join(' '),
|
h.triton(['volume', 'delete', '-y', '-w', validVolumeName].join(' '),
|
||||||
function onDelVolume(delVolErr, stdout, stderr) {
|
function onDelVolume(delVolErr, stdout, stderr) {
|
||||||
|
// If there was nothing to delete, this will fail so that's the
|
||||||
|
// normal case. Too bad we don't have a --force option.
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -54,6 +60,8 @@ test('triton volume create ...', testOpts, function (tt) {
|
|||||||
'--name',
|
'--name',
|
||||||
invalidVolumeName
|
invalidVolumeName
|
||||||
].join(' '), function (volCreateErr, stdout, stderr) {
|
].join(' '), function (volCreateErr, stdout, stderr) {
|
||||||
|
t.ok(volCreateErr, 'create should have failed' +
|
||||||
|
(volCreateErr ? '' : ', but succeeded'));
|
||||||
t.equal(stderr.indexOf(expectedErrMsg), 0,
|
t.equal(stderr.indexOf(expectedErrMsg), 0,
|
||||||
'stderr should include error message: ' + expectedErrMsg);
|
'stderr should include error message: ' + expectedErrMsg);
|
||||||
t.end();
|
t.end();
|
||||||
@ -169,4 +177,75 @@ test('triton volume create ...', testOpts, function (tt) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test that we can create a volume with a valid fabric network and the
|
||||||
|
// volume ends up on that network.
|
||||||
|
|
||||||
|
tt.test(' find fabric network', function (t) {
|
||||||
|
h.triton(['network', 'list', '-j'].join(' '),
|
||||||
|
function onGetNetworks(getNetworksErr, stdout, stderr) {
|
||||||
|
var resultsObj;
|
||||||
|
|
||||||
|
t.ifErr(getNetworksErr, 'should succeed getting network list');
|
||||||
|
|
||||||
|
// turn the JSON lines into a JSON object
|
||||||
|
resultsObj = JSON.parse('[' + stdout.trim().replace(/\n/g, ',')
|
||||||
|
+ ']');
|
||||||
|
|
||||||
|
t.ok(resultsObj.length > 0,
|
||||||
|
'should find at least 1 network, found '
|
||||||
|
+ resultsObj.length);
|
||||||
|
|
||||||
|
FABRIC_NETWORKS = resultsObj.filter(function fabricFilter(net) {
|
||||||
|
// keep only those networks that are marked as fabric=true
|
||||||
|
return (net.fabric === true);
|
||||||
|
});
|
||||||
|
|
||||||
|
t.ok(FABRIC_NETWORKS.length > 0,
|
||||||
|
'should find at least 1 fabric network, found '
|
||||||
|
+ FABRIC_NETWORKS.length);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tt.test(' triton volume on fabric network', function (t) {
|
||||||
|
h.triton([
|
||||||
|
'volume',
|
||||||
|
'create',
|
||||||
|
'--name',
|
||||||
|
'node-triton-test-volume-create-fabric-network',
|
||||||
|
'--network',
|
||||||
|
FABRIC_NETWORKS[0].id,
|
||||||
|
'-w'
|
||||||
|
].join(' '), function (volCreateErr, stdout, stderr) {
|
||||||
|
t.ifErr(volCreateErr, 'volume creation should succeed');
|
||||||
|
|
||||||
|
currentVolume = JSON.parse(stdout);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tt.test(' check volume was created', function (t) {
|
||||||
|
h.safeTriton(t, ['volume', 'get', currentVolume.name],
|
||||||
|
function onGetVolume(getVolErr, stdout) {
|
||||||
|
var volumeObj;
|
||||||
|
|
||||||
|
t.ifError(getVolErr, 'getting volume should succeed');
|
||||||
|
|
||||||
|
volumeObj = JSON.parse(stdout);
|
||||||
|
t.equal(volumeObj.networks[0], FABRIC_NETWORKS[0].id,
|
||||||
|
'expect network to match fabric we passed');
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tt.test(' delete volume', function (t) {
|
||||||
|
h.triton(['volume', 'delete', '-y', '-w', currentVolume.name].join(' '),
|
||||||
|
function onDelVolume(delVolErr, stdout, stderr) {
|
||||||
|
t.ifError(delVolErr, 'deleting volume should succeed');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user