Revert "Refactor generateModel"

This reverts commit 816d7fd5343ef4e91f6880ddea11b5c566b9e227.

Change-Id: I2a45c2a2d9a49cabcd620faa5753d39c70c1fbf6
diff --git a/generate-cookiecutter-products.groovy b/generate-cookiecutter-products.groovy
index f98251f..1fc38b3 100644
--- a/generate-cookiecutter-products.groovy
+++ b/generate-cookiecutter-products.groovy
@@ -82,117 +82,14 @@
     }
     common.warningMsg("Fetching:\n" +
         "DISTRIB_REVISION from ${distribRevision}")
-    common.infoMsg('Using context:\n')
-    print(prettyPrint(toJson(context)))
+    common.infoMsg("Using context:\n" + context)
+    print prettyPrint(toJson(context))
     return context
 
 }
 
-def generateModel(context, contextName, saltMasterName, virtualenv, modelEnv, templateEnvDir, multiModels = true) {
-    def common = new com.mirantis.mk.Common()
-    def generatedModel = multiModels ? "${modelEnv}/${contextName}" : modelEnv
-    def templateContext = readYaml text: context
-    def clusterDomain = templateContext.default_context.cluster_domain
-    def clusterName = templateContext.default_context.cluster_name
-    def outputDestination = "${generatedModel}/classes/cluster/${clusterName}"
-    def templateBaseDir = templateEnvDir
-    def templateDir = "${templateEnvDir}/dir"
-    def templateOutputDir = templateBaseDir
-    dir(templateEnvDir) {
-        if (fileExists(new File(templateEnvDir, 'tox.ini').toString())) {
-            tempContextFile = 'tempContext.yaml'
-            writeFile file: tempContextFile, text: context
-            common.warningMsg('Generating models using context:\n')
-            print(context)
-            withEnv(["CONFIG_FILE=$tempContextFile",
-                     "OUTPUT_DIR=$templateOutputDir",
-            ]) {
-                print('[Cookiecutter build] Result:\n' +
-                    sh(returnStdout: true, script: 'tox -ve generate_auto'))
-            }
-            // dropme after impelementation new format
-            sh "mkdir -p ${generatedModel}/nodes/"
-            def nodeFile = "${generatedModel}/nodes/${saltMasterName}.${clusterDomain}.yml"
-            def nodeString = """classes:
-- cluster.${clusterName}.infra.config
-parameters:
-  _param:
-    linux_system_codename: xenial
-    reclass_data_revision: master
-  linux:
-    system:
-      name: ${saltMasterName}
-      domain: ${clusterDomain}
-    """
-            writeFile(file: nodeFile, text: nodeString)
-            //
-        } else {
-            common.warningMsg("Old format: Generating model from context ${contextName}")
-            def productList = ["infra", "cicd", "kdt", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"]
-            for (product in productList) {
-                // get templateOutputDir and productDir
-                templateOutputDir = "${templateEnvDir}/output/${product}"
-                productDir = product
-                templateDir = "${templateEnvDir}/cluster_product/${productDir}"
-                // Bw for 2018.8.1 and older releases
-                if (product.startsWith("stacklight") && (!fileExists(templateDir))) {
-                    common.warningMsg("Old release detected! productDir => 'stacklight2' ")
-                    productDir = "stacklight2"
-                    templateDir = "${templateEnvDir}/cluster_product/${productDir}"
-                }
-                // generate infra unless its explicitly disabled
-                if ((product == "infra" && templateContext.default_context.get("infra_enabled", "True").toBoolean())
-                    || (templateContext.default_context.get(product + "_enabled", "False").toBoolean())) {
-
-                    common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
-
-                    sh "rm -rf ${templateOutputDir} || true"
-                    sh "mkdir -p ${templateOutputDir}"
-                    sh "mkdir -p ${outputDestination}"
-
-                    buildCookiecutterTemplate(templateDir, context, templateOutputDir, virtualenv, templateBaseDir)
-                    sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
-                } else {
-                    common.warningMsg("Product " + product + " is disabled")
-                }
-            }
-
-            def localRepositories = templateContext.default_context.local_repositories
-            localRepositories = localRepositories ? localRepositories.toBoolean() : false
-            def offlineDeployment = templateContext.default_context.offline_deployment
-            offlineDeployment = offlineDeployment ? offlineDeployment.toBoolean() : false
-            if (localRepositories && !offlineDeployment) {
-                def mcpVersion = templateContext.default_context.mcp_version
-                def aptlyModelUrl = templateContext.default_context.local_model_url
-                def ssh = new com.mirantis.mk.Ssh()
-                dir(path: modelEnv) {
-                    ssh.agentSh "git submodule add \"${aptlyModelUrl}\" \"classes/cluster/${clusterName}/cicd/aptly\""
-                    if (!(mcpVersion in ["nightly", "testing", "stable"])) {
-                        ssh.agentSh "cd \"classes/cluster/${clusterName}/cicd/aptly\";git fetch --tags;git checkout ${mcpVersion}"
-                    }
-                }
-            }
-
-            def nodeFile = "${generatedModel}/nodes/${saltMasterName}.${clusterDomain}.yml"
-            def nodeString = """classes:
-- cluster.${clusterName}.infra.config
-parameters:
-  _param:
-    linux_system_codename: xenial
-    reclass_data_revision: master
-  linux:
-    system:
-      name: ${saltMasterName}
-      domain: ${clusterDomain}
-    """
-            sh "mkdir -p ${generatedModel}/nodes/"
-            writeFile(file: nodeFile, text: nodeString)
-        }
-    }
-}
-
 timeout(time: 1, unit: 'HOURS') {
-    node('jsl-image-publisher.mcp.mirantis.net') {
+    node(slaveNode) {
         def context = globalVariatorsUpdate()
         def RequesterEmail = context.get('email_address', '')
         def templateEnv = "${env.WORKSPACE}/template"
@@ -264,13 +161,9 @@
                     if (context.get('cfg_failsafe_ssh_public_key')) {
                         writeFile file: 'failsafe-ssh-key.pub', text: context['cfg_failsafe_ssh_public_key']
                     }
-                    templateEnv
-                    if (!fileExists(new File(templateEnv, 'tox.ini').toString())) {
-                        python.setupCookiecutterVirtualenv(cutterEnv)
-                    }
+                    python.setupCookiecutterVirtualenv(cutterEnv)
                     // FIXME refactor generateModel
-                    //python.generateModel(common2.dumpYAML(['default_context': context]), 'default_context', context['salt_master_hostname'], cutterEnv, modelEnv, templateEnv, false)
-                    generateModel(common2.dumpYAML(['default_context': context]), 'default_context', context['salt_master_hostname'], cutterEnv, modelEnv, templateEnv, false)
+                    python.generateModel(common2.dumpYAML(['default_context': context]), 'default_context', context['salt_master_hostname'], cutterEnv, modelEnv, templateEnv, false)
                     git.commitGitChanges(modelEnv, "Create model ${context['cluster_name']}", "${user}@localhost", "${user}")
                 }
             }
@@ -423,7 +316,7 @@
             throw e
         } finally {
             stage('Clean workspace directories') {
-                //sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
+                sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
             }
             // common.sendNotification(currentBuild.result,"",["slack"])
         }