Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make most ITs work with both linux and windows #143

Merged
merged 16 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Consolidate SSH keys and users.
  • Loading branch information
Stephen Shank committed Oct 10, 2019
commit 5423f9da7be7dfdb8f284cca149d77ff6e27bb75
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.LABEL;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.NUM_EXECUTORS;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.PROJECT_ID;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.RUN_AS_USER;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.SSH_PRIVATE_KEY;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.TEST_TIMEOUT_MULTIPLIER;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.ZONE;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.createTemplate;
Expand All @@ -43,7 +45,6 @@
import com.google.jenkins.plugins.computeengine.ComputeEngineCloud;
import com.google.jenkins.plugins.computeengine.InstanceConfiguration;
import com.trilead.ssh2.Connection;
import com.trilead.ssh2.ServerHostKeyVerifier;
import hudson.model.labels.LabelAtom;
import hudson.slaves.NodeProvisioner.PlannedNode;
import java.io.IOException;
Expand Down Expand Up @@ -154,18 +155,11 @@ public void testConnectionWithTemplateSshKey() throws IOException, Exception {
int port = SSH_PORT;
conn = new Connection(host, port);
conn.connect(
new ServerHostKeyVerifier() {
public boolean verifyServerHostKey(
String hostname, int port, String serverHostKeyAlgorithm, byte[] serverHostKey)
throws Exception {
return true;
}
},
(hostname, portnum, serverHostKeyAlgorithm, serverHostKey) -> true,
SSH_TIMEOUT,
SSH_TIMEOUT);
assertTrue(
conn.authenticateWithPublicKey(
ITUtil.SSH_USER, ITUtil.SSH_PRIVATE_KEY.toCharArray(), ""));
log.info(String.format("Connected to SSH. Authenticating as user %s", RUN_AS_USER));
assertTrue(conn.authenticateWithPublicKey(RUN_AS_USER, SSH_PRIVATE_KEY.toCharArray(), ""));
} finally {
if (conn != null) {
conn.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ class ITUtil {
windows ? System.getenv("GOOGLE_BOOT_DISK_PROJECT_ID") : "debian-cloud";
private static final String BOOT_DISK_IMAGE_NAME =
windows
? System.getenv("GOOGLE_BOOT_DISK_IMAGE_NAME")
? String.format(
"projects/%s/global/images/%s",
BOOT_DISK_PROJECT_ID, System.getenv("GOOGLE_BOOT_DISK_IMAGE_NAME"))
: "projects/debian-cloud/global/images/family/debian-9";
private static final String BOOT_DISK_SIZE_GB_STR = windows ? "50" : "10";
private static final Node.Mode NODE_MODE = Node.Mode.EXCLUSIVE;
private static final String ACCELERATOR_NAME = "";
private static final String ACCELERATOR_COUNT = "";
private static final String RUN_AS_USER = "jenkins";
static final String RUN_AS_USER = "jenkins";
static final String NULL_TEMPLATE = null;
private static final String NETWORK_NAME = format("projects/%s/global/networks/default");
private static final String SUBNETWORK_NAME = "default";
Expand All @@ -128,15 +130,13 @@ class ITUtil {
private static final String RETENTION_TIME_MINUTES_STR = "";
private static final String LAUNCH_TIMEOUT_SECONDS_STR = "";
static final int SNAPSHOT_TIMEOUT = windows ? 300 : 120;
static final String SSH_USER = "test-user";
private static final GoogleKeyPair SSH_KEY = GoogleKeyPair.generate(SSH_USER);
private static final GoogleKeyPair WINDOWS_SSH_KEY = GoogleKeyPair.generate("");
private static final GoogleKeyPair SSH_KEY = GoogleKeyPair.generate(RUN_AS_USER);
static final String SSH_PRIVATE_KEY = SSH_KEY.getPrivateKey();
private static final String WINDOWS_STARTUP_SCRIPT =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to de-dup these startup scripts with their counterparts in the launchers? Same question with the SSH setup logic here.

"Stop-Service sshd\n"
+ "$ConfiguredPublicKey = "
+ "\""
+ WINDOWS_SSH_KEY.getPublicKey().trim().substring(1)
+ SSH_KEY.getPublicKey().trim().substring(RUN_AS_USER.length() + 1)
+ "\"\n"
+ "Write-Output \"Second phase\"\n"
+ "# We are in the second phase of startup where we need to set up authorized_keys for the specified user.\n"
Expand Down Expand Up @@ -203,7 +203,7 @@ private static String initWindowsSshCredentials(CredentialsStore store) throws I
CredentialsScope.GLOBAL,
null,
RUN_AS_USER,
new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource(WINDOWS_SSH_KEY.getPrivateKey()),
new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource(SSH_KEY.getPrivateKey()),
null,
"integration test private key for windows");
store.addCredentials(Domain.global(), windowsPrivateKeyCredentials);
Expand Down