Skip to content

Commit da26282

Browse files
authored
Fixes to update the Java version for integration tests (#751)
Signed-off-by: Govind Kamat <[email protected]>
1 parent 12fd07a commit da26282

File tree

9 files changed

+35
-37
lines changed

9 files changed

+35
-37
lines changed

.github/workflows/integ-test.yml

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ jobs:
4949
echo "JAVA21_HOME=$JAVA_HOME" >> $GITHUB_ENV
5050
echo "BUILD_JAVA_HOME=$JAVA_HOME" >> $GITHUB_ENV
5151
52+
- name: Install JDK 21
53+
uses: actions/setup-java@v3
54+
with:
55+
distribution: 'adopt'
56+
java-version: '21'
57+
- run: echo "JAVA21_HOME=$JAVA_HOME" >> $GITHUB_ENV
58+
5259
- name: Install JDK 17
5360
uses: actions/setup-java@v3
5461
with:

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ check-pip:
3939
@if ! $(PIP) > /dev/null 2>&1 || ! $(PIP) install pip > /dev/null 2>&1; then make pyinst38; fi
4040

4141
check-java:
42-
@if ! test "$(JAVA_HOME)" || ! java --version > /dev/null 2>&1 || ! javadoc --help > /dev/null 2>&1; then \
42+
@if ! test "$(JAVA21_HOME)" || ! java --version > /dev/null 2>&1 || ! javadoc --help > /dev/null 2>&1; then \
4343
echo "Java installation issues for running integration tests" >&2; \
4444
exit 1; \
4545
fi

osbenchmark/builder/provisioner.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def install(self, os_home_path, plugin_url=None):
346346
self.logger.info("Installing [%s] into [%s]", self.plugin_name, os_home_path)
347347
install_cmd = '%s install --batch "%s"' % (installer_binary_path, self.plugin_name)
348348

349-
return_code = process.run_subprocess_with_logging(install_cmd, env=self.env())
349+
output, return_code = process.run_subprocess_with_logging(install_cmd, env=self.env(), capture_output=True)
350350
if return_code == 0:
351351
self.logger.info("Successfully installed [%s].", self.plugin_name)
352352
elif return_code == 64:
@@ -356,9 +356,9 @@ def install(self, os_home_path, plugin_url=None):
356356
raise exceptions.SupplyError("I/O error while trying to install [%s]" % self.plugin_name)
357357
else:
358358
raise exceptions.BenchmarkError(
359-
"Unknown error while trying to install [%s] (installer return code [%s]). "
359+
"Unknown error '%s' while trying to install [%s] (installer return code [%s]). "
360360
"Please check the logs." %
361-
(self.plugin_name, str(return_code)))
361+
(output, self.plugin_name, str(return_code)))
362362

363363
def invoke_install_hook(self, phase, variables):
364364
self.hook_handler.invoke(phase.name, variables=variables, env=self.env())

osbenchmark/builder/supplier.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ def run(self, command, override_src_dir=None):
702702
log_file = os.path.join(self.log_dir, "build.log")
703703

704704
# we capture all output to a dedicated build log file
705-
build_cmd = "export JAVA_HOME={}; cd {}; {} > {} 2>&1".format(self.java_home, src_dir, command, log_file)
705+
build_cmd = "export JAVA_HOME={}; cd {}; {} < /dev/null > {} 2>&1".format(self.java_home, src_dir, command, log_file)
706706
self.logger.info("Running build command [%s]", build_cmd)
707707

708708
if process.run_subprocess(build_cmd):

osbenchmark/resources/provision_configs/main/provision_config_instances/v1/vanilla/config.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jdk.unbundled.release_url = https://artifacts.opensearch.org/releases/bundle/ope
1616

1717
docker_image=opensearchproject/opensearch
1818
# major version of the JDK that is used to build OpenSearch
19-
build.jdk = 17
19+
build.jdk = 21
2020
# list of JDK major versions that are used to run OpenSearch
21-
runtime.jdk = 17,16,15,14,13,12,11,8
21+
runtime.jdk = 21,17,16,15,14,13,12,11,8
2222
runtime.jdk.bundled = true

osbenchmark/utils/process.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def run_subprocess_with_output(command_line):
4040
logger.debug("Running subprocess [%s] with output.", command_line)
4141
command_line_args = shlex.split(command_line)
4242

43-
with subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as command_line_process:
43+
with subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL) as command_line_process:
4444
has_output = True
4545
lines = []
4646
while has_output:
@@ -57,7 +57,7 @@ def run_subprocess_with_out_and_err(command_line):
5757
logger.debug("Running subprocess [%s] with stdout and stderr.", command_line)
5858
command_line_args = shlex.split(command_line)
5959

60-
sp = subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
60+
sp = subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL)
6161
sp.wait()
6262
out, err = sp.communicate()
6363
return out.decode('UTF-8'), err.decode('UTF-8'), sp.returncode
@@ -68,7 +68,7 @@ def run_subprocess_with_stderr(command_line):
6868
logger.debug("Running subprocess [%s] with stderr but no stdout.", command_line)
6969
command_line_args = shlex.split(command_line)
7070

71-
sp = subprocess.Popen(command_line_args, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
71+
sp = subprocess.Popen(command_line_args, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL)
7272
sp.wait()
7373
_, err = sp.communicate()
7474
return err.decode('UTF-8'), sp.returncode
@@ -91,7 +91,7 @@ def exit_status_as_bool(runnable, quiet=False):
9191

9292

9393
def run_subprocess_with_logging(command_line, header=None, level=logging.INFO, stdin=None, stdout=subprocess.PIPE,
94-
stderr=subprocess.STDOUT, env=None, detach=False):
94+
stderr=subprocess.STDOUT, env=None, detach=False, capture_output=False):
9595
"""
9696
Runs the provided command line in a subprocess. All output will be captured by a logger.
9797
@@ -128,7 +128,7 @@ def run_subprocess_with_logging(command_line, header=None, level=logging.INFO, s
128128
logger.log(level=level, msg=stdout)
129129

130130
logger.debug("Subprocess [%s] finished with return code [%s].", command_line, str(command_line_process.returncode))
131-
return command_line_process.returncode
131+
return (stdout, command_line_process.returncode) if capture_output else command_line_process.returncode
132132

133133

134134
def is_benchmark_process(p):

tests/builder/provisioner_test.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def test_invokes_hook_no_java_home(self):
243243
class PluginInstallerTests(TestCase):
244244
@mock.patch("osbenchmark.utils.process.run_subprocess_with_logging")
245245
def test_install_plugin_successfully(self, installer_subprocess):
246-
installer_subprocess.return_value = 0
246+
installer_subprocess.return_value = "output", 0
247247

248248
plugin = provision_config.PluginDescriptor(name="unit-test-plugin", config="default", variables={"active": True})
249249
installer = provisioner.PluginInstaller(plugin,
@@ -254,11 +254,11 @@ def test_install_plugin_successfully(self, installer_subprocess):
254254

255255
installer_subprocess.assert_called_with(
256256
'/opt/opensearch/bin/opensearch-plugin install --batch "unit-test-plugin"',
257-
env={"JAVA_HOME": "/usr/local/javas/java8"})
257+
env={"JAVA_HOME": "/usr/local/javas/java8"}, capture_output=True)
258258

259259
@mock.patch("osbenchmark.utils.process.run_subprocess_with_logging")
260260
def test_install_plugin_with_bundled_jdk(self, installer_subprocess):
261-
installer_subprocess.return_value = 0
261+
installer_subprocess.return_value = "output", 0
262262

263263
plugin = provision_config.PluginDescriptor(name="unit-test-plugin", config="default", variables={"active": True})
264264
installer = provisioner.PluginInstaller(plugin,
@@ -270,12 +270,12 @@ def test_install_plugin_with_bundled_jdk(self, installer_subprocess):
270270

271271
installer_subprocess.assert_called_with(
272272
'/opt/opensearch/bin/opensearch-plugin install --batch "unit-test-plugin"',
273-
env={})
273+
env={}, capture_output=True)
274274

275275
@mock.patch("osbenchmark.utils.process.run_subprocess_with_logging")
276276
def test_install_unknown_plugin(self, installer_subprocess):
277277
# unknown plugin
278-
installer_subprocess.return_value = 64
278+
installer_subprocess.return_value = "output", 64
279279

280280
plugin = provision_config.PluginDescriptor(name="unknown")
281281
installer = provisioner.PluginInstaller(plugin,
@@ -288,12 +288,12 @@ def test_install_unknown_plugin(self, installer_subprocess):
288288

289289
installer_subprocess.assert_called_with(
290290
'/opt/opensearch/bin/opensearch-plugin install --batch "unknown"',
291-
env={"JAVA_HOME": "/usr/local/javas/java8"})
291+
env={"JAVA_HOME": "/usr/local/javas/java8"}, capture_output=True)
292292

293293
@mock.patch("osbenchmark.utils.process.run_subprocess_with_logging")
294294
def test_install_plugin_with_io_error(self, installer_subprocess):
295295
# I/O error
296-
installer_subprocess.return_value = 74
296+
installer_subprocess.return_value = "output", 74
297297

298298
plugin = provision_config.PluginDescriptor(name="simple")
299299
installer = provisioner.PluginInstaller(plugin,
@@ -306,12 +306,12 @@ def test_install_plugin_with_io_error(self, installer_subprocess):
306306

307307
installer_subprocess.assert_called_with(
308308
'/opt/opensearch/bin/opensearch-plugin install --batch "simple"',
309-
env={"JAVA_HOME": "/usr/local/javas/java8"})
309+
env={"JAVA_HOME": "/usr/local/javas/java8"}, capture_output=True)
310310

311311
@mock.patch("osbenchmark.utils.process.run_subprocess_with_logging")
312312
def test_install_plugin_with_unknown_error(self, installer_subprocess):
313313
# some other error
314-
installer_subprocess.return_value = 12987
314+
installer_subprocess.return_value = "output", 12987
315315

316316
plugin = provision_config.PluginDescriptor(name="simple")
317317
installer = provisioner.PluginInstaller(plugin,
@@ -320,12 +320,12 @@ def test_install_plugin_with_unknown_error(self, installer_subprocess):
320320

321321
with self.assertRaises(exceptions.BenchmarkError) as ctx:
322322
installer.install(os_home_path="/opt/opensearch")
323-
self.assertEqual("Unknown error while trying to install [simple] (installer return code [12987]). Please check the logs.",
323+
self.assertEqual("Unknown error 'output' while trying to install [simple] (installer return code [12987]). Please check the logs.",
324324
ctx.exception.args[0])
325325

326326
installer_subprocess.assert_called_with(
327327
'/opt/opensearch/bin/opensearch-plugin install --batch "simple"',
328-
env={"JAVA_HOME": "/usr/local/javas/java8"})
328+
env={"JAVA_HOME": "/usr/local/javas/java8"}, capture_output=True)
329329

330330
def test_pass_plugin_properties(self):
331331
plugin = provision_config.PluginDescriptor(name="unit-test-plugin",

tests/builder/supplier_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ def test_build_on_jdk_8(self, jvm_resolve_path, mock_run_subprocess):
152152

153153
calls = [
154154
# Actual call
155-
mock.call("export JAVA_HOME=/opt/jdk8; cd /src; ./gradlew clean > logs/build.log 2>&1"),
155+
mock.call("export JAVA_HOME=/opt/jdk8; cd /src; ./gradlew clean < /dev/null > logs/build.log 2>&1"),
156156
# Return value check
157-
mock.call("export JAVA_HOME=/opt/jdk8; cd /src; ./gradlew assemble > logs/build.log 2>&1"),
157+
mock.call("export JAVA_HOME=/opt/jdk8; cd /src; ./gradlew assemble < /dev/null > logs/build.log 2>&1"),
158158
]
159159

160160
mock_run_subprocess.assert_has_calls(calls)
@@ -170,9 +170,9 @@ def test_build_on_jdk_10(self, jvm_resolve_path, mock_run_subprocess):
170170

171171
calls = [
172172
# Actual call
173-
mock.call("export JAVA_HOME=/opt/jdk10; cd /src; ./gradlew clean > logs/build.log 2>&1"),
173+
mock.call("export JAVA_HOME=/opt/jdk10; cd /src; ./gradlew clean < /dev/null > logs/build.log 2>&1"),
174174
# Return value check
175-
mock.call("export JAVA_HOME=/opt/jdk10; cd /src; ./gradlew assemble > logs/build.log 2>&1"),
175+
mock.call("export JAVA_HOME=/opt/jdk10; cd /src; ./gradlew assemble < /dev/null > logs/build.log 2>&1"),
176176
]
177177

178178
mock_run_subprocess.assert_has_calls(calls)

tox.ini

+1-10
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,7 @@ deps=
1616
pytest
1717
passenv =
1818
HOME
19-
JAVA_HOME
20-
JAVA8_HOME
21-
JAVA9_HOME
22-
JAVA10_HOME
23-
JAVA11_HOME
24-
JAVA12_HOME
25-
JAVA13_HOME
26-
JAVA14_HOME
27-
JAVA15_HOME
28-
JAVA16_HOME
19+
JAVA*_HOME
2920
BENCHMARK_HOME
3021
SSH_AUTH_SOCK
3122
THESPLOG_FILE

0 commit comments

Comments
 (0)