Skip to content

Commit

Permalink
Improve Network Integration Tests (#474)
Browse files Browse the repository at this point in the history
Make the network tests generic, allowing us to tests any implementation.
  • Loading branch information
mateoflorido authored Jun 14, 2024
1 parent 468b810 commit ddb3266
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 56 deletions.
2 changes: 0 additions & 2 deletions build-scripts/patches/moonray/apply
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ rm "${DIR}/../../../tests/integration/tests/test_gateway.py"
rm "${DIR}/../../../tests/integration/tests/test_ingress.py"
## TODO: restore when cleanup is implemented
rm "${DIR}/../../../tests/integration/tests/test_cleanup.py"
## TODO: restore when network test is fixed
rm "${DIR}/../../../tests/integration/tests/test_network.py"

git commit -a -m "Remove unrelated tests"

Expand Down
4 changes: 4 additions & 0 deletions src/k8s/pkg/k8sd/features/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import (
"github.com/canonical/k8s/pkg/snap"
)

// StatusInterface defines the interface for checking the status of the built-in features.
type StatusInterface interface {
// CheckDNS checks the status of the DNS feature.
CheckDNS(context.Context, snap.Snap) error
// CheckNetwork checks the status of the Network feature.
CheckNetwork(context.Context, snap.Snap) error
}

// statusChecks implements the StatusInterface.
type statusChecks struct {
checkDNS func(context.Context, snap.Snap) error
checkNetwork func(context.Context, snap.Snap) error
Expand Down
67 changes: 13 additions & 54 deletions tests/integration/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,6 @@


def test_network(session_instance: harness.Instance):
p = session_instance.exec(
[
"k8s",
"kubectl",
"get",
"pod",
"-n",
"kube-system",
"-l",
"k8s-app=cilium",
"-o",
"json",
],
capture_output=True,
)

out = json.loads(p.stdout.decode())
assert len(out["items"]) > 0

cilium_pod = out["items"][0]

p = session_instance.exec(
[
"k8s",
"kubectl",
"exec",
"-it",
cilium_pod["metadata"]["name"],
"-n",
"kube-system",
"-c",
"cilium-agent",
"--",
"cilium",
"status",
"--brief",
],
capture_output=True,
)

assert p.stdout.decode().strip() == "OK"

manifest = MANIFESTS_DIR / "nginx-pod.yaml"
p = session_instance.exec(
["k8s", "kubectl", "apply", "-f", "-"],
Expand All @@ -78,20 +36,21 @@ def test_network(session_instance: harness.Instance):
[
"k8s",
"kubectl",
"exec",
"-it",
cilium_pod["metadata"]["name"],
"-n",
"kube-system",
"-c",
"cilium-agent",
"--",
"cilium",
"endpoint",
"list",
"get",
"pod",
"-l",
"app=nginx",
"-o",
"json",
],
capture_output=True,
)
assert "nginx" in p.stdout.decode().strip()

out = json.loads(p.stdout.decode())

assert len(out["items"]) > 0, "No NGINX pod found"
podIP = out["items"][0]["status"]["podIP"]

util.stubbornly(retries=5, delay_s=5).on(session_instance).until(
lambda p: "Welcome to nginx!" in p.stdout.decode()
).exec(["curl", "-s", f"http://{podIP}"])

0 comments on commit ddb3266

Please sign in to comment.