This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add support for using local charms in integration tests
* Added `--use-local` test option to direct pytest to use local charms. Invoked with `tox run -e integration -- --use-local` * pytest fixtures for charms return a generic string if a local copy of the charm does not exist. Returns a Path if a charm is packed. * Made `get_slurmd_res()` a coroutine so it could be used with asyncio.gather(...) * Updated pylibjuju to generic version rather than pin to 3.1.0.1. * Removed references to ETCD. * Fixed faulty integration test that was calling out to slurmctld and not slurmrestd. Signed-off-by: Jason C. Nucciarone <[email protected]>
- Loading branch information
1 parent
96a2c6a
commit 1287ba6
Showing
4 changed files
with
132 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,36 +13,110 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Configure integration test run.""" | ||
"""Configure slurmrestd operator integration tests.""" | ||
|
||
import pathlib | ||
import logging | ||
import os | ||
from pathlib import Path | ||
from typing import Union | ||
|
||
import pytest | ||
from _pytest.config.argparsing import Parser | ||
from helpers import ETCD, NHC | ||
from helpers import NHC | ||
from pytest_operator.plugin import OpsTest | ||
|
||
logger = logging.getLogger(__name__) | ||
SLURMCTLD_DIR = Path(os.getenv("SLURMCTLD_DIR", "../slurmctld-operator")) | ||
SLURMD_DIR = Path(os.getenv("SLURMD_DIR", "../slurmd-operator")) | ||
SLURMDBD_DIR = Path(os.getenv("SLURMDBD_DIR", "../slurmdbd-operator")) | ||
|
||
def pytest_addoption(parser: Parser) -> None: | ||
|
||
def pytest_addoption(parser) -> None: | ||
parser.addoption( | ||
"--charm-base", | ||
action="store", | ||
default="[email protected]", | ||
help="Charm base version to use for integration tests", | ||
) | ||
parser.addoption( | ||
"--charm-base", action="store", default="[email protected]", help="Charm base to test." | ||
"--use-local", | ||
action="store_true", | ||
default=False, | ||
help="Use SLURM operators located on localhost rather than pull from Charmhub", | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def charm_base(request) -> str: | ||
"""Get slurmdbd charm base to use.""" | ||
return request.config.getoption("--charm-base") | ||
return request.config.option.charm_base | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
async def slurmrestd_charm(ops_test: OpsTest) -> Path: | ||
"""Pack slurmrestd charm to use for integration testing.""" | ||
return await ops_test.build_charm(".") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
async def slurmctld_charm(request, ops_test: OpsTest) -> Union[str, Path]: | ||
"""Pack slurmctld charm to use for integration tests when --use-local is specified. | ||
Returns: | ||
`str` "slurmctld" if --use-local not specified or if SLURMD_DIR does not exist. | ||
""" | ||
if request.config.option.use_local: | ||
logger.info("Using local slurmctld operator rather than pulling from Charmhub") | ||
if SLURMCTLD_DIR.exists(): | ||
return await ops_test.build_charm(SLURMCTLD_DIR) | ||
else: | ||
logger.warning( | ||
f"{SLURMCTLD_DIR} not found. " | ||
f"Defaulting to latest/edge slurmctld operator from Charmhub" | ||
) | ||
|
||
return "slurmctld" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
async def slurmrestd_charm(ops_test: OpsTest): | ||
"""Slurmrestd charm used for integration testing.""" | ||
charm = await ops_test.build_charm(".") | ||
return charm | ||
async def slurmd_charm(request, ops_test: OpsTest) -> Union[str, Path]: | ||
"""Pack slurmd charm to use for integration tests when --use-local is specified. | ||
Returns: | ||
`str` "slurmd" if --use-local not specified or if SLURMD_DIR does not exist. | ||
""" | ||
if request.config.option.use_local: | ||
logger.info("Using local slurmd operator rather than pulling from Charmhub") | ||
if SLURMD_DIR.exists(): | ||
return await ops_test.build_charm(SLURMD_DIR) | ||
else: | ||
logger.warning( | ||
f"{SLURMD_DIR} not found. " | ||
f"Defaulting to latest/edge slurmd operator from Charmhub" | ||
) | ||
|
||
return "slurmd" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
async def slurmdbd_charm(request, ops_test: OpsTest) -> Union[str, Path]: | ||
"""Pack slurmdbd charm to use for integration tests when --use-local is specified. | ||
Returns: | ||
`str` "slurmdbd" if --use-local not specified or if SLURMDBD_DIR does not exist. | ||
""" | ||
if request.config.option.use_local: | ||
logger.info("Using local slurmdbd operator rather than pulling from Charmhub") | ||
if SLURMDBD_DIR.exists(): | ||
return await ops_test.build_charm(SLURMDBD_DIR) | ||
else: | ||
logger.warning( | ||
f"{SLURMDBD_DIR} not found. " | ||
f"Defaulting to latest/edge slurmdbd operator from Charmhub" | ||
) | ||
|
||
return "slurmdbd" | ||
|
||
|
||
def pytest_sessionfinish(session, exitstatus) -> None: | ||
"""Clean up repository after test session has completed.""" | ||
pathlib.Path(ETCD).unlink(missing_ok=True) | ||
pathlib.Path(NHC).unlink(missing_ok=True) | ||
Path(NHC).unlink(missing_ok=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters