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

[DPE-1626] Add support for certificates and CA renewal #94

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
5 changes: 2 additions & 3 deletions lib/charms/opensearch/v0/constants_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
ServiceStopped = "The OpenSearch service stopped."
ServiceStopFailed = "An error occurred while attempting to stop the OpenSearch service."
ServiceIsStopping = "The OpenSearch service is stopping."
TLSRelationMissing = "The TLS operator is not related to OpenSearch. Cannot start this unit."
TLSNotFullyConfigured = "Waiting for TLS to be fully configured..."
TLSRelationBrokenError = (
"Relation broken with the TLS Operator while TLS not fully configured. Stopping OpenSearch."
)
TLSRelationBrokenError = "Relation broken with the TLS Operator while TLS not fully configured."
NoNodeUpInCluster = "No node is up in this cluster."
TooManyNodesRemoved = (
"Too many nodes being removed at the same time, please scale your application up."
Expand Down
59 changes: 59 additions & 0 deletions lib/charms/opensearch/v0/helper_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

"""Utility functions for running commands."""

import logging
import os
import subprocess
from types import SimpleNamespace

from charms.opensearch.v0.opensearch_exceptions import OpenSearchCmdError

# The unique Charmhub library identifier, never change it
LIBID = "f7199a359074406db94294bef78e3f2a"

# Increment this major API version when introducing breaking changes
LIBAPI = 0

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 1


logger = logging.getLogger(__name__)


def run_cmd(command: str, args: str = None) -> SimpleNamespace:
"""Run command.

Arg:
command: can contain arguments
args: command line arguments
"""
if args is not None:
command = f"{command} {args}"

command = " ".join(command.split())

logger.debug(f"Executing command: {command}")

try:
output = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
text=True,
encoding="utf-8",
timeout=25,
env=os.environ,
)

if output.returncode != 0:
logger.error(f"err: {output.stderr} / out: {output.stdout}")
raise OpenSearchCmdError(cmd=command, out=output.stdout, err=output.stderr)

return SimpleNamespace(cmd=command, out=output.stdout, err=output.stderr)
except (TimeoutError, subprocess.TimeoutExpired):
raise OpenSearchCmdError(cmd=command)
Loading