Skip to content

Commit

Permalink
Create a PR main.tf template and use tfvars to specify test envs (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximenoel8 authored Jan 3, 2024
1 parent f976aff commit 5ff370a
Show file tree
Hide file tree
Showing 17 changed files with 817 additions and 2,963 deletions.
48 changes: 30 additions & 18 deletions jenkins_pipelines/environments/common/pipeline-pull-request.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def run(params) {
jenkins_workspace = '/home/jenkins/jenkins-build/workspace/'
environment_workspace = null
env.common_params = ''
tfvariables_file = 'susemanager-ci/terracumber_config/tf_files/variables/PR-testing-variables.tf'
tfvars_product_version = "susemanager-ci/terracumber_config/tf_files/tfvars/PR-testing-${product_version}.tfvars"
tfvars_platform_localisation = "susemanager-ci/terracumber_config/tf_files/tfvars/PR-testing-${platform_localisation}-environments.tfvars"
tf_local_variables = 'susemanager-ci/terracumber_config/tf_files/tfvars/PR-testing-additionnal-repos.tf'
try {
stage('Get environment') {
echo "DEBUG: first environment: ${first_env}"
Expand Down Expand Up @@ -205,8 +209,8 @@ def run(params) {
// Define test environment parameters
env.resultdir = "${WORKSPACE}/results"
env.resultdirbuild = "${resultdir}/${BUILD_NUMBER}"
env.tf_file = "susemanager-ci/terracumber_config/tf_files/${product_name}-PR-tests-env${env_number}.tf" //TODO: Make it possible to use environments for SUMA
env.common_params = "--outputdir ${resultdir} --tf ${tf_file} --gitfolder ${resultdir}/sumaform"
env.tf_file = "susemanager-ci/terracumber_config/tf_files/PR-testing-template.tf"
env.common_params = "--outputdir ${resultdir} --tf ${tf_file} --gitfolder ${resultdir}/sumaform --tf_variables_description_file=${tfvariables_file}"

if (params.terraform_parallelism) {
env.common_params = "${env.common_params} --parallelism ${params.terraform_parallelism}"
Expand All @@ -228,38 +232,46 @@ def run(params) {
echo "DEBUG: Deploy 1"
ws(environment_workspace){
if(must_test) {
// Delete old terraform.tfvars
sh "rm -f ${env.resultdir}/sumaform/terraform.tfvars"
// Merge product en platform variables into terraform.tfvars
sh "cat ${tfvars_product_version} ${tfvars_platform_localisation} >> ${env.resultdir}/sumaform/terraform.tfvars"
// Add environment to use in tfvars
sh "echo 'ENVIRONMENT = \'${env_number}\'' >> ${env.resultdir}/sumaform/terraform.tfvars"
// Copy the variable declaration file
sh "cp ${tf_local_variables} ${env.resultdir}/sumaform/"

// Add all repositories variables
// Passing the built repository by parameter using a environment variable to terraform file
// TODO: We will need to add a logic to replace the host, when we use IBS for spacewalk
env.PULL_REQUEST_REPO= "http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${builder_project}:${pull_request_number}/${build_repo}/${arch}"
env.MASTER_REPO = "http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${source_project}/${build_repo}/${arch}"
env.MASTER_OTHER_REPO = "http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${other_project}/${other_build_repo}/${arch}"
env.MASTER_SUMAFORM_TOOLS_REPO = "http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${sumaform_tools_project}/${build_repo}/${arch}"
env.TEST_PACKAGES_REPO = "http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${test_packages_project}/rpm/${arch}"
env.UPDATE_REPO = update_repo
sh "echo \"############ Repositories variables ############\" >> ${env.resultdir}/sumaform/terraform.tfvars"
sh "echo PULL_REQUEST_REPO = \\\"http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${builder_project}:${pull_request_number}/${build_repo}/${arch}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"
sh "echo MASTER_REPO = \\\"http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${source_project}/${build_repo}/${arch}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"
sh "echo MASTER_OTHER_REPO = \\\"http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${other_project}/${other_build_repo}/${arch}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"
sh "echo MASTER_SUMAFORM_TOOLS_REPO = \\\"http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${sumaform_tools_project}/${build_repo}/${arch}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"
sh "echo TEST_PACKAGES_REPO = \\\"http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${test_packages_project}/rpm/${arch}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"
sh "echo UPDATE_REPO = \\\"${update_repo}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"

if (additional_repo_url == '') {
echo "Adding dummy repo for update repo"
env.ADDITIONAL_REPO_URL = additional_repo
sh "echo ADDITIONAL_REPO_URL = \\\"${additional_repo}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"
} else {
echo "Adding ${additional_repo_url}"
env.ADDITIONAL_REPO_URL = additional_repo_url
sh "echo ADDITIONAL_REPO_URL = \\\"${additional_repo_url}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"
}

env.SLE_CLIENT_REPO = "http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${sles_client_repo}/SLE_15/${arch}"
env.RHLIKE_CLIENT_REPO = "http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${el_client_repo}/${EL}/${arch}"
env.DEBLIKE_CLIENT_REPO = "http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${ubuntu_client_repo}/xUbuntu_22.04/${arch}"
env.OPENSUSE_CLIENT_REPO = "http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${openSUSE_client_repo}/openSUSE_Leap_15.0/${arch}"
sh "echo SLE_CLIENT_REPO = \\\"http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${sles_client_repo}/SLE_15/${arch}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"
sh "echo RHLIKE_CLIENT_REPO = \\\"http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${el_client_repo}/${EL}/${arch}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"
sh "echo DEBLIKE_CLIENT_REPO = \\\"http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${ubuntu_client_repo}/xUbuntu_22.04/${arch}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"
sh "echo OPENSUSE_CLIENT_REPO = \\\"http://${fqdn_jenkins_node}/workspace/${short_product_name}-pr${env_number}/repos/${openSUSE_client_repo}/openSUSE_Leap_15.0/${arch}\\\" >> ${env.resultdir}/sumaform/terraform.tfvars"

// Provision the environment
if (terraform_init) {
env.TERRAFORM_INIT = '--init'
} else {
env.TERRAFORM_INIT = ''
}

echo "DEBUG: Deploy 5"
sh "set +x; source /home/jenkins/.credentials set -x; export TF_VAR_SLE_CLIENT_REPO=${SLE_CLIENT_REPO};export TF_VAR_RHLIKE_CLIENT_REPO=${RHLIKE_CLIENT_REPO};export TF_VAR_DEBLIKE_CLIENT_REPO=${DEBLIKE_CLIENT_REPO};export TF_VAR_OPENSUSE_CLIENT_REPO=${OPENSUSE_CLIENT_REPO};export TF_VAR_PULL_REQUEST_REPO=${PULL_REQUEST_REPO}; export TF_VAR_MASTER_OTHER_REPO=${MASTER_OTHER_REPO};export TF_VAR_MASTER_SUMAFORM_TOOLS_REPO=${MASTER_SUMAFORM_TOOLS_REPO}; export TF_VAR_TEST_PACKAGES_REPO=${TEST_PACKAGES_REPO}; export TF_VAR_MASTER_REPO=${MASTER_REPO};export TF_VAR_UPDATE_REPO=${UPDATE_REPO};export TF_VAR_ADDITIONAL_REPO_URL=${ADDITIONAL_REPO_URL};export TF_VAR_CUCUMBER_GITREPO=${cucumber_gitrepo}; export TF_VAR_CUCUMBER_BRANCH=${cucumber_ref}; export TERRAFORM=${terraform_bin}; export TERRAFORM_PLUGINS=${terraform_bin_plugins}; ./terracumber-cli ${common_params} --logfile ${resultdirbuild}/sumaform.log ${env.TERRAFORM_INIT} --taint '.*(domain|main_disk).*' --runstep provision"
echo "DEBUG: Deploy 6"
sh "set +x; source /home/jenkins/.credentials set -x; export TF_VAR_CUCUMBER_GITREPO=${cucumber_gitrepo}; export TF_VAR_CUCUMBER_BRANCH=${cucumber_ref}; export TERRAFORM=${terraform_bin}; export TERRAFORM_PLUGINS=${terraform_bin_plugins}; ./terracumber-cli ${common_params} --logfile ${resultdirbuild}/sumaform.log ${env.TERRAFORM_INIT} --taint '.*(domain|main_disk).*' --runstep provision"
deployed = true

// Collect and tag Flaky tests from the GitHub Board
Expand Down
2 changes: 2 additions & 0 deletions jenkins_pipelines/environments/uyuni-prs-ci-tests
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ node('pull-request-test') {
properties([
buildDiscarder(logRotator(numToKeepStr: '30', daysToKeepStr: '15')),
parameters([
string(name: 'platform_localisation', defaultValue: 'PRV', description: 'Decide if it will be run in \'PRV\' or \'NUE\''),
string(name: 'product_version', defaultValue: 'uyuni', description: 'Select if we are using \'uyuni\' or \'manager43\' project'),
string(name: 'pull_request_number', defaultValue: '', description: 'Required: Uyuni Pull Request Number'),
string(name: 'email_to', defaultValue: '', description: 'Recommended: Receive a report to your e-mail when it finishes with links to the results, artifacts and logs'),
booleanParam(name: 'run_all_scopes', defaultValue: false, description: 'Secondary tests: Check to run all functional scopes. List of secondary tests: https://github.com/uyuni-project/uyuni/blob/master/testsuite/features/secondary/ '),
Expand Down
211 changes: 211 additions & 0 deletions terracumber_config/tf_files/PR-testing-template.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
terraform {
required_version = "1.0.10"
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
version = "0.6.3"
}
}
}

provider "libvirt" {
uri = "qemu+tcp://${var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].hypervisor}/system"
}

module "cucumber_testsuite" {
source = "./modules/cucumber_testsuite"

product_version = var.PRODUCT_VERSION

// Cucumber repository configuration for the controller
git_username = var.GIT_USER
git_password = var.GIT_PASSWORD
git_repo = var.CUCUMBER_GITREPO
branch = var.CUCUMBER_BRANCH

cc_username = var.SCC_USER
cc_password = var.SCC_PASSWORD
mirror = var.MIRROR
use_mirror_images = var.USE_MIRROR_IMAGES

images = var.IMAGES

use_avahi = false
name_prefix = "suma-pr${var.ENVIRONMENT}-"
domain = var.DOMAIN
from_email = "root@suse.de"

no_auth_registry = "registry.${var.DOMAIN}"
auth_registry = "registry.${var.DOMAIN}:5000/cucutest"
auth_registry_username = "cucutest"
auth_registry_password = "cucusecret"
git_profiles_repo = var.GIT_PROFILES_REPO

server_http_proxy = "http-proxy.${var.DOMAIN}:3128"
custom_download_endpoint = "ftp://${var.DOWNLOAD_ENDPOINT}:445"

# when changing images, please also keep in mind to adjust the image matrix at the end of the README.
host_settings = {
controller = {
provider_settings = {
mac = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].mac["controller"]
vcpu = 2
memory = 2048
}
}
server = {
provider_settings = {
mac = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].mac["server"]
vcpu = 8
memory = 32768
}
additional_repos_only = var.ADDITIONAL_REPOS_ONLY
additional_repos = local.additional_repos["server"]
image = var.IMAGE
additional_packages = [ "venv-salt-minion" ]
install_salt_bundle = true
server_mounted_mirror = var.MIRROR
}
proxy = {
provider_settings = {
mac = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].mac["proxy"]
vcpu = 2
memory = 2048
}
additional_repos_only = var.ADDITIONAL_REPOS_ONLY
additional_repos = local.additional_repos["proxy"]
image = var.IMAGE
additional_packages = [ "venv-salt-minion" ]
install_salt_bundle = true
}
suse-minion = {
image = var.SUSE_MINION_IMAGE
name = "min-suse"
provider_settings = {
mac = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].mac["suse-minion"]
vcpu = 2
memory = 2048
}
additional_repos = local.additional_repos["suse-minion"]
additional_packages = [ "venv-salt-minion" ]
install_salt_bundle = true
}
suse-sshminion = {
image = var.SUSE_MINION_IMAGE
name = "minssh-suse"
provider_settings = {
mac = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].mac["suse-sshminion"]
vcpu = 2
memory = 2048
}
additional_repos = local.additional_repos["suse-minion"]
additional_packages = [ "venv-salt-minion", "iptables" ]
install_salt_bundle = true
}
redhat-minion = {
image = var.RHLIKE_MINION_IMAGE
name = "min-rocky8"
provider_settings = {
mac = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].mac["rhlike-minion"]
memory = 2048
vcpu = 2
}
additional_repos = {
client_repo = var.RHLIKE_CLIENT_REPO,
}
additional_packages = [ "venv-salt-minion" ]
install_salt_bundle = true
}
debian-minion = {
image = var.DEBLIKE_MINION_IMAGE
name = "min-ubuntu2204"
provider_settings = {
mac = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].mac["deblike-minion"]
vcpu = 2
memory = 2048
}
additional_repos = {
client_repo = var.DEBLIKE_CLIENT_REPO,
}
additional_packages = [ "venv-salt-minion" ]
// FIXME: cloudl-init fails if venv-salt-minion is not avaiable
// We can set "install_salt_bundle = true" as soon as venv-salt-minion is available Uyuni:Stable
install_salt_bundle = true
}
build-host = {
image = "sles15sp4o"
name = "min-build"
provider_settings = {
mac = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].mac["build-host"]
memory = 2048
}
additional_repos = {
tools_update_pr = var.SLE_CLIENT_REPO
}
additional_packages = [ "venv-salt-minion" ]
install_salt_bundle = true
}
pxeboot-minion = {
image = "sles15sp4o"
additional_repos = {
tools_update_pr = var.SLE_CLIENT_REPO
}
additional_packages = [ "venv-salt-minion" ]
install_salt_bundle = true
}
kvm-host = {
image = var.IMAGE
name = "min-kvm"
additional_grains = {
hvm_disk_image = {
leap = {
hostname = "suma-pr${var.ENVIRONMENT}-min-nested"
image = "http://${var.DOWNLOAD_ENDPOINT}/distribution/leap/15.5/appliances/openSUSE-Leap-15.5-Minimal-VM.x86_64-Cloud.qcow2"
hash = "http://${var.DOWNLOAD_ENDPOINT}/distribution/leap/15.5/appliances/openSUSE-Leap-15.5-Minimal-VM.x86_64-Cloud.qcow2.sha256"
}
sles = {
hostname = "suma-pr${var.ENVIRONMENT}-min-nested"
image = "http://${var.DOWNLOAD_ENDPOINT}/install/SLE-15-SP4-Minimal-GM/SLES15-SP4-Minimal-VM.x86_64-OpenStack-Cloud-GM.qcow2"
hash = "http://${var.DOWNLOAD_ENDPOINT}/install/SLE-15-SP4-Minimal-GM/SLES15-SP4-Minimal-VM.x86_64-OpenStack-Cloud-GM.qcow2.sha256"
}
}
}
provider_settings = {
mac = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].mac["kvm-host"]
}
additional_repos_only = var.ADDITIONAL_REPOS_ONLY
additional_repos = local.additional_repos["kvm-host"]
additional_packages = [ "venv-salt-minion", "mkisofs" ]
install_salt_bundle = true
}
}
nested_vm_host = "suma-pr${var.ENVIRONMENT}-min-nested"
nested_vm_mac = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].mac["nested-vm"]
provider_settings = {
pool = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].pool
network_name = null
bridge = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].bridge
additional_network = var.ENVIRONMENT_CONFIGURATION[var.ENVIRONMENT].additional_network
}
}


resource "null_resource" "add_test_information" {
triggers = {
always_run = "${timestamp()}"
}
provisioner "file" {
source = "../../susemanager-ci/terracumber_config/scripts/set_custom_header.sh"
destination = "/tmp/set_custom_header.sh"
connection {
type = "ssh"
user = "root"
password = "linux"
host = "${module.cucumber_testsuite.configuration.server.hostname}"
}
}
}

output "configuration" {
value = module.cucumber_testsuite.configuration
}
Loading

0 comments on commit 5ff370a

Please sign in to comment.