Skip to content

Commit

Permalink
[DPE-3647] Pin snap to rev37 (2.10.0-ubuntu1) (#197)
Browse files Browse the repository at this point in the history
Add snap pinning and make sure we are installing the correct version in integration tests.

Closes #123
  • Loading branch information
phvalguima authored Mar 8, 2024
1 parent ab2136d commit 79ad1e5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
logger = logging.getLogger(__name__)


OPENSEARCH_SNAP_REVISION = 37


class OpenSearchSnap(OpenSearchDistribution):
"""Snap distribution of opensearch, only overrides properties and logic proper to the snap."""

Expand All @@ -58,11 +61,13 @@ def __init__(self, charm, peer_relation: str):
@override
def install(self):
"""Install opensearch from the snapcraft store."""
if self._opensearch.present:
return
try:
self._opensearch.ensure(snap.SnapState.Latest, channel="edge")
self._opensearch.ensure(snap.SnapState.Latest, revision=OPENSEARCH_SNAP_REVISION)
self._opensearch.connect("process-control")
if not self._opensearch.held:
# hold the snap in charm determined revision
self._opensearch.hold()

except SnapError as e:
logger.error(f"Failed to install opensearch. \n{e}")
raise OpenSearchInstallError()
Expand Down
1 change: 1 addition & 0 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
APP_NAME = METADATA["name"]

EXPECTED_SNAP_REVISION = 37
SERIES = "jammy"
UNIT_IDS = [0, 1, 2]
IDLE_PERIOD = 75
Expand Down
31 changes: 31 additions & 0 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
# See LICENSE file for licensing details.

import logging
import subprocess

import pytest
import yaml
from pytest_operator.plugin import OpsTest

from .helpers import (
APP_NAME,
EXPECTED_SNAP_REVISION,
MODEL_CONFIG,
SERIES,
get_admin_secrets,
Expand Down Expand Up @@ -141,3 +144,31 @@ 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.group(1)
@pytest.mark.abort_on_fail
async def test_check_pinned_revision(ops_test: OpsTest) -> None:
"""Test check the pinned revision."""
leader_id = await get_leader_unit_id(ops_test)

installed_info = yaml.safe_load(
subprocess.check_output(
[
"juju",
"ssh",
f"opensearch/{leader_id}",
"--",
"sudo",
"snap",
"info",
"opensearch",
"--color=never",
"--unicode=always",
],
text=True,
).replace("\r\n", "\n")
)["installed"].split()
logger.info(f"Installed snap: {installed_info}")
assert installed_info[1] == f"({EXPECTED_SNAP_REVISION})"
assert installed_info[3] == "held"

0 comments on commit 79ad1e5

Please sign in to comment.