2020-04-29 16:08:25 +00:00
|
|
|
import os
|
2021-12-03 20:20:35 +00:00
|
|
|
import pytest
|
2020-04-29 16:08:25 +00:00
|
|
|
|
|
|
|
import testinfra.utils.ansible_runner
|
|
|
|
|
|
|
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
|
|
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
|
|
|
|
|
|
|
|
|
|
|
def test_service(host):
|
|
|
|
svc = host.service("containerd")
|
|
|
|
assert svc.is_running
|
|
|
|
assert svc.is_enabled
|
|
|
|
|
|
|
|
|
2021-12-03 20:20:35 +00:00
|
|
|
def test_version(host):
|
2020-04-29 16:08:25 +00:00
|
|
|
crictl = "/usr/local/bin/crictl"
|
|
|
|
path = "unix:///var/run/containerd/containerd.sock"
|
|
|
|
with host.sudo():
|
|
|
|
cmd = host.command(crictl + " --runtime-endpoint " + path + " version")
|
|
|
|
assert cmd.rc == 0
|
|
|
|
assert "RuntimeName: containerd" in cmd.stdout
|
2021-12-03 20:20:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('image, dest', [
|
|
|
|
('quay.io/kubespray/hello-world:latest', '/tmp/hello-world.tar')
|
|
|
|
])
|
|
|
|
def test_image_pull_save_load(host, image, dest):
|
|
|
|
nerdctl = "/usr/local/bin/nerdctl"
|
|
|
|
dest_file = host.file(dest)
|
|
|
|
|
|
|
|
with host.sudo():
|
|
|
|
pull_cmd = host.command(nerdctl + " pull " + image)
|
|
|
|
assert pull_cmd.rc ==0
|
|
|
|
|
|
|
|
with host.sudo():
|
|
|
|
save_cmd = host.command(nerdctl + " save -o " + dest + " " + image)
|
|
|
|
assert save_cmd.rc == 0
|
|
|
|
assert dest_file.exists
|
|
|
|
|
|
|
|
with host.sudo():
|
|
|
|
load_cmd = host.command(nerdctl + " load < " + dest)
|
|
|
|
assert load_cmd.rc == 0
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('image', [
|
|
|
|
('quay.io/kubespray/hello-world:latest')
|
|
|
|
])
|
|
|
|
def test_run(host, image):
|
|
|
|
nerdctl = "/usr/local/bin/nerdctl"
|
|
|
|
|
|
|
|
with host.sudo():
|
|
|
|
cmd = host.command(nerdctl + " -n k8s.io run " + image)
|
|
|
|
assert cmd.rc == 0
|
|
|
|
assert "Hello from Docker" in cmd.stdout
|