xoxys.k3s/molecule/default/tests/test_default.py

47 lines
1.2 KiB
Python
Raw Permalink Normal View History

2022-10-05 20:54:36 +00:00
import json
2022-10-03 20:58:05 +00:00
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
def test_k3s_running_and_enabled(host):
k3s = host.service("k3s")
assert k3s.is_running
assert k3s.is_enabled
def test_iscsid_running_and_enabled(host):
k3s = host.service("iscsid")
assert k3s.is_running
assert k3s.is_enabled
2022-10-03 20:58:05 +00:00
def test_k3s_node_ready(host):
jsonpth = '{range .items[*]}{@.metadata.name}:{range @.status.conditions[?(@.type=="Ready")]}{@.type}={@.status};{end}{end}' # noqa
2022-10-17 19:26:56 +00:00
nodes = host.run(f"k3s kubectl get nodes -o jsonpath='{jsonpth}'").stdout
2022-10-03 20:58:05 +00:00
assert "rocky9-k3s:Ready=True;" in nodes
def test_k3s_node_labels(host):
2024-02-18 20:09:43 +00:00
jsonpth = "{.items[0].metadata.labels}" # noqa
nodes = host.run(f"k3s kubectl get nodes -o jsonpath='{jsonpth}'").stdout
assert '"node.kubernetes.io/exclude-from-external-load-balancers":"true"' in nodes
2022-10-03 20:58:05 +00:00
def test_k3s_cluster_ready(host):
2022-10-17 19:26:56 +00:00
cluster = host.run("k3s kubectl get --raw='/readyz'").stdout
2022-10-03 20:58:05 +00:00
assert cluster == "ok"
2022-10-05 20:54:36 +00:00
def test_k3s_cni(host):
cni = json.loads(host.file("/etc/cni/net.d/10-calico.conflist").content_string)
assert cni["plugins"][0]["type"] == "calico"