Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

libvirt: automatic fallback to qemu #158

Merged
merged 7 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions molecule_vagrant/modules/vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,14 @@
{% endif %}
{% endif %}
{% if instance.provider == 'libvirt' %}
{% if no_kvm is sameas true and 'driver' not in instance.provider_options %}
libvirt.driver='qemu'
{% endif %}
{% set libvirt_use_qemu = no_kvm %}
{% if 'driver' in instance.provider_options and 'qemu' in instance.provider_options['driver'] %}
{% set libvirt_use_qemu = true %}
{% endif %}
{% if libvirt_use_qemu is sameas true %}
{% if 'cpu_mode' not in instance.provider_options %}
# When using qemu instead of kvm, some libvirt systems
# will use EPYC as vCPU model inside the new VM.
Expand Down Expand Up @@ -543,6 +550,7 @@ def _write_vagrantfile(self):
VAGRANTFILE_TEMPLATE,
instances=instances,
cachier=self.cachier,
no_kvm=not os.path.exists("/dev/kvm"),
)
molecule.util.write_file(self._vagrantfile, template)

Expand Down
15 changes: 4 additions & 11 deletions molecule_vagrant/test/functional/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import pytest
import os
import vagrant

from molecule import util
from molecule import logger
Expand Down Expand Up @@ -53,10 +54,10 @@ def test_command_init_scenario(temp_dir):
env = os.environ
if "TESTBOX" in env:
conf["platforms"][0]["box"] = env["TESTBOX"]
if not os.path.exists("/dev/kvm"):
if "vagrant-libvirt" in list(
map(lambda x: x.name, vagrant.Vagrant().plugin_list())
):
conf["driver"]["provider"] = {"name": "libvirt"}
for p in conf["platforms"]:
p["provider_options"] = {"driver": '"qemu"'}
util.write_file(confpath, util.safe_dump(conf))

cmd = ["molecule", "--debug", "test", "-s", "test-scenario"]
Expand All @@ -77,10 +78,6 @@ def test_command_init_scenario(temp_dir):
)
def test_vagrant_root(temp_dir, scenario):

env = os.environ
if not os.path.exists("/dev/kvm"):
env.update({"VIRT_DRIVER": "'qemu'"})

scenario_directory = os.path.join(
os.path.dirname(util.abs_path(__file__)), os.path.pardir, "scenarios"
)
Expand All @@ -93,10 +90,6 @@ def test_vagrant_root(temp_dir, scenario):

def test_multi_node(temp_dir):

env = os.environ
if not os.path.exists("/dev/kvm"):
env.update({"VIRT_DRIVER": "'qemu'"})

scenario_directory = os.path.join(
os.path.dirname(util.abs_path(__file__)), os.path.pardir, "scenarios"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ platforms:
- name: instance
config_options:
synced_folder: true
provider_options:
driver: ${VIRT_DRIVER:-kvm}
box: ${TESTBOX:-centos/7}
instance_raw_config_args:
- 'vm.synced_folder ".", "/vagrant", type: "rsync"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ platforms:
memory: 256
cpus: 1
provider_options:
driver: ${VIRT_DRIVER:-kvm}
# using session with network leads to troubles
qemu_use_session: false
config_options:
Expand All @@ -35,7 +34,6 @@ platforms:
memory: 256
cpus: 2
provider_options:
driver: ${VIRT_DRIVER:-kvm}
# using session with network leads to troubles
qemu_use_session: false
instance_raw_config_args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ platforms:
- name: instance
box: ${TESTBOX:-centos/7}
provider_options:
driver: ${VIRT_DRIVER:-kvm}
# using session with network leads to troubles
qemu_use_session: false
interfaces:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ platforms:
- name: instance
provider_options:
nic_model_type: e1000
driver: ${VIRT_DRIVER:-kvm}
box: ${TESTBOX:-centos/7}
provisioner:
name: ansible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ driver:
platforms:
- name: instance
box: ${TESTBOX:-centos/7}
provider_options:
driver: ${VIRT_DRIVER:-kvm}
instance_raw_config_args:
- "vm.provision :shell, inline: \"echo #{Dir.pwd} > /tmp/workdir\""
provisioner:
Expand Down