-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update test suite to use pytest operator
* refactor tests to use pytest-operator and move integration test logic from github actions to pytest * refactor integration CI to use actions-operator to set up environment * generalize test suite to make it more transferable to other environments/clouds
- Loading branch information
1 parent
04a3d4e
commit 51a184e
Showing
6 changed files
with
141 additions
and
83 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
ops==1.1.0 | ||
git+https://github.com/juju-solutions/resource-oci-image@1964d748022b762b9dce6e8bb7bdf12835102c72 | ||
oci-image | ||
serialized-data-interface<0.4 |
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
pytest | ||
flake8 | ||
black==20.8b1 | ||
pyyaml |
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import logging | ||
from pathlib import Path | ||
|
||
import pytest | ||
import yaml | ||
from pytest_operator.plugin import OpsTest | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text()) | ||
|
||
MINIO_CONFIG = { | ||
"access-key": "minio", | ||
"secret-key": "minio-secret-key", | ||
} | ||
|
||
APP_NAME = "minio" | ||
CHARM_ROOT = "." | ||
|
||
|
||
@pytest.mark.abort_on_fail | ||
async def test_build_and_deploy(ops_test: OpsTest): | ||
built_charm_path = await ops_test.build_charm(CHARM_ROOT) | ||
log.info(f"Built charm {built_charm_path}") | ||
|
||
image_path = METADATA["resources"]["oci-image"]["upstream-source"] | ||
resources = {"oci-image": image_path} | ||
|
||
await ops_test.model.deploy( | ||
entity_url=built_charm_path, | ||
resources=resources, | ||
config=MINIO_CONFIG, | ||
) | ||
await ops_test.model.wait_for_idle(timeout=60 * 10) | ||
|
||
|
||
async def test_connect_client_to_server(ops_test: OpsTest): | ||
""" | ||
Tests a deployed MinIO app by trying to connect to it from a pod and do trivial actions with it | ||
""" | ||
# TODO: This presumes we're using microk8s. Fix that. | ||
# could just call kubectl and count on the outside environment aliasing it for us? | ||
# or could pass kubectl path in as a variable? | ||
|
||
application = ops_test.model.applications[APP_NAME] | ||
config = await application.get_config() | ||
port = config["port"]["value"] | ||
alias = "ci" | ||
bucket = "testbucket" | ||
# TODO: how do I dynamically retrieve the minio k8s service name? | ||
service_name = APP_NAME | ||
model_name = ops_test.model_name | ||
log.info(f"ops_test.model_name = {ops_test.model_name}") | ||
|
||
url = f"http://{service_name}.{model_name}.svc.cluster.local:{port}" | ||
|
||
minio_cmd = ( | ||
f"mc alias set {alias} {url} {MINIO_CONFIG['access-key']} {MINIO_CONFIG['secret-key']}" | ||
f"&& mc mb {alias}/{bucket}" | ||
f"&& mc rb {alias}/{bucket}" | ||
) | ||
|
||
kubectl_cmd = ( | ||
"microk8s", | ||
"kubectl", | ||
"run", | ||
"--rm", | ||
"-i", | ||
"--restart=Never", | ||
"--command", | ||
f"--namespace={ops_test.model_name}", | ||
"minio-deployment-test", | ||
"--image=minio/mc", | ||
"--", | ||
"sh", | ||
"-c", | ||
minio_cmd, | ||
) | ||
|
||
ret_code, stdout, stderr = await ops_test.run(*kubectl_cmd) | ||
|
||
assert ( | ||
ret_code == 0 | ||
), f"Test returned code {ret_code} with stdout:\n{stdout}\nstderr:\n{stderr}" |
File renamed without changes.
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