From cbddd6f521494cc14d39e61d312951b34c7e7cbc Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 13 Oct 2023 14:22:13 +0400 Subject: [PATCH 1/3] restructured qemu-system command options in create.yml playbook --- molecule_qemu/playbooks/create.yml | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 04f3933..959ff76 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -267,24 +267,29 @@ ansible.builtin.command: >- qemu-system-{{ item.image_arch }} -name {{ item.name }} + -daemonize + -pidfile {{ item.path_pid }} + + -display none + -m {{ item.vm_memory }} + -smp {{ item.vm_cpus }} + -boot d -cdrom {{ molecule_ephemeral_directory }}/run/cloud-init/{{ item.name }}.iso -drive if=virtio,file={{ item.path_disk }} - -m {{ item.vm_memory }} - -smp {{ item.vm_cpus }} + {% if item.network_mode == 'vmnet-shared' %} - -nic vmnet-shared,model=virtio-net-pci,mac={{ item.network_mac }} + -nic vmnet-shared,model=virtio-net-pci,mac={{ item.network_mac }} {% endif %} + {% if item.network_mode == 'user' %} - {% if item.network_extra_args == '' %} - -nic user,model=virtio-net-pci,hostfwd=tcp::{{ item.network_ssh_port }}-:22 - {% else %} - -nic user,model=virtio-net-pci,hostfwd=tcp::{{ item.network_ssh_port }}-:22,{{ item.network_extra_args }} - {% endif %} + {% if item.network_extra_args == '' %} + -nic user,model=virtio-net-pci,hostfwd=tcp::{{ item.network_ssh_port }}-:22 + {% else %} + -nic user,model=virtio-net-pci,hostfwd=tcp::{{ item.network_ssh_port }}-:22,{{ item.network_extra_args }} + {% endif %} {% endif %} - -display none - -daemonize - -pidfile {{ item.path_pid }} + -bios {{ molecule_driver_directory }}/edk2-{{ item.image_arch }}.fd {% if item.image_arch == 'aarch64' %} -machine virt From 6df6cf96a5a555157c672c7a7f1523619af7e42b Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 13 Oct 2023 14:28:58 +0400 Subject: [PATCH 2/3] added qemu machine type support for x86_64 and arm64 architectures --- molecule_qemu/playbooks/create.yml | 46 +++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 959ff76..5a095df 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -140,6 +140,23 @@ ansible.builtin.set_fact: qemu_cap_kvm: "{{ kvm_support.rc == 0 }}" + - name: Set QEMU machine (x86_64) + when: ansible_machine == 'x86_64' + ansible.builtin.set_fact: + qemu_machine: "x86_64" + + - name: Set QEMU machine (arm64) + when: ansible_machine == 'arm64' + ansible.builtin.set_fact: + qemu_machine: "aarch64" + + - name: Assert QEMU machine + ansible.builtin.assert: + that: + - qemu_machine is defined + fail_msg: "QEMU machine is not supported" + success_msg: "QEMU machine is supported" + ### prerequisites ######################################################### - name: Create driver directory @@ -291,19 +308,28 @@ {% endif %} -bios {{ molecule_driver_directory }}/edk2-{{ item.image_arch }}.fd + {% if item.image_arch == 'aarch64' %} - -machine virt - {% if qemu_cap_hvf and item.image_arch == ansible_machine %} - -cpu host - -accel hvf - {% else %} - -cpu cortex-a72 - {% endif %} + -machine virt + {% if item.image_arch == qemu_machine %} + -cpu host + {% if qemu_cap_hvf %} + -accel hvf + {% endif %} + {% else %} + -cpu cortex-a72 + {% endif %} {% endif %} - {% if qemu_cap_kvm and item.image_arch == ansible_machine %} - -cpu host - -enable-kvm + + {% if item.image_arch == 'x86_64' %} + {% if item.image_arch == qemu_machine %} + -cpu host + {% if qemu_cap_kvm %} + -enable-kvm + {% endif %} + {% endif %} {% endif %} + {{ item.vm_extra_args }} args: creates: "{{ item.path_pid }}" From ee16507a53ae8d338d7019c84b251febe01992bd Mon Sep 17 00:00:00 2001 From: Andrey Gubarev Date: Fri, 13 Oct 2023 14:41:37 +0400 Subject: [PATCH 3/3] refactored conditions for enabling hvf and kvm in qemu playbooks --- molecule_qemu/playbooks/create.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/molecule_qemu/playbooks/create.yml b/molecule_qemu/playbooks/create.yml index 5a095df..9ed63e8 100644 --- a/molecule_qemu/playbooks/create.yml +++ b/molecule_qemu/playbooks/create.yml @@ -311,22 +311,18 @@ {% if item.image_arch == 'aarch64' %} -machine virt - {% if item.image_arch == qemu_machine %} + {% if item.image_arch == qemu_machine and qemu_cap_hvf %} -cpu host - {% if qemu_cap_hvf %} - -accel hvf - {% endif %} + -accel hvf {% else %} -cpu cortex-a72 {% endif %} {% endif %} {% if item.image_arch == 'x86_64' %} - {% if item.image_arch == qemu_machine %} + {% if item.image_arch == qemu_machine and qemu_cap_kvm %} -cpu host - {% if qemu_cap_kvm %} - -enable-kvm - {% endif %} + -enable-kvm {% endif %} {% endif %}