Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3193 from dwnusbaum/JENKINS-48365
[JENKINS-48365] Install detached plugins when upgrading Jenkins past the version the plugins were detached
- Loading branch information
Showing
6 changed files
with
171 additions
and
4 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
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
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
121 changes: 121 additions & 0 deletions
121
test/src/test/java/jenkins/install/LoadDetachedPluginsTest.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,121 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2017 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package jenkins.install; | ||
|
||
import hudson.ClassicPluginStrategy; | ||
import hudson.ClassicPluginStrategy.DetachedPlugin; | ||
import hudson.PluginManager; | ||
import hudson.PluginManagerUtil; | ||
import hudson.PluginWrapper; | ||
import hudson.util.VersionNumber; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.RestartableJenkinsRule; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class LoadDetachedPluginsTest { | ||
|
||
@Rule public RestartableJenkinsRule rr = PluginManagerUtil.newRestartableJenkinsRule(); | ||
|
||
@Issue("JENKINS-48365") | ||
@Test | ||
@LocalData | ||
public void upgradeFromJenkins1() throws IOException { | ||
VersionNumber since = new VersionNumber("1.550"); | ||
rr.then(r -> { | ||
List<DetachedPlugin> detachedPlugins = ClassicPluginStrategy.getDetachedPlugins(since); | ||
assertThat("Plugins have been detached since the pre-upgrade version", | ||
detachedPlugins.size(), greaterThan(4)); | ||
assertThat("Plugins detached between the pre-upgrade version and the current version should be installed", | ||
getInstalledDetachedPlugins(r, detachedPlugins).size(), equalTo(detachedPlugins.size())); | ||
assertNoFailedPlugins(r); | ||
}); | ||
} | ||
|
||
@Issue("JENKINS-48365") | ||
@Test | ||
@LocalData | ||
public void upgradeFromJenkins2() { | ||
VersionNumber since = new VersionNumber("2.0"); | ||
rr.then(r -> { | ||
List<DetachedPlugin> detachedPlugins = ClassicPluginStrategy.getDetachedPlugins(since); | ||
assertThat("Plugins have been detached since the pre-upgrade version", | ||
detachedPlugins.size(), greaterThan(1)); | ||
assertThat("Plugins detached between the pre-upgrade version and the current version should be installed", | ||
getInstalledDetachedPlugins(r, detachedPlugins).size(), equalTo(detachedPlugins.size())); | ||
assertNoFailedPlugins(r); | ||
}); | ||
} | ||
|
||
@Test | ||
public void newInstallation() { | ||
rr.then(r -> { | ||
List<DetachedPlugin> detachedPlugins = ClassicPluginStrategy.getDetachedPlugins(); | ||
assertThat("Detached plugins should exist", detachedPlugins, not(empty())); | ||
assertThat("Detached plugins should not be installed on a new instance", | ||
getInstalledDetachedPlugins(r, detachedPlugins), empty()); | ||
assertNoFailedPlugins(r); | ||
}); | ||
rr.then(r -> { | ||
List<DetachedPlugin> detachedPlugins = ClassicPluginStrategy.getDetachedPlugins(); | ||
assertThat("Detached plugins should exist", detachedPlugins, not(empty())); | ||
assertThat("Detached plugins should not be installed after restarting", | ||
getInstalledDetachedPlugins(r, detachedPlugins), empty()); | ||
assertNoFailedPlugins(r); | ||
}); | ||
} | ||
|
||
private List<PluginWrapper> getInstalledDetachedPlugins(JenkinsRule r, List<DetachedPlugin> detachedPlugins) { | ||
PluginManager pluginManager = r.jenkins.getPluginManager(); | ||
List<PluginWrapper> installedPlugins = new ArrayList<>(); | ||
for (DetachedPlugin plugin : detachedPlugins) { | ||
PluginWrapper wrapper = pluginManager.getPlugin(plugin.getShortName()); | ||
if (wrapper != null) { | ||
installedPlugins.add(wrapper); | ||
assertTrue("Detached plugins should be active if installed", wrapper.isActive()); | ||
assertThat("Detached plugins should not have dependency errors", wrapper.getDependencyErrors(), empty()); | ||
} | ||
} | ||
return installedPlugins; | ||
} | ||
|
||
private void assertNoFailedPlugins(JenkinsRule r) { | ||
assertThat("Detached plugins and their dependencies should not fail to install", | ||
r.jenkins.getPluginManager().getFailedPlugins(), empty()); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...src/test/resources/jenkins/install/LoadDetachedPluginsTest/upgradeFromJenkins1/config.xml
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,34 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<disabledAdministrativeMonitors/> | ||
<version>1.550</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<useSecurity>true</useSecurity> | ||
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/> | ||
<securityRealm class="hudson.security.SecurityRealm$None"/> | ||
<disableRememberMe>false</disableRememberMe> | ||
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/> | ||
<workspaceDir>${JENKINS_HOME}/workspace/${ITEM_FULLNAME}</workspaceDir> | ||
<buildsDir>${ITEM_ROOTDIR}/builds</buildsDir> | ||
<jdks/> | ||
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/> | ||
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/> | ||
<clouds/> | ||
<quietPeriod>5</quietPeriod> | ||
<scmCheckoutRetryCount>0</scmCheckoutRetryCount> | ||
<views> | ||
<hudson.model.AllView> | ||
<owner class="hudson" reference="../../.."/> | ||
<name>All</name> | ||
<filterExecutors>false</filterExecutors> | ||
<filterQueue>false</filterQueue> | ||
<properties class="hudson.model.View$PropertyList"/> | ||
</hudson.model.AllView> | ||
</views> | ||
<primaryView>All</primaryView> | ||
<slaveAgentPort>0</slaveAgentPort> | ||
<label></label> | ||
<nodeProperties/> | ||
<globalNodeProperties/> | ||
</hudson> |
1 change: 1 addition & 0 deletions
1
...l/LoadDetachedPluginsTest/upgradeFromJenkins2/jenkins.install.InstallUtil.lastExecVersion
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 @@ | ||
2.0 |