mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2025-12-13 21:34:40 +03:00
Convert CRI-O molecule to ansible verifier
This commit is contained in:
@@ -45,4 +45,4 @@ provisioner:
|
||||
create: ../../../../../tests/cloud_playbooks/create-kubevirt.yml
|
||||
prepare: ../../../molecule/prepare.yml
|
||||
verifier:
|
||||
name: testinfra
|
||||
name: ansible
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import os
|
||||
|
||||
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("crio")
|
||||
assert svc.is_running
|
||||
assert svc.is_enabled
|
||||
|
||||
|
||||
def test_run(host):
|
||||
crictl = "/usr/local/bin/crictl"
|
||||
path = "unix:///var/run/crio/crio.sock"
|
||||
with host.sudo():
|
||||
cmd = host.command(crictl + " --runtime-endpoint " + path + " version")
|
||||
assert cmd.rc == 0
|
||||
assert "RuntimeName: cri-o" in cmd.stdout
|
||||
|
||||
def test_run_pod(host):
|
||||
runtime = "crun"
|
||||
|
||||
run_command = "/usr/local/bin/crictl run --with-pull --runtime {} /tmp/container.json /tmp/sandbox.json".format(runtime)
|
||||
with host.sudo():
|
||||
cmd = host.command(run_command)
|
||||
assert cmd.rc == 0
|
||||
|
||||
with host.sudo():
|
||||
log_f = host.file("/tmp/runc1.0.log")
|
||||
|
||||
assert log_f.exists
|
||||
assert b"Hello from Docker" in log_f.content
|
||||
11
roles/container-engine/cri-o/molecule/default/verify.yml
Normal file
11
roles/container-engine/cri-o/molecule/default/verify.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
- name: Test CRI-O cri
|
||||
import_playbook: ../../../molecule/test_cri.yml
|
||||
vars:
|
||||
container_manager: crio
|
||||
cri_socket: unix:///var/run/crio/crio.sock
|
||||
cri_name: cri-o
|
||||
- name: Test running a container with crun
|
||||
import_playbook: ../../../molecule/test_runtime.yml
|
||||
vars:
|
||||
container_runtime: crun
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "runc1"
|
||||
"name": "{{ container_runtime }}1"
|
||||
},
|
||||
"image": {
|
||||
"image": "quay.io/kubespray/hello-world:latest"
|
||||
},
|
||||
"log_path": "runc1.0.log",
|
||||
"log_path": "{{ container_runtime }}1.0.log",
|
||||
"linux": {}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "runc1",
|
||||
"name": "{{ container_runtime }}1",
|
||||
"namespace": "default",
|
||||
"attempt": 1,
|
||||
"uid": "hdishd83djaidwnduwk28bcsb"
|
||||
42
roles/container-engine/molecule/test_runtime.yml
Normal file
42
roles/container-engine/molecule/test_runtime.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
---
|
||||
- name: Test container runtime
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
become: true
|
||||
roles:
|
||||
- role: ../../kubespray_defaults
|
||||
tasks:
|
||||
- name: Copy test container files
|
||||
template:
|
||||
src: "{{ item }}.j2"
|
||||
dest: "/tmp/{{ item }}"
|
||||
owner: root
|
||||
mode: "0644"
|
||||
loop:
|
||||
- container.json
|
||||
- sandbox.json
|
||||
- name: Check running a container with runtime {{ container_runtime }}
|
||||
block:
|
||||
- name: Run container
|
||||
command:
|
||||
argv:
|
||||
- "{{ bin_dir }}/crictl"
|
||||
- run
|
||||
- --with-pull
|
||||
- --runtime
|
||||
- "{{ container_runtime }}"
|
||||
- /tmp/container.json
|
||||
- /tmp/sandbox.json
|
||||
- name: Check log file
|
||||
slurp:
|
||||
src: "/tmp/{{ container_runtime }}1.0.log"
|
||||
register: log_file
|
||||
failed_when: >
|
||||
log_file is failed or
|
||||
'Hello from Docker' not in (log_file.content | b64decode)
|
||||
rescue:
|
||||
- name: Display container manager config on error
|
||||
command: "{{ bin_dir }}/crictl info"
|
||||
- name: Check container manager logs
|
||||
command: journalctl -u {{ container_manager }}
|
||||
failed_when: true
|
||||
Reference in New Issue
Block a user