Adding functional test for ISO image

This change provides functional testing for both UEFI and legacy boot mode.
This test builds an ISO image, run VM with a predefined IP address,
and checks SSH connectivity.

Change-Id: I498b78b4264a2f373837e3267a58b4309c8588fe
This commit is contained in:
Alexander Noskov 2020-08-18 20:34:23 +00:00
parent afb1093f1a
commit f45d429c3c
11 changed files with 263 additions and 41 deletions

View File

@ -75,6 +75,7 @@ build_collator:
ifeq ($(IMAGE_ID), none)
ifeq ($(USE_PROXY), true)
docker build . \
--iidfile $(BUILD_DIR)/image_id \
--tag $(IMAGE) \
--label $(LABEL) \
--label "org.opencontainers.image.revision=$(COMMIT)" \
@ -90,6 +91,7 @@ ifeq ($(USE_PROXY), true)
--build-arg GIT_COMMIT=$(COMMIT)
else
docker build . \
--iidfile $(BUILD_DIR)/image_id \
--tag $(IMAGE) \
--label $(LABEL) \
--label "org.opencontainers.image.revision=$(COMMIT)" \
@ -98,7 +100,6 @@ else
--label "org.opencontainers.image.title=$(IMAGE_NAME)" \
--build-arg GIT_COMMIT=$(COMMIT)
endif
echo $(shell docker images -q $(IMAGE)) > $(BUILD_DIR)/image_id
else
echo $(IMAGE_ID) > $(BUILD_DIR)/image_id
endif

View File

@ -80,6 +80,7 @@ build_isogen:
ifeq ($(IMAGE_ID), none)
ifeq ($(USE_PROXY), true)
docker build . \
--iidfile $(BUILD_DIR)/image_id \
--tag $(IMAGE) \
--label $(LABEL) \
--label "org.opencontainers.image.revision=$(COMMIT)" \
@ -95,6 +96,7 @@ ifeq ($(USE_PROXY), true)
--build-arg GIT_COMMIT=$(COMMIT)
else
docker build . \
--iidfile $(BUILD_DIR)/image_id \
--tag $(IMAGE) \
--label $(LABEL) \
--label "org.opencontainers.image.revision=$(COMMIT)" \
@ -103,7 +105,6 @@ else
--label "org.opencontainers.image.title=$(IMAGE_NAME)" \
--build-arg GIT_COMMIT=$(COMMIT)
endif
echo $(shell docker images -q $(IMAGE)) > $(BUILD_DIR)/image_id
else
echo $(IMAGE_ID) > $(BUILD_DIR)/image_id
endif
@ -124,7 +125,7 @@ endif
# style checks
lint: test-shellcheck
tests: lint unit_tests
tests: lint unit_tests run_isogen
test-shellcheck: $(SH_TO_CHECK)

View File

@ -1,47 +1,18 @@
---
links:
- name: pxe0
id: pxe0
- id: ens4
type: phy
ethernet_mac_address: 52:54:00:7d:15:63
- name: oam0
type: phy
id: oam0
ethernet_mac_address: 52:54:00:bf:b2:d8
- name: stor0
id: stor0
type: phy
ethernet_mac_address: 52:54:00:9b:2c:71
- name: underlay0
type: phy
id: underlay0
ethernet_mac_address: 52:54:00:9b:2c:71
networks:
- id: pxe0-ipv4
- id: private-ipv4
type: ipv4
link: pxe0
ip_address: 192.168.10.100
netmask: 255.255.255.0
- id: oam0-ipv4
type: ipv4
link: oam0
ip_address: 192.168.100.100
link: ens4
ip_address: 192.168.122.100
netmask: 255.255.255.0
routes:
- network: 0.0.0.0
netmask: 0.0.0.0
gateway: 192.168.100.1
- id: stor0-ipv4
type: ipv4
link: stor0
ip_address: 192.168.20.100
netmask: 255.255.255.0
- id: underlay0-ipv4
type: ipv4
link: underlay0
ip_address: 192.168.30.100
netmask: 255.255.255.0
gateway: 192.168.122.1
services:
- address: 8.8.8.8
type: dns

View File

@ -1,5 +1,11 @@
#cloud-config
runcmd:
- kubeadm init --pod-network-cidr=192.168.0.0/24 --ignore-preflight-errors 'SystemVerification'
- kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes --all node-role.kubernetes.io/master-
ssh_pwauth: True
chpasswd:
list: |
root:deploY!K8s
deployer:deploY!K8s
users:
- default
- name: deployer
gecos: deployer
ssh_pwauth: True

View File

@ -20,3 +20,27 @@
make:
chdir: "{{ zuul.project.src_dir }}"
target: tests
- name: install libvirt
include_role:
name: libvirt-install
tasks_from: "{{ item }}"
with_items:
- main
- configure
- virt_net:
state: active
name: default
- name: Launch and test VM with UEFI boot mode
include_role:
name: libvirt-domain
vars:
vm_name: ubuntu_focal_uefi
boot_mode: UEFI
src_image: /home/zuul/src/opendev.org/airship/images/iso-builder/build/ubuntu-focal.iso
- name: Launch and test VM with Legacy boot mode
include_role:
name: libvirt-domain
vars:
vm_name: ubuntu_focal_legacy
boot_mode: legacy
src_image: /home/zuul/src/opendev.org/airship/images/iso-builder/build/ubuntu-focal.iso

View File

@ -0,0 +1,31 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: Define VM {{ vm_name }}
virt:
name: "{{ vm_name }}"
command: define
xml: "{{ lookup('template', 'templates/domain.xml.j2') }}"
- name: Start VM {{ vm_name }}
virt:
name: "{{ vm_name }}"
state: running
- name: Wait for ssh to come up on {{ vm_name }}
wait_for: host=192.168.122.100 port=22 delay=5 timeout=300
- name: Destroy VM {{ vm_name }}
virt:
name: "{{ vm_name }}"
command: destroy

View File

@ -0,0 +1,13 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- include_tasks: domain.yaml

View File

@ -0,0 +1,82 @@
<domain type='qemu'>
<name>{{ vm_name }}</name>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>1</vcpu>
<resource>
<partition>/machine</partition>
</resource>
<os>
<type arch='x86_64' machine='pc-i440fx-bionic'>hvm</type>
{% if boot_mode is defined and boot_mode == 'UEFI' %}
<loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
{% endif %}
<bootmenu enable='no'/>
</os>
<features>
<acpi/>
<apic/>
<vmport state='off'/>
</features>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='{{ src_image }}'/>
<target dev='hda' bus='ide'/>
<readonly/>
<boot order='1'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0' model='piix3-uhci'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='network'>
<mac address='52:54:00:7d:15:63'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</interface>
<serial type='pty'>
<target type='isa-serial' port='1'>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port='1'/>
</console>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<video>
<model type='cirrus' vram='16384' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</memballoon>
<rng model='virtio'>
<backend model='random'>/dev/urandom</backend>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</rng>
</devices>
<seclabel type='dynamic' model='dac' relabel='yes'/>
</domain>

View File

@ -0,0 +1,13 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
libvirt_qemu_config_file: /etc/libvirt/qemu.conf

View File

@ -0,0 +1,25 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: configure libvirt
become: yes
block:
- name: Set libvirt security driver
lineinfile:
path: "{{ libvirt_qemu_config_file }}"
state: present
regexp: '^\s*security_driver\s*=.*$'
line: "security_driver = \"{{ libvirt_security_driver | default('none') }}\""
- name: libvirtd restarted
service:
name: libvirtd
state: restarted

View File

@ -0,0 +1,55 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- block:
- name: Ensuring Libvirt, Qemu and support packages are present
become: yes
vars:
- packages:
Debian:
- qemu
- libvirt-bin
- libguestfs-tools
- qemu-kvm
- python3-lxml
- python3-libvirt
- dnsmasq
- ebtables
- ovmf
RedHat:
- edk2-ovmf
- libguestfs-tools
- libvirt
- libvirt-devel
- libvirt-daemon-kvm
- qemu-kvm
package:
name: "{{ packages[ansible_os_family] }}"
state: present
- name: Add user "{{ ansible_user }}" to libvirt group
become: yes
user:
name: "{{ ansible_user }}"
groups:
- libvirt
append: yes
- name: Reset ssh connection to allow user changes to affect "{{ ansible_user }}"
meta: reset_connection
ignore_errors: true
- name: Start libvirtd
service:
name: libvirtd
state: started
enabled: true
become: yes