Skip to content

Commit

Permalink
tests: add auto cloud-init test
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hopps <[email protected]>
  • Loading branch information
choppsv1 committed Nov 19, 2024
1 parent a696539 commit f17f525
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tests/qemu/munet-cloud.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
topology:
ipv6-enable: false
networks-autonumber: true
dns-network: "mgmt0"
initial-setup-host-cmd: |
cd %RUNDIR%
[ -e root-key ] || ssh-keygen -b 2048 -t rsa -f root-key -q -N ""
networks:
- name: mgmt0
ip: 192.168.0.254/24
nat: true
nodes:
- name: h1
connections:
- to: "mgmt0"
- to: "r1"
ip: 10.0.1.1/24
- name: r1
kind: disk-linux
connections:
- to: "mgmt0"
- to: "h1"
ip: 10.0.1.2/24

kinds:
- name: disk-linux
ssh-identity-file: "%RUNDIR%/../root-key"
ssh-user: "root"
qemu:
disk-template: "https://cdimage.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2"
# disk-template: "https://dl.rockylinux.org/pub/rocky/7/images/x86_64/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2"
cloud-init: true
console:
user: "root"
password: "foobar"
timeout: 3600
memory: "1G"
kvm: true
ncpu: 2

cli:
commands:
- name: con
exec: "socat /dev/stdin,rawer,escape=0x1d,,echo=0,icanon=0 unix-connect:%RUNDIR%/s/console"
format: "con HOST [HOST ...]"
help: "open console on given hosts, * for all"
new-window: true
top-level: true
- name: vcon
exec: "socat /dev/stdin,rawer,escape=0x1d,,echo=0,icanon=0 unix-connect:%RUNDIR%/s/vcon0"
format: "vcon HOST [HOST ...]"
help: "open console on given hosts, * for all"
new-window: true
top-level: true
- name: vcon1
exec: "socat /dev/stdin,rawer,escape=0x1d,,echo=0,icanon=0 unix-connect:%RUNDIR%/s/vcon1"
format: "vcon1 HOST [HOST ...]"
help: "open console on given hosts, * for all"
new-window: true
top-level: true
- name: mon
exec: "socat /dev/stdin,rawer,escape=0x1d,,echo=0,icanon=0 unix-connect:%RUNDIR%/s/monitor"
format: "mon NODE [NODE ...]"
help: "open monitor on given hosts, * for all"
new-window: true
top-level: true
- name: ssh
exec: "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null %IPADDR%"
kinds: ["linux"]
format: "ssh NODE [NODE ...]"
top-level: true
new-window: true
- name: sship
exec: "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {}"
format: "sship [user@]ip-addr"
top-level: true
new-window: true
- name: vtysh
exec: "expect -c 'spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null %IPADDR% ; expect \"assword:\"; send \"\n\"; interact'"
format: "vtysh NODE"
top-level: true
new-window: true
47 changes: 47 additions & 0 deletions tests/qemu/test_cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 eval: (blacken-mode 1) -*-
# SPDX-License-Identifier: GPL-2.0-or-later
#
# September 13 2022, Christian Hopps <[email protected]>
#
# Copyright 2022, LabN Consulting, L.L.C.
#
"Tests of L3Qemu node type"
import logging

import pytest


# All tests are coroutines
pytestmark = [
pytest.mark.asyncio,
pytest.mark.parametrize("unet", ["munet-cloud"], indirect=["unet"]),
]


async def test_qemu_up(unet):
r1 = unet.hosts["r1"]
output = r1.monrepl.cmd_nostatus("info status")
assert output == "VM status: running"


async def test_net_up(unet):
h1 = unet.hosts["h1"]
r1 = unet.hosts["r1"]

h1mgmt0ip = h1.get_intf_addr("eth0").ip
r1mgmt0ip = r1.get_intf_addr("eth0").ip

h1r1ip = h1.get_intf_addr("eth1").ip
r1h1ip = r1.get_intf_addr("eth1").ip

logging.debug(h1.cmd_raises("ping -w1 -c1 192.168.0.254"))
logging.debug(h1.cmd_raises(f"ping -w1 -c1 {r1mgmt0ip}"))
logging.debug(h1.cmd_raises(f"ping -w1 -c1 {r1h1ip}"))

# Convert to SSH when we download the root-key artifact
# logging.debug(r1.conrepl.cmd_raises("ping -w1 -c1 192.168.0.254"))
# logging.debug(r1.conrepl.cmd_raises(f"ping -w1 -c1 {h1mgmt0ip}"))
# logging.debug(r1.conrepl.cmd_raises(f"ping -w1 -c1 {h1r1ip}"))
logging.debug(r1.cmd_raises("ping -w1 -c1 192.168.0.254"))
logging.debug(r1.cmd_raises(f"ping -w1 -c1 {h1mgmt0ip}"))
logging.debug(r1.cmd_raises(f"ping -w1 -c1 {h1r1ip}"))

0 comments on commit f17f525

Please sign in to comment.