Initial changes for testing VM creation for CentOS

Adding updates to the VM creation steps to hopefully allow for
CentOS test VMs to be able to be fired up.  Also refactors basic
OS support for the module to be more flexible by loading defaults
from files.

Change-Id: Ie4456d199dd3d965e533070f4321f50075dfe1df
This commit is contained in:
Julia Kreger 2015-06-13 10:05:05 -04:00
parent 7cf3fa47e4
commit 9521f6a9b2
5 changed files with 71 additions and 22 deletions

View File

@ -0,0 +1,20 @@
---
libvirt_service_name: libvirtd
required_packages:
- qemu-img
- qemu-kvm-tools
- qemu-kvm
- qemu-kvm-common
- sgabios
- libvirt
- libvirt-client
- libvirt-daemon
- libvirt-daemon-config-network
- libvirt-daemon-config-nwfilter
- libvirt-daemon-driver-network
- libvirt-daemon-driver-nodedev
- libvirt-daemon-driver-nwfilter
- libvirt-daemon-driver-qemu
- libvirt-daemon-driver-secret
- libvirt-daemon-driver-storage
- libvirt-daemon-kvm

View File

@ -0,0 +1,8 @@
---
libvirt_service_name: libvirt-bin
required_packages:
- libvirt-bin
- qemu-utils
- qemu-kvm
- qemu-system-x86
- sgabios

View File

@ -0,0 +1,12 @@
---
libvirt_service_name: libvirtd
required_packages:
- qemu-img
- qemu-kvm-tools
- qemu-kvm
- qemu-kvm-common
- qemu-system-x86
- sgabios
- libvirt
- libvirt-client
- libvirt-daemon

View File

@ -38,6 +38,15 @@ VM_EMULATOR=${VM_EMULATOR:-/usr/bin/qemu-system-x86_64}
VM_CPU=${VM_CPU:-1}
VM_RAM=${VM_RAM:-3072}
VM_DISK=${VM_DISK:-10}
VM_MACHINE="pc-1.0"
# CentOS provides a single emulator package
# which differs from other distributions, and
# needs to be explicitly set.
if [ -e /etc/centos-release ]; then
VM_EMULATOR=/usr/libexec/qemu-kvm
VM_MACHINE="pc"
fi
# VM network
VM_NET_BRIDGE=${VM_NET_BRIDGE:-default}
@ -95,6 +104,12 @@ function create_node {
if [ -n "$LOGDIR" ] ; then
mkdir -p "$LOGDIR"
if [ -e /etc/centos-release ]; then
# NOTE(TheJulia): For some unknown reason, libvirt's log folder permissions
# on CentOS ship in an inoperable state. Users must be able to read a folder
# to open files in the folder structure.
chmod o+rx "$LOGDIR/.."
fi
fi
PREALLOC=
@ -112,15 +127,20 @@ function create_node {
volume_path=$(virsh vol-path --pool $LIBVIRT_STORAGE_POOL $VOL_NAME)
# Pre-touch the VM to set +C, as it can only be set on empty files.
touch "$volume_path"
chattr +C "$volume_path" || true
# NOTE(TheJulia): CentOS default installs with an XFS root, and chattr
# fails to set +C on XFS. This could be more elegent, however the use
# case is for CI testing.
if [ ! -e /etc/centos-release ]; then
chattr +C "$volume_path" || true
fi
vm_xml="
<domain type='qemu'>
<name>${NAME}</name>
<memory unit='KiB'>${MEM}</memory>
<vcpu>${CPU}</vcpu>
<os>
<type arch='${ARCH}' machine='pc-1.0'>hvm</type>
<type arch='${ARCH}' machine='${VM_MACHINE}'>hvm</type>
<boot dev='network'/>
<bootmenu enable='no'/>
<bios useserial='yes'/>

View File

@ -14,27 +14,16 @@
#
# TODO: Consider converting to ansible virt module.
---
- name: "Install testing apt packages for Ubuntu/Debian"
when: ansible_os_family == 'Debian'
apt: name={{ item }} state=present
with_items:
- libvirt-bin
- qemu-utils
- qemu-kvm
- qemu-system-x86
- sgabios
- name: "Install testing yum packages for RedHat/CentOS/Fedora/OpenSuse"
when: ansible_os_family in ['CentOS', 'Fedora', 'OpenSuse', 'RedHat']
yum: name={{ item }} state=present
with_items:
- libvirt-client
- qemu-img
- qemu-kvm-tools
- qemu-kvm
- qemu-system-x86
- sgabios
- name: "Load Distribution defaults"
include_vars: "{{ item }}"
with_first_found:
- "../defaults/required_defaults_{{ ansible_distribution }}.yml"
- "../defaults/required_defaults_{{ ansible_os_family }}.yml"
- name: "Install required packages"
action: "{{ ansible_pkg_mgr }} name={{item}} state=present"
with_items: required_packages
- name: "Restart libvirt service"
service: name=libvirt-bin state=restarted
service: name={{libvirt_service_name}} state=restarted
- name: "Create virtual machines"
script: create_vm_nodes-for-role.sh
environment: