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 #18 from canonical/enable-local-testing
Add support for using local charms in integration tests
- Loading branch information
Showing
5 changed files
with
61 additions
and
71 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
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,35 +13,62 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Configure integration test run.""" | ||
"""Configure slurmdbd 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 | ||
from pytest_operator.plugin import OpsTest | ||
|
||
logger = logging.getLogger(__name__) | ||
SLURMCTLD_DIR = Path(os.getenv("SLURMCTLD_DIR", "../slurmctld-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 slurmdbd_charm(ops_test: OpsTest) -> Path: | ||
"""Pack slurmdbd charm to use for integration tests.""" | ||
return await ops_test.build_charm(".") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
async def slurmdbd_charm(ops_test: OpsTest): | ||
"""Build slurmdbd charm to use for integration tests.""" | ||
charm = await ops_test.build_charm(".") | ||
return charm | ||
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" | ||
) | ||
|
||
def pytest_sessionfinish(session, exitstatus) -> None: | ||
"""Clean up repository after test session has completed.""" | ||
pathlib.Path(ETCD).unlink(missing_ok=True) | ||
return "slurmctld" |
This file was deleted.
Oops, something went wrong.
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,16 +13,13 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Test slurmdbd charm against other SLURM charms in the latest/edge channel.""" | ||
"""Test slurmdbd charm against other SLURM operators.""" | ||
|
||
import asyncio | ||
import logging | ||
import pathlib | ||
from typing import Any, Coroutine | ||
|
||
import pytest | ||
import tenacity | ||
from helpers import get_slurmctld_res | ||
from pytest_operator.plugin import OpsTest | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -31,30 +28,31 @@ | |
SLURMCTLD = "slurmctld" | ||
DATABASE = "mysql" | ||
ROUTER = "mysql-router" | ||
UNIT_NAME = f"{SLURMDBD}/0" | ||
|
||
|
||
@pytest.mark.abort_on_fail | ||
@pytest.mark.skip_if_deployed | ||
@pytest.mark.order(1) | ||
async def test_build_and_deploy_against_edge( | ||
ops_test: OpsTest, slurmdbd_charm: Coroutine[Any, Any, pathlib.Path], charm_base: str | ||
ops_test: OpsTest, charm_base: str, slurmdbd_charm, slurmctld_charm | ||
) -> None: | ||
"""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() | ||
# Pack charms | ||
slurmdbd, slurmctld = await asyncio.gather(slurmdbd_charm, slurmctld_charm) | ||
await asyncio.gather( | ||
ops_test.model.deploy( | ||
str(await slurmdbd_charm), | ||
str(slurmdbd), | ||
application_name=SLURMDBD, | ||
num_units=1, | ||
base=charm_base, | ||
), | ||
ops_test.model.deploy( | ||
SLURMCTLD, | ||
str(slurmctld), | ||
application_name=SLURMCTLD, | ||
channel="edge", | ||
channel="edge" if isinstance(slurmctld, str) else None, | ||
num_units=1, | ||
resources=slurmctld_res, | ||
base=charm_base, | ||
), | ||
ops_test.model.deploy( | ||
|
@@ -72,16 +70,14 @@ async def test_build_and_deploy_against_edge( | |
base="[email protected]", | ||
), | ||
) | ||
# Attach resources to charms. | ||
await ops_test.juju("attach-resource", SLURMCTLD, f"etcd={slurmctld_res['etcd']}") | ||
# Set relations for charmed applications. | ||
await ops_test.model.integrate(f"{SLURMDBD}:{SLURMDBD}", f"{SLURMCTLD}:{SLURMDBD}") | ||
await ops_test.model.integrate(f"{SLURMDBD}-{ROUTER}:backend-database", f"{DATABASE}:database") | ||
await ops_test.model.integrate(f"{SLURMDBD}:database", f"{SLURMDBD}-{ROUTER}:database") | ||
# Reduce the update status frequency to accelerate the triggering of deferred events. | ||
async with ops_test.fast_forward(): | ||
await ops_test.model.wait_for_idle(apps=[SLURMDBD], status="active", timeout=1000) | ||
assert ops_test.model.applications[SLURMDBD].units[0].workload_status == "active" | ||
assert ops_test.model.units.get(UNIT_NAME).workload_status == "active" | ||
|
||
|
||
@pytest.mark.abort_on_fail | ||
|
@@ -94,7 +90,7 @@ async def test_build_and_deploy_against_edge( | |
async def test_slurmdbd_is_active(ops_test: OpsTest) -> None: | ||
"""Test that slurmdbd is active inside Juju unit.""" | ||
logger.info("Checking that slurmdbd daemon is active inside unit") | ||
slurmdbd_unit = ops_test.model.applications[SLURMDBD].units[0] | ||
slurmdbd_unit = ops_test.model.units.get(UNIT_NAME) | ||
res = (await slurmdbd_unit.ssh("systemctl is-active slurmdbd")).strip("\n") | ||
assert res == "active" | ||
|
||
|
@@ -109,7 +105,7 @@ async def test_slurmdbd_is_active(ops_test: OpsTest) -> None: | |
async def test_slurmdbd_port_listen(ops_test: OpsTest) -> None: | ||
"""Test that slurmdbd is listening on port 6819.""" | ||
logger.info("Checking that slurmdbd is listening on port 6819") | ||
slurmdbd_unit = ops_test.model.applications[SLURMDBD].units[0] | ||
slurmdbd_unit = ops_test.model.units.get(UNIT_NAME) | ||
res = await slurmdbd_unit.ssh("sudo lsof -t -n -iTCP:6819 -sTCP:LISTEN") | ||
assert res != "" | ||
|
||
|
@@ -124,6 +120,6 @@ async def test_slurmdbd_port_listen(ops_test: OpsTest) -> None: | |
async def test_munge_is_active(ops_test: OpsTest) -> None: | ||
"""Test that munge is active inside Juju unit.""" | ||
logger.info("Checking that munge is active inside Juju unit") | ||
slurmdbd_unit = ops_test.model.applications[SLURMDBD].units[0] | ||
slurmdbd_unit = ops_test.model.units.get(UNIT_NAME) | ||
res = (await slurmdbd_unit.ssh("systemctl is-active munge")).strip("\n") | ||
assert res == "active" |
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