Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add warning about virtualization #46

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
54 changes: 54 additions & 0 deletions plugins/modules/check_virtualization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/python

from __future__ import absolute_import, division, print_function
__metaclass__ = type

import subprocess
import shutil
from ansible.module_utils.basic import AnsibleModule


def check_kvm_ok():
"""Check if the kvm-ok binary exists and run it to check virtualization."""
# Check if 'kvm-ok' exists
if shutil.which('kvm-ok') is None:
return False, "The 'kvm-ok' binary is not found. Virtualization support cannot be checked."

try:
# Run the 'kvm-ok' command
result = subprocess.run(
['kvm-ok'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if result.returncode == 0:
return True, result.stdout.decode('utf-8').strip()
else:
return False, "Virtualization is disabled. Nox will not be able to run VMs."
except Exception as e:
return False, f"Failed to execute 'kvm-ok': {str(e)}"


def main():
# Define the arguments that the module will accept (no arguments in this
# case)
module_args = dict()

# Initialize the Ansible module
module = AnsibleModule(
argument_spec=module_args,
supports_check_mode=True
)

# Check if kvm-ok is available and run it
success, message = check_kvm_ok()

# If kvm-ok is missing or virtualization is disabled, warn the user
if not success:
module.warn(message)

# Return success (even if there are warnings) and the appropriate message
module.exit_json(changed=False, msg="Virtualization check completed.")


if __name__ == '__main__':
main()
6 changes: 5 additions & 1 deletion roles/nox/tasks/00-preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
tags: always
fluencelabs.provider.check_tar_type:

- name: check that virtualization is enabled
tags: always
check_virtualization:

- name: check "fluence_instance_id" variable
tags: always
ansible.builtin.assert:
Expand Down Expand Up @@ -85,4 +89,4 @@
- name: print nox config file
debug:
msg: "{{ lookup('ansible.builtin.file', 'files/{{ fluence_project_dir }}/.fluence/configs/{{ fluence_instance_id }}_Config.toml') }}"
when: show_nox_config is defined
when: show_nox_config is defined
2 changes: 1 addition & 1 deletion roles/prerequisites/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
state: started
enabled: true
daemon_reload: true

- name: enable default network
community.libvirt.virt_net:
autostart: true
Expand Down