Skip to content

Commit 1c32896

Browse files
[test] port linux package packaging tests (#31943)
Add packaging tests for the linux package distributions to the java test project and remove them from bats. Most of the tests that lived in 30_deb_package.bats and 40_rpm_package.bats are applicable to both package types and are combined into a single type of test case. Others are separated out into separate cases to make their intent more clear For #26741
1 parent ce519fe commit 1c32896

24 files changed

+1122
-499
lines changed

qa/vagrant/build.gradle

+3-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ plugins {
2828

2929
dependencies {
3030
compile "junit:junit:${versions.junit}"
31-
compile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
31+
compile "org.hamcrest:hamcrest-core:${versions.hamcrest}"
32+
compile "org.hamcrest:hamcrest-library:${versions.hamcrest}"
3233
compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
3334

3435
compile "org.apache.httpcomponents:httpcore:${versions.httpcore}"
@@ -91,13 +92,5 @@ tasks.thirdPartyAudit.excludes = [
9192
'org.apache.log4j.Priority',
9293
// commons-logging provided dependencies
9394
'javax.servlet.ServletContextEvent',
94-
'javax.servlet.ServletContextListener',
95-
// from randomized testing
96-
'org.apache.tools.ant.BuildException',
97-
'org.apache.tools.ant.DirectoryScanner',
98-
'org.apache.tools.ant.Task',
99-
'org.apache.tools.ant.types.FileSet',
100-
'org.easymock.EasyMock',
101-
'org.easymock.IArgumentMatcher',
102-
'org.jmock.core.Constraint'
95+
'javax.servlet.ServletContextListener'
10396
]

qa/vagrant/src/main/java/org/elasticsearch/packaging/PackagingTests.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,19 @@
1919

2020
package org.elasticsearch.packaging;
2121

22+
import org.elasticsearch.packaging.test.DefaultDebPreservationTests;
23+
import org.elasticsearch.packaging.test.DefaultDebBasicTests;
24+
import org.elasticsearch.packaging.test.DefaultRpmPreservationTests;
25+
import org.elasticsearch.packaging.test.DefaultRpmBasicTests;
26+
import org.elasticsearch.packaging.test.OssDebPreservationTests;
27+
import org.elasticsearch.packaging.test.OssDebBasicTests;
28+
import org.elasticsearch.packaging.test.OssRpmPreservationTests;
29+
import org.elasticsearch.packaging.test.OssRpmBasicTests;
2230
import org.elasticsearch.packaging.test.OssTarTests;
2331
import org.elasticsearch.packaging.test.OssZipTests;
2432
import org.elasticsearch.packaging.test.DefaultTarTests;
2533
import org.elasticsearch.packaging.test.DefaultZipTests;
34+
import org.elasticsearch.packaging.test.PackageDependenciesTests;
2635

2736
import org.junit.runner.RunWith;
2837
import org.junit.runners.Suite;
@@ -31,8 +40,17 @@
3140
@RunWith(Suite.class)
3241
@SuiteClasses({
3342
DefaultTarTests.class,
34-
DefaultZipTests.class,
3543
OssTarTests.class,
36-
OssZipTests.class
44+
DefaultZipTests.class,
45+
OssZipTests.class,
46+
PackageDependenciesTests.class,
47+
DefaultRpmBasicTests.class,
48+
OssRpmBasicTests.class,
49+
DefaultDebBasicTests.class,
50+
OssDebBasicTests.class,
51+
DefaultDebPreservationTests.class,
52+
OssDebPreservationTests.class,
53+
DefaultRpmPreservationTests.class,
54+
OssRpmPreservationTests.class
3755
})
3856
public class PackagingTests {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 org.elasticsearch.packaging.util.Distribution;
23+
24+
public class DefaultDebBasicTests extends PackageTestCase {
25+
26+
@Override
27+
protected Distribution distribution() {
28+
return Distribution.DEFAULT_DEB;
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 org.elasticsearch.packaging.util.Distribution;
23+
24+
public class DefaultDebPreservationTests extends DebPreservationTestCase {
25+
26+
@Override
27+
protected Distribution distribution() {
28+
return Distribution.DEFAULT_DEB;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 org.elasticsearch.packaging.util.Distribution;
23+
24+
public class DefaultRpmBasicTests extends PackageTestCase {
25+
26+
@Override
27+
protected Distribution distribution() {
28+
return Distribution.DEFAULT_RPM;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 org.elasticsearch.packaging.util.Distribution;
23+
24+
public class DefaultRpmPreservationTests extends RpmPreservationTestCase {
25+
26+
@Override
27+
protected Distribution distribution() {
28+
return Distribution.DEFAULT_RPM;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 org.elasticsearch.packaging.util.Distribution;
23+
24+
public class OssDebBasicTests extends PackageTestCase {
25+
26+
@Override
27+
protected Distribution distribution() {
28+
return Distribution.OSS_DEB;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 org.elasticsearch.packaging.util.Distribution;
23+
24+
public class OssDebPreservationTests extends DebPreservationTestCase {
25+
26+
@Override
27+
protected Distribution distribution() {
28+
return Distribution.OSS_DEB;
29+
}
30+
}

0 commit comments

Comments
 (0)