Repository: incubator-slider Updated Branches: refs/heads/develop d6844f98a -> 3ad0e566d
SLIDER-636 add CLI keytab command with install, delete, and list options Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/3ad0e566 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/3ad0e566 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/3ad0e566 Branch: refs/heads/develop Commit: 3ad0e566d95cef35de1b6c749489509cf42b1c0c Parents: d6844f9 Author: Jon Maron <[email protected]> Authored: Tue Dec 23 18:13:50 2014 -0500 Committer: Jon Maron <[email protected]> Committed: Tue Dec 23 18:13:50 2014 -0500 ---------------------------------------------------------------------- .../org/apache/slider/client/SliderClient.java | 93 ++++- .../apache/slider/client/SliderClientAPI.java | 14 + .../slider/common/params/ActionKeytabArgs.java | 81 +++++ .../apache/slider/common/params/Arguments.java | 3 + .../apache/slider/common/params/ClientArgs.java | 8 + .../slider/common/params/SliderActions.java | 2 + .../TestDeprecatedInstallKeytabCommand.groovy | 210 +++++++++++ .../slider/client/TestInstallKeytab.groovy | 210 ----------- .../client/TestKeytabCommandOptions.groovy | 360 +++++++++++++++++++ 9 files changed, 757 insertions(+), 224 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3ad0e566/slider-core/src/main/java/org/apache/slider/client/SliderClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java index 225b0e0..98bb36f 100644 --- a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java +++ b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java @@ -24,8 +24,10 @@ import com.google.common.base.Preconditions; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.LocatedFileStatus; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.PathNotFoundException; +import org.apache.hadoop.fs.RemoteIterator; import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.DFSConfigKeys; @@ -82,6 +84,7 @@ import org.apache.slider.common.params.ActionCreateArgs; import org.apache.slider.common.params.ActionEchoArgs; import org.apache.slider.common.params.ActionFlexArgs; import org.apache.slider.common.params.ActionFreezeArgs; +import org.apache.slider.common.params.ActionKeytabArgs; import org.apache.slider.common.params.ActionKillContainerArgs; import org.apache.slider.common.params.ActionListArgs; import org.apache.slider.common.params.ActionLookupArgs; @@ -377,13 +380,15 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe exitCode = actionInstallPkg(serviceArgs.getActionInstallPackageArgs()); } else if (ACTION_INSTALL_KEYTAB.equals(action)) { exitCode = actionInstallKeytab(serviceArgs.getActionInstallKeytabArgs()); + } else if (ACTION_KEYTAB.equals(action)) { + exitCode = actionKeytab(serviceArgs.getActionKeytabArgs()); } else if (ACTION_BUILD.equals(action)) { exitCode = actionBuild(clusterName, serviceArgs.getActionBuildArgs()); } else if (ACTION_CREATE.equals(action)) { exitCode = actionCreate(clusterName, serviceArgs.getActionCreateArgs()); } else if (ACTION_FREEZE.equals(action)) { exitCode = actionFreeze(clusterName, - serviceArgs.getActionFreezeArgs()); + serviceArgs.getActionFreezeArgs()); } else if (ACTION_THAW.equals(action)) { exitCode = actionThaw(clusterName, serviceArgs.getActionThawArgs()); } else if (ACTION_DESTROY.equals(action)) { @@ -392,17 +397,17 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe exitCode = actionDiagnostic(serviceArgs.getActionDiagnosticArgs()); } else if (ACTION_EXISTS.equals(action)) { exitCode = actionExists(clusterName, - serviceArgs.getActionExistsArgs()); + serviceArgs.getActionExistsArgs()); } else if (ACTION_FLEX.equals(action)) { exitCode = actionFlex(clusterName, serviceArgs.getActionFlexArgs()); } else if (ACTION_HELP.equals(action)) { log.info(serviceArgs.usage()); } else if (ACTION_KILL_CONTAINER.equals(action)) { exitCode = actionKillContainer(clusterName, - serviceArgs.getActionKillContainerArgs()); + serviceArgs.getActionKillContainerArgs()); } else if (ACTION_AM_SUICIDE.equals(action)) { exitCode = actionAmSuicide(clusterName, - serviceArgs.getActionAMSuicideArgs()); + serviceArgs.getActionAMSuicideArgs()); } else if (ACTION_LIST.equals(action)) { exitCode = actionList(clusterName, serviceArgs.getActionListArgs()); } else if (ACTION_LOOKUP.equals(action)) { @@ -413,7 +418,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe exitCode = actionResolve(serviceArgs.getActionResolveArgs()); } else if (ACTION_STATUS.equals(action)) { exitCode = actionStatus(clusterName, - serviceArgs.getActionStatusArgs()); + serviceArgs.getActionStatusArgs()); } else if (ACTION_UPDATE.equals(action)) { exitCode = actionUpdate(clusterName, serviceArgs.getActionUpdateArgs()); } else if (ACTION_VERSION.equals(action)) { @@ -713,20 +718,73 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe } @Override - public int actionInstallKeytab(ActionInstallKeytabArgs installKeytabInfo) + public int actionKeytab(ActionKeytabArgs keytabInfo) throws YarnException, IOException { + if (keytabInfo.install) { + return actionInstallKeytab(keytabInfo); + } else if (keytabInfo.delete) { + return actionDeleteKeytab(keytabInfo); + } else if (keytabInfo.list) { + return actionListKeytab(keytabInfo); + } else { + throw new BadCommandArgumentsException( + "Keytab option specified not found.\n" + + CommonArgs.usage(serviceArgs, ACTION_KEYTAB)); + } + } + + private int actionListKeytab(ActionKeytabArgs keytabInfo) throws IOException { + String folder = keytabInfo.folder != null ? keytabInfo.folder : StringUtils.EMPTY; + Path keytabPath = sliderFileSystem.buildKeytabInstallationDirPath(folder); + RemoteIterator<LocatedFileStatus> files = + sliderFileSystem.getFileSystem().listFiles(keytabPath, true); + log.info("Keytabs:"); + while (files.hasNext()) { + log.info("\t" + files.next().getPath().toString()); + } + + return EXIT_SUCCESS; + } + + private int actionDeleteKeytab(ActionKeytabArgs keytabInfo) + throws BadCommandArgumentsException, IOException { + if (StringUtils.isEmpty(keytabInfo.folder)) { + throw new BadCommandArgumentsException( + "A valid destination keytab sub-folder name is required (e.g. 'security').\n" + + CommonArgs.usage(serviceArgs, ACTION_KEYTAB)); + } + if (StringUtils.isEmpty(keytabInfo.keytab)) { + throw new BadCommandArgumentsException("A keytab name is required."); + } + + Path pkgPath = sliderFileSystem.buildKeytabInstallationDirPath(keytabInfo.folder); + + Path fileInFs = new Path(pkgPath, keytabInfo.keytab ); + log.info("Deleting keytab {}", fileInFs); + if (!sliderFileSystem.getFileSystem().exists(fileInFs)) { + throw new BadCommandArgumentsException("No keytab to delete found at " + + fileInFs.toUri().toString()); + } + + sliderFileSystem.getFileSystem().delete(fileInFs, false); + + return EXIT_SUCCESS; + } + + private int actionInstallKeytab(ActionKeytabArgs keytabInfo) + throws BadCommandArgumentsException, IOException { Path srcFile = null; - if (StringUtils.isEmpty(installKeytabInfo.folder)) { + if (StringUtils.isEmpty(keytabInfo.folder)) { throw new BadCommandArgumentsException( "A valid destination keytab sub-folder name is required (e.g. 'security').\n" - + CommonArgs.usage(serviceArgs, ACTION_INSTALL_KEYTAB)); + + CommonArgs.usage(serviceArgs, ACTION_KEYTAB)); } - if (StringUtils.isEmpty(installKeytabInfo.keytabUri)) { + if (StringUtils.isEmpty(keytabInfo.keytab)) { throw new BadCommandArgumentsException("A valid local keytab location is required."); } else { - File keytabFile = new File(installKeytabInfo.keytabUri); + File keytabFile = new File(keytabInfo.keytab); if (!keytabFile.exists() || keytabFile.isDirectory()) { throw new BadCommandArgumentsException("Unable to access supplied keytab file at " + keytabFile.getAbsolutePath()); @@ -735,20 +793,20 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe } } - Path pkgPath = sliderFileSystem.buildKeytabInstallationDirPath(installKeytabInfo.folder); + Path pkgPath = sliderFileSystem.buildKeytabInstallationDirPath(keytabInfo.folder); sliderFileSystem.getFileSystem().mkdirs(pkgPath); sliderFileSystem.getFileSystem().setPermission(pkgPath, new FsPermission( FsAction.ALL, FsAction.NONE, FsAction.NONE)); Path fileInFs = new Path(pkgPath, srcFile.getName()); - log.info("Installing keytab {} at {} and overwrite is {}.", srcFile, fileInFs, installKeytabInfo.overwrite); - if (sliderFileSystem.getFileSystem().exists(fileInFs) && !installKeytabInfo.overwrite) { + log.info("Installing keytab {} at {} and overwrite is {}.", srcFile, fileInFs, keytabInfo.overwrite); + if (sliderFileSystem.getFileSystem().exists(fileInFs) && !keytabInfo.overwrite) { throw new BadCommandArgumentsException("Keytab exists at " + fileInFs.toUri().toString() + ". Use --overwrite to overwrite."); } - sliderFileSystem.getFileSystem().copyFromLocalFile(false, installKeytabInfo.overwrite, srcFile, fileInFs); + sliderFileSystem.getFileSystem().copyFromLocalFile(false, keytabInfo.overwrite, srcFile, fileInFs); sliderFileSystem.getFileSystem().setPermission(fileInFs, new FsPermission( FsAction.READ_WRITE, FsAction.NONE, FsAction.NONE)); @@ -756,6 +814,13 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe } @Override + public int actionInstallKeytab(ActionInstallKeytabArgs installKeytabInfo) + throws YarnException, IOException { + log.warn("The 'install-keytab' option has been deprecated. Please use 'keytab --install'."); + return actionKeytab(new ActionKeytabArgs(installKeytabInfo)); + } + + @Override public int actionInstallPkg(ActionInstallPackageArgs installPkgInfo) throws YarnException, IOException { http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3ad0e566/slider-core/src/main/java/org/apache/slider/client/SliderClientAPI.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderClientAPI.java b/slider-core/src/main/java/org/apache/slider/client/SliderClientAPI.java index 40b71a0..9b0f10f 100644 --- a/slider-core/src/main/java/org/apache/slider/client/SliderClientAPI.java +++ b/slider-core/src/main/java/org/apache/slider/client/SliderClientAPI.java @@ -32,6 +32,7 @@ import org.apache.slider.common.params.ActionFlexArgs; import org.apache.slider.common.params.ActionFreezeArgs; import org.apache.slider.common.params.ActionInstallKeytabArgs; import org.apache.slider.common.params.ActionInstallPackageArgs; +import org.apache.slider.common.params.ActionKeytabArgs; import org.apache.slider.common.params.ActionKillContainerArgs; import org.apache.slider.common.params.ActionListArgs; import org.apache.slider.common.params.ActionRegistryArgs; @@ -94,11 +95,24 @@ public interface SliderClientAPI extends Service { * @throws YarnException Yarn problems * @throws IOException other problems * @throws BadCommandArgumentsException bad arguments. + * @deperecated use #actionKeytab */ int actionInstallKeytab(ActionInstallKeytabArgs installKeytabInfo) throws YarnException, IOException; /** + * Manage keytabs leveraged by slider + * + * @param keytabInfo the arguments needed to manage the keytab + * @throws YarnException Yarn problems + * @throws IOException other problems + * @throws BadCommandArgumentsException bad arguments. + * @deperecated use #actionKeytab + */ + int actionKeytab(ActionKeytabArgs keytabInfo) + throws YarnException, IOException; + + /** * Upload application package to user home directory * * @param installPkgInfo the arguments needed to upload the package http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3ad0e566/slider-core/src/main/java/org/apache/slider/common/params/ActionKeytabArgs.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/common/params/ActionKeytabArgs.java b/slider-core/src/main/java/org/apache/slider/common/params/ActionKeytabArgs.java new file mode 100644 index 0000000..32b1d2b --- /dev/null +++ b/slider-core/src/main/java/org/apache/slider/common/params/ActionKeytabArgs.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.slider.common.params; + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; + +@Parameters(commandNames = {SliderActions.ACTION_KEYTAB}, + commandDescription = SliderActions.DESCRIBE_ACTION_KEYTAB) + +public class ActionKeytabArgs extends AbstractActionArgs { + + public ActionKeytabArgs(ActionInstallKeytabArgs installKeytabInfo) { + this.install = true; + this.overwrite = installKeytabInfo.overwrite; + this.keytab = installKeytabInfo.keytabUri; + this.folder = installKeytabInfo.folder; + } + + public ActionKeytabArgs() { + super(); + } + + @Override + public String getActionName() { + return SliderActions.ACTION_INSTALL_KEYTAB; + } + + @Parameter(names = {ARG_KEYTABINSTALL}, + description = "Install the keytab") + public boolean install; + + @Parameter(names = {ARG_KEYTABDELETE}, + description = "Delete the keytab") + public boolean delete; + + @Parameter(names = {ARG_KEYTABLIST}, + description = "List of installed keytabs") + public boolean list; + + @Parameter(names = {ARG_KEYTAB}, + description = "Path or name of the keytab") + public String keytab; + + @Parameter(names = {ARG_FOLDER}, + description = "The name of the folder in which to store the keytab") + public String folder; + + @Parameter(names = {ARG_OVERWRITE}, description = "Overwrite existing keytab") + public boolean overwrite = false; + + /** + * Get the min #of params expected + * @return the min number of params in the {@link #parameters} field + */ + public int getMinParams() { + return 0; + } + + @Override + public int getMaxParams() { + return 3; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3ad0e566/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java b/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java index 42efb33..002b77d 100644 --- a/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java +++ b/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java @@ -60,6 +60,9 @@ public interface Arguments { String ARG_IMAGE = "--image"; String ARG_INTERNAL = "--internal"; String ARG_KEYTAB = "--keytab"; + String ARG_KEYTABINSTALL = "--install"; + String ARG_KEYTABDELETE = "--delete"; + String ARG_KEYTABLIST = "--list"; String ARG_LEVEL = "--level"; String ARG_LIST = "--list"; String ARG_LISTCONF = "--listconf"; http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3ad0e566/slider-core/src/main/java/org/apache/slider/common/params/ClientArgs.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/common/params/ClientArgs.java b/slider-core/src/main/java/org/apache/slider/common/params/ClientArgs.java index a3b7997..a0f82e6 100644 --- a/slider-core/src/main/java/org/apache/slider/common/params/ClientArgs.java +++ b/slider-core/src/main/java/org/apache/slider/common/params/ClientArgs.java @@ -58,6 +58,7 @@ public class ClientArgs extends CommonArgs { private final ActionHelpArgs actionHelpArgs = new ActionHelpArgs(); private final ActionInstallPackageArgs actionInstallPackageArgs = new ActionInstallPackageArgs(); private final ActionInstallKeytabArgs actionInstallKeytabArgs = new ActionInstallKeytabArgs(); + private final ActionKeytabArgs actionKeytabArgs = new ActionKeytabArgs(); private final ActionKillContainerArgs actionKillContainerArgs = new ActionKillContainerArgs(); private final ActionListArgs actionListArgs = new ActionListArgs(); @@ -94,6 +95,7 @@ public class ClientArgs extends CommonArgs { actionHelpArgs, actionInstallPackageArgs, actionInstallKeytabArgs, + actionKeytabArgs, actionKillContainerArgs, actionListArgs, actionLookupArgs, @@ -143,6 +145,9 @@ public class ClientArgs extends CommonArgs { public ActionInstallKeytabArgs getActionInstallKeytabArgs() { return actionInstallKeytabArgs; } + public ActionKeytabArgs getActionKeytabArgs() { + return actionKeytabArgs; } + public ActionUpdateArgs getActionUpdateArgs() { return actionUpdateArgs; } @@ -241,6 +246,9 @@ public class ClientArgs extends CommonArgs { } else if (SliderActions.ACTION_INSTALL_PACKAGE.equals(action)) { bindCoreAction(actionInstallPackageArgs); + } else if (SliderActions.ACTION_KEYTAB.equals(action)) { + bindCoreAction(actionKeytabArgs); + } else if (SliderActions.ACTION_INSTALL_KEYTAB.equals(action)) { bindCoreAction(actionInstallKeytabArgs); http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3ad0e566/slider-core/src/main/java/org/apache/slider/common/params/SliderActions.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/common/params/SliderActions.java b/slider-core/src/main/java/org/apache/slider/common/params/SliderActions.java index 4b92a32..3dee8ff 100644 --- a/slider-core/src/main/java/org/apache/slider/common/params/SliderActions.java +++ b/slider-core/src/main/java/org/apache/slider/common/params/SliderActions.java @@ -47,6 +47,7 @@ public interface SliderActions { String ACTION_DIAGNOSTICS = "diagnostics"; String ACTION_INSTALL_PACKAGE = "install-package"; String ACTION_INSTALL_KEYTAB = "install-keytab"; + String ACTION_KEYTAB = "keytab"; String DESCRIBE_ACTION_AM_SUICIDE = "Tell the Slider Application Master to simulate a process failure by terminating itself"; String DESCRIBE_ACTION_BUILD = @@ -85,6 +86,7 @@ public interface SliderActions { "Print the Slider version information"; String DESCRIBE_ACTION_INSTALL_PACKAGE = "Install the application package in the home directory under sub-folder packages"; String DESCRIBE_ACTION_INSTALL_KEYTAB = "Install the Kerberos keytab file in the sub-folder 'keytabs' of the user's Slider base directory"; + String DESCRIBE_ACTION_KEYTAB = "Manage a Kerberos keytab file (install, delete, list) in the sub-folder 'keytabs' of the user's Slider base directory"; String DESCRIBE_ACTION_DIAGNOSTIC = "Diagnose the configuration of the running slider application and slider client"; } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3ad0e566/slider-core/src/test/groovy/org/apache/slider/client/TestDeprecatedInstallKeytabCommand.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/client/TestDeprecatedInstallKeytabCommand.groovy b/slider-core/src/test/groovy/org/apache/slider/client/TestDeprecatedInstallKeytabCommand.groovy new file mode 100644 index 0000000..a06b3ca --- /dev/null +++ b/slider-core/src/test/groovy/org/apache/slider/client/TestDeprecatedInstallKeytabCommand.groovy @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.slider.client + +import org.apache.commons.io.FileUtils +import org.apache.hadoop.fs.FileUtil +import org.apache.hadoop.fs.Path +import org.apache.hadoop.fs.RawLocalFileSystem +import org.apache.hadoop.yarn.conf.YarnConfiguration +import org.apache.slider.common.params.Arguments +import org.apache.slider.common.params.ClientArgs +import org.apache.slider.common.tools.SliderFileSystem +import org.apache.slider.common.tools.SliderUtils +import org.apache.slider.core.exceptions.BadCommandArgumentsException +import org.apache.slider.core.exceptions.SliderException +import org.apache.slider.core.main.ServiceLauncher +import org.apache.slider.core.main.ServiceLauncherBaseTest +import org.junit.Before +import org.junit.Test + +/** + * Test a keytab installation + */ +class TestDeprecatedInstallKeytabCommand extends ServiceLauncherBaseTest { + final shouldFail = new GroovyTestCase().&shouldFail + + private static SliderFileSystem testFileSystem + + @Before + public void setupFilesystem() { + org.apache.hadoop.fs.FileSystem fileSystem = new RawLocalFileSystem() + YarnConfiguration configuration = SliderUtils.createConfiguration() + fileSystem.setConf(configuration) + testFileSystem = new SliderFileSystem(fileSystem, configuration) + } + + @Test + public void testInstallKeytab() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder"]) + Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) + File installedKeytab = new File(installedPath.toUri().path) + assert installedKeytab.exists() + assert FileUtils.readFileToString(installedKeytab).equals( + FileUtils.readFileToString(localKeytab)) + } + + @Test + public void testInstallKeytabWithNoFolder() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + shouldFail(BadCommandArgumentsException) { + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath]) + } + } + + @Test + public void testInstallKeytabWithNoKeytab() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + shouldFail(BadCommandArgumentsException) { + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_FOLDER, + "testFolder"]) + } + } + + @Test + public void testInstallKeytabAllowingOverwrite() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder"]) + Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) + File installedKeytab = new File(installedPath.toUri().path) + assert installedKeytab.exists() + assert FileUtils.readFileToString(installedKeytab).equals(FileUtils.readFileToString(localKeytab)) + launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder", + Arguments.ARG_OVERWRITE] + ) + assert installedKeytab.exists() + assert FileUtils.readFileToString(installedKeytab).equals( + FileUtils.readFileToString(localKeytab)) + } + + @Test + public void testInstallKeytabNotAllowingOverwrite() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder"]) + Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) + File installedKeytab = new File(installedPath.toUri().path) + assert installedKeytab.exists() + assert FileUtils.readFileToString(installedKeytab).equals(FileUtils.readFileToString(localKeytab)) + shouldFail(BadCommandArgumentsException) { + launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder"]) + } + } + + @Test + public void testInstallKeytabWithMissingKeytab() throws Throwable { + // create a mock keytab file + YarnConfiguration conf = SliderUtils.createConfiguration() + shouldFail(BadCommandArgumentsException) { + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_KEYTAB, + "HeyIDontExist.keytab", + Arguments.ARG_FOLDER, + "testFolder"]) + } + } + + private File getTempLocation () { + return new File(System.getProperty("user.dir") + "/target"); + } + + static class TestSliderClient extends SliderClient { + public TestSliderClient() { + super() + } + + @Override + protected void initHadoopBinding() throws IOException, SliderException { + sliderFileSystem = testFileSystem + } + + } +} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3ad0e566/slider-core/src/test/groovy/org/apache/slider/client/TestInstallKeytab.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/client/TestInstallKeytab.groovy b/slider-core/src/test/groovy/org/apache/slider/client/TestInstallKeytab.groovy deleted file mode 100644 index 2bbad6a..0000000 --- a/slider-core/src/test/groovy/org/apache/slider/client/TestInstallKeytab.groovy +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.slider.client - -import org.apache.commons.io.FileUtils -import org.apache.hadoop.fs.FileUtil -import org.apache.hadoop.fs.Path -import org.apache.hadoop.fs.RawLocalFileSystem -import org.apache.hadoop.yarn.conf.YarnConfiguration -import org.apache.slider.common.params.Arguments -import org.apache.slider.common.params.ClientArgs -import org.apache.slider.common.tools.SliderFileSystem -import org.apache.slider.common.tools.SliderUtils -import org.apache.slider.core.exceptions.BadCommandArgumentsException -import org.apache.slider.core.exceptions.SliderException -import org.apache.slider.core.main.ServiceLauncher -import org.apache.slider.core.main.ServiceLauncherBaseTest -import org.junit.Before -import org.junit.Test - -/** - * Test a keytab installation - */ -class TestInstallKeytab extends ServiceLauncherBaseTest { - final shouldFail = new GroovyTestCase().&shouldFail - - private static SliderFileSystem testFileSystem - - @Before - public void setupFilesystem() { - org.apache.hadoop.fs.FileSystem fileSystem = new RawLocalFileSystem() - YarnConfiguration configuration = SliderUtils.createConfiguration() - fileSystem.setConf(configuration) - testFileSystem = new SliderFileSystem(fileSystem, configuration) - } - - @Test - public void testInstallKeytab() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(tempLocation, "test", true); - String contents = UUID.randomUUID().toString() - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration() - ServiceLauncher launcher = launch(TestSliderClient, - conf, - [ - ClientArgs.ACTION_INSTALL_KEYTAB, - ClientArgs.ARG_KEYTAB, - localKeytab.absolutePath, - Arguments.ARG_FOLDER, - "testFolder"]) - Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) - File installedKeytab = new File(installedPath.toUri().path) - assert installedKeytab.exists() - assert FileUtils.readFileToString(installedKeytab).equals( - FileUtils.readFileToString(localKeytab)) - } - - @Test - public void testInstallKeytabWithNoFolder() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(tempLocation, "test", true); - String contents = UUID.randomUUID().toString() - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration() - shouldFail(BadCommandArgumentsException) { - ServiceLauncher launcher = launch(TestSliderClient, - conf, - [ - ClientArgs.ACTION_INSTALL_KEYTAB, - ClientArgs.ARG_KEYTAB, - localKeytab.absolutePath]) - } - } - - @Test - public void testInstallKeytabWithNoKeytab() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(tempLocation, "test", true); - String contents = UUID.randomUUID().toString() - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration() - shouldFail(BadCommandArgumentsException) { - ServiceLauncher launcher = launch(TestSliderClient, - conf, - [ - ClientArgs.ACTION_INSTALL_KEYTAB, - ClientArgs.ARG_FOLDER, - "testFolder"]) - } - } - - @Test - public void testInstallKeytabAllowingOverwrite() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(tempLocation, "test", true); - String contents = UUID.randomUUID().toString() - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration() - ServiceLauncher launcher = launch(TestSliderClient, - conf, - [ - ClientArgs.ACTION_INSTALL_KEYTAB, - ClientArgs.ARG_KEYTAB, - localKeytab.absolutePath, - Arguments.ARG_FOLDER, - "testFolder"]) - Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) - File installedKeytab = new File(installedPath.toUri().path) - assert installedKeytab.exists() - assert FileUtils.readFileToString(installedKeytab).equals(FileUtils.readFileToString(localKeytab)) - launcher = launch(TestSliderClient, - conf, - [ - ClientArgs.ACTION_INSTALL_KEYTAB, - ClientArgs.ARG_KEYTAB, - localKeytab.absolutePath, - Arguments.ARG_FOLDER, - "testFolder", - Arguments.ARG_OVERWRITE] - ) - assert installedKeytab.exists() - assert FileUtils.readFileToString(installedKeytab).equals( - FileUtils.readFileToString(localKeytab)) - } - - @Test - public void testInstallKeytabNotAllowingOverwrite() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(tempLocation, "test", true); - String contents = UUID.randomUUID().toString() - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration() - ServiceLauncher launcher = launch(TestSliderClient, - conf, - [ - ClientArgs.ACTION_INSTALL_KEYTAB, - ClientArgs.ARG_KEYTAB, - localKeytab.absolutePath, - Arguments.ARG_FOLDER, - "testFolder"]) - Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) - File installedKeytab = new File(installedPath.toUri().path) - assert installedKeytab.exists() - assert FileUtils.readFileToString(installedKeytab).equals(FileUtils.readFileToString(localKeytab)) - shouldFail(BadCommandArgumentsException) { - launcher = launch(TestSliderClient, - conf, - [ - ClientArgs.ACTION_INSTALL_KEYTAB, - ClientArgs.ARG_KEYTAB, - localKeytab.absolutePath, - Arguments.ARG_FOLDER, - "testFolder"]) - } - } - - @Test - public void testInstallKeytabWithMissingKeytab() throws Throwable { - // create a mock keytab file - YarnConfiguration conf = SliderUtils.createConfiguration() - shouldFail(BadCommandArgumentsException) { - ServiceLauncher launcher = launch(TestSliderClient, - conf, - [ - ClientArgs.ACTION_INSTALL_KEYTAB, - ClientArgs.ARG_KEYTAB, - "HeyIDontExist.keytab", - Arguments.ARG_FOLDER, - "testFolder"]) - } - } - - private File getTempLocation () { - return new File(System.getProperty("user.dir") + "/target"); - } - - static class TestSliderClient extends SliderClient { - public TestSliderClient() { - super() - } - - @Override - protected void initHadoopBinding() throws IOException, SliderException { - sliderFileSystem = testFileSystem - } - - } -} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3ad0e566/slider-core/src/test/groovy/org/apache/slider/client/TestKeytabCommandOptions.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/client/TestKeytabCommandOptions.groovy b/slider-core/src/test/groovy/org/apache/slider/client/TestKeytabCommandOptions.groovy new file mode 100644 index 0000000..38662ef --- /dev/null +++ b/slider-core/src/test/groovy/org/apache/slider/client/TestKeytabCommandOptions.groovy @@ -0,0 +1,360 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.slider.client + +import org.apache.commons.io.FileUtils +import org.apache.hadoop.fs.FileUtil +import org.apache.hadoop.fs.Path +import org.apache.hadoop.fs.RawLocalFileSystem +import org.apache.hadoop.util.StringUtils +import org.apache.hadoop.yarn.conf.YarnConfiguration +import org.apache.log4j.AppenderSkeleton +import org.apache.log4j.Logger +import org.apache.log4j.spi.LoggingEvent +import org.apache.slider.common.params.Arguments +import org.apache.slider.common.params.ClientArgs +import org.apache.slider.common.tools.SliderFileSystem +import org.apache.slider.common.tools.SliderUtils +import org.apache.slider.core.exceptions.BadCommandArgumentsException +import org.apache.slider.core.exceptions.SliderException +import org.apache.slider.core.main.ServiceLauncher +import org.apache.slider.core.main.ServiceLauncherBaseTest +import org.junit.Before +import org.junit.Test + +/** + * Test a keytab installation + */ +class TestKeytabCommandOptions extends ServiceLauncherBaseTest { + final shouldFail = new GroovyTestCase().&shouldFail + + private static SliderFileSystem testFileSystem + + @Before + public void setupFilesystem() { + org.apache.hadoop.fs.FileSystem fileSystem = new RawLocalFileSystem() + YarnConfiguration configuration = SliderUtils.createConfiguration() + fileSystem.setConf(configuration) + testFileSystem = new SliderFileSystem(fileSystem, configuration) + File testFolderDir = new File(testFileSystem.buildKeytabInstallationDirPath("").toUri().path) + testFolderDir.deleteDir() + + } + + @Test + public void testInstallKeytab() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABINSTALL, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder"]) + Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) + File installedKeytab = new File(installedPath.toUri().path) + assert installedKeytab.exists() + assert FileUtils.readFileToString(installedKeytab).equals( + FileUtils.readFileToString(localKeytab)) + } + + @Test + public void testInstallThenDeleteKeytab() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder"]) + Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) + File installedKeytab = new File(installedPath.toUri().path) + assert installedKeytab.exists() + assert FileUtils.readFileToString(installedKeytab).equals( + FileUtils.readFileToString(localKeytab)) + + launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABDELETE, + ClientArgs.ARG_KEYTAB, + localKeytab.name, + Arguments.ARG_FOLDER, + "testFolder"]) + + assert !installedKeytab.exists() + + } + + @Test + public void testInstallThenListKeytab() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder"]) + Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) + File installedKeytab = new File(installedPath.toUri().path) + assert installedKeytab.exists() + assert FileUtils.readFileToString(installedKeytab).equals( + FileUtils.readFileToString(localKeytab)) + + // install an additional copy into another folder to test listing + launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_INSTALL_KEYTAB, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder2"]) + + TestAppender testAppender = new TestAppender(); + + Logger.getLogger(SliderClient.class).addAppender(testAppender); + + try { + launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABLIST] + ) + assert testAppender.events.size() == 3 + assert testAppender.events.get(1).message == + "\tfile:/Users/jmaron/.slider/keytabs/testFolder/" + installedKeytab.name + assert testAppender.events.get(2).message == + "\tfile:/Users/jmaron/.slider/keytabs/testFolder2/" + installedKeytab.name + } finally { + Logger.getLogger(SliderClient.class).removeAppender(testAppender); + } + + // now listing while specifying the folder name + testAppender = new TestAppender(); + + Logger.getLogger(SliderClient.class).addAppender(testAppender); + + try { + launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABLIST, + Arguments.ARG_FOLDER, + "testFolder"]) + assert testAppender.events.size() == 2 + assert testAppender.events.get(1).message == + "\tfile:/Users/jmaron/.slider/keytabs/testFolder/" + installedKeytab.name + } finally { + Logger.getLogger(SliderClient.class).removeAppender(testAppender); + } + } + + @Test + public void testDeleteNonExistentKeytab() throws Throwable { + // create a mock keytab file + YarnConfiguration conf = SliderUtils.createConfiguration() + shouldFail(BadCommandArgumentsException) { + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABDELETE, + ClientArgs.ARG_KEYTAB, + "HeyIDontExist.keytab", + Arguments.ARG_FOLDER, + "testFolder"]) + } + } + + @Test + public void testInstallKeytabWithNoFolder() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + shouldFail(BadCommandArgumentsException) { + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABINSTALL, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath]) + } + } + + @Test + public void testInstallKeytabWithNoKeytab() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + shouldFail(BadCommandArgumentsException) { + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABINSTALL, + ClientArgs.ARG_FOLDER, + "testFolder"]) + } + } + + @Test + public void testInstallKeytabAllowingOverwrite() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABINSTALL, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder"]) + Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) + File installedKeytab = new File(installedPath.toUri().path) + assert installedKeytab.exists() + assert FileUtils.readFileToString(installedKeytab).equals(FileUtils.readFileToString(localKeytab)) + launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABINSTALL, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder", + Arguments.ARG_OVERWRITE] + ) + assert installedKeytab.exists() + assert FileUtils.readFileToString(installedKeytab).equals( + FileUtils.readFileToString(localKeytab)) + } + + @Test + public void testInstallKeytabNotAllowingOverwrite() throws Throwable { + // create a mock keytab file + File localKeytab = + FileUtil.createLocalTempFile(tempLocation, "test", true); + String contents = UUID.randomUUID().toString() + FileUtils.write(localKeytab, contents); + YarnConfiguration conf = SliderUtils.createConfiguration() + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABINSTALL, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder"]) + Path installedPath = new Path(testFileSystem.buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()) + File installedKeytab = new File(installedPath.toUri().path) + assert installedKeytab.exists() + assert FileUtils.readFileToString(installedKeytab).equals(FileUtils.readFileToString(localKeytab)) + shouldFail(BadCommandArgumentsException) { + launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABINSTALL, + ClientArgs.ARG_KEYTAB, + localKeytab.absolutePath, + Arguments.ARG_FOLDER, + "testFolder"]) + } + } + + @Test + public void testInstallKeytabWithMissingKeytab() throws Throwable { + // create a mock keytab file + YarnConfiguration conf = SliderUtils.createConfiguration() + shouldFail(BadCommandArgumentsException) { + ServiceLauncher launcher = launch(TestSliderClient, + conf, + [ + ClientArgs.ACTION_KEYTAB, + ClientArgs.ARG_KEYTABINSTALL, + ClientArgs.ARG_KEYTAB, + "HeyIDontExist.keytab", + Arguments.ARG_FOLDER, + "testFolder"]) + } + } + + private File getTempLocation () { + return new File(System.getProperty("user.dir") + "/target"); + } + + static class TestSliderClient extends SliderClient { + public TestSliderClient() { + super() + } + + @Override + protected void initHadoopBinding() throws IOException, SliderException { + sliderFileSystem = testFileSystem + } + + } + + static class TestAppender extends AppenderSkeleton{ + public List<LoggingEvent> events = new ArrayList<LoggingEvent>(); + public void close() {} + public boolean requiresLayout() {return false;} + @Override + protected void append(LoggingEvent event) { + events.add(event); + } + }}
