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.
Merge pull request #15 from canonical/enable-local-testing
Add support for using local charms in integration tests
- Loading branch information
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