changes according to latest code review
This commit is contained in:
parent
43620ff56f
commit
c68c975d88
@ -19,6 +19,9 @@ Known issues:
|
|||||||
|
|
||||||
Use `triton volume --help` to get help on all of these commands.
|
Use `triton volume --help` to get help on all of these commands.
|
||||||
|
|
||||||
|
Note that these commands are hidden for now. They will be made visible by
|
||||||
|
default once the server-side support for volumes is shipped in Triton.
|
||||||
|
|
||||||
- [joyent/node-triton#183] `triton profile create` will no longer use ANSI
|
- [joyent/node-triton#183] `triton profile create` will no longer use ANSI
|
||||||
codes for styling if stdout isn't a TTY.
|
codes for styling if stdout isn't a TTY.
|
||||||
|
|
||||||
|
@ -152,11 +152,9 @@ do_create.options = [
|
|||||||
names: ['size', 's'],
|
names: ['size', 's'],
|
||||||
type: 'string',
|
type: 'string',
|
||||||
helpArg: 'SIZE',
|
helpArg: 'SIZE',
|
||||||
help: 'The `size` input parameter must match the following regular ' +
|
help: 'The size of the volume to create, in the form ' +
|
||||||
'expression: /(\d+)(g|m|G|M|gb|mb|GB|MB)/ All units are in ' +
|
'`<integer><unit>`, e.g. `20G`. <integer> must be > 0. Supported ' +
|
||||||
'ibibytes (mebibytes and gibibytes). `g`, `G`, `gb` and `GB` ' +
|
'units are `G` or `g` for gibibytes and `M` or `m` for mebibytes.',
|
||||||
'stand for "gibibytes". `m`, `M`, `mb` and `MB` stand for ' +
|
|
||||||
'"mebibytes".',
|
|
||||||
completionType: 'tritonvolumesize'
|
completionType: 'tritonvolumesize'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -118,13 +118,19 @@ function do_delete(subcmd, opts, args, cb) {
|
|||||||
function deleteVolumes(ctx, next) {
|
function deleteVolumes(ctx, next) {
|
||||||
vasync.forEachParallel({
|
vasync.forEachParallel({
|
||||||
func: function doDeleteVolume(volumeId, done) {
|
func: function doDeleteVolume(volumeId, done) {
|
||||||
|
if (opts.wait === undefined) {
|
||||||
|
console.log('Deleting volume %s...', volumeId);
|
||||||
|
}
|
||||||
|
|
||||||
self.top.tritonapi.deleteVolume({
|
self.top.tritonapi.deleteVolume({
|
||||||
id: volumeId,
|
id: volumeId,
|
||||||
wait: opts.wait && opts.wait.length > 0,
|
wait: opts.wait && opts.wait.length > 0,
|
||||||
waitTimeout: opts.wait_timeout * 1000
|
waitTimeout: opts.wait_timeout * 1000
|
||||||
}, function onVolDeleted(volDelErr) {
|
}, function onVolDeleted(volDelErr) {
|
||||||
if (!volDelErr) {
|
if (!volDelErr) {
|
||||||
|
if (opts.wait !== undefined) {
|
||||||
console.log('Deleted volume %s', volumeId);
|
console.log('Deleted volume %s', volumeId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error('Error when deleting volume %s: %s',
|
console.error('Error when deleting volume %s: %s',
|
||||||
volumeId, volDelErr);
|
volumeId, volDelErr);
|
||||||
|
@ -22,25 +22,21 @@ function throwInvalidSize(size) {
|
|||||||
* If "size" is not a valid size string, an error is thrown.
|
* If "size" is not a valid size string, an error is thrown.
|
||||||
*/
|
*/
|
||||||
function parseVolumeSize(size) {
|
function parseVolumeSize(size) {
|
||||||
assert.optionalString(size, 'size');
|
assert.string(size, 'size');
|
||||||
|
|
||||||
var MIBS_IN_GB = 1024;
|
var MIBS_IN_GB = 1024;
|
||||||
|
|
||||||
var MULTIPLIERS_TABLE = {
|
var MULTIPLIERS_TABLE = {
|
||||||
g: MIBS_IN_GB,
|
g: MIBS_IN_GB,
|
||||||
GB: MIBS_IN_GB,
|
G: MIBS_IN_GB,
|
||||||
m: 1,
|
m: 1,
|
||||||
MB: 1
|
M: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
var multiplierSymbol, multiplier;
|
var multiplierSymbol, multiplier;
|
||||||
var baseValue;
|
var baseValue;
|
||||||
|
|
||||||
if (size === undefined) {
|
var matches = size.match(/^([1-9]\d*)(g|m|G|M)$/);
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
var matches = size.match(/(\d+)(g|m|G|M|gb|mb|GB|MB)/);
|
|
||||||
if (!matches) {
|
if (!matches) {
|
||||||
throwInvalidSize(size);
|
throwInvalidSize(size);
|
||||||
}
|
}
|
||||||
|
92
test/unit/parseVolumeSize.test.js
Normal file
92
test/unit/parseVolumeSize.test.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* 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) 2017, Joyent, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unit tests for `parseVolumeSize` used by `triton volume ...`.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var assert = require('assert-plus');
|
||||||
|
var test = require('tape');
|
||||||
|
|
||||||
|
var parseVolumeSize = require('../../lib/volumes').parseVolumeSize;
|
||||||
|
|
||||||
|
test('parseVolumeSize', function (tt) {
|
||||||
|
tt.test('parsing invalid sizes', function (t) {
|
||||||
|
var invalidVolumeSizes = [
|
||||||
|
'foo',
|
||||||
|
'0',
|
||||||
|
'-42',
|
||||||
|
'-42m',
|
||||||
|
'-42g',
|
||||||
|
'',
|
||||||
|
'42Gasdf',
|
||||||
|
'42gasdf',
|
||||||
|
'42asdf',
|
||||||
|
'asdf42G',
|
||||||
|
'asdf42g',
|
||||||
|
'asdf42',
|
||||||
|
'042g',
|
||||||
|
'042G',
|
||||||
|
'042',
|
||||||
|
0,
|
||||||
|
42,
|
||||||
|
-42,
|
||||||
|
42.1,
|
||||||
|
-42.1,
|
||||||
|
undefined,
|
||||||
|
null,
|
||||||
|
{}
|
||||||
|
];
|
||||||
|
|
||||||
|
invalidVolumeSizes.forEach(function parse(invalidVolumeSize) {
|
||||||
|
var parseErr;
|
||||||
|
|
||||||
|
try {
|
||||||
|
parseVolumeSize(invalidVolumeSize);
|
||||||
|
} catch (err) {
|
||||||
|
parseErr = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
t.ok(parseErr, 'parsing invalid volume size: ' + invalidVolumeSize +
|
||||||
|
' should throw');
|
||||||
|
});
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
tt.test('parsing valid sizes', function (t) {
|
||||||
|
var validVolumeSizes = [
|
||||||
|
{input: '42g', expectedOutput: 42 * 1024},
|
||||||
|
{input: '42G', expectedOutput: 42 * 1024},
|
||||||
|
{input: '42m', expectedOutput: 42},
|
||||||
|
{input: '42M', expectedOutput: 42}
|
||||||
|
];
|
||||||
|
|
||||||
|
validVolumeSizes.forEach(function parse(validVolumeSize) {
|
||||||
|
var parseErr;
|
||||||
|
var volSizeInMebibytes;
|
||||||
|
|
||||||
|
try {
|
||||||
|
volSizeInMebibytes = parseVolumeSize(validVolumeSize.input);
|
||||||
|
} catch (err) {
|
||||||
|
parseErr = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
t.ifErr(parseErr, 'parsing valid volume size: ' +
|
||||||
|
validVolumeSize.input + ' should not throw');
|
||||||
|
t.equal(validVolumeSize.expectedOutput, volSizeInMebibytes,
|
||||||
|
'parsed volume size for "' + validVolumeSize.input + '" ' +
|
||||||
|
'should equal to ' + validVolumeSize.expectedOutput +
|
||||||
|
' mebibytes');
|
||||||
|
});
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user