HDDS-207. ozone listVolume command accepts random values as argument. Contributed by Lokesh Jain.

This commit is contained in:
Xiaoyu Yao 2018-07-18 11:05:42 -07:00
parent d5d444732b
commit 129269f989
4 changed files with 28 additions and 6 deletions

View File

@ -52,7 +52,9 @@ Test ozone shell
${result} = Execute on datanode ozone oz -createVolume ${protocol}${server}/${volume} -user bilbo -quota 100TB -root
Should not contain ${result} Failed
Should contain ${result} Creating Volume: ${volume}
${result} = Execute on datanode ozone oz -listVolume o3://ozoneManager -user bilbo | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.volumeName=="${volume}")'
${result} = Execute on datanode ozone oz -listVolume ${protocol}${server}/ -user bilbo | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.volumeName=="${volume}")'
Should contain ${result} createdOn
${result} = Execute on datanode ozone oz -listVolume -user bilbo | grep -Ev 'Removed|DEBUG|ERROR|INFO|TRACE|WARN' | jq -r '.[] | select(.volumeName=="${volume}")'
Should contain ${result} createdOn
Execute on datanode ozone oz -updateVolume ${protocol}${server}/${volume} -user bill -quota 10TB
${result} = Execute on datanode ozone oz -infoVolume ${protocol}${server}/${volume} | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '. | select(.volumeName=="${volume}") | .owner | .name'
@ -66,7 +68,7 @@ Test ozone shell
Should Be Equal ${result} GROUP
${result} = Execute on datanode ozone oz -updateBucket ${protocol}${server}/${volume}/bb1 -removeAcl group:samwise:r | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '. | select(.bucketName=="bb1") | .acls | .[] | select(.name=="frodo") | .type'
Should Be Equal ${result} USER
${result} = Execute on datanode ozone oz -listBucket o3://ozoneManager/${volume}/ | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.bucketName=="bb1") | .volumeName'
${result} = Execute on datanode ozone oz -listBucket ${protocol}${server}/${volume}/ | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.bucketName=="bb1") | .volumeName'
Should Be Equal ${result} ${volume}
Run Keyword and Return If ${withkeytest} Test key handling ${protocol} ${server} ${volume}
Execute on datanode ozone oz -deleteBucket ${protocol}${server}/${volume}/bb1
@ -80,6 +82,6 @@ Test key handling
Execute on datanode ls -l NOTICE.txt.1
${result} = Execute on datanode ozone oz -infoKey ${protocol}${server}/${volume}/bb1/key1 | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '. | select(.keyName=="key1")'
Should contain ${result} createdOn
${result} = Execute on datanode ozone oz -listKey o3://ozoneManager/${volume}/bb1 | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.keyName=="key1") | .keyName'
${result} = Execute on datanode ozone oz -listKey ${protocol}${server}/${volume}/bb1 | grep -Ev 'Removed|WARN|DEBUG|ERROR|INFO|TRACE' | jq -r '.[] | select(.keyName=="key1") | .keyName'
Should Be Equal ${result} key1
Execute on datanode ozone oz -deleteKey ${protocol}${server}/${volume}/bb1/key1 -v

View File

@ -71,6 +71,7 @@
import org.apache.hadoop.util.ToolRunner;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
@ -332,7 +333,7 @@ public void testUpdateVolume() throws Exception {
public void testListVolume() throws Exception {
LOG.info("Running testListVolume");
String protocol = clientProtocol.getName().toLowerCase();
String commandOutput;
String commandOutput, commandError;
List<VolumeInfo> volumes;
final int volCount = 20;
final String user1 = "test-user-a-" + protocol;
@ -361,8 +362,15 @@ public void testListVolume() throws Exception {
assertNotNull(vol);
}
String[] args = new String[] {"-listVolume", url + "/abcde", "-user",
user1, "-length", "100"};
assertEquals(1, ToolRunner.run(shell, args));
commandError = err.toString();
Assert.assertTrue(commandError.contains("Invalid URI:"));
err.reset();
// test -length option
String[] args = new String[] {"-listVolume", url + "/", "-user",
args = new String[] {"-listVolume", url + "/", "-user",
user1, "-length", "100"};
assertEquals(0, ToolRunner.run(shell, args));
commandOutput = out.toString();

View File

@ -207,6 +207,7 @@ private void addVolumeCommands(Options options) {
"For example : ozone oz -listVolume <ozoneURI>" +
"-user <username> -root or ozone oz " +
"-listVolume");
listVolume.setOptionalArg(true);
options.addOption(listVolume);
Option updateVolume =

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.ozone.web.ozShell.volume;
import com.google.common.base.Strings;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.client.OzoneClientUtils;
import org.apache.hadoop.ozone.client.OzoneVolume;
@ -30,6 +31,7 @@
import org.apache.hadoop.ozone.web.utils.OzoneUtils;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
@ -77,7 +79,16 @@ protected void execute(CommandLine cmd)
}
String ozoneURIString = cmd.getOptionValue(Shell.LIST_VOLUME);
verifyURI(ozoneURIString);
if (Strings.isNullOrEmpty(ozoneURIString)) {
ozoneURIString = "/";
}
URI ozoneURI = verifyURI(ozoneURIString);
if (!Strings.isNullOrEmpty(ozoneURI.getPath()) && !ozoneURI.getPath()
.equals("/")) {
throw new OzoneClientException(
"Invalid URI: " + ozoneURI + " . Specified path not used." + ozoneURI
.getPath());
}
if (cmd.hasOption(Shell.USER)) {
userName = cmd.getOptionValue(Shell.USER);