Skip to content

Commit

Permalink
fix(ci): Clean lxc instances on bundle integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
orfeas-k committed Nov 27, 2024
1 parent 7d1429d commit 8eacbbe
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions requirements-integration-v2.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pytest-operator
pyyaml
sh
tenacity
jq
2 changes: 2 additions & 0 deletions requirements-integration-v2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ jedi==0.19.1
# via ipython
jinja2==3.1.4
# via pytest-operator
jq==1.8.0
# via -r requirements-integration-v2.in
jsonschema==4.17.3
# via -r requirements-integration-v2.in
juju==3.5.2.0
Expand Down
1 change: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This directory has the following structure:
│   ├── charmcraft.py
│   ├── k8s_resources.py
│   └── localize_bundle.py
│   └── lxc.py
├── kfp_globals.py
├── pipelines/
│   └── ... # Sample pipelines
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/helpers/lxc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sh
import jq

def clean_charmcraft_lxc_instances() -> None:
"""
Delete lxc instances in project "charmcraft" that are prefixed with "charmcraft-".
Based on https://discourse.charmhub.io/t/how-to-quickly-clean-unused-lxd-instances-from-charmcraft-pack/15975
"""
lxc_instances = sh.lxc.list(project="charmcraft", format="json")
lxc_instances_charmcraft = jq.compile('.[] | select(.name | startswith("charmcraft-")) | .name').input_text(lxc_instances).all()
for instance in lxc_instances_charmcraft:
print(f"Deleting lxc instance '{instance}'")
sh.lxc.delete(instance, project="charmcraft")
4 changes: 3 additions & 1 deletion tests/integration/test_kfp_functional_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from helpers.k8s_resources import apply_manifests, fetch_response
from helpers.localize_bundle import get_resources_from_charm_file
from helpers.charmcraft import charmcraft_clean
from helpers.lxc import clean_charmcraft_lxc_instances
from kfp_globals import (
CHARM_PATH_TEMPLATE,
KFP_CHARMS,
Expand Down Expand Up @@ -97,7 +98,8 @@ async def test_build_and_deploy(ops_test: OpsTest, request, lightkube_client):
context.update([(f"{charm.replace('-', '_')}", charm_file)])

if charmcraft_clean_flag == True:
charmcraft_clean(charms_to_build)
# charmcraft_clean(charms_to_build)
clean_charmcraft_lxc_instances()

# Render kfp-operators bundle file with locally built charms and their resources
rendered_bundle = render_bundle(
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/test_kfp_functional_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from helpers.k8s_resources import apply_manifests, fetch_response
from helpers.localize_bundle import get_resources_from_charm_file
from helpers.charmcraft import charmcraft_clean
from helpers.lxc import clean_charmcraft_lxc_instances
from kfp_globals import (
CHARM_PATH_TEMPLATE,
KFP_CHARMS,
Expand Down Expand Up @@ -99,7 +100,8 @@ async def test_build_and_deploy(ops_test: OpsTest, request, lightkube_client):
context.update([(f"{charm.replace('-', '_')}", charm_file)])

if charmcraft_clean_flag == True:
charmcraft_clean(charms_to_build)
# charmcraft_clean(charms_to_build)
clean_charmcraft_lxc_instances()

# Render kfp-operators bundle file with locally built charms and their resources
rendered_bundle = render_bundle(
Expand Down

0 comments on commit 8eacbbe

Please sign in to comment.