Skip to content

Commit

Permalink
Keep these changes, revert the rest
Browse files Browse the repository at this point in the history
  • Loading branch information
phvalguima committed Feb 12, 2024
1 parent afbca49 commit 2f9fed7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 26 deletions.
8 changes: 0 additions & 8 deletions lib/charms/opensearch/v0/opensearch_base_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,6 @@ def _on_update_status(self, event: UpdateStatusEvent):
if not self.opensearch.is_node_up():
return

# Extra logging: list shards and index status
logger.debug(
"indices status:\n"
f"{self.opensearch.request('GET', '/_cat/indices?v')}\n"
"indices shards:\n"
f"{self.opensearch.request('GET', '/_cat/shards?v')}\n"
)

# if there are exclusions to be removed
if self.unit.is_leader():
self.opensearch_exclusions.cleanup()
Expand Down
35 changes: 22 additions & 13 deletions lib/charms/opensearch/v0/opensearch_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,26 +268,35 @@ def apply_config(self, config: OpenSearchPluginConfig) -> bool:
"""
self._keystore.delete(config.secret_entries_to_del)
self._keystore.add(config.secret_entries_to_add)
if config.secret_entries_to_del or config.secret_entries_to_add:
self._keystore.reload_keystore()

# Add and remove configuration if applies
settings = ClusterTopology.get_cluster_settings(
current_settings = ClusterTopology.get_cluster_settings(
self._charm.opensearch,
include_defaults=True,
)
should_restart = False
# Do we have the option set?
if any([key in config.config_entries_to_del for key in settings.keys()]):
self._opensearch_config.delete_plugin(config.config_entries_to_del)
should_restart = True
to_remove = config.config_entries_to_del
if isinstance(config.config_entries_to_del, list):
# No keys should have value "None", therefore, setting them to None means
# the original current_settings will be changed.
to_remove = dict(
zip(config.config_entries_to_del, [None] * len(config.config_entries_to_del))
)
if current_settings == {
**current_settings,
**to_remove,
**config.config_entries_to_add,
}:
# Nothing to do here
return False

# Update the configuration
if config.config_entries_to_del:
self._opensearch_config.delete_plugin(config.config_entries_to_del)
if config.config_entries_to_add:
self._opensearch_config.add_plugin(config.config_entries_to_add)
should_restart = True

if config.secret_entries_to_del or config.secret_entries_to_add:
self._keystore.reload_keystore()

# Return True if some configuration entries changed
return should_restart
return True

def status(self, plugin: OpenSearchPlugin) -> PluginState:
"""Returns the status for a given plugin."""
Expand Down
11 changes: 6 additions & 5 deletions lib/charms/opensearch/v0/opensearch_relation_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,16 @@ def update_certs(self, relation_id, ca_chain=None):
return
if not ca_chain:
try:
ca_chain = self.charm.secrets.get_object(Scope.APP, CertType.APP_ADMIN.val).get(
"chain"
)
if ca_chain := self.charm.secrets.get_object(
Scope.APP, CertType.APP_ADMIN.val
).get("chain"):
self.opensearch_provides.set_tls_ca(relation_id, ca_chain)
else:
logger.warning("unable to get ca_chain")
except AttributeError:
# cert doesn't exist - presumably we don't yet have a TLS relation.
return

self.opensearch_provides.set_tls_ca(relation_id, ca_chain)

def _on_relation_changed(self, event: RelationChangedEvent) -> None:
if not self.unit.is_leader():
return
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/ha/test_large_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ async def test_set_roles_manually(
assert node.temperature is None, "Node temperature was erroneously set."

# change cluster name and roles + temperature, should trigger a rolling restart

logger.info("Changing cluster name and roles + temperature.")
await ops_test.model.applications[app].set_config(
{"cluster_name": "new_cluster_name", "roles": "cluster_manager, data.cold"}
)
Expand All @@ -131,6 +133,8 @@ async def test_set_roles_manually(
wait_for_exact_units=len(nodes),
idle_period=IDLE_PERIOD,
)

logger.info("Checking if the cluster name and roles + temperature were changed.")
assert await check_cluster_formation_successful(
ops_test, leader_unit_ip, get_application_unit_names(ops_test, app=app)
)
Expand Down
30 changes: 30 additions & 0 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# See LICENSE file for licensing details.

import logging
import subprocess

import pytest
from pytest_operator.plugin import OpsTest
Expand Down Expand Up @@ -138,3 +139,32 @@ async def test_actions_rotate_admin_password(ops_test: OpsTest) -> None:
ops_test, "GET", test_url, resp_status_code=True, user_password=password1
)
assert http_resp_code == 401


@pytest.mark.abort_on_fail
async def test_check_number_of_restarts(ops_test: OpsTest) -> None:
"""Test check number of restarts.
The number of restarts should be 1 for each unit.
"""
for unit in range(DEFAULT_NUM_UNITS):
for logentry in [
"Started Service for snap",
"Stopped Service for snap",
]:
result = int(
subprocess.run(
'juju exec --application opensearch -- "sudo '
"journalctl -u snap.opensearch.daemon.service "
"--boot | grep "
"'" + logentry + "' | wc -l\"",
shell=True,
capture_output=True,
)
.stdout.decode()
.replace("\n", "")
.split("opensearch")[1]
.split(":")[1]
)
logger.info(f"Number of '{logentry}' for unit {unit}: {result}")
assert result == 1

0 comments on commit 2f9fed7

Please sign in to comment.