Merge changes from topic '10422'
authorAndrew Grimberg <agrimberg@linuxfoundation.org>
Sat, 23 Jun 2018 15:10:35 +0000 (15:10 +0000)
committerGerrit Code Review <gerrit@linuxfoundation.org>
Sat, 23 Jun 2018 15:10:35 +0000 (15:10 +0000)
* changes:
  Enable ensure-documented check
  Document undocumented macros
  Document undocumented ci-jobs macros
  Document undocumented maven macros

docs/jjb/lf-ci-jobs.rst
docs/jjb/lf-macros.rst
info-schema
jenkins-init-scripts/README
jjb/lf-ci-jobs.yaml
jjb/lf-macros.yaml
shell/jenkins-configure-clouds.sh
shell/license-check.sh [new file with mode: 0644]

index 453035a..93ef067 100644 (file)
@@ -236,6 +236,7 @@ OpenStack Cloud plugin version supported:
 * 2.32
 * 2.33
 * 2.34
+* 2.35
 
 Cloud configuration are managed via a directory structure in ci-management as
 follows:
@@ -450,6 +451,34 @@ other file changes. Verifies INFO.yaml files follow the schema defined in
         (default: true)
     :gerrit_verify_triggers: Override Gerrit Triggers.
 
+.. _license-checker:
+
+License Checker
+---------------
+
+Job to scan projects for files missing license headers.
+
+:Template Names:
+    - {project-name}-license-check
+    - gerrit-license-check
+    - github-license-check
+
+:Optional parameters:
+
+    :file-patterns: Space-separated list of file patterns to scan.
+        (default: \*.go \*.groovy \*.java \*.py \*.sh)
+    :spdx-disable: Disable the SPDX-Identifier checker. (default: false)
+    :lhc-version: Version of LHC to use. (default: 0.2.0)
+    :license-exclude-paths: Comma-separated list of paths to exclude from the
+        license checker. The paths used here will be matched using a contains
+        rule so it is best to be as precise with the path as possible.
+        For example a path of '/src/generated/' will be searched as
+        '**/src/generated/**'.
+        Example: org/opendaylight/yang/gen,protobuff/messages
+        (default: '')
+    :licenses-allowed: Comma-separated list of allowed licenses.
+        (default: Apache-2.0,EPL-1.0,MIT)
+
 .. _gjjb-packer-merge:
 
 Packer Merge
index 241ce12..419c2c6 100644 (file)
@@ -16,6 +16,26 @@ called DEPENDENCY_BUILD_ORDER which can be used if necessary to build
 projects in the specified order. The order is determined by first patch
 instance for a project in the patch list.
 
+lf-license-check
+----------------
+
+Checks files for
+
+:Required parameters:
+
+    :file-patterns: Space-separated list of file patterns to scan.
+        For example: \*.go \*.groovy \*.java \*.py \*.sh
+    :spdx-disable: Disable the SPDX-Identifier checker.
+    :lhc-version: Version of LHC to use.
+    :license-exclude-paths: Comma-separated list of paths to exclude from the
+        license checker. The paths used here will be matched using a contains
+        rule so it is best to be as precise with the path as possible.
+        For example a path of '/src/generated/' will be searched as
+        '**/src/generated/**'.
+        Example: org/opendaylight/yang/gen,protobuff/messages
+    :licenses-allowed: Comma-separated list of allowed licenses.
+        For example: Apache-2.0,EPL-1.0,MIT
+
 lf-infra-create-netrc
 ---------------------
 
index c98a470..bb596c2 100644 (file)
@@ -13,7 +13,6 @@ $id: 'https://github.com/lfit/releng-global-jjb/blob/master/info-schema'
 
 required:
   - 'project'
-  - 'version'
   - 'project_creation_date'
   - 'project_category'
   - 'lifecycle_state'
index 8548786..2d85978 100644 (file)
@@ -11,5 +11,5 @@ it to Jenkins for job use.
 To use this create a managed file in Jenkins with the contents:
 
     #!/bin/bash
-    git clone https://gerrit.example.org/r/ci-management.git /opt/ciman
+    git clone --recurse-submodules https://gerrit.example.org/r/ci-management.git /opt/ciman
     /opt/ciman/jjb/global-jjb/jenkins-init-scripts/init.sh
index 788dc46..ed6a5c5 100644 (file)
@@ -36,7 +36,6 @@
       - gerrit-packer-merge
       - gerrit-packer-verify
 
-
 - job-group:
     name: '{project-name}-github-packer-jobs'
 
         pattern: '.*\.groovy'
       - compare-type: REG_EXP
         pattern: '.*\.sh'
+      - compare-type: REG_EXP
+        pattern: '.*\.bat'
+      - compare-type: REG_EXP
+        pattern: '.*\.ps1'
       - compare-type: REG_EXP
         pattern: '.*\.(yaml|yml)'
       - compare-type: REG_EXP
     github_included_regions:
       - '.*\.groovy'
       - '.*\.sh'
+      - '.*\.bat'
+      - '.*\.ps1'
       - '.*\.(yaml|yml)'
       - '.*\/global-jjb'
 
           github-hooks: true
           included-regions: '{obj:github_included_regions}'
 
+#################
+# License Check #
+#################
+
+- lf_license_check: &lf_license_check
+    name: lf-license-check
+
+    ######################
+    # Default parameters #
+    ######################
+
+    branch: master
+    build-days-to-keep: 7
+    build-timeout: 15
+    file-patterns: >
+        *.go
+        *.groovy
+        *.java
+        *.py
+        *.sh
+    git-url: '$GIT_URL/$PROJECT'
+    lhc-version: 0.2.0
+    license-exclude-paths: ''
+    licenses-allowed: Apache-2.0,EPL-1.0,MIT
+    spdx-disable: false
+    stream: master
+
+    #####################
+    # Job Configuration #
+    #####################
+
+    project-type: freestyle
+    node: '{build-node}'
+    concurrent: true
+
+    properties:
+      - lf-infra-properties:
+          build-days-to-keep: '{build-days-to-keep}'
+
+    parameters:
+      - lf-infra-parameters:
+          project: '{project}'
+          branch: '{branch}'
+          stream: '{stream}'
+          lftools-version: '{lftools-version}'
+
+    wrappers:
+      - lf-infra-wrappers:
+          build-timeout: '{build-timeout}'
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+    builders:
+      - lf-license-check:
+          file-patterns: '{file-patterns}'
+          spdx-disable: '{spdx-disable}'
+          lhc-version: '{lhc-version}'
+          license-exclude-paths: '{license-exclude-paths}'
+          licenses-allowed: '{licenses-allowed}'
+
+    publishers:
+      - lf-infra-publish
+
+- job-template:
+    name: '{project-name}-license-check'
+    id: gerrit-license-check
+    <<: *lf_license_check
+
+    git-url: '$GIT_URL/$GERRIT_PROJECT'
+
+    scm:
+      - lf-infra-gerrit-scm:
+          git-url: '{git-url}'
+          refspec: '$GERRIT_REFSPEC'
+          branch: '$GERRIT_BRANCH'
+          # Submodules are out of the project's control
+          submodule-recursive: false
+          choosing-strategy: gerrit
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+    triggers:
+      - gerrit:
+          server-name: '{gerrit-server-name}'
+          # Trigger should not be overridable as we want to always run
+          trigger-on:
+            - patchset-created-event:
+                exclude-drafts: false
+                exclude-trivial-rebase: false
+                exclude-no-code-change: false
+            - draft-published-event
+            - comment-added-contains-event:
+                comment-contains-value: recheck$
+          projects:
+            - project-compare-type: ANT
+              project-pattern: '**'
+              branches:
+                - branch-compare-type: ANT
+                  branch-pattern: '**'
+
+- job-template:
+    name: '{project-name}-license-check'
+    id: github-license-check
+    <<: *lf_license_check
+
+    properties:
+      - github:
+          url: '{git-url}/{github-org}/{project}'
+
+    scm:
+      - lf-infra-github-scm:
+          url: '{git-clone-url}{github-org}/{project}'
+          refspec: '+refs/pull/*:refs/remotes/origin/pr/*'
+          branch: '$sha1'
+          # Submodules are out of the project's control
+          submodule-recursive: false
+          choosing-strategy: default
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+    triggers:
+      - github-pull-request:
+          trigger-phrase: '^recheck$'
+          only-trigger-phrase: false
+          status-context: 'License Check'
+          permit-all: true
+          github-hooks: true
+
 ####################
 # Info YAML Verify #
 ####################
               file-paths:
                 - compare-type: REG_EXP
                   pattern: 'packer\/provision\/.*\.sh'
+                - compare-type: REG_EXP
+                  pattern: 'packer\/provision\/.*\.bat'
+                - compare-type: REG_EXP
+                  pattern: 'packer\/provision\/.*\.ps1'
                 - compare-type: REG_EXP
                   pattern: 'packer\/provision\/{templates}\.yaml'
                 - compare-type: REG_EXP
           # included-regions MUST match Gerrit Trigger file-paths
           included-regions:
             - 'packer\/provision\/.*\.sh'
+            - 'packer\/provision\/.*\.bat'
+            - 'packer\/provision\/.*\.ps1'
             - 'packer\/provision\/{templates}\.yaml'
             - 'packer\/provision\/local-{templates}\.yaml'
             - 'packer\/templates\/{templates}\.json'
index 6a0cab9..1267197 100644 (file)
       - inject:
           properties-file: $WORKSPACE/.dependency.properties
 
+- builder:
+    name: lf-license-check
+    builders:
+      - inject:
+          properties-content: |
+              FILE_PATTERNS={file-patterns}
+              SPDX_DISABLE={spdx-disable}
+              LHC_VERSION={lhc-version}
+              LICENSE_EXCLUDE_PATHS={license-exclude-paths}
+              LICENSES_ALLOWED={licenses-allowed}
+      - shell: !include-raw-escape:
+          - ../shell/license-check.sh
+
 - builder:
     name: lf-infra-create-netrc
     builders:
     builders:
       - inject:
           properties-content: |
-              PROJECT='{project}'
-              GERRIT_COMMIT_MESSAGE='{gerrit-commit-message}'
-              GERRIT_HOST='{gerrit-host}'
-              GERRIT_TOPIC='{gerrit-topic}'
-              GERRIT_USER='{gerrit-user}'
-              REVIEWERS_EMAIL='{reviewers-email}'
+              PROJECT={project}
+              GERRIT_COMMIT_MESSAGE={gerrit-commit-message}
+              GERRIT_HOST={gerrit-host}
+              GERRIT_TOPIC={gerrit-topic}
+              GERRIT_USER={gerrit-user}
+              REVIEWERS_EMAIL={reviewers-email}
       - shell: !include-raw-escape: ../shell/gerrit-push-patch.sh
 
 - builder:
index 3f7dd6a..da0b732 100644 (file)
@@ -46,8 +46,21 @@ mkdir -p "$SCRIPT_DIR"
 
 silos="${jenkins_silos:-jenkins}"
 
+set +x  # Disable `set -x` to prevent printing passwords
+echo "Configuring $silo"
+JENKINS_URL=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" url)
+JENKINS_USER=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" user)
+JENKINS_PASSWORD=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" password)
+export JENKINS_URL
+export JENKINS_USER
+export JENKINS_PASSWORD
+OS_PLUGIN_VER="$(lftools jenkins plugins list \
+    | grep 'Openstack Cloud Plugin' | awk -F':' '{print $2}')"
+
 set -eu -o pipefail
 
+version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
+
 get_cfg() {
     if [ -z ${3+x} ]; then
         >&2 echo "Usage: get_cfg CFG_FILE SETTING DEFAULT"
@@ -63,7 +76,7 @@ get_cfg() {
         exit 1
     fi
 
-    cfg=$(grep "${setting^^}" "$cfg_file" | tail -1 | awk -F'=' '{print $2}')
+    cfg=$(grep "^${setting^^}=" "$cfg_file" | tail -1 | awk -F'=' '{print $2}')
     cfg=${cfg:-"$default"}
     echo "$cfg"
 }
@@ -153,6 +166,7 @@ get_minion_options() {
     if [ "$silo" == "sandbox" ]; then
         instance_cap=$(get_cfg "$cfg_file" SANDBOX_CAP "null")
     fi
+    min_instance_cap=$(get_cfg "$cfg_file" MIN_INSTANCE_CAP "null")
 
     floating_ip_pool=$(get_cfg "$cfg_file" FLOATING_IP_POOL "")
     security_groups=$(get_cfg "$cfg_file" SECURITY_GROUPS "default")
@@ -164,25 +178,49 @@ get_minion_options() {
     fs_root=$(get_cfg "$cfg_file" FS_ROOT "/w")
     retention_time=$(get_cfg "$cfg_file" RETENTION_TIME "0")
 
-    if [ ! -z "$volume_size" ]; then
-        echo "    new BootSource.VolumeFromImage(\"$image_name\", $volume_size),"
-    else
-        echo "    new BootSource.Image(\"$image_name\"),"
+    if version_ge "$OS_PLUGIN_VER" "2.35"; then
+        if [ ! -z "$volume_size" ]; then
+            echo "    new BootSource.VolumeFromImage(\"$image_name\", $volume_size),"
+        else
+            echo "    new BootSource.Image(\"$image_name\"),"
+        fi
+        echo "    \"${flavors[${hardware_id}]}\","
+        echo "    \"$network_id\","
+        echo "    \"$user_data_id\","
+        echo "    $instance_cap,"
+        echo "    $min_instance_cap,"
+        echo "    \"$floating_ip_pool\","
+        echo "    \"$security_groups\","
+        echo "    \"$availability_zone\","
+        echo "    $start_timeout,"
+        echo "    \"$key_pair_name\","
+        echo "    $num_executors,"
+        echo "    \"$jvm_options\","
+        echo "    \"$fs_root\","
+        echo "    new LauncherFactory.SSH(\"$key_pair_name\", \"\"),"
+        echo "    $retention_time"
+
+    else  # SlaveOptions() structure for versions <= 2.34
+        if [ ! -z "$volume_size" ]; then
+            echo "    new BootSource.VolumeFromImage(\"$image_name\", $volume_size),"
+        else
+            echo "    new BootSource.Image(\"$image_name\"),"
+        fi
+        echo "    \"${flavors[${hardware_id}]}\","
+        echo "    \"$network_id\","
+        echo "    \"$user_data_id\","
+        echo "    $instance_cap,"
+        echo "    \"$floating_ip_pool\","
+        echo "    \"$security_groups\","
+        echo "    \"$availability_zone\","
+        echo "    $start_timeout,"
+        echo "    \"$key_pair_name\","
+        echo "    $num_executors,"
+        echo "    \"$jvm_options\","
+        echo "    \"$fs_root\","
+        echo "    new LauncherFactory.SSH(\"$key_pair_name\", \"\"),"
+        echo "    $retention_time"
     fi
-    echo "    \"${flavors[${hardware_id}]}\","
-    echo "    \"$network_id\","
-    echo "    \"$user_data_id\","
-    echo "    $instance_cap,"
-    echo "    \"$floating_ip_pool\","
-    echo "    \"$security_groups\","
-    echo "    \"$availability_zone\","
-    echo "    $start_timeout,"
-    echo "    \"$key_pair_name\","
-    echo "    $num_executors,"
-    echo "    \"$jvm_options\","
-    echo "    \"$fs_root\","
-    echo "    new LauncherFactory.SSH(\"$key_pair_name\", \"\"),"
-    echo "    $retention_time"
 }
 
 get_template_cfg() {
@@ -253,13 +291,5 @@ for silo in $silos; do
         cat "$insert_file" >> "$script_file"
     done
 
-    set +x  # Disable `set -x` to prevent printing passwords
-    echo "Configuring $silo"
-    JENKINS_URL=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" url)
-    JENKINS_USER=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" user)
-    JENKINS_PASSWORD=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" password)
-    export JENKINS_URL
-    export JENKINS_USER
-    export JENKINS_PASSWORD
     lftools jenkins groovy "$script_file"
 done
diff --git a/shell/license-check.sh b/shell/license-check.sh
new file mode 100644 (file)
index 0000000..8466cf9
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2017 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+# Scans files for license header violations
+#
+# This script is meant to be called by a Jenkins job and was not designed to
+# run standalone refer to the below Inputs for details on optional ENVVAR
+# inputs.
+
+echo "---> license-check.sh"
+
+# --- Inputs
+
+# Space separated list of file patterns to scan for license headers.
+file_patterns=("${FILE_PATTERNS:-*.go *.groovy *.java *.py *.sh}")
+# Version of the License Header Checker to install
+lhc_version="${LHC_VERSION:-0.2.0}"
+# Comma-separated list of paths to exclude from license checking
+license_exclude_paths="${LICENSE_EXCLUDE_PATHS:-}"
+# Comma-separated list of allowed licenses
+licenses_allowed="${LICENSES_ALLOWED:-Apache-2.0,EPL-1.0,MIT}"
+
+if [[ "${SPDX_DISABLE}" == "true" ]]; then
+    disable_spdx="--disable-spdx"
+else
+    disable_spdx=""
+fi
+
+# --- Script start
+
+# DO NOT enable -u because LICENSE_EXCLUDE_PATHS is unbound.
+# Ensure we fail the job if any steps fail.
+set -eux -o pipefail
+
+if hash lhc 2>/dev/null; then
+    echo "License Header Checker is installed."
+    lhc --version
+else
+    echo "License Header Checker is not installed. Installing..."
+    mkdir "$WORKSPACE/bin"
+    wget -nv -O "/tmp/lhc.tar.gz" "https://nexus.opendaylight.org/content/repositories/hosted_installers/org/linuxfoundation/lhc/${lhc_version}/lhc-${lhc_version}.tar.gz"
+    tar -zxvf /tmp/lhc.tar.gz -C "$WORKSPACE/bin"
+    chmod +x "$WORKSPACE/bin/lhc"
+    export PATH="$WORKSPACE/bin:$PATH"
+    lhc --version
+fi
+
+
+set -f  # Disable globbing for $file_patterns to pass '*'
+# Purposely disable SC2068 for $file_patterns
+# shellcheck disable=SC2068
+lhc --license "$licenses_allowed" ${disable_spdx} \
+    --exclude "$license_exclude_paths" \
+    ${file_patterns[@]}
+set +f