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

Conversation

stephenashank
Copy link
Contributor

This is a proof of concept, see CONTRIBUTING.md for information on the integration tests. I'll be updating the documentation there as well.

Once you have a disk image created for windows, and the corresponding environment variables, you will be able to run mvn -Dit.windows=true verify and run the tests using windows agents. This should increase test coverage and get rid of the need to have separate duplicated tests.
When running simply mvn verify the test behavior is unchanged from before this change.

There are still issues with this PR when it comes to running the windows tests, but I wanted to get this out for early feedback.

@stephenashank stephenashank added the WIP Work in progress label Sep 24, 2019
@@ -63,6 +65,7 @@

@BeforeClass
public static void init() throws Exception {
Assume.assumeFalse(windows);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, the premise of the ComputeEngineCloudWorkerFailedIT is that worker creation fails because there is no startup script which means Java is not installed on the agent. However, the way that Windows agents are created for integration tests right now means that java comes pre-installed on the image.
Unlike assertFalse, which leads to a failure, assumeFalse will skip tests. We can use this to skip tests it doesn't make sense to run with windows agents like this.

@craigdbarber
Copy link
Contributor

LGTM.
Were there meant to be changes made to the contributing docs with this PR?

@craigdbarber
Copy link
Contributor

Forgoing clicking the approve button, as I assume you'll want to merge a later PR in a finished state.

@stephenashank
Copy link
Contributor Author

Still having issues with the tests themselves. This will include changes to the documentation when those are working.

@stephenashank stephenashank force-pushed the feature/issue49windows branch from 641fbe1 to 31a07f2 Compare October 12, 2019 01:03
* limitations under the License.
*/

// Windows Agent IT pipeline, run manually.
Copy link
Contributor

Choose a reason for hiding this comment

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

Having two files named "Jenkinsfile" could be confusing. Perhaps we can have Jenkinsfile.windows and Jenkinsfile.linux, both in the top level directory. The CI configuration allows you to specify the filename, so we're not limited to the "Jenkinsfile" naming convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

import lombok.Getter;

@Getter
public enum Commands {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing javadoc header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -122,7 +119,6 @@ public void testMultipleLabelsProvisionedWithLabels() throws Exception {
private void checkOneNode(PlannedNode plannedNode, String desc)
throws InterruptedException, java.util.concurrent.ExecutionException {
String name = plannedNode.displayName;
plannedNode.future.get();
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reasoning for removing this part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing that we care about most in this test is whether both configurations were used, which can be tested without waiting for the instances to fully launch by looking at the configuration of each planned node. This also speeds up this test, especially in the windows case.

import org.junit.rules.Timeout;
import org.jvnet.hudson.test.JenkinsRule;

public class ConfigAsCodeNonStandardJavaIT {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing javadoc header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// Wait for the node creation to finish
planned.iterator().next().future.get();
Instance instance = client.getInstance(PROJECT_ID, ZONE, name);
assertNotNull(instance);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we think there's value in attempting to run a command to ensure Java is properly installed? Perhaps "java version", and making sure it doesn't error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is tested for in the launch process, which will only complete if it's able to use java to start the agent process. This test shouldn't progress beyond line 80 until that finishes. Maybe it would make sense to have a build step here, which would confirm that the agent jar was used and java is properly installed.

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.

public enum Commands {
ECHO("echo %s", "echo %s"),
EXIT("exit /b %s", "exit %s"),
SLEEP("ping /n %s /l 1024 google.com ", "sleep %s");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is a little weird. I was not able to get the proper windows equivalent "timeout" to work. Looking around I found that there are some weird issues with running the command in non-interactive scripts, discussed in places such as this comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Is using Powershell a viable alternative to batch? If so, we could consider using -NonInteractive: https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/About/about_PowerShell_exe?view=powershell-5.1#-noninteractive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip, while I had trouble using powershell within the existing batch scripts, this led me to finding the Powershell plugin which automatically applies the NonInteractive flag when running scripts, and I was able to remove this hack.

@@ -58,7 +58,18 @@
*/
@Override
public Boolean call() throws IOException {
HttpRequest request = createMetadataRequest();
HttpRequest initialRequest = createMetadataRequest(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This came up in #148 as well. Having the preemption event occur before the agent is running and listening for preemption events is rare, but given that it can and does happen it makes sense to check that it's not already preempted before beginning the long poll to wait for a change to the metadata (which won't happen in that case).

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense.

@stephenashank stephenashank changed the title WIP: Make most ITs work with both linux and windows Make most ITs work with both linux and windows Oct 16, 2019
}
} finally {
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In general I'm weary of swallowing exceptions like this. I think at the very least we should consider logging it as a warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added logging

@@ -87,8 +78,7 @@ private boolean authenticateSSH(
return isAuthenticated;
}

private boolean bootstrap(ComputeEngineComputer computer, TaskListener listener)
throws IOException, Exception { // TODO(evanbrown): better exceptions
private Optional<Connection> bootstrap(ComputeEngineComputer computer, TaskListener listener) {
if (computer == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Preconditions.checkNotNull()

}
} finally {
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above re: swallowing exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added logging

…, use powershell to use sleep command. Update documentation for running windows ITs. Remove obsolete windows IT files.
@stephenashank stephenashank force-pushed the feature/issue49windows branch from 6a3d605 to 7f0dc57 Compare October 16, 2019 23:39
@stephenashank stephenashank removed the WIP Work in progress label Oct 17, 2019
@craigdbarber
Copy link
Contributor

Wanted to verify these deletes were intentional:

  • ...test/java/com/google/jenkins/plugins/computeengine/integration/ConfigAsCodeWindowsIT.java
  • ...ava/com/google/jenkins/plugins/computeengine/integration/ComputeEngineCloudWindowsIT.java

@stephenashank
Copy link
Contributor Author

Yes, those are no longer needed. ConfigAsCodeTestIT now replaces ConfigAsCodeWindowsIT, while ComputeEngineCloudWorkerCreatedIT, ComputeEngineCloudSnapshotCreatedIT, and ComputeEngineCloudIgnoreProxyIT replace ComputeEngineCloudWindowsIT when running the windows integration tests.

Copy link
Contributor

@craigdbarber craigdbarber left a comment

Choose a reason for hiding this comment

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

LGTM

@stephenashank stephenashank merged commit 0fa6715 into jenkinsci:master Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants