Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Auto-generate version file when slurmdbd operator is packed (#16)
Browse files Browse the repository at this point in the history
* refactor: Auto-generate version file at packing

This commit removes the version file generation
job step from the release workflow, removes
the version file generation utilities from the
integration tests, and modifies charmcraft.yaml
so that the version file will be automatically
generated when the slurmdbd charm is packed.

Signed-off-by: Jason C. Nucciarone <[email protected]>

* chore(lint): Remove unused imports

Unused imports left in helpers.py in integration tests.

Signed-off-by: NucciTheBoss <[email protected]>

---------

Signed-off-by: Jason C. Nucciarone <[email protected]>
Signed-off-by: NucciTheBoss <[email protected]>
  • Loading branch information
NucciTheBoss authored Aug 4, 2023
1 parent 41c0bee commit 7f92190
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create version file
run: git describe --tags --always --dirty > version
- name: Select charmhub channel
uses: canonical/charming-actions/[email protected]
id: channel
Expand Down
18 changes: 18 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2020 Omnivector Solutions, LLC.
# See LICENSE file for licensing details.

type: charm
bases:
- build-on:
Expand All @@ -13,7 +16,22 @@ bases:
- name: centos
channel: "7"
architectures: [amd64]

parts:
charm:
build-packages: [git]
charm-python-packages: [setuptools]

# Create a version file and pack it into the charm. This is dynamically generated
# as part of the build process for a charm to ensure that the git revision of the
# charm is always recorded in this version file.
version-file:
plugin: nil
build-packages:
- git
override-build: |
VERSION=$(git -C $CRAFT_PART_SRC/../../charm/src describe --dirty --always)
echo "Setting version to $VERSION"
echo $VERSION > $CRAFT_PART_INSTALL/version
stage:
- version
3 changes: 1 addition & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import pytest
from _pytest.config.argparsing import Parser
from helpers import ETCD, VERSION
from helpers import ETCD
from pytest_operator.plugin import OpsTest


Expand All @@ -45,4 +45,3 @@ async def slurmdbd_charm(ops_test: OpsTest):
def pytest_sessionfinish(session, exitstatus) -> None:
"""Clean up repository after test session has completed."""
pathlib.Path(ETCD).unlink(missing_ok=True)
pathlib.Path(VERSION).unlink(missing_ok=True)
13 changes: 0 additions & 13 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@

import logging
import pathlib
import shlex
import subprocess
from typing import Dict
from urllib import request

logger = logging.getLogger(__name__)

ETCD = "etcd-v3.5.0-linux-amd64.tar.gz"
ETCD_URL = f"https://github.com/etcd-io/etcd/releases/download/v3.5.0/{ETCD}"
VERSION = "version"
VERSION_NUM = subprocess.run(
shlex.split("git describe --always"), stdout=subprocess.PIPE, text=True
).stdout.strip("\n")


def get_slurmctld_res() -> Dict[str, pathlib.Path]:
Expand All @@ -38,10 +32,3 @@ def get_slurmctld_res() -> Dict[str, pathlib.Path]:
request.urlretrieve(ETCD_URL, etcd)

return {"etcd": etcd}


def get_slurmdbd_res() -> None:
"""Get slurmdbd charm resources needed for deployment."""
if not (version := pathlib.Path(VERSION)).exists():
logger.info(f"Setting resource {VERSION} to value {VERSION_NUM}")
version.write_text(VERSION_NUM)
3 changes: 1 addition & 2 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import pytest
import tenacity
from helpers import get_slurmctld_res, get_slurmdbd_res
from helpers import get_slurmctld_res
from pytest_operator.plugin import OpsTest

logger = logging.getLogger(__name__)
Expand All @@ -42,7 +42,6 @@ async def test_build_and_deploy_against_edge(
"""Test that the slurmdbd charm can stabilize against slurmctld and MySQL."""
logger.info(f"Deploying {SLURMDBD} against {SLURMCTLD} and {DATABASE}")
slurmctld_res = get_slurmctld_res()
get_slurmdbd_res()
await asyncio.gather(
ops_test.model.deploy(
str(await slurmdbd_charm),
Expand Down

0 comments on commit 7f92190

Please sign in to comment.