Skip to content

Commit

Permalink
Reduce requirements for the model/bundle for tests specifically on op…
Browse files Browse the repository at this point in the history
…enstack (#259)

* Reduce requirements for the model/bundle for tests specifically on openstack
* More defensive implementation in Bundle.needs_trust
  • Loading branch information
addyess authored Jan 24, 2025
1 parent 9a99a44 commit 8cb3867
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion charms/worker/k8s/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
charm-lib-contextual-status @ git+https://github.com/charmed-kubernetes/charm-lib-contextual-status@255dd4a23defc16dcdac832306e5f460a0f1200c
charm-lib-interface-external-cloud-provider @ git+https://github.com/charmed-kubernetes/charm-lib-interface-external-cloud-provider@e1c5fc69e98100a7d43c0ad5a7969bba1ecbcd40
charm-lib-interface-external-cloud-provider @ git+https://github.com/charmed-kubernetes/charm-lib-interface-external-cloud-provider@e9cadd749ff8e2a6c81fadb0268a8b10e26876be
charm-lib-node-base @ git+https://github.com/charmed-kubernetes/layer-kubernetes-node-base@e35bbe08c1035849ed10a6838fa676c7847bc757#subdirectory=ops
charm-lib-reconciler @ git+https://github.com/charmed-kubernetes/charm-lib-reconciler@f818cc30d1a22be43ffdfecf7fbd9c3fd2967502
ops-interface-kube-control @ git+https://github.com/charmed-kubernetes/interface-kube-control.git@main#subdirectory=ops
Expand Down
10 changes: 6 additions & 4 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def cloud_profile(ops_test: OpsTest):
profile_name = f"juju-{ops_test.model.name}"
lxd.remove_profile(profile_name)
lxd.apply_profile("k8s.profile", profile_name)
elif _type == "ec2" and ops_test.model:
elif _type in ("ec2", "openstack") and ops_test.model:
await ops_test.model.set_config({"container-networking-method": "local", "fan-config": ""})


Expand Down Expand Up @@ -192,7 +192,7 @@ async def deploy_model(
await cloud_profile(ops_test)
async with ops_test.fast_forward("60s"):
bundle_yaml = bundle.render(ops_test.tmp_path)
await the_model.deploy(bundle_yaml)
await the_model.deploy(bundle_yaml, trust=bundle.needs_trust)
await the_model.wait_for_idle(
apps=list(bundle.applications),
status="active",
Expand Down Expand Up @@ -244,11 +244,13 @@ def valid_namespace_name(s: str) -> str:


@pytest.fixture()
@pytest.mark.usefixtures("kubernetes_cluster")
async def api_client(ops_test: OpsTest, module_name: str):
async def api_client(
kubernetes_cluster, ops_test: OpsTest, module_name: str # pylint: disable=unused-argument
):
"""Create a k8s API client and namespace for the test.
Args:
kubernetes_cluster: The k8s model.
ops_test: The pytest-operator plugin.
module_name: The name of the module.
"""
Expand Down
14 changes: 4 additions & 10 deletions tests/integration/data/test-bundle-openstack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,21 @@ series: jammy
applications:
k8s:
charm: k8s
num_units: 3
num_units: 1
constraints: cores=2 mem=8G root-disk=16G
expose: true
options:
bootstrap-node-taints: "node-role.kubernetes.io/control-plane=:NoSchedule"
k8s-worker:
charm: k8s-worker
num_units: 2
constraints: cores=2 mem=8G root-disk=16G
openstack-integrator:
charm: openstack-integrator
channel: edge
num_units: 1
trust: true
base: ubuntu@22.04
openstack-cloud-controller:
charm: openstack-cloud-controller
channel: edge
cinder-csi:
charm: cinder-csi
channel: edge
relations:
- [k8s, k8s-worker:cluster]
- [k8s, k8s-worker:containerd]
- [openstack-cloud-controller:kube-control, k8s:kube-control]
- [cinder-csi:kube-control, k8s:kube-control]
- [openstack-cloud-controller:external-cloud-provider, k8s:external-cloud-provider]
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class Bundle:
series: Series for Machines in the bundle
content: Loaded content from the path
applications: Mapping of applications in the bundle.
needs_trust: True if the bundle needs to be trusted
"""

path: Path
Expand Down Expand Up @@ -423,6 +424,15 @@ def applications(self) -> Mapping[str, dict]:
"""
return self.content["applications"]

@property
def needs_trust(self) -> bool:
"""Check if the bundle needs to be trusted.
Returns:
bool: True if the bundle needs to be trusted
"""
return any(app.get("trust", False) for app in self.applications.values())

async def discover_charm_files(self, ops_test: OpsTest) -> Dict[str, Charm]:
"""Discover charm files for the applications in the bundle.
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
STORAGE_CLASS_NAME = "csi-cinder-default"

pytestmark = [
pytest.mark.bundle(file="test-bundle-openstack.yaml", apps_local=["k8s", "k8s-worker"]),
pytest.mark.bundle(file="test-bundle-openstack.yaml", apps_local=["k8s"]),
pytest.mark.clouds(CLOUD_TYPE),
]

Expand Down

0 comments on commit 8cb3867

Please sign in to comment.