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

CSS-10565: java home is set in the rock #34

Merged
merged 1 commit into from
Sep 20, 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
4 changes: 2 additions & 2 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
juju-channel: 3.1/stable
juju-channel: 3.4/stable
provider: microk8s
microk8s-addons: "ingress storage dns rbac registry"
channel: 1.25-strict/stable
channel: 1.28-strict/stable
- name: Run integration tests
run: tox -e ${{ matrix.tox-environments }}
4 changes: 2 additions & 2 deletions .github/workflows/test_and_publish_charm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
secrets: inherit
with:
integration-test-provider: microk8s
integration-test-provider-channel: 1.25-strict/stable
integration-test-juju-channel: 3.1/stable
integration-test-provider-channel: 1.28-strict/stable
integration-test-juju-channel: 3.4/stable
integration-test-modules: '["test_charm"]'
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ This project uses `tox` for managing test environments. There are some pre-confi
that can be used for linting and formatting code when you're preparing contributions to the charm:

```shell
tox run -e format # update your code according to linting rules
tox run -e fmt # update your code according to linting rules
tox run -e lint # code style
tox run -e unit # unit tests
tox run -e integration # integration tests
tox # runs 'format', 'lint', and 'unit' environments
tox # runs 'fmt', 'lint', and 'unit' environments
```

## Set up your development environment
Expand Down
5 changes: 2 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
ADMIN_ENTRYPOINT,
APP_NAME,
APPLICATION_PORT,
JAVA_HOME,
LOG_FILES,
METRICS_PORT,
RELATION_VALUES,
Expand Down Expand Up @@ -227,14 +226,14 @@ def set_truststore_password(self, container):
container: The application container.
"""
command = [
f"{JAVA_HOME}/bin/keytool",
"keytool",
"-storepass",
"changeit",
"-storepasswd",
"-new",
self._state.truststore_pwd,
"-keystore",
f"{JAVA_HOME}/lib/security/cacerts",
"$JAVA_HOME/lib/security/cacerts",
]
try:
container.exec(command).wait_output()
Expand Down
2 changes: 0 additions & 2 deletions src/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
"sync_ldap_url",
]

JAVA_HOME = "/usr/lib/jvm/java-11-openjdk-amd64"

# Observability literals
METRICS_PORT = 6080
LOG_FILES = ["/usr/lib/ranger/admin/ews/logs/ranger-admin-ranger-k8s-0-.log"]
Expand Down
16 changes: 5 additions & 11 deletions src/relations/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
from ops.pebble import ExecError
from requests.auth import HTTPBasicAuth

from literals import (
CERTIFICATE_NAME,
HEADERS,
INDEX_NAME,
JAVA_HOME,
OPENSEARCH_SCHEMA,
)
from literals import CERTIFICATE_NAME, HEADERS, INDEX_NAME, OPENSEARCH_SCHEMA
from utils import log_event_handler

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -97,10 +91,10 @@ def update_certificates(self, relation_broken=False) -> None:
if not relation_broken and certificate:
container.push("/opensearch.crt", certificate)
command = [
f"{JAVA_HOME}/bin/keytool",
"keytool",
"-importcert",
"-keystore",
f"{JAVA_HOME}/lib/security/cacerts",
"$JAVA_HOME/lib/security/cacerts",
"-file",
"/opensearch.crt",
"-alias",
Expand All @@ -111,10 +105,10 @@ def update_certificates(self, relation_broken=False) -> None:
]
else:
command = [
f"{JAVA_HOME}/bin/keytool",
"keytool",
"-delete",
"-keystore",
f"{JAVA_HOME}/lib/security/cacerts",
"$JAVA_HOME/lib/security/cacerts",
"-alias",
CERTIFICATE_NAME,
"-storepass",
Expand Down
2 changes: 0 additions & 2 deletions src/relations/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,11 @@ def _set_policy_manager(self, event):
relation = self.charm.model.get_relation(
self.relation_name, event.relation.id
)
data = event.relation.data[event.app]

if relation:
relation.data[self.charm.app].update(
{
"policy_manager_url": self.charm.config["policy-mgr-url"],
"service_name": data["name"],
}
)

Expand Down
5 changes: 1 addition & 4 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
-----END CERTIFICATE-----""",
}

JAVA_HOME = "/usr/lib/jvm/java-11-openjdk-amd64"


class MockService:
"""Defines functionality for the Ranger MockService."""
Expand Down Expand Up @@ -353,7 +351,6 @@ def test_policy_on_relation_changed(self):
relation_data = harness.get_relation_data(rel_id, "ranger-k8s")
expected_data = {
"policy_manager_url": "http://ranger-k8s:6080",
"service_name": "trino-service",
}
self.assertEqual(relation_data, expected_data)

Expand Down Expand Up @@ -546,7 +543,7 @@ def simulate_admin_lifecycle(harness):
container = harness.model.unit.get_container("ranger")
harness.charm.on.ranger_pebble_ready.emit(container)

harness.handle_exec("ranger", [f"{JAVA_HOME}/bin/keytool"], result=0)
harness.handle_exec("ranger", ["keytool"], result=0)

# Simulate database readiness.
event = make_database_changed_event()
Expand Down
61 changes: 9 additions & 52 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_path}
PYTHONBREAKPOINT=ipdb.set_trace
PY_COLORS=1
charm: TEST_FILE=test_charm.py
scaling: TEST_FILE=test_scaling.py
upgrades: TEST_FILE=test_upgrades.py
policy: TEST_FILE=test_policy.py
usersync: TEST_FILE=test_usersync.py
passenv =
PYTHONPATH
CHARM_BUILD_DIR
Expand All @@ -27,73 +32,25 @@ passenv =
description = Run integration tests
deps =
ipdb==0.13.9
juju==3.1.0.1
juju==3.5.2.0
pytest==7.1.3
pytest-operator==0.29.0
pytest-asyncio==0.21
-r{toxinidir}/requirements.txt
commands =
pytest {[vars]tst_path}integration -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}

[testenv:integration-charm]
[testenv:integration-{charm,scaling,upgrades,policy,usersync}]
description = Run integration tests
deps =
ipdb==0.13.9
juju==3.1.0.1
juju==3.5.2.0
pytest==7.1.3
pytest-operator==0.22.0
pytest-asyncio==0.21
-r{toxinidir}/requirements.txt
commands =
pytest {[vars]tst_path}integration/test_charm.py -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}

[testenv:integration-scaling]
description = Run integration tests
deps =
ipdb==0.13.9
juju==3.1.0.1
pytest==7.1.3
pytest-operator==0.22.0
pytest-asyncio==0.21
-r{toxinidir}/requirements.txt
commands =
pytest {[vars]tst_path}integration/test_scaling.py -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}

[testenv:integration-upgrades]
description = Run integration tests
deps =
ipdb==0.13.9
juju==3.1.0.1
pytest==7.4.0
pytest-operator==0.29.0
pytest-asyncio==0.21
-r{toxinidir}/requirements.txt
commands =
pytest {[vars]tst_path}integration/test_upgrades.py -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}

[testenv:integration-policy]
description = Run integration tests
deps =
ipdb==0.13.9
juju==3.1.0.1
pytest==7.4.0
pytest-operator==0.29.0
pytest-asyncio==0.21
-r{toxinidir}/requirements.txt
commands =
pytest {[vars]tst_path}integration/test_policy.py -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}

[testenv:integration-usersync]
description = Run integration tests
deps =
ipdb==0.13.9
juju==3.1.0.1
pytest==7.4.0
pytest-operator==0.29.0
pytest-asyncio==0.21
-r{toxinidir}/requirements.txt
commands =
pytest {[vars]tst_path}integration/test_usersync.py -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}
pytest {[vars]tst_path}integration/{env:TEST_FILE} -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}

[testenv:unit]
description = Run tests
Expand Down
Loading