提交 321cd04d 编写于 作者: D Daniel Beck 提交者: GitHub

Merge pull request #2396 from pjanouse/JENKINS-34915

[JENKINS-34915] CLI commands wait-node-online/wait-node-offline extracted from core to CLI
/*
* The MIT License
*
* Copyright (c) 2016, Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.cli;
import hudson.Extension;
import hudson.model.Node;
import org.kohsuke.args4j.Argument;
/**
* @author pjanouse
* @since TODO
*/
@Extension
public class WaitNodeOfflineCommand extends CLICommand {
@Argument(metaVar="NODE", usage="Name of the node", required=true)
public Node node;
@Override
public String getShortDescription() {
return Messages.WaitNodeOfflineCommand_ShortDescription();
}
@Override
protected int run() throws Exception {
node.toComputer().waitUntilOffline();
return 0;
}
}
/*
* The MIT License
*
* Copyright (c) 2016, Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.cli;
import hudson.Extension;
import hudson.model.Node;
import org.kohsuke.args4j.Argument;
/**
* @author pjanouse
* @since TODO
*/
@Extension
public class WaitNodeOnlineCommand extends CLICommand {
@Argument(metaVar="NODE", usage="Name of the node", required=true)
public Node node;
@Override
public String getShortDescription() {
return Messages.WaitNodeOnlineCommand_ShortDescription();
}
@Override
protected int run() throws Exception {
node.toComputer().waitUntilOnline();
return 0;
}
}
......@@ -1494,7 +1494,6 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
/**
* Blocks until the node becomes online/offline.
*/
@CLIMethod(name="wait-node-online")
public void waitUntilOnline() throws InterruptedException {
synchronized (statusChangeLock) {
while (!isOnline())
......@@ -1502,7 +1501,6 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
}
}
@CLIMethod(name="wait-node-offline")
public void waitUntilOffline() throws InterruptedException {
synchronized (statusChangeLock) {
while (!isOffline())
......
......@@ -91,4 +91,6 @@ DisconnectNodeCommand.ShortDescription=Disconnects from a node.
QuietDownCommand.ShortDescription=Quiet down Jenkins, in preparation for a restart. Don\u2019t start any builds.
CancelQuietDownCommand.ShortDescription=Cancel the effect of the "quiet-down" command.
OfflineNodeCommand.ShortDescription=Stop using a node for performing builds temporarily, until the next "online-node" command.
WaitNodeOnlineCommand.ShortDescription=Wait for a node to become online.
WaitNodeOfflineCommand.ShortDescription=Wait for a node to become offline.
......@@ -137,4 +137,8 @@ CancelQuietDownCommand.ShortDescription=\
OfflineNodeCommand.ShortDescription=\
\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u0435\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0432\u0430\u043d\u0435 \u043d\u0430 \u043f\u043e\u043b\u0437\u0432\u0430\u043d\u0435\u0442\u043e \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0430 \u0437\u0430 \u0438\u0437\u0433\u0440\u0430\u0436\u0434\u0430\u043d\u0438\u044f \u0434\u043e\u043a\u0430\u0442\u043e \u043d\u0435 \u0441\u0435\
\u0432\u044a\u0432\u0435\u0434\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u0442\u0430 \u201eonline-node\u201c.
WaitNodeOnlineCommand.ShortDescription=\
\u0418\u0437\u0447\u0430\u043a\u0432\u0430\u043d\u0435 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0430 \u0434\u0430 \u0435 \u043d\u0430 \u043b\u0438\u043d\u0438\u044f.
WaitNodeOfflineCommand.ShortDescription=\
\u0418\u0437\u0447\u0430\u043a\u0432\u0430\u043d\u0435 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0430 \u0434\u0430 \u043d\u0435 \u0435 \u043d\u0430 \u043b\u0438\u043d\u0438\u044f.
......@@ -57,4 +57,6 @@ DisconnectNodeCommand.ShortDescription=Desconectarse de un nodo
QuietDownCommand.ShortDescription=Poner Jenkins en modo quieto y estar preparado para un reinicio. No comenzar ninguna ejecuci\u00f3n.
CancelQuietDownCommand.ShortDescription=Cancelar el efecto del comando "quiet-down".
OfflineNodeCommand.ShortDescription=Dejar de utilizar un nodo temporalmente hasta que se ejecute el comando "online-node".
WaitNodeOnlineCommand.ShortDescription=Esperando hasta que el nodo est activado
WaitNodeOfflineCommand.ShortDescription=Esperando a que el nodo est desactivado
......@@ -5,3 +5,6 @@ ClearQueueCommand.ShortDescription=Pulisce la coda di lavoro
ReloadConfigurationCommand.ShortDescription=Discard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk.
ConnectNodeCommand.ShortDescription=Riconnettersi ad un nodo
OfflineNodeCommand.ShortDescription=Stop using a node for performing builds temporarily, until the next "online-node" command.
WaitNodeOnlineCommand.ShortDescription=Attende che il nodo sia attivo
WaitNodeOfflineCommand.ShortDescription=Attende che un nodo sia disattivo
......@@ -79,4 +79,6 @@ DisconnectNodeCommand.ShortDescription=\u30ce\u30fc\u30c9\u3068\u306e\u63a5\u7d9
QuietDownCommand.ShortDescription=Jenkins\u306f\u518d\u8d77\u52d5\u306b\u5411\u3051\u3066\u7d42\u4e86\u51e6\u7406\u3092\u5b9f\u65bd\u4e2d\u3067\u3059\u3002\u30d3\u30eb\u30c9\u3092\u958b\u59cb\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002
CancelQuietDownCommand.ShortDescription="quiet-down"\u30b3\u30de\u30f3\u30c9\u306e\u51e6\u7406\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u307e\u3059\u3002
OfflineNodeCommand.ShortDescription="online-node"\u30b3\u30de\u30f3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u308b\u307e\u3067\u3001\u30d3\u30eb\u30c9\u3092\u5b9f\u884c\u3059\u308b\u30ce\u30fc\u30c9\u306e\u4f7f\u7528\u3092\u4e00\u6642\u7684\u306b\u505c\u6b62\u3057\u307e\u3059\u3002
WaitNodeOnlineCommand.ShortDescription=\u30ce\u30fc\u30c9\u304c\u30aa\u30f3\u30e9\u30a4\u30f3\u306b\u306a\u308b\u306e\u3092\u5f85\u3061\u307e\u3059\u3002
WaitNodeOfflineCommand.ShortDescription=\u30ce\u30fc\u30c9\u304c\u30aa\u30d5\u30e9\u30a4\u30f3\u306b\u306a\u308b\u306e\u3092\u5f85\u3061\u307e\u3059\u3002
......@@ -90,4 +90,6 @@ DisconnectNodeCommand.ShortDescription=Atsijungia nuo mazgo.
QuietDownCommand.ShortDescription=Tyliai nuleisti Jenkins\u0105, pasiruo\u0161iant paleidimui i\u0161 naujo. Neprad\u0117ti joki\u0173 vykdym\u0173.
CancelQuietDownCommand.ShortDescription=Nutraukti \u201etylaus i\u0161jungimo\u201c komandos efekt\u0105.
OfflineNodeCommand.ShortDescription=Laikinai nebenaudoti mazgo darb\u0173 vykdymui, kol bus \u012fvykdyta kita \u201emazgas \u012fjungtas\u201c komanda.
WaitNodeOnlineCommand.ShortDescription=Laukti, kol mazgas prisijungs.
WaitNodeOfflineCommand.ShortDescription=Laukti, kol mazgas atsijungs.
......@@ -125,4 +125,6 @@ DisconnectNodeCommand.ShortDescription=Desconectar do n\u00f3
QuietDownCommand.ShortDescription=Desativar em modo silencioso, em prepara\u00e7\u00e3o para o rein\u00edcio. N\u00e3o come\u00e7e nenhum build.
CancelQuietDownCommand.ShortDescription=Cancela o comando "quiet-down"
OfflineNodeCommand.ShortDescription=Temporariamente n\u00e3o usando um n\u00f3 para os builds. Aguardando o pr\u00f3ximo comando de modo-online
WaitNodeOnlineCommand.ShortDescription=Aguarda por um n\u00f3 que se torne online
WaitNodeOfflineCommand.ShortDescription=Aguarde por um n\u00f3 ficar offline.
......@@ -82,4 +82,6 @@ ConnectNodeCommand.ShortDescription=\u9023\u7dda\u5230\u6307\u5b9a\u7bc0\u9ede\u
QuietDownCommand.ShortDescription=\u8b93 Jenkins \u6c89\u6fb1\u4e00\u4e0b\uff0c\u6e96\u5099\u91cd\u65b0\u555f\u52d5\u3002\u5148\u4e0d\u8981\u518d\u5efa\u7f6e\u4efb\u4f55\u4f5c\u696d\u3002
CancelQuietDownCommand.ShortDescription=\u53d6\u6d88 "quiet-down" \u6307\u4ee4\u3002
OfflineNodeCommand.ShortDescription=\u66ab\u6642\u4e0d\u4f7f\u7528\u6307\u5b9a\u7bc0\u9ede\u4f86\u5efa\u7f6e\uff0c\u76f4\u5230\u57f7\u884c "online-node" \u6307\u4ee4\u70ba\u6b62\u3002
WaitNodeOnlineCommand.ShortDescription=\u7b49\u5019\u6307\u5b9a\u7bc0\u9ede\u4e0a\u7dda\u3002
WaitNodeOfflineCommand.ShortDescription=\u7b49\u5019\u6307\u5b9a\u7bc0\u9ede\u96e2\u7dda\u3002
......@@ -95,8 +95,6 @@ CLI.clear-queue.shortDescription=Clears the build queue.
CLI.disable-job.shortDescription=Disables a job.
CLI.enable-job.shortDescription=Enables a job.
CLI.online-node.shortDescription=Resume using a node for performing builds, to cancel out the earlier "offline-node" command.
CLI.wait-node-online.shortDescription=Wait for a node to become online.
CLI.wait-node-offline.shortDescription=Wait for a node to become offline.
Computer.Caption=Agent {0}
Computer.NoSuchSlaveExists=No such agent "{0}" exists. Did you mean "{1}"?
......
......@@ -148,10 +148,6 @@ CLI.delete-node.shortDescription=\
CLI.online-node.shortDescription=\
\u041e\u0442\u043d\u043e\u0432\u043e \u0434\u0430 \u0441\u0435 \u043f\u043e\u043b\u0437\u0432\u0430 \u043c\u0430\u0448\u0438\u043d\u0430 \u0437\u0430 \u0438\u0437\u0433\u0440\u0430\u0436\u0434\u0430\u043d\u0438\u044f. \u041e\u0442\u043c\u0435\u043d\u044f\u043d\u0435 \u043d\u0430 \u043f\u0440\u0435\u0434\u0445\u043e\u0434\u043d\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\
\u201eoffline-node\u201c.
CLI.wait-node-online.shortDescription=\
\u0418\u0437\u0447\u0430\u043a\u0432\u0430\u043d\u0435 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0430 \u0434\u0430 \u0435 \u043d\u0430 \u043b\u0438\u043d\u0438\u044f.
CLI.wait-node-offline.shortDescription=\
\u0418\u0437\u0447\u0430\u043a\u0432\u0430\u043d\u0435 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0430 \u0434\u0430 \u043d\u0435 \u0435 \u043d\u0430 \u043b\u0438\u043d\u0438\u044f.
ComputerSet.DisplayName=\
\u041a\u043e\u043c\u043f\u044e\u0442\u0440\u0438
......
......@@ -284,8 +284,6 @@ ResultTrend.Aborted=Cancelado
TextParameterDefinition.DisplayName=Parmetro de texto
AbstractProject.AssignedLabelString_NoMatch_DidYouMean=No hay ningn nodo que cumpla esta asignacin. Quizs se refiera a ''{1}'' en lugar de ''{0}''?
ResultTrend.Success=Correcto
CLI.wait-node-online.shortDescription=Esperando hasta que el nodo est activado
CLI.wait-node-offline.shortDescription=Esperando a que el nodo est desactivado
AbstractProject.CancelPermission.Description=Este permiso permite que se pueda cancelar un trabajo.
Run.Summary.NotBuilt=no se ha ejecutado
AbstractProject.DiscoverPermission.Description=Este permiso garantiza que se pueda descubrir tareas. \
......
......@@ -73,14 +73,10 @@ BallColor.Unstable=Instabile
CLI.disable-job.shortDescription=Disabilita un job
CLI.enable-job.shortDescription=Abilita un job
CLI.online-node.shortDescription=Resume using a node for performing builds, to cancel out the earlier "offline-node" command.
CLI.wait-node-online.shortDescription=Attende che il nodo sia attivo
CLI.wait-node-offline.shortDescription=Attende che un nodo sia disattivo
ComputerSet.DisplayName=nodes
Executor.NotAvailable=N/A
FreeStyleProject.DisplayName=Configura una build di tipo generico
FreeStyleProject.Description=Questa \u00E8 la funzione principale di Jenkins. Jenkins effettuer\u00E0 una compilazione del progetto, combinando qualsiasi SCM con qualsiasi sistema di compilazione e si pu\u00F2 usare anche per qualcosa di altro che non sia un programma di compilazione.
......
......@@ -295,8 +295,6 @@ CLI.clear-queue.shortDescription=\u30d3\u30eb\u30c9\u30ad\u30e5\u30fc\u3092\u30a
CLI.disable-job.shortDescription=\u30b8\u30e7\u30d6\u3092\u7121\u52b9\u5316\u3057\u307e\u3059\u3002
CLI.enable-job.shortDescription=\u30b8\u30e7\u30d6\u3092\u6709\u52b9\u5316\u3057\u307e\u3059\u3002
CLI.online-node.shortDescription=\u76f4\u524d\u306b\u5b9f\u884c\u3057\u305f"online-node"\u30b3\u30de\u30f3\u30c9\u3092\u53d6\u308a\u6d88\u3057\u3001\u30d3\u30eb\u30c9\u3092\u5b9f\u884c\u3059\u308b\u30ce\u30fc\u30c9\u306e\u4f7f\u7528\u3092\u518d\u958b\u3057\u307e\u3059\u3002
CLI.wait-node-online.shortDescription=\u30ce\u30fc\u30c9\u304c\u30aa\u30f3\u30e9\u30a4\u30f3\u306b\u306a\u308b\u306e\u3092\u5f85\u3061\u307e\u3059\u3002
CLI.wait-node-offline.shortDescription=\u30ce\u30fc\u30c9\u304c\u30aa\u30d5\u30e9\u30a4\u30f3\u306b\u306a\u308b\u306e\u3092\u5f85\u3061\u307e\u3059\u3002
BuildAuthorizationToken.InvalidTokenProvided=\u8a8d\u8a3c\u30c8\u30fc\u30af\u30f3\u304c\u9593\u9055\u3063\u3066\u3044\u307e\u3059\u3002
ManageJenkinsAction.DisplayName=Jenkins\u306e\u7ba1\u7406
......
......@@ -70,8 +70,6 @@ CLI.clear-queue.shortDescription=I\u0161valo vykdymo eil\u0119.
CLI.disable-job.shortDescription=I\u0161jungia darb\u0105.
CLI.enable-job.shortDescription=\u012ejungia darb\u0105.
CLI.disconnect-node.shortDescription=Atsijungia nuo mazgo.
CLI.wait-node-online.shortDescription=Laukti, kol mazgas prisijungs.
CLI.wait-node-offline.shortDescription=Laukti, kol mazgas atsijungs.
Computer.Caption=Agentas {0}
Computer.NoSuchSlaveExists=N\u0117ra tokio agento \u201e{0}\u201c. Ar tur\u0117jote omeny \u201e{1}\u201c?
......
......@@ -347,8 +347,6 @@ AbstractProject.WorkspaceTitle=Workspace de {0}
UpdateCenter.PluginCategory.listview-column=Lista as colunas da view
# {0} is waiting for a checkpoint on {1}
Run._is_waiting_for_a_checkpoint_on_={0} est\u00e1 aguardando por um checkpoint em {1}
# Wait for a node to become offline.
CLI.wait-node-offline.shortDescription=Aguarde por um n\u00f3 ficar offline.
# \ in workspace {0}
AbstractBuild.BuildingInWorkspace=\ no workspace {0}
# Jenkins is restarting
......@@ -439,8 +437,6 @@ AbstractProject.CancelPermission.Description=Esta permiss\u00e3o deixa que seja
Jenkins.CheckDisplayName.NameNotUniqueWarning=O nome de exibi\u00e7\u00e3o "{0}", \u00e9 usado por um job e pode causar confus\u00e3o nos resultados da pesquisa.
# Custom workspace is empty.
AbstractProject.CustomWorkspaceEmpty=O workspace customizado est\u00e1 vazio.
# Wait for a node to become online.
CLI.wait-node-online.shortDescription=Aguarda por um n\u00f3 que se torne online
# Artifacts of {0} {1}
Run.ArtifactsBrowserTitle=Artefatos de {0} {1}
# Build with Parameters
......
......@@ -80,9 +80,6 @@ CLI.disable-job.shortDescription=\u505c\u7528\u4f5c\u696d\u3002
CLI.enable-job.shortDescription=\u555f\u7528\u4f5c\u696d\u3002
CLI.disconnect-node.shortDescription=\u4e2d\u65b7\u8207\u6307\u5b9a\u7bc0\u9ede\u7684\u9023\u7dda\u3002
CLI.online-node.shortDescription=\u7e7c\u7e8c\u4f7f\u7528\u6307\u5b9a\u7bc0\u9ede\u4f86\u5efa\u7f6e\uff0c\u53d6\u6d88\u5148\u524d\u7684 "offline-node" \u6307\u4ee4\u3002
CLI.wait-node-online.shortDescription=\u7b49\u5019\u6307\u5b9a\u7bc0\u9ede\u4e0a\u7dda\u3002
CLI.wait-node-offline.shortDescription=\u7b49\u5019\u6307\u5b9a\u7bc0\u9ede\u96e2\u7dda\u3002
ComputerSet.DisplayName=\u7bc0\u9ede
......@@ -90,14 +87,12 @@ Descriptor.From=(from <a href="{1}">{0}</a>)
Executor.NotAvailable=N/A
FreeStyleProject.DisplayName=\u5efa\u7f6e Free-Style \u8edf\u9ad4\u5c08\u6848
FreeStyleProject.Description=\
\u9019\u662f Jenkins \u7684\u4e3b\u8981\u529f\u80fd\u3002\
Jenkins \u80fd\u642d\u914d\u5404\u5f0f\u7a0b\u5f0f\u78bc\u7ba1\u7406\u3001\u5efa\u7f6e\u7cfb\u7d71\u4f86\u5efa\u7f6e\u60a8\u7684\u5c08\u6848\uff0c\
\u751a\u81f3\u9084\u80fd\u505a\u8edf\u9ad4\u5efa\u7f6e\u4ee5\u5916\u7684\u5176\u4ed6\u4e8b\u60c5\u3002
Hudson.BadPortNumber=\u9023\u63a5\u57e0\u865f {0} \u7121\u6548
Hudson.Computer.Caption=Master
Hudson.Computer.DisplayName=master
......
/*
* The MIT License
*
* Copyright 2016 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @author pjanouse
*/
package hudson.cli;
import hudson.slaves.DumbSlave;
import jenkins.model.Jenkins;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.fail;
public class WaitNodeOfflineCommandTest {
private CLICommandInvoker command;
@Rule
public final JenkinsRule j = new JenkinsRule();
@Before
public void setUp() {
command = new CLICommandInvoker(j, "wait-node-offline");
}
@Test
public void waitNodeOfflineShouldFailIfNodeDoesNotExist() throws Exception {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("never_created");
assertThat(result, failedWith(3));
assertThat(result, hasNoStandardOutput());
assertThat(result.stderr(), containsString("ERROR: No such node 'never_created'"));
}
@Test
public void waitNodeOfflineShouldSucceedOnOfflineNode() throws Exception {
DumbSlave slave = j.createSlave("aNode", "", null);
slave.toComputer().setTemporarilyOffline(true);
while (true) {
if(slave.toComputer().isOffline())
break;
Thread.sleep(100);
}
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
assertThat(result, succeededSilently());
assertThat(slave.toComputer().isOffline(), equalTo(true));
}
@Test
public void waitNodeOfflineShouldSucceedOnGoingOfflineNode() throws Exception {
DumbSlave slave = j.createSlave("aNode", "", null);
slave.toComputer().setTemporarilyOffline(true);
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
assertThat(result, succeededSilently());
assertThat(slave.toComputer().isOffline(), equalTo(true));
}
@Test
public void waitNodeOfflineShouldSucceedOnDisconnectedNode() throws Exception {
DumbSlave slave = j.createSlave("aNode", "", null);
slave.toComputer().disconnect();
while (true) {
if(slave.toComputer().isOffline())
break;
Thread.sleep(100);
}
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
assertThat(result, succeededSilently());
assertThat(slave.toComputer().isOffline(), equalTo(true));
}
@Test
public void waitNodeOfflineShouldSucceedOnDisconnectingNode() throws Exception {
DumbSlave slave = j.createSlave("aNode", "", null);
slave.toComputer().disconnect();
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
assertThat(result, succeededSilently());
assertThat(slave.toComputer().isOffline(), equalTo(true));
}
@Test
public void waitNodeOfflineShouldTimeoutOnOnlineNode() throws Exception {
DumbSlave slave = j.createSlave("aNode", "", null);
slave.toComputer().waitUntilOnline();
boolean timeoutOccurred = false;
FutureTask task = new FutureTask(new Callable() {
public Object call() {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
fail("Never should return from previous CLI call!");
return null;
}
});
try {
task.get(30, TimeUnit.SECONDS);
} catch (TimeoutException e) {
timeoutOccurred = true;
} finally {
task.cancel(true);
}
if(!timeoutOccurred)
fail("Missing timeout for CLI call");
}
}
/*
* The MIT License
*
* Copyright 2016 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @author pjanouse
*/
package hudson.cli;
import hudson.slaves.DumbSlave;
import jenkins.model.Jenkins;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.fail;
public class WaitNodeOnlineCommandTest {
private CLICommandInvoker command;
@Rule
public final JenkinsRule j = new JenkinsRule();
@Before
public void setUp() {
command = new CLICommandInvoker(j, "wait-node-online");
}
@Test
public void waitNodeOnlineShouldFailIfNodeDoesNotExist() throws Exception {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("never_created");
assertThat(result, failedWith(3));
assertThat(result, hasNoStandardOutput());
assertThat(result.stderr(), containsString("ERROR: No such node 'never_created'"));
}
@Test
public void waitNodeOnlineShouldSucceedOnGoingOnlineNode() throws Exception {
DumbSlave slave = j.createSlave("aNode", "", null);
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
assertThat(result, succeededSilently());
assertThat(slave.toComputer().isOnline(), equalTo(true));
}
@Test
public void waitNodeOnlineShouldTimeoutOnGoingOfflineNode() throws Exception {
DumbSlave slave = j.createSlave("aNode", "", null);
slave.toComputer().setTemporarilyOffline(true);
boolean timeoutOccurred = false;
FutureTask task = new FutureTask(new Callable() {
public Object call() {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
fail("Never should return from previous CLI call!");
return null;
}
});
try {
task.get(30, TimeUnit.SECONDS);
} catch (TimeoutException e) {
timeoutOccurred = true;
} finally {
task.cancel(true);
}
if(!timeoutOccurred)
fail("Missing timeout for CLI call");
}
@Test
public void waitNodeOnlineShouldTimeoutOnDisconnectedNode() throws Exception {
DumbSlave slave = j.createSlave("aNode", "", null);
slave.toComputer().disconnect();
slave.toComputer().waitUntilOffline();
boolean timeoutOccurred = false;
FutureTask task = new FutureTask(new Callable() {
public Object call() {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
fail("Never should return from previous CLI call!");
return null;
}
});
try {
task.get(30, TimeUnit.SECONDS);
} catch (TimeoutException e) {
timeoutOccurred = true;
} finally {
task.cancel(true);
}
if(!timeoutOccurred)
fail("Missing timeout for CLI call");
}
@Test
public void waitNodeOnlineShouldTimeoutOnDisconnectingNode() throws Exception {
DumbSlave slave = j.createSlave("aNode", "", null);
slave.toComputer().disconnect();
boolean timeoutOccurred = false;
FutureTask task = new FutureTask(new Callable() {
public Object call() {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
fail("Never should return from previous CLI call!");
return null;
}
});
try {
task.get(30, TimeUnit.SECONDS);
} catch (TimeoutException e) {
timeoutOccurred = true;
} finally {
task.cancel(true);
}
if(!timeoutOccurred)
fail("Missing timeout for CLI call");
}
@Test
public void waitNodeOnlineShouldSuccessOnOnlineNode() throws Exception {
DumbSlave slave = j.createSlave("aNode", "", null);
slave.toComputer().waitUntilOnline();
while (true) {
if(slave.toComputer().isOnline())
break;
Thread.sleep(100);
}
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
assertThat(result, succeededSilently());
assertThat(slave.toComputer().isOnline(), equalTo(true));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册