From 645bba31975f037ba44de6a159aa8355334c41e6 Mon Sep 17 00:00:00 2001 From: Joshua Kwan Date: Mon, 23 Apr 2018 18:34:40 -0700 Subject: [PATCH] Don't force the use of underscore to separate slave prefix from number. * Underscores complicate things when you want to create DNS records for the ephemeral slaves. * The user can always add the underscore back in their config. This should be documented as a breaking functional change but I don't really see that people would be designing tons of functionality around this underscore. As a result, there is no migration from pre- to post- removal versions of the plugin. --- .../tools/CloudProvisioningAlgorithm.java | 4 ++-- .../tools/CloudProvisioningAlgorithmTest.java | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithm.java b/src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithm.java index 20f37720..e9075000 100644 --- a/src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithm.java +++ b/src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithm.java @@ -70,7 +70,7 @@ public static String findUnusedName(CloudProvisioningRecord record) { final int maxAttempts = hasCap ? (templateInstanceCap) : 100; for (int attempt = 0; attempt < maxAttempts; attempt++) { final String suffix = hasCap ? calcSequentialSuffix(attempt) : calcRandomSuffix(attempt); - final String nodeName = cloneNamePrefix + "_" + suffix; + final String nodeName = cloneNamePrefix + suffix; if (!existingNames.contains(nodeName)) { return nodeName; } @@ -134,4 +134,4 @@ static BigInteger toBigInteger(final long msb, final long lsb) { final BigInteger bigNumber = new BigInteger(bytes); return bigNumber; } -} \ No newline at end of file +} diff --git a/src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithmTest.java b/src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithmTest.java index 785e36fb..02f2af5b 100644 --- a/src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithmTest.java +++ b/src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithmTest.java @@ -200,8 +200,8 @@ public void findUnusedNameGivenZeroOfTwoExistsThenReturnsOneThenTwo() { // Given final CloudProvisioningRecord record = createInstance(2, 0, 0); final String prefix = record.getTemplate().getCloneNamePrefix(); - final String expected1 = prefix + "_1"; - final String expected2 = prefix + "_2"; + final String expected1 = prefix + "1"; + final String expected2 = prefix + "2"; // When final String actual1 = CloudProvisioningAlgorithm.findUnusedName(record); @@ -219,10 +219,10 @@ public void findUnusedNameGivenMiddleOfThreeStillExistsThenReturnsOneThenThree() // Given final CloudProvisioningRecord record = createInstance(3, 0, 0); final String prefix = record.getTemplate().getCloneNamePrefix(); - final String expected1 = prefix + "_1"; - final String unwanted = prefix + "_2"; + final String expected1 = prefix + "1"; + final String unwanted = prefix + "2"; record.setCurrentlyUnwanted(unwanted, false); - final String expected2 = prefix + "_3"; + final String expected2 = prefix + "3"; // When final String actual1 = CloudProvisioningAlgorithm.findUnusedName(record); @@ -240,9 +240,9 @@ public void findUnusedNameGivenNoSpaceThenThrowsIllegalStateException() { // Given final CloudProvisioningRecord record = createInstance(3, 0, 0); final String prefix = record.getTemplate().getCloneNamePrefix(); - final String unwanted = prefix + "_1"; - final String active = prefix + "_2"; - final String planned = prefix + "_3"; + final String unwanted = prefix + "1"; + final String active = prefix + "2"; + final String planned = prefix + "3"; record.setCurrentlyUnwanted(unwanted, false); record.addCurrentlyActive(active); record.addCurrentlyPlanned(planned); @@ -264,7 +264,7 @@ public void findUnusedNameGivenOneOfTwoHasEndedThenReturnsOne() { // Given final CloudProvisioningRecord record = createInstance(2, 0, 0); final String prefix = record.getTemplate().getCloneNamePrefix(); - final String expected = prefix + "_1"; + final String expected = prefix + "1"; // When final String actual1 = CloudProvisioningAlgorithm.findUnusedName(record); @@ -296,7 +296,7 @@ public void findUnusedNameGivenUncappedInstancesThenReturnsUniqueNames() { // Then final List uniques = new ArrayList(new LinkedHashSet(actuals)); assertThat(actuals, equalTo(uniques)); - assertThat(actuals, everyItem(startsWith(prefix + "_"))); + assertThat(actuals, everyItem(startsWith(prefix))); } private CloudProvisioningRecord createInstance(int capacity, int provisioned, int planned) {