diff --git a/tests/qemu/munet-cloud.yaml b/tests/qemu/munet-cloud.yaml new file mode 100644 index 0000000..bc2f381 --- /dev/null +++ b/tests/qemu/munet-cloud.yaml @@ -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 diff --git a/tests/qemu/test_cloud.py b/tests/qemu/test_cloud.py new file mode 100644 index 0000000..ef6febf --- /dev/null +++ b/tests/qemu/test_cloud.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: GPL-2.0-or-later +# +# September 13 2022, Christian Hopps +# +# 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}"))