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

Auto-generate version file when slurmctld operator is packed #16

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/channel@2.2.0
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
8 changes: 3 additions & 5 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
import pathlib

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


def pytest_addoption(parser: Parser) -> None:
def pytest_addoption(parser) -> None:
parser.addoption(
"--charm-base", action="store", default="ubuntu@22.04", help="Charm base to test."
)


@pytest.fixture(scope="module")
def charm_base(request) -> str:
"""Get slurmdbd charm base to use."""
"""Get slurmctld charm base to use."""
return request.config.getoption("--charm-base")


Expand All @@ -45,4 +44,3 @@ async def slurmctld_charm(ops_test: OpsTest):
def pytest_sessionfinish(session, exitstatus) -> None:
"""Clean up repository after test session has completed."""
pathlib.Path(NHC).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,26 +16,13 @@

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

logger = logging.getLogger(__name__)

NHC = "lbnl-nhc-1.4.3.tar.gz"
NHC_URL = f"https://github.com/mej/nhc/releases/download/1.4.3/{NHC}"
VERSION = "version"
VERSION_NUM = subprocess.run(
shlex.split("git describe --always"), stdout=subprocess.PIPE, text=True
).stdout.strip("\n")


def get_slurmctld_res() -> None:
"""Get slurmctld resources needed for charm deployment."""
if not (version := pathlib.Path(VERSION)).exists():
logger.info(f"Setting resource {VERSION} to value {VERSION_NUM}")
version.write_text(VERSION_NUM)


def get_slurmd_res() -> Dict[str, pathlib.Path]:
Expand Down
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_slurmd_res
from helpers import get_slurmd_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(
) -> None:
"""Test that the slurmctld charm can stabilize against slurmd, slurmdbd, and MySQL."""
logger.info(f"Deploying {SLURMCTLD} against {SLURMD}, {SLURMDBD}, and {DATABASE}")
get_slurmctld_res()
slurmd_res = get_slurmd_res()
await asyncio.gather(
ops_test.model.deploy(
Expand Down