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

Commit

Permalink
libvirt: automatic fallback to qemu (#158)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sorin Sbarnea <[email protected]>
Co-authored-by: anadahz <[email protected]>
Co-authored-by: Gonéri Le Bouder <[email protected]>
  • Loading branch information
5 people authored Jan 5, 2022
1 parent 58a4e66 commit 0b1ef52
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 19 deletions.
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

0 comments on commit 0b1ef52

Please sign in to comment.