Skip to content

Commit

Permalink
Introduce a new libvirt module for testing Salt: "salt_testenv" (#1404)
Browse files Browse the repository at this point in the history
* Introduce new libvirt module for testing Salt: salt_testenv

* Add 'salt_obs_flavor' variable to 'salt_testenv'

* Install venv-salt-minion-testsuite also in SLE15 (all SPs) and Leap

* Fix logic to prevent installing classic Salt in SLE12

* Refactor code to avoid unnecessary extra files

* Increase VM memory for salt_testenv to run integration tests
  • Loading branch information
meaksh authored Oct 5, 2023
1 parent d16f5e4 commit f56856e
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend_modules/libvirt/host/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ locals {
contains(var.roles, "build_host") ? { vcpu = 2 } : {},
contains(var.roles, "controller") ? { memory = 2048 } : {},
contains(var.roles, "grafana") ? { memory = 4096 } : {},
contains(var.roles, "salt_testenv") ? { memory = 4096, vcpu = 2 } : {},
contains(var.roles, "virthost") ? { memory = 4096, vcpu = 3 } : {},
contains(var.roles, "jenkins") ? { memory = 16384, vcpu = 4 } : {},
var.provider_settings,
Expand Down
26 changes: 26 additions & 0 deletions modules/salt_testenv/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module "salt_testenv" {
source = "../host"

base_configuration = var.base_configuration
use_os_released_updates = var.use_os_released_updates
name = var.name
additional_repos = var.additional_repos
additional_repos_only = var.additional_repos_only
additional_packages = var.additional_packages
swap_file_size = var.swap_file_size
ssh_key_path = var.ssh_key_path
image = var.image
provider_settings = var.provider_settings
install_salt_bundle = true

grains = {
mirror = var.base_configuration["mirror"]
salt_obs_flavor = var.salt_obs_flavor
}

roles = ["salt_testenv"]
}

output "configuration" {
value = module.salt_testenv.configuration
}
55 changes: 55 additions & 0 deletions modules/salt_testenv/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
variable "base_configuration" {
description = "use module.base.configuration, see the main.tf example file"
}

variable "name" {
description = "hostname, without the domain part"
type = string
}

variable "use_os_released_updates" {
description = "Apply all updates from SUSE Linux Enterprise repos"
default = false
}

variable "salt_obs_flavor" {
description = "One of: products, products:testing or products:next"
type = string
default = "products:testing"
}

variable "additional_repos" {
description = "extra repositories in the form {label = url}, see README_ADVANCED.md"
default = {}
}

variable "additional_repos_only" {
description = "whether to exclusively use additional repos"
default = false
}

variable "additional_packages" {
description = "extra packages to install, see README_ADVANCED.md"
default = []
}

variable "swap_file_size" {
description = "Swap file size in MiB, or 0 for none"
default = 0
}

variable "ssh_key_path" {
description = "path of additional pub ssh key you want to use to access VMs, see README_ADVANCED.md"
default = null
}

variable "provider_settings" {
description = "Map of provider-specific settings, see the backend-specific README file"
default = {}
}

variable "image" {
description = "An image name, e.g. sles12sp4 or opensuse154o"
type = string
default = "opensuse154o"
}
1 change: 1 addition & 0 deletions modules/salt_testenv/versions.tf
113 changes: 113 additions & 0 deletions salt/salt_testenv/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
include:
- default

{% if grains['os'] == 'SUSE' and grains['osrelease_info'][0] == 15 %}
{% if grains['osfullname'] == 'SLES' %}
{% set repo_path = "15" if grains["osrelease"] == 15 else "15-SP" + grains["osrelease_info"][1]|string %}
development_tools_repo_pool:
pkgrepo.managed:
- baseurl: http://{{ grains.get("mirror") | default("download.suse.de/ibs", true) }}/SUSE/Products/SLE-Module-Development-Tools/{{ repo_path }}/x86_64/product/
- refresh: True

development_tools_repo_updates:
pkgrepo.managed:
- baseurl: http://{{ grains.get("mirror") | default("download.suse.de/ibs", true) }}/SUSE/Updates/SLE-Module-Development-Tools/{{ repo_path }}/x86_64/update/
- refresh: True
{% endif %}

{% if grains['osrelease_info'][1] >= 3 %}
{% set repo_path = grains["osrelease"] %}
{% else %}
{% set repo_path = "SLE_15_SP" + grains["osrelease_info"][1]|string %}
{% endif %}

salt_testsuite_dependencies_repo:
pkgrepo.managed:
- baseurl: http://{{ grains.get("mirror") | default("download.opensuse.org", true) }}/repositories/systemsmanagement:saltstack:products:test-dependencies/{{ repo_path }}/
- refresh: True
- gpgcheck: 0
- gpgkey: http://{{ grains.get("mirror") | default("download.opensuse.org", true) }}/repositories/systemsmanagement:saltstack:products:test-dependencies/{{ repo_path }}/repodata/repomd.xml.key

salt_testing_repo:
pkgrepo.managed:
- baseurl: http://{{ grains.get("mirror") | default("download.opensuse.org", true) }}/repositories/systemsmanagement:saltstack:{{ grains["salt_obs_flavor"] }}/{{ repo_path }}/
- refresh: True
- gpgcheck: 0
- gpgkey: http://{{ grains.get("mirror") | default("download.opensuse.org", true) }}/repositories/systemsmanagement:saltstack:{{ grains["salt_obs_flavor"] }}/{{ repo_path }}/repodata/repomd.xml.key

install_salt_testsuite:
pkg.installed:
- name: python3-salt-testsuite
- require:
- pkgrepo: salt_testsuite_dependencies_repo
- pkgrepo: salt_testing_repo

{% endif %}

{% if grains['os'] == 'Debian' %}
{% if grains['osrelease'] == '9' %}
{% set repo_path = 'Debian_9.0' %}
{% elif grains['osrelease'] == '10' %}
{% set repo_path = 'Debian_10' %}
{% elif grains['osrelease'] == '11' %}
{% set repo_path = 'Debian_11' %}
{% elif grains['osrelease'] == '12' %}
{% set repo_path = 'Debian_12' %}
{% endif %}
{% elif grains['osfullname'] == 'Ubuntu' %}
{% if grains['osrelease'] == '20.04' %}
{% set repo_path = 'Ubuntu_20.04' %}
{% elif grains['osrelease'] == '22.04' %}
{% set repo_path = 'Ubuntu_22.04' %}
{% endif %}
{% elif grains['osfullname'] == 'AlmaLinux' %}
{% if grains['osrelease_info'][0] == 8 %}
{% set repo_path = 'AlmaLinux_8' %}
{% elif grains['osrelease_info'][0] == 9 %}
{% set repo_path = 'AlmaLinux_9' %}
{% endif %}
{% elif grains['osfullname'] == 'CentOS Linux' %}
{% if grains['osrelease_info'][0] == 7 %}
{% set repo_path = 'CentOS_7' %}
{% endif %}
{% elif grains['osfullname'] == 'SLES' %}
{% if grains['osrelease_info'][0] == 12 %}
{% set repo_path = 'SLE_12' %}
{% elif grains['osrelease_info'][0] == 15 %}
{% set repo_path = 'SLE_15' %}
{% endif %}
{% elif grains['osfullname'] == 'Leap' %}
{% if grains['osrelease_info'][0] == 15 %}
{% set repo_path = 'openSUSE_Leap_15' %}
{% endif %}
{% endif %}

{% if grains["salt_obs_flavor"] == "products" %}
{% set salt_flavor_path = "bundle" %}
{% elif grains["salt_obs_flavor"] == "products:testing" %}
{% set salt_flavor_path = "bundle:testing" %}
{% elif grains["salt_obs_flavor"] == "products:next" %}
{% set salt_flavor_path = "bundle:next" %}
{% else %}
{{ raise("Unknown salt_obs_flavor set") }}
{% endif %}

salt_bundle_testsuite_repo:
pkgrepo.managed:
{% if grains['os'] in ["Debian", "Ubuntu"] %}
- humanname: salt_bundle_testsuite_repo
- file: /etc/apt/sources.list.d/salt_bundle_testsuite_repo.list
- name: deb http://{{ grains.get("mirror") | default("download.opensuse.org", true) }}/repositories/systemsmanagement:saltstack:{{ salt_flavor_path }}:testsuite/{{ repo_path }}/ /
- key_url: http://{{ grains.get("mirror") | default("download.opensuse.org", true) }}/repositories/systemsmanagement:saltstack:{{ salt_flavor_path }}:testsuite/{{ repo_path }}/Release.key
{% else %}
- baseurl: http://{{ grains.get("mirror") | default("download.opensuse.org", true) }}/repositories/systemsmanagement:saltstack:{{ salt_flavor_path }}:testsuite/{{ repo_path }}/
- gpgkey: http://{{ grains.get("mirror") | default("download.opensuse.org", true) }}/repositories/systemsmanagement:saltstack:{{ salt_flavor_path }}:testsuite/{{ repo_path }}/repodata/repomd.xml.key
- gpgcheck: 0
{% endif %}
- refresh: True

install_salt_bundle_testsuite:
pkg.installed:
- name: venv-salt-minion-testsuite
- require:
- pkgrepo: salt_bundle_testsuite_repo
4 changes: 4 additions & 0 deletions salt/top.sls
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ base:
'roles:registry':
- match: grain
- registry

'roles:salt_testenv':
- match: grain
- salt_testenv

0 comments on commit f56856e

Please sign in to comment.