Browse Source

Convert CRI-O molecule to ansible verifier

pull/12302/head
Max Gautier 3 months ago
parent
commit
68c4ee23cb
Failed to extract signature
7 changed files with 57 additions and 39 deletions
  1. 2
      roles/container-engine/cri-o/molecule/default/molecule.yml
  2. 35
      roles/container-engine/cri-o/molecule/default/tests/test_default.py
  3. 11
      roles/container-engine/cri-o/molecule/default/verify.yml
  4. 0
      roles/container-engine/molecule/files/10-mynet.conf
  5. 4
      roles/container-engine/molecule/templates/container.json.j2
  6. 2
      roles/container-engine/molecule/templates/sandbox.json.j2
  7. 42
      roles/container-engine/molecule/test_runtime.yml

2
roles/container-engine/cri-o/molecule/default/molecule.yml

@ -45,4 +45,4 @@ provisioner:
create: ../../../../../tests/cloud_playbooks/create-kubevirt.yml
prepare: ../../../molecule/prepare.yml
verifier:
name: testinfra
name: ansible

35
roles/container-engine/cri-o/molecule/default/tests/test_default.py

@ -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

@ -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

roles/container-engine/cri-o/molecule/default/files/10-mynet.conf → roles/container-engine/molecule/files/10-mynet.conf

roles/container-engine/cri-o/molecule/default/files/container.json → roles/container-engine/molecule/templates/container.json.j2

@ -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": {}
}

roles/container-engine/cri-o/molecule/default/files/sandbox.json → roles/container-engine/molecule/templates/sandbox.json.j2

@ -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

@ -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
Loading…
Cancel
Save