Skip to content

Commit

Permalink
Adds Whereabouts integration test
Browse files Browse the repository at this point in the history
Whereabouts depends on Multus, which means that the integration
test is deploying Multus as well.
  • Loading branch information
claudiubelu committed Jul 19, 2024
1 parent f73a54f commit 7cd4146
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 7 deletions.
5 changes: 5 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Copyright 2024 Canonical, Ltd.
#

pytest_plugins = ["k8s_test_harness.plugin"]
58 changes: 56 additions & 2 deletions tests/integration/test_whereabouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,60 @@
# Copyright 2024 Canonical, Ltd.
#

import logging
import os
from pathlib import Path

def test_integration_whereabouts():
assert False, "Integration tests are not yet implemented yet"
from k8s_test_harness import harness
from k8s_test_harness.util import env_util, k8s_util

LOG = logging.getLogger(__name__)

DIR = Path(__file__).absolute().parent
MANIFESTS_DIR = DIR / ".." / "templates"


def _get_whereabouts_helm_cmd():
whereabouts_rock = env_util.get_build_meta_info_for_rock_version(
"whereabouts", "0.6.3", "amd64"
)
images = [
k8s_util.HelmImage(whereabouts_rock.image),
]

# Get the registry name from the image URI.
registry = "docker.io"
parts = images[0].uri.split("/")
if len(parts) > 1:
registry = parts[0]

return k8s_util.get_helm_command(
"whereabouts",
"oci://registry-1.docker.io/bitnamicharts/whereabouts",
"whereabouts",
images=images,
set_configs=[f"image.registry={registry}"],
)


def test_integration_whereabouts(module_instance: harness.Instance):
# We also need multus in order to test out whereabouts.
# It should become Available if everything is fine with it.
helm_cmd = k8s_util.get_helm_command(
"multus", "oci://registry-1.docker.io/bitnamicharts/multus-cni"
)
module_instance.exec(helm_cmd)
k8s_util.wait_for_daemonset(module_instance, "multus-multus-cni", "kube-system")

module_instance.exec(_get_whereabouts_helm_cmd())
k8s_util.wait_for_daemonset(module_instance, "whereabouts", "whereabouts")

# Create a NetworkAttachmentDefinition and a deployment requiring it.
for filename in ["whereabouts-net-definition.yaml", "deployment.yaml"]:
manifest = MANIFESTS_DIR / filename
module_instance.exec(
["k8s", "kubectl", "apply", "-f", "-"],
input=Path(manifest).read_bytes(),
)

k8s_util.wait_for_deployment(module_instance, "netshoot-deployment")
2 changes: 1 addition & 1 deletion tests/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ coverage[toml]==7.2.5
pytest==7.3.1
PyYAML==6.0.1
tenacity==8.2.3
git+https://github.com/claudiubelu/k8s-test-harness.git@main
git+https://github.com/canonical/k8s-test-harness.git@main
25 changes: 25 additions & 0 deletions tests/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: netshoot-deployment
labels:
app: netshoot-deployment
spec:
replicas: 1
selector:
matchLabels:
app: netshoot-pod
template:
metadata:
annotations:
k8s.v1.cni.cncf.io/networks: whereabouts-conf
labels:
app: netshoot-pod
spec:
containers:
- name: netshoot
image: nicolaka/netshoot
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
22 changes: 22 additions & 0 deletions tests/templates/whereabouts-net-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: whereabouts-conf
spec:
config: '{
"cniVersion": "0.3.1",
"plugins": [
{
"type": "macvlan",
"capabilities": { "ips": true },
"master": "eth0",
"mode": "bridge",
"ipam": {
"type": "whereabouts",
"range": "192.168.20.0/24",
"range_start": "192.168.20.10",
"range_end": "192.168.20.100",
"gateway": "192.168.20.1"
}
} ]
}'
17 changes: 13 additions & 4 deletions tests/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,20 @@ pass_env =
ROCK_*

[testenv: integration]
allowlist_externals =
echo
description = Run integration tests
deps = -r {tox_root}/requirements-test.txt
commands =
# TODO: Implement integration tests here
echo "WARNING: This is a placeholder test - no test is implemented here."
pytest -v \
--maxfail 1 \
--tb native \
--log-cli-level DEBUG \
--disable-warnings \
{posargs} \
{tox_root}/integration
pass_env =
TEST_*
ROCK_*
BUILT_ROCKS_METADATA

[flake8]
max-line-length = 120
Expand Down

0 comments on commit 7cd4146

Please sign in to comment.