Strict checking that XOS is using SemVer version

Tag and use new XOS version when testing

Change-Id: Idda46440f885c4f4ee4e6aa0bace379a7587f480
diff --git a/jjb/defaults.yaml b/jjb/defaults.yaml
index 3ab54c1..1447fc3 100644
--- a/jjb/defaults.yaml
+++ b/jjb/defaults.yaml
@@ -67,6 +67,9 @@
     # for matching repos that build docker images with imagebuilder
     imagebuilder-projects-regexp: '^(xos.*|cord-tester|chameleon|rcord|mcord|ecord|acordion|addressmanager|epc-service|exampleservice|fabric|fabric-crossconnect|globalxos|hippie-oss|hss_db|hypercache|internetemulator|kubernetes-service|monitoring|olt-service|onos-service|openstack|progran|sdn-controller|simpleexampleservice|templateservice|vEE|vEG|vBBU|venb|vHSS|vMME|vnaas|vPGWC|vPGWU|vrouter|vsg|vsg-hw|vSGW|vSM|vspgwc|vspgwu|vtn-service|vtr)$'
 
+    # strictness of version checks
+    semver-strict: 0
+
     # matching repos that should be version tagged by the version-tag job
     # (basically the same as imagebuilder projects + helm charts + tools
     version-tag-projects-regexp: '^(xos.*|helm-charts|automation-tools|cord-tester|chameleon|rcord|mcord|ecord|acordion|addressmanager|epc-service|exampleservice|fabric|fabric-crossconnect|globalxos|hippie-oss|hss_db|hypercache|internetemulator|kubernetes-service|monitoring|olt-service|onos-service|openstack|progran|sdn-controller|simpleexampleservice|templateservice|vEE|vEG|vBBU|venb|vHSS|vMME|vnaas|vPGWC|vPGWU|vrouter|vsg|vsg-hw|vSGW|vSM|vspgwc|vspgwu|vtn-service|vtr)$'
diff --git a/jjb/pipeline/all-xos-api-test-helm.groovy b/jjb/pipeline/all-xos-api-test-helm.groovy
index bc83a81..4e1384b 100644
--- a/jjb/pipeline/all-xos-api-test-helm.groovy
+++ b/jjb/pipeline/all-xos-api-test-helm.groovy
@@ -109,6 +109,44 @@
       }
     }
 
+    stage('tag update') {
+      steps {
+        sh """
+           #!/usr/bin/env bash
+           set -eu -o pipefail
+
+           # skip projects that aren't the XOS core repository
+           if [ "${gerrit_project}" != "xos" ]; then
+             exit 0
+           fi
+
+           echo "" > \${WORKSPACE}/updated_dockerfiles
+           XOS_MAJOR=\$(cut -b 1 cord/orchestration/xos/VERSION)
+           XOS_VERSION=\$(cat cord/orchestration/xos/VERSION)
+
+           # update services
+           for df in cord/orchestration/xos_services/*/Dockerfile.synchronizer cord/orchestration/profiles/*/Dockerfile.synchronizer
+           do
+             df_contents=\$(cat "\$df")
+             if [[ "\$df_contents" =~ "FROM xosproject/xos-synchronizer-base:\${XOS_MAJOR}" ||
+                   "\$df_contents" =~ "FROM xosproject/xos-synchronizer-base:master" ]]
+             then
+               sed -i "s/^FROM\\(.*\\):.*\$/FROM\\1:\$XOS_VERSION/" "\$df"
+               echo "\${WORKSPACE}/\$df" >> \${WORKSPACE}/updated_dockerfiles
+             fi
+           done
+
+           # create values file with core version tags
+           cat << EOF > \${WORKSPACE}/xos_tags.yaml
+           ---
+           xos_coreImage: 'xosproject/xos-core:\$(XOS_VERSION}'
+           xos_chameleonImage: 'xosproject/chameleon:\$(XOS_VERSION}'
+           xos_toscaImage: 'xosproject/xos-tosca:\$(XOS_VERSION}'
+
+           EOF
+           """
+      }
+    }
 
     stage('prep') {
       parallel {
@@ -170,6 +208,11 @@
 
            helm_install_args='-f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml'
 
+           # skip projects that aren't the XOS core repository
+           if [ "${gerrit_project}" != "xos" ]; then
+             helm_install_args+=' -f $WORKSPACE/xos_tags.yaml'
+           fi
+
            pushd cord/helm-charts
 
            helm dep up xos-core
diff --git a/jjb/pipeline/xos-synchronizer-update.groovy b/jjb/pipeline/xos-synchronizer-update.groovy
index d2cdfda..96251d9 100644
--- a/jjb/pipeline/xos-synchronizer-update.groovy
+++ b/jjb/pipeline/xos-synchronizer-update.groovy
@@ -12,8 +12,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// Run XOS api tests after changing the containers to use the `candidate`
-// parent, which may include synchronizer changes
+// Run XOS api tests after changing the containers to use the current XOS
+// container versions as parent, which may include synchronizer framework
+// changes
 
 CORE_CONTAINER="null"
 
@@ -109,22 +110,36 @@
       }
     }
 
-    stage('candiate tag') {
+    stage('tag update') {
       steps {
         sh """
+           #!/usr/bin/env bash
+           set -eu -o pipefail
+
            echo "" > \${WORKSPACE}/updated_dockerfiles
            XOS_MAJOR=\$(cut -b 1 cord/orchestration/xos/VERSION)
+           XOS_VERSION=\$(cat cord/orchestration/xos/VERSION)
 
+           # update services
            for df in cord/orchestration/xos_services/*/Dockerfile.synchronizer cord/orchestration/profiles/*/Dockerfile.synchronizer
            do
              df_contents=\$(cat "\$df")
              if [[ "\$df_contents" =~ "FROM xosproject/xos-synchronizer-base:\${XOS_MAJOR}" ||
                    "\$df_contents" =~ "FROM xosproject/xos-synchronizer-base:master" ]]
              then
-               sed -i "s/^FROM\\(.*\\):.*\$/FROM\\1:candidate/" "\$df"
+               sed -i "s/^FROM\\(.*\\):.*\$/FROM\\1:\$XOS_VERSION/" "\$df"
                echo "\${WORKSPACE}/\$df" >> \${WORKSPACE}/updated_dockerfiles
              fi
            done
+
+           # create values file with core version tags
+           cat << EOF > \${WORKSPACE}/xos_tags.yaml
+           ---
+           xos_coreImage: 'xosproject/xos-core:\$(XOS_VERSION}'
+           xos_chameleonImage: 'xosproject/chameleon:\$(XOS_VERSION}'
+           xos_toscaImage: 'xosproject/xos-tosca:\${XOS_VERSION}'
+
+           EOF
            """
       }
     }
@@ -218,7 +233,7 @@
            #!/usr/bin/env bash
            set -eu -o pipefail
 
-           helm_install_args='-f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml'
+           helm_install_args='-f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml -f $WORKSPACE/xos_tags.yaml'
 
            pushd cord/helm-charts
 
diff --git a/jjb/shell/tagcollisionreject.sh b/jjb/shell/tagcollisionreject.sh
index 86fe317..09c014c 100755
--- a/jjb/shell/tagcollisionreject.sh
+++ b/jjb/shell/tagcollisionreject.sh
@@ -22,6 +22,8 @@
 VERSIONFILE="" # file path to file containing version number
 NEW_VERSION="" # version number found in $VERSIONFILE
 
+SEMVER_STRICT=${SEMVER_STRICT:-0} # require semver versions
+
 releaseversion=0
 fail_validation=0
 
@@ -64,7 +66,13 @@
     echo "Version string '$NEW_VERSION' found in '$VERSIONFILE' is a SemVer released version!"
     releaseversion=1
   else
-    echo "Version string '$NEW_VERSION' found in '$VERSIONFILE' is not a SemVer released version, skipping."
+    if [ "$SEMVER_STRICT" -eq "1" ]
+    then
+      echo "Version string '$NEW_VERSION' in '$VERSIONFILE' is not a SemVer released version, SEMVER_STRICT enabled, failing!"
+      fail_validation=1
+    else
+      echo "Version string '$NEW_VERSION' in '$VERSIONFILE' is not a SemVer released version, skipping."
+    fi
   fi
 }
 
diff --git a/jjb/shell/versiontag.sh b/jjb/shell/versiontag.sh
index 4287914..60042d8 100755
--- a/jjb/shell/versiontag.sh
+++ b/jjb/shell/versiontag.sh
@@ -23,6 +23,8 @@
 VERSIONFILE="" # file path to file containing version number
 NEW_VERSION="" # version number found in $VERSIONFILE
 
+SEMVER_STRICT=${SEMVER_STRICT:-0} # require semver versions
+
 releaseversion=0
 fail_validation=0
 
@@ -53,7 +55,13 @@
     echo "Version string '$NEW_VERSION' in '$VERSIONFILE' is a SemVer released version!"
     releaseversion=1
   else
-    echo "Version string '$NEW_VERSION' in '$VERSIONFILE' is not a SemVer released version, skipping."
+    if [ "$SEMVER_STRICT" -eq "1" ]
+    then
+      echo "Version string '$NEW_VERSION' in '$VERSIONFILE' is not a SemVer released version, SEMVER_STRICT enabled, failing!"
+      fail_validation=1
+    else
+      echo "Version string '$NEW_VERSION' in '$VERSIONFILE' is not a SemVer released version, skipping."
+    fi
   fi
 }
 
diff --git a/jjb/verify/xos.yaml b/jjb/verify/xos.yaml
index fdf135b..4a474b6 100644
--- a/jjb/verify/xos.yaml
+++ b/jjb/verify/xos.yaml
@@ -8,6 +8,7 @@
     jobs:
       - 'verify-xos-jobs':
           branch-regexp: '{supported-branches-regexp}'
+          semver-strict: 1
 
 - job-group:
     name: 'verify-xos-jobs'
diff --git a/jjb/versioning.yaml b/jjb/versioning.yaml
index 420b13f..16e810b 100644
--- a/jjb/versioning.yaml
+++ b/jjb/versioning.yaml
@@ -67,6 +67,9 @@
     concurrent: true
 
     builders:
+      - inject:
+          properties-content:
+            SEMVER_STRICT={semver-strict}
       - shell: !include-raw-escape: shell/tagcollisionreject.sh
 
 
@@ -110,5 +113,8 @@
     concurrent: true
 
     builders:
+      - inject:
+          properties-content:
+            SEMVER_STRICT={semver-strict}
       - shell: !include-raw-escape: shell/versiontag.sh