Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: use actual value of java_home to prevent misinterpretation as string #37

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ def set_truststore_password(self, container):
Args:
container: The application container.
"""
out, _ = container.exec(
["/bin/sh", "-c", "echo $JAVA_HOME"]
).wait_output()
java_home = out.strip()

command = [
"keytool",
"-storepass",
Expand All @@ -233,7 +238,7 @@ def set_truststore_password(self, container):
"-new",
self._state.truststore_pwd,
"-keystore",
"$JAVA_HOME/lib/security/cacerts",
f"{java_home}/lib/security/cacerts",
]
try:
container.exec(command).wait_output()
Expand Down
8 changes: 6 additions & 2 deletions src/relations/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,18 @@ def update_certificates(self, relation_broken=False) -> None:

certificate = self.charm._state.opensearch_certificate
truststore_pwd = self.charm._state.truststore_pwd
out, _ = container.exec(
["/bin/sh", "-c", "echo $JAVA_HOME"]
).wait_output()
java_home = out.strip()

if not relation_broken and certificate:
container.push("/opensearch.crt", certificate)
command = [
"keytool",
"-importcert",
"-keystore",
"$JAVA_HOME/lib/security/cacerts",
f"{java_home}/lib/security/cacerts",
"-file",
"/opensearch.crt",
"-alias",
Expand All @@ -108,7 +112,7 @@ def update_certificates(self, relation_broken=False) -> None:
"keytool",
"-delete",
"-keystore",
"$JAVA_HOME/lib/security/cacerts",
f"{java_home}/lib/security/cacerts",
"-alias",
CERTIFICATE_NAME,
"-storepass",
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ def simulate_usersync_lifecycle(harness):
harness.charm.on.ranger_pebble_ready.emit(container)

harness.update_config({"charm-function": "usersync"})
harness.handle_exec(
"ranger", ["/bin/sh"], result="/usr/lib/jvm/java-21-openjdk-amd64/"
)

# Simulate LDAP readiness.
rel_id = harness.add_relation("ldap", "comsys-openldap-k8s")
Expand All @@ -543,6 +546,9 @@ def simulate_admin_lifecycle(harness):
container = harness.model.unit.get_container("ranger")
harness.charm.on.ranger_pebble_ready.emit(container)

harness.handle_exec(
"ranger", ["/bin/sh"], result="/usr/lib/jvm/java-21-openjdk-amd64/"
)
harness.handle_exec("ranger", ["keytool"], result=0)

# Simulate database readiness.
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ passenv =
description = Run integration tests
deps =
ipdb==0.13.9
juju==3.5.2.0
juju==3.5.2.1
pytest==7.1.3
pytest-operator==0.29.0
pytest-asyncio==0.21
Expand All @@ -44,7 +44,7 @@ commands =
description = Run integration tests
deps =
ipdb==0.13.9
juju==3.5.2.0
juju==3.5.2.1
pytest==7.1.3
pytest-operator==0.22.0
pytest-asyncio==0.21
Expand Down
Loading