|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.packaging.test; |
| 21 | + |
| 22 | +import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering; |
| 23 | +import org.elasticsearch.packaging.util.Distribution; |
| 24 | +import org.elasticsearch.packaging.util.Installation; |
| 25 | +import org.elasticsearch.packaging.util.Shell; |
| 26 | +import org.junit.Before; |
| 27 | +import org.junit.BeforeClass; |
| 28 | + |
| 29 | +import java.nio.file.Files; |
| 30 | +import java.nio.file.Paths; |
| 31 | + |
| 32 | +import static org.elasticsearch.packaging.util.Cleanup.cleanEverything; |
| 33 | +import static org.elasticsearch.packaging.util.FileUtils.assertPathsDontExist; |
| 34 | +import static org.elasticsearch.packaging.util.FileUtils.assertPathsExist; |
| 35 | +import static org.elasticsearch.packaging.util.Packages.SYSVINIT_SCRIPT; |
| 36 | +import static org.elasticsearch.packaging.util.Packages.assertInstalled; |
| 37 | +import static org.elasticsearch.packaging.util.Packages.assertRemoved; |
| 38 | +import static org.elasticsearch.packaging.util.Packages.install; |
| 39 | +import static org.elasticsearch.packaging.util.Packages.remove; |
| 40 | +import static org.elasticsearch.packaging.util.Packages.packageStatus; |
| 41 | +import static org.elasticsearch.packaging.util.Packages.verifyPackageInstallation; |
| 42 | +import static org.elasticsearch.packaging.util.Platforms.isDPKG; |
| 43 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 44 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 45 | +import static org.hamcrest.core.Is.is; |
| 46 | +import static org.junit.Assert.assertTrue; |
| 47 | +import static org.junit.Assume.assumeThat; |
| 48 | +import static org.junit.Assume.assumeTrue; |
| 49 | + |
| 50 | +@TestCaseOrdering(TestCaseOrdering.AlphabeticOrder.class) |
| 51 | +public abstract class DebPreservationTestCase extends PackagingTestCase { |
| 52 | + |
| 53 | + private static Installation installation; |
| 54 | + |
| 55 | + protected abstract Distribution distribution(); |
| 56 | + |
| 57 | + @BeforeClass |
| 58 | + public static void cleanup() { |
| 59 | + installation = null; |
| 60 | + cleanEverything(); |
| 61 | + } |
| 62 | + |
| 63 | + @Before |
| 64 | + public void onlyCompatibleDistributions() { |
| 65 | + assumeTrue("only dpkg platforms", isDPKG()); |
| 66 | + assumeTrue("only compatible distributions", distribution().packaging.compatible); |
| 67 | + } |
| 68 | + |
| 69 | + public void test10Install() { |
| 70 | + assertRemoved(distribution()); |
| 71 | + installation = install(distribution()); |
| 72 | + assertInstalled(distribution()); |
| 73 | + verifyPackageInstallation(installation, distribution()); |
| 74 | + } |
| 75 | + |
| 76 | + public void test20Remove() { |
| 77 | + assumeThat(installation, is(notNullValue())); |
| 78 | + |
| 79 | + remove(distribution()); |
| 80 | + |
| 81 | + // some config files were not removed |
| 82 | + |
| 83 | + assertPathsExist( |
| 84 | + installation.config, |
| 85 | + installation.config("elasticsearch.yml"), |
| 86 | + installation.config("jvm.options"), |
| 87 | + installation.config("log4j2.properties") |
| 88 | + ); |
| 89 | + |
| 90 | + // keystore was removed |
| 91 | + |
| 92 | + assertPathsDontExist( |
| 93 | + installation.config("elasticsearch.keystore"), |
| 94 | + installation.config(".elasticsearch.keystore.initial_md5sum") |
| 95 | + ); |
| 96 | + |
| 97 | + // doc files were removed |
| 98 | + |
| 99 | + assertPathsDontExist( |
| 100 | + Paths.get("/usr/share/doc/" + distribution().flavor.name), |
| 101 | + Paths.get("/usr/share/doc/" + distribution().flavor.name + "/copyright") |
| 102 | + ); |
| 103 | + |
| 104 | + // sysvinit service file was not removed |
| 105 | + assertTrue(Files.exists(SYSVINIT_SCRIPT)); |
| 106 | + |
| 107 | + // defaults file was not removed |
| 108 | + assertTrue(Files.exists(installation.envFile)); |
| 109 | + } |
| 110 | + |
| 111 | + public void test30Purge() { |
| 112 | + assumeThat(installation, is(notNullValue())); |
| 113 | + |
| 114 | + final Shell sh = new Shell(); |
| 115 | + sh.run("dpkg --purge " + distribution().flavor.name); |
| 116 | + |
| 117 | + assertRemoved(distribution()); |
| 118 | + |
| 119 | + assertPathsDontExist( |
| 120 | + installation.config, |
| 121 | + installation.envFile, |
| 122 | + SYSVINIT_SCRIPT |
| 123 | + ); |
| 124 | + |
| 125 | + assertThat(packageStatus(distribution()).exitCode, is(1)); |
| 126 | + } |
| 127 | +} |
0 commit comments