Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tests/test-simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import time
import requests
import os.path

import utils


Expand Down Expand Up @@ -136,15 +135,16 @@ def test_microk8s_services_running(self):
assert running_node_services == set(node_services), "Not all node services are running"

def test_microk8s_stop_start(self):
coredns_procs = utils._get_process("coredns")
assert len(coredns_procs) > 0, "Expected to find a coredns process running."
assert (
utils.is_coredns_running()
), "Expected CoreDNS pod to be running before microk8s stop."

utils.run_until_success("/snap/bin/microk8s.stop", timeout_insec=180)

new_coredns_procs = utils._get_process("coredns")
assert len(new_coredns_procs) == 0, "coredns found still running after microk8s stop."
assert not utils.is_coredns_running(), "CoreDNS pod still running after microk8s stop."

utils.run_until_success("/snap/bin/microk8s.start", timeout_insec=180)

new_coredns_procs = utils._get_process("coredns")
assert len(new_coredns_procs) > 0, "Expected to find a new coredns process running."
assert (
utils.is_coredns_running()
), "Expected CoreDNS pod to be running after microk8s start."
26 changes: 26 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import yaml
import platform
import psutil
import subprocess
from subprocess import check_output, CalledProcessError, check_call


Expand Down Expand Up @@ -90,6 +91,31 @@ def kubectl_get(target, timeout_insec=300):
return yaml.safe_load(output)


def is_coredns_running():
cmd = [
"/snap/bin/microk8s",
"kubectl",
"get",
"pods",
"-n",
"kube-system",
"-l",
"k8s-app=kube-dns",
"--no-headers",
]

result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

if result.returncode != 0:
return False

for line in result.stdout.splitlines():
if "Running" in line:
return True

return False


def wait_for_pod_state(
pod, namespace, desired_state, desired_reason=None, label=None, timeout_insec=600
):
Expand Down