<commit_before>/**
 * The openstack-cloud Jenkins pipeline library
 */


// Loads the list of extra parameters into the environment
def load_extra_params_as_vars(extra_params) {
  if (extra_params) {
    def props = readProperties text: extra_params
    for(key in props.keySet()) {
      value = props["${key}"]
      env."${key}" = "${value}"
    }
  }
}

// When a CI lockable resource slot name is used for the `cloud_env` value,
// this function overrides the os_cloud and os_project_name values to correspond
// to the target OpenStack platform associated with the slot and the 'cloud-ci'
// OpenStack project used exclusively for the Cloud CI
def load_os_params_from_resource(cloud_env) {
  if (cloud_env.startsWith("engcloud-ci-slot")) {
    env.os_cloud = "engcloud"
    env.os_project_name = "cloud-ci"
  } else if (cloud_env.startsWith("susecloud-ci-slot")) {
    env.os_cloud = "susecloud"
    env.os_project_name = "cloud-ci"
  } else if (os_project_name == "cloud-ci") {
    error("""The OpenStack 'cloud-ci' project is reserved and may only be used with
'cloud_env' values that correspond to CI Lockable Resource slots.
Please adjust your 'cloud_env' or 'os_project_name' parameter values to avoid this error.""")
  }
}

def ansible_playbook(playbook, params='') {
  sh("""
    cd $WORKSPACE
    source automation-git/scripts/jenkins/cloud/jenkins-helper.sh
    if [[ -e automation-git/scripts/jenkins/cloud/ansible/input.yml ]]; then
      ansible_playbook """+playbook+""".yml -e @input.yml """+params+"""
    else
      ansible_playbook """+playbook+""".yml """+params+"""
    fi
  """)
}

def trigger_build(job_name, parameters, propagate=true, wait=true) {
  def slaveJob = build job: job_name, parameters: parameters, propagate: propagate, wait: wait
  if (wait && !propagate) {
    def jobResult = slaveJob.getResult()
    def jobUrl = slaveJob.buildVariables.blue_ocean_buildurl
    def jobMsg = "Build ${jobUrl} completed with: ${jobResult}"
    echo jobMsg
    if (jobResult != 'SUCCESS') {
      error(jobMsg)
    }<commit_msg>openstack-crowbar/ardana: protect lockable resource slots<commit_after>/**
 * The openstack-cloud Jenkins pipeline library
 */


// Loads the list of extra parameters into the environment
def load_extra_params_as_vars(extra_params) {
  if (extra_params) {
    def props = readProperties text: extra_params
    for(key in props.keySet()) {
      value = props["${key}"]
      env."${key}" = "${value}"
    }
  }
}

// When a CI lockable resource slot name is used for the `cloud_env` value,
// this function overrides the os_cloud and os_project_name values to correspond
// to the target OpenStack platform associated with the slot and the 'cloud-ci'
// OpenStack project used exclusively for the Cloud CI.
//
// This function also enforces the following two rules:
// 1. the 'cloud-ci' OpenStack project (supplied via `os_project_name`) is reserved
//    and may only be used with 'cloud_env' values that correspond to CI Lockable Resource
//    slots
// 2. CI Lockable Resource slots may not be used directly by manually triggered jobs.
//
def load_os_params_from_resource(cloud_env) {
  def is_lockable_resource = false
  if (cloud_env.startsWith("engcloud-ci-slot")) {
    env.os_cloud = "engcloud"
    env.os_project_name = "cloud-ci"
    is_lockable_resource = true
  } else if (cloud_env.startsWith("susecloud-ci-slot")) {
    env.os_cloud = "susecloud"
    env.os_project_name = "cloud-ci"
    is_lockable_resource = true
  } else if (os_project_name == "cloud-ci") {
    def errMsg = """The OpenStack 'cloud-ci' project is reserved and may only be used with
'cloud_env' values that correspond to CI Lockable Resource slots.
Please adjust your 'cloud_env' or 'os_project_name' parameter values to avoid this error."""
    echo errMsg
    error(errMsg)
  }

  if (is_lockable_resource && currentBuild.upstreamBuilds.isEmpty()) {
    def errMsg = """The '${cloud_env}' cloud environment name may not be used with manually triggered jobs.
Please adjust your 'cloud_env' parameter value to avoid this error, or use the parent job instead."""
    echo errMsg
    error(errMsg)
  }
}

def ansible_playbook(playbook, params='') {
  sh("""
    cd $WORKSPACE
    source automation-git/scripts/jenkins/cloud/jenkins-helper.sh
    if [[ -e automation-git/scripts/jenkins/cloud/ansible/input.yml ]]; then
      ansible_playbook """+playbook+""".yml -e @input.yml """+params+"""
    else
      ansible_playbook """+playbook+""".yml """+params+"""
    fi
  """)
}

def trigger_build(job_name, parameters, propagate=true, wait=true) {
  def slaveJob = build job: job_name, parameters: parameters, propagate: propagate, wait: wait
  if (wait && !propagate) {
    def jobResult = slaveJob.getResult()
    def jobUrl = slaveJob.buildVariables.blue_ocean_buildurl
    def jobMsg = "Build ${jobUrl} completed with: ${jobResult}"
    echo jobMsg
    if (jobResult != 'SUCCESS') {
      error(jobMsg)
    }
{'fraction_non_alphanumeric': 0.1172901921132457, 'fraction_numerical': 0.0004044489383215369, 'mean_word_length': 3.8777120315581852, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3949494', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1531, 'n_words': 472}