forked from awslabs/ec2-spot-jenkins-plugin
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Fleet Label Cloud and created tests for CasC (#418)
* Added support for the CreateFleet API * Fixed EC2CreateFleet usage of launch template overrides for retreiving instance type and weight capacity * Added EC2CreateFleet to list of all fleets * Created tests for EC2CreateFleet * Made revisions to EC2CreateFleet. Updated tests to include testing for getStateBatch and isCreateFleet methods * Rename all occurances of EC2Fleet to Fleet, and rename CreateFleet to EC2Fleet * Renaming instances of 'EC2Fleet' to 'Fleet' * Updated comment noting the usage of EC2Fleets as a Fleet * Add permision checks and add missing permissions for EC2Fleets, fleets created by the CreateFleet API * Change the fleet cloud name for the Jenkins CasC field for backwards compatability. Added ggburris to the list of contributors * Removed commented out code and fixed indentations * Changed the fleet label cloud name for the Jenkins CasC field for backwards compatibility * Fixed EC2Fleet naming mistakes * Updated Fleet Label Cloud and created tests for CasC * Change naming ec2Fleet to eC2Fleet for CasC * @change naming ec2FleetLabel to eC2FleetLabel for CasC * Removed testing print statements --------- Co-authored-by: Prathibha Datta Kumar <[email protected]>
- Loading branch information
1 parent
74a8d88
commit d5e8e94
Showing
6 changed files
with
171 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelCloudConfigurationAsCodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.amazon.jenkins.ec2fleet; | ||
|
||
import com.amazon.jenkins.ec2fleet.fleet.Fleet; | ||
import com.amazon.jenkins.ec2fleet.fleet.Fleets; | ||
import hudson.plugins.sshslaves.SSHConnector; | ||
import hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy; | ||
import io.jenkins.plugins.casc.ConfiguratorException; | ||
import io.jenkins.plugins.casc.misc.ConfiguredWithCode; | ||
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.nullable; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class FleetLabelCloudConfigurationAsCodeTest { | ||
@Rule | ||
public JenkinsRule jenkinsRule = new JenkinsConfiguredWithCodeRule(); | ||
|
||
@Before | ||
public void before() { | ||
final Fleet fleet = mock(Fleet.class); | ||
Fleets.setGet(fleet); | ||
when(fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) | ||
.thenReturn(new FleetStateStats("", 2, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-1", "i-2")), Collections.emptyMap())); | ||
} | ||
|
||
@Test | ||
@ConfiguredWithCode( | ||
value = "FleetLabelCloud/name-required-configuration-as-code.yml", | ||
expected = ConfiguratorException.class, | ||
message = "error configuring 'jenkins' with class io.jenkins.plugins.casc.core.JenkinsConfigurator configurator") | ||
public void configurationWithNullName_shouldFail() { | ||
} | ||
|
||
@Test | ||
@ConfiguredWithCode("FleetLabelCloud/min-configuration-as-code.yml") | ||
public void shouldCreateCloudFromMinConfiguration() { | ||
assertEquals(jenkinsRule.jenkins.clouds.size(), 1); | ||
FleetLabelCloud cloud = (FleetLabelCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet-label"); | ||
|
||
assertEquals("ec2-fleet-label", cloud.name); | ||
assertNull(cloud.getRegion()); | ||
assertNull(cloud.getEndpoint()); | ||
assertNull(cloud.getFsRoot()); | ||
assertFalse(cloud.isPrivateIpUsed()); | ||
assertFalse(cloud.isAlwaysReconnect()); | ||
assertEquals(cloud.getIdleMinutes(), 0); | ||
assertEquals(cloud.getMinSize(), 0); | ||
assertEquals(cloud.getMaxSize(), 0); | ||
assertEquals(cloud.getNumExecutors(), 1); | ||
assertFalse(cloud.isRestrictUsage()); | ||
assertEquals(cloud.getInitOnlineTimeoutSec(), 180); | ||
assertEquals(cloud.getInitOnlineCheckIntervalSec(), 15); | ||
assertEquals(cloud.getCloudStatusIntervalSec(), 10); | ||
assertFalse(cloud.isDisableTaskResubmit()); | ||
assertFalse(cloud.isNoDelayProvision()); | ||
assertNull(cloud.getEc2KeyPairName()); | ||
} | ||
|
||
@Test | ||
@ConfiguredWithCode("FleetLabelCloud/max-configuration-as-code.yml") | ||
public void shouldCreateCloudFromMaxConfiguration() { | ||
assertEquals(jenkinsRule.jenkins.clouds.size(), 1); | ||
FleetLabelCloud cloud = (FleetLabelCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet-label"); | ||
|
||
assertEquals("ec2-fleet-label", cloud.name); | ||
assertEquals(cloud.getRegion(), "us-east-2"); | ||
assertEquals(cloud.getEndpoint(), "http://a.com"); | ||
assertEquals(cloud.getFsRoot(), "my-root"); | ||
assertTrue(cloud.isPrivateIpUsed()); | ||
assertTrue(cloud.isAlwaysReconnect()); | ||
assertEquals(cloud.getIdleMinutes(), 22); | ||
assertEquals(cloud.getMinSize(), 11); | ||
assertEquals(cloud.getMaxSize(), 75); | ||
assertEquals(cloud.getNumExecutors(), 24); | ||
assertFalse(cloud.isRestrictUsage()); | ||
assertEquals(cloud.getInitOnlineTimeoutSec(), 267); | ||
assertEquals(cloud.getInitOnlineCheckIntervalSec(), 13); | ||
assertEquals(cloud.getCloudStatusIntervalSec(), 11); | ||
assertTrue(cloud.isDisableTaskResubmit()); | ||
assertFalse(cloud.isNoDelayProvision()); | ||
assertEquals(cloud.getAwsCredentialsId(), "xx"); | ||
assertEquals(cloud.getEc2KeyPairName(), "keyPairName"); | ||
|
||
SSHConnector sshConnector = (SSHConnector) cloud.getComputerConnector(); | ||
assertEquals(sshConnector.getSshHostKeyVerificationStrategy().getClass(), NonVerifyingKeyVerificationStrategy.class); | ||
} | ||
|
||
@Test | ||
@ConfiguredWithCode("FleetLabelCloud/empty-name-configuration-as-code.yml") | ||
public void configurationWithEmptyName_shouldUseDefault() { | ||
assertEquals(jenkinsRule.jenkins.clouds.size(), 3); | ||
|
||
for (FleetLabelCloud cloud : jenkinsRule.jenkins.clouds.getAll(FleetLabelCloud.class)){ | ||
|
||
assertTrue(cloud.name.startsWith(FleetLabelCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); | ||
assertEquals(("FleetLabelCloud".length() + CloudNames.SUFFIX_LENGTH + 1), cloud.name.length()); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...esources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/empty-name-configuration-as-code.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
jenkins: | ||
clouds: | ||
- eC2FleetLabel: | ||
name: "" | ||
- eC2FleetLabel: | ||
name: "" | ||
- eC2FleetLabel: | ||
name: "" |
26 changes: 26 additions & 0 deletions
26
src/test/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/max-configuration-as-code.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
jenkins: | ||
clouds: | ||
- eC2FleetLabel: | ||
name: ec2-fleet-label | ||
awsCredentialsId: xx | ||
computerConnector: | ||
sshConnector: | ||
credentialsId: cred | ||
sshHostKeyVerificationStrategy: | ||
NonVerifyingKeyVerificationStrategy | ||
region: us-east-2 | ||
endpoint: http://a.com | ||
fsRoot: my-root | ||
privateIpUsed: true | ||
alwaysReconnect: true | ||
idleMinutes: 22 | ||
minSize: 11 | ||
maxSize: 75 | ||
numExecutors: 24 | ||
restrictUsage: false | ||
initOnlineTimeoutSec: 267 | ||
initOnlineCheckIntervalSec: 13 | ||
cloudStatusIntervalSec: 11 | ||
disableTaskResubmit: true | ||
noDelayProvision: false | ||
ec2KeyPairName: "keyPairName" |
4 changes: 4 additions & 0 deletions
4
src/test/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/min-configuration-as-code.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jenkins: | ||
clouds: | ||
- eC2FleetLabel: | ||
name: ec2-fleet-label |
9 changes: 9 additions & 0 deletions
9
...urces/com/amazon/jenkins/ec2fleet/FleetLabelCloud/name-required-configuration-as-code.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
jenkins: | ||
clouds: | ||
- eC2FleetLabel: | ||
awsCredentialsId: xx | ||
region: us-east-2 | ||
idleMinutes: 33 | ||
minSize: 15 | ||
maxSize: 90 | ||
numExecutors: 12 |