Skip to content

Commit

Permalink
Remove lxd-profile.yaml from charms, but test with a well known profi…
Browse files Browse the repository at this point in the history
…le (#49)
  • Loading branch information
addyess authored Mar 22, 2024
1 parent 565ac7f commit 40e7b85
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
17 changes: 0 additions & 17 deletions charms/worker/lxd-profile.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ def switch(self, name: str, path: Path):
app["channel"] = None


async def cloud_profile(ops_test: OpsTest):
"""Apply lxd-profile to the model if the juju cloud is lxd."""
controller = await ops_test.model.get_controller()
cloud = await controller.cloud()
if cloud.cloud.type_ == "lxd":
lxd = LXDSubstrate(None, None)
profile_name = f"juju-{ops_test.model.name}"
lxd.remove_profile(profile_name)
lxd.apply_profile("k8s.profile", profile_name)


@contextlib.asynccontextmanager
async def deploy_model(
request: pytest.FixtureRequest,
Expand Down Expand Up @@ -188,6 +199,7 @@ async def deploy_model(
config=config,
)
with ops_test.model_context(model_name) as the_model:
await cloud_profile(ops_test)
async with ops_test.fast_forward("60s"):
await the_model.deploy(bundle.render)
await the_model.wait_for_idle(
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/cos_substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ def apply_profile(
target_profile_name (Optional[str]): Name of the target profile. Defaults to 'cos-profile'.
"""
profile_path = Path("tests/integration/data") / profile_name
with open(profile_path) as file:

with profile_path.open() as file:
try:
raw_profile = yaml.safe_load(file)
config = raw_profile.get("config", {})
devices = raw_profile.get("devices", {})
self.client.profiles.create(target_profile_name, config=config, devices=devices)
log.info(f"Profile {target_profile_name} applied successfully.")
except (yaml.YAMLError, Exception) as e:
log.error(f"Failed to read or apply LXD profile: {e}")
log.exception(f"Failed to read or apply LXD profile: {e}")

def create_container(self, name: str):
"""Create a container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See LICENSE file for licensing details.
description: "LXD profile for Canonical Kubernetes"
config:
boot.autostart: "true"
linux.kernel_modules: ip_vs,ip_vs_rr,ip_vs_wrr,ip_vs_sh,ip_tables,ip6_tables,iptable_raw,netlink_diag,nf_nat,overlay,br_netfilter,xt_socket
raw.lxc: |
lxc.apparmor.profile=unconfined
Expand Down

0 comments on commit 40e7b85

Please sign in to comment.