use of org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential in project acceptance-test-harness by jenkinsci.
the class ForemanNodeSharingPluginTest method setUp.
/**
* Setup instance before each test.
* @throws Exception if occurs.
*/
@Before
public void setUp() throws Exception {
jenkins.runScript("import hudson.slaves.NodeProvisioner; NodeProvisioner.NodeProvisionerInvoker." + "INITIALDELAY = NodeProvisioner.NodeProvisionerInvoker.RECURRENCEPERIOD = 60;");
foreman = dockerForeman.get();
sshslave1 = docker1.get();
CredentialsPage c = new CredentialsPage(jenkins, ManagedCredentials.DEFAULT_DOMAIN);
c.open();
final SshPrivateKeyCredential sc = c.add(SshPrivateKeyCredential.class);
sc.username.set("test");
sc.selectEnterDirectly().privateKey.set(sshslave1.getPrivateKeyString());
sc.scope.select("GLOBAL");
c.create();
// CS IGNORE MagicNumber FOR NEXT 2 LINES. REASON: Mock object.
elasticSleep(10000);
if (populateForeman(foreman.getUrl().toString() + "/api/v2", sshslave1.getIpAddress(), labelExpression1) != 0) {
throw new Exception("failed to populate foreman");
}
if (populateForeman(foreman.getUrl().toString() + "/api/v2", "dummy", labelExpression2) != 0) {
throw new Exception("failed to populate foreman");
}
jenkins.configure();
cloud = addCloud(jenkins.getConfigPage());
// CS IGNORE MagicNumber FOR NEXT 2 LINES. REASON: Mock object.
elasticSleep(10000);
}
use of org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential in project acceptance-test-harness by jenkinsci.
the class SshSlaveController method install.
@Override
public Future<Slave> install(Jenkins j) {
ManagedCredentials credential = new ManagedCredentials(j);
try {
credential.open();
if (credential.checkIfCredentialsExist(fingerprint) == null) {
CredentialsPage cp = new CredentialsPage(j, ManagedCredentials.DEFAULT_DOMAIN);
SshPrivateKeyCredential sc = cp.add(SshPrivateKeyCredential.class);
sc.username.set(machine.getUser());
sc.description.set(fingerprint);
sc.selectEnterDirectly().privateKey.set(keyPair.readPrivateKey());
cp.create();
}
} catch (IOException e) {
throw new AssertionError(e);
}
final Slave s = create(machine.getPublicIpAddress(), j);
// Slave is configured, now wait till its online
return new Future<Slave>() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return slaveWaitComplete.get();
}
@Override
public boolean isDone() {
return slaveWaitComplete.get() || s.isOnline();
}
@Override
public Slave get() throws InterruptedException, ExecutionException {
waitForOnLineSlave(s, slaveReadyTimeOutInSec);
return s;
}
@Override
public Slave get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
if (unit != TimeUnit.SECONDS) {
timeout = unit.toSeconds(timeout);
}
waitForOnLineSlave(s, (int) timeout);
return s;
}
};
}
use of org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential in project acceptance-test-harness by jenkinsci.
the class TSRCreateSlaveTest method newSlave.
@Test
@Since("1.560")
public void newSlave() {
// this test requires a newer version of credentials plugin that has inline "Add" button
// I'm not sure exactly which version it is, but 1.532 LTS doesn't have it, and 1.555 has it,
// so it's somewhere in between
// TODO: this should be converted to "@WithPlugin("ssh-credentials") with specific version tag,
// not the core version
// Just to make sure the dumb slave is set up properly, we should seed it
// with a FS root and executors
final DumbSlave s = jenkins.slaves.create(DumbSlave.class);
{
SshSlaveLauncher l = s.setLauncher(SshSlaveLauncher.class);
String username = "user1";
String privateKey = "1212122112";
String description = "Ssh key";
l.host.set("127.0.0.1");
// make sure this exists
l.credentialsId.resolve();
try {
l.credentialsId.select(String.format("%s (%s)", username, description));
fail();
} catch (NoSuchElementException e) {
// ignore
}
SshCredentialDialog f = l.addCredential();
{
SshPrivateKeyCredential sc = f.select(SshPrivateKeyCredential.class);
sc.description.set(description);
sc.username.set(username);
sc.selectEnterDirectly().privateKey.set(privateKey);
}
f.add();
l.credentialsId.select(String.format("%s (%s)", username, description));
}
s.save();
}
use of org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential in project acceptance-test-harness by jenkinsci.
the class SshSlaveLauncher method keyCredentials.
/**
* Add username/key based credentials to the configuration
*
* @param username to use
* @param key for the private key to use
* @return the SshSlaveLauncher to be configured
*/
public SshSlaveLauncher keyCredentials(String username, String key, @CheckForNull String passphrase) {
final SshCredentialDialog dia = this.addCredential();
final SshPrivateKeyCredential cred = dia.select(SshPrivateKeyCredential.class);
cred.username.set(username);
if (passphrase != null) {
cred.passphrase.set(passphrase);
}
cred.enterDirectly(key);
cred.add();
waitForCredentialVisible(username);
return this;
}
use of org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential in project acceptance-test-harness by jenkinsci.
the class CredentialsTest method createSshKeys.
@Test
@WithPlugins("ssh-credentials")
public void createSshKeys() throws Exception {
CredentialsPage cp = new CredentialsPage(jenkins, ManagedCredentials.DEFAULT_DOMAIN);
cp.open();
SshPrivateKeyCredential sc = cp.add(SshPrivateKeyCredential.class);
sc.username.set(CRED_USER);
sc.selectEnterDirectly().privateKey.set(CRED_PWD);
sc.description.set("ssh_creds");
cp.create();
// now verify
final ManagedCredentials c = new ManagedCredentials(jenkins);
String href = c.credentialById("ssh_creds");
cp.setConfigUrl(href);
verifyValueForCredential(cp, sc.username, CRED_USER);
verifyValueForCredentialKey(sc, CRED_PWD, false);
}
Aggregations