Add ability to test a new nodegenerator tool for Salt model testing

New nodegenerator tool testing step is added as part of Salt model testing
workflow. This step will be only executed on master branches and only for
test-cookiecutter-reclass-chunk job, to do not affect all other jobs.
Also added step will be non-voting and will not affect current flow.

Change-Id: Ibeb431274b14097531df9931937cf07b95c77f47
Related-Prod: PROD-26064 (PROD:26064)
diff --git a/src/com/mirantis/mk/SaltModelTesting.groovy b/src/com/mirantis/mk/SaltModelTesting.groovy
index c4bd4fa..585cb8b 100644
--- a/src/com/mirantis/mk/SaltModelTesting.groovy
+++ b/src/com/mirantis/mk/SaltModelTesting.groovy
@@ -277,6 +277,7 @@
     def aptRepoUrl = config.get('aptRepoUrl', "")
     def aptRepoGPG = config.get('aptRepoGPG', "")
     def testContext = config.get('testContext', 'test')
+    def nodegenerator = config.get('nodegenerator', false)
     config['envOpts'] = [
         "RECLASS_ENV=${reclassEnv}", "SALT_STOPSTART_WAIT=5",
         "HOSTNAME=${dockerHostname}", "CLUSTER_NAME=${clusterName}",
@@ -342,6 +343,31 @@
             archiveArtifacts artifacts: "nodesinfo.tar.gz"
         }
     ]
+    // this tool should be tested in master branch only
+    // and not for all jobs, as pilot will be used cc-reclass-chunk
+    if (nodegenerator) {
+        config['runCommands']['005_Test_new_nodegenerator'] = {
+            try {
+                sh('''#!/bin/bash
+                new_generated_dir=/srv/salt/_new_generated
+                mkdir -p ${new_generated_dir}
+                nodegenerator -b /srv/salt/reclass/classes/ -o ${new_generated_dir} ${CLUSTER_NAME}
+                diff -r /srv/salt/reclass/nodes/_generated ${new_generated_dir} > /tmp/nodegenerator.diff
+                tar -czf /tmp/_generated.tar.gz /srv/salt/reclass/nodes/_generated/
+                tar -czf /tmp/_new_generated.tar.gz ${new_generated_dir}/
+                tar -czf /tmp/_model.tar.gz /srv/salt/reclass/classes/cluster/*
+                ''')
+            } catch (Exception e) {
+                print "Test new nodegenerator tool is failed: ${e}"
+            }
+        }
+        config['runFinally']['002_Archive_nodegenerator_artefact'] = {
+            sh(script: "cd /tmp; [ -f nodegenerator.diff ] && tar -czf ${env.WORKSPACE}/nodegenerator.tar.gz nodegenerator.diff _generated.tar.gz _new_generated.tar.gz _model.tar.gz", returnStatus: true)
+            if (fileExists('nodegenerator.tar.gz')) {
+                archiveArtifacts artifacts: "nodegenerator.tar.gz"
+            }
+        }
+    }
     testResult = setupDockerAndTest(config)
     if (testResult) {
         common.infoMsg("Node test for context: ${testContext} model: ${reclassEnv} finished: SUCCESS")