Skip to content

Commit

Permalink
[DPE-5004] Fix internal version hassle by moving to hashes (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu1nness committed Aug 21, 2024
1 parent 0f1eca9 commit 3eaf3a6
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 64 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/internal_version_check.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/requirements.txt
/requirements-last-build.txt
/charm_internal_version

*.idea
.vscode/
Expand Down
1 change: 0 additions & 1 deletion charm_internal_version

This file was deleted.

45 changes: 23 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tenacity = "^8.2.3"
pyyaml = "^6.0.1"
jinja2 = "^3.1.3"
poetry-core = "^1.9.0"
data-platform-helpers = "^0.1.2"
data-platform-helpers = "^0.1.3"
pyOpenSSL = "^24.2.1"

[tool.poetry.group.charm-libs.dependencies]
Expand Down Expand Up @@ -66,7 +66,7 @@ juju = "~3.4.0"
pytest = "^8.1.1"
pytest-asyncio = "^0.21.1"
pytest-mock = "^3.14.0"
pytest-operator = "^0.34.0"
pytest-operator = "^0.36.0"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v19.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v19.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v19.0.0", subdirectory = "python/pytest_plugins/github_secrets"}
Expand Down
23 changes: 23 additions & 0 deletions scripts/gen_charm_internal_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

# This file consistently generates a hash, whether there's uncommited code or not
# and writes it into the `charm_internal_version` file

if git --version > /dev/null; then
# Compute base files
BASE=$(git ls-files -s)
# Compute diff files
DIFF=$(git diff --raw)
# Compute staged files
STAGED=$(git diff --raw --staged)

HASH=$(echo $BASE $DIFF $STAGED | git hash-object --stdin | cut -c 1-8)
echo $HASH > charm_internal_version
echo "Hash for this build is ${HASH}"
else
echo "Git is not installed"
exit 1
fi
4 changes: 2 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,10 @@ def upgrade_in_progress(self):
return self.upgrade._upgrade.in_progress

@property
def get_charm_internal_revision(self) -> int:
def get_charm_internal_revision(self) -> str:
"""Returns the contents of the get_charm_internal_revision file."""
with open(Config.CHARM_INTERNAL_VERSION_FILE, "r") as f:
return int(f.read())
return f.read().strip()

# END: properties

Expand Down
3 changes: 3 additions & 0 deletions tests/integration/upgrade/test_sharding_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
@pytest.mark.runner(["self-hosted", "linux", "X64", "jammy", "large"])
@pytest.mark.group(1)
@pytest.mark.abort_on_fail
@pytest.mark.skip("Need a new version published with new charm internal version")
async def test_build_and_deploy(ops_test: OpsTest) -> None:
"""Build deploy, and integrate, a sharded cluster."""
num_units_cluster_config = {
Expand All @@ -58,6 +59,7 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
@pytest.mark.runner(["self-hosted", "linux", "X64", "jammy", "large"])
@pytest.mark.group(1)
@pytest.mark.abort_on_fail
@pytest.mark.skip("Need a new version published with new charm internal version")
async def test_upgrade(
ops_test: OpsTest, continuous_writes_to_shard_one, continuous_writes_to_shard_two
) -> None:
Expand Down Expand Up @@ -113,6 +115,7 @@ async def test_upgrade(
@pytest.mark.runner(["self-hosted", "linux", "X64", "jammy", "large"])
@pytest.mark.group(1)
@pytest.mark.abort_on_fail
@pytest.mark.skip("Need a new version published with new charm internal version")
async def test_pre_upgrade_check_failure(ops_test: OpsTest) -> None:
"""Verify that the pre-upgrade check fails if there is a problem with one of the shards."""
# Disable network on a replicas prior to integration.
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_version_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
CHARMHUB_DEPLOYMENT = "ch"
LOCAL_DEPLOYMENT = "local"
RELATION_TO_CHECK_VERSION = "sharding"
CHARM_VERSION = 123
CHARM_VERSION = "123"
VALID_VERSION = CHARM_VERSION
INVALID_VERSION = 456
INVALID_VERSION = "456"
APP_0 = "APP_0"
APP_1 = "APP_1"
APP_2 = "APP_2"
Expand All @@ -40,7 +40,7 @@ def add_invalid_relation(self, deployment=LOCAL_DEPLOYMENT):
self.harness.update_relation_data(
rel_id,
f"{APP_0}",
{VERSION_CONST: str(INVALID_VERSION), DEPLOYMENT_TYPE: deployment},
{VERSION_CONST: INVALID_VERSION, DEPLOYMENT_TYPE: deployment},
)

def add_valid_relation(self, deployment=LOCAL_DEPLOYMENT):
Expand All @@ -49,7 +49,7 @@ def add_valid_relation(self, deployment=LOCAL_DEPLOYMENT):
self.harness.update_relation_data(
rel_id,
f"{APP_1}",
{VERSION_CONST: str(VALID_VERSION), DEPLOYMENT_TYPE: deployment},
{VERSION_CONST: VALID_VERSION, DEPLOYMENT_TYPE: deployment},
)

def add_relation_with_no_version(self):
Expand Down
10 changes: 10 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set_env =
PY_COLORS = 1
allowlist_externals =
poetry
sh

[testenv:build-{production,dev,wrapper}]
# Wrap `charmcraft pack`
Expand All @@ -28,13 +29,16 @@ allowlist_externals =
charmcraft
charmcraftcache
mv
rm
commands_pre =
poetry export --only main,charm-libs --output requirements.txt
sh scripts/gen_charm_internal_version.sh
commands =
build-production: charmcraft pack {posargs}
build-dev: charmcraftcache pack {posargs}
commands_post =
mv requirements.txt requirements-last-build.txt
rm charm_internal_version


[testenv:format]
Expand Down Expand Up @@ -65,13 +69,19 @@ commands =
description = Run unit tests
set_env =
{[testenv]set_env}
allowlist_externals =
{[testenv]allowlist_externals}
rm
commands_pre =
poetry install --only main,charm-libs,unit
sh scripts/gen_charm_internal_version.sh
commands =
poetry run coverage run --source={[vars]src_path},{[vars]lib_path} \
-m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit
poetry run coverage report
poetry run coverage xml
commands_post =
rm charm_internal_version

[testenv:integration]
description = Run integration tests
Expand Down

0 comments on commit 3eaf3a6

Please sign in to comment.