|
26 | 26 | import com.carrotsearch.randomizedtesting.annotations.Timeout; |
27 | 27 | import org.apache.logging.log4j.LogManager; |
28 | 28 | import org.apache.logging.log4j.Logger; |
| 29 | +import org.elasticsearch.packaging.util.Archives; |
29 | 30 | import org.elasticsearch.packaging.util.Distribution; |
| 31 | +import org.elasticsearch.packaging.util.Docker; |
| 32 | +import org.elasticsearch.packaging.util.FileUtils; |
30 | 33 | import org.elasticsearch.packaging.util.Installation; |
| 34 | +import org.elasticsearch.packaging.util.Packages; |
31 | 35 | import org.elasticsearch.packaging.util.Platforms; |
32 | 36 | import org.elasticsearch.packaging.util.Shell; |
33 | 37 | import org.junit.Assert; |
|
40 | 44 | import org.junit.runner.Description; |
41 | 45 | import org.junit.runner.RunWith; |
42 | 46 |
|
| 47 | +import java.nio.file.Files; |
43 | 48 | import java.nio.file.Paths; |
44 | 49 |
|
45 | 50 | import static org.elasticsearch.packaging.util.Cleanup.cleanEverything; |
@@ -119,7 +124,78 @@ protected static Distribution distribution() { |
119 | 124 | return distribution; |
120 | 125 | } |
121 | 126 |
|
122 | | - protected Shell newShell() throws Exception { |
| 127 | + protected static void install() throws Exception { |
| 128 | + switch (distribution.packaging) { |
| 129 | + case TAR: |
| 130 | + case ZIP: |
| 131 | + installation = Archives.installArchive(distribution); |
| 132 | + Archives.verifyArchiveInstallation(installation, distribution); |
| 133 | + break; |
| 134 | + case DEB: |
| 135 | + case RPM: |
| 136 | + installation = Packages.installPackage(distribution); |
| 137 | + Packages.verifyPackageInstallation(installation, distribution, newShell()); |
| 138 | + break; |
| 139 | + case DOCKER: |
| 140 | + installation = Docker.runContainer(distribution); |
| 141 | + Docker.verifyContainerInstallation(installation, distribution); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * Starts and stops elasticsearch, and performs assertions while it is running. |
| 147 | + */ |
| 148 | + protected void assertWhileRunning(Platforms.PlatformAction assertions) throws Exception { |
| 149 | + try { |
| 150 | + switch (distribution.packaging) { |
| 151 | + case TAR: |
| 152 | + case ZIP: |
| 153 | + Archives.runElasticsearch(installation, sh); |
| 154 | + break; |
| 155 | + case DEB: |
| 156 | + case RPM: |
| 157 | + Packages.startElasticsearch(sh, installation); |
| 158 | + break; |
| 159 | + case DOCKER: |
| 160 | + // nothing, "installing" docker image is running it |
| 161 | + } |
| 162 | + |
| 163 | + } catch (Exception e ){ |
| 164 | + if (Files.exists(installation.home.resolve("elasticsearch.pid"))) { |
| 165 | + String pid = FileUtils.slurp(installation.home.resolve("elasticsearch.pid")).trim(); |
| 166 | + logger.info("Dumping jstack of elasticsearch processb ({}) that failed to start", pid); |
| 167 | + sh.runIgnoreExitCode("jstack " + pid); |
| 168 | + } |
| 169 | + if (Files.exists(installation.logs.resolve("elasticsearch.log"))) { |
| 170 | + logger.warn("Elasticsearch log:\n" + |
| 171 | + FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz")); |
| 172 | + } |
| 173 | + throw e; |
| 174 | + } |
| 175 | + |
| 176 | + try { |
| 177 | + assertions.run(); |
| 178 | + } catch (Exception e) { |
| 179 | + logger.warn("Elasticsearch log:\n" + |
| 180 | + FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz")); |
| 181 | + throw e; |
| 182 | + } |
| 183 | + |
| 184 | + switch (distribution.packaging) { |
| 185 | + case TAR: |
| 186 | + case ZIP: |
| 187 | + Archives.stopElasticsearch(installation); |
| 188 | + break; |
| 189 | + case DEB: |
| 190 | + case RPM: |
| 191 | + Packages.stopElasticsearch(sh); |
| 192 | + break; |
| 193 | + case DOCKER: |
| 194 | + // nothing, removing container is handled externally |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + protected static Shell newShell() throws Exception { |
123 | 199 | Shell sh = new Shell(); |
124 | 200 | if (distribution().hasJdk == false) { |
125 | 201 | Platforms.onLinux(() -> { |
|
0 commit comments