Merge "Sync grains before hosts update"
diff --git a/src/com/mirantis/mk/Aws.groovy b/src/com/mirantis/mk/Aws.groovy
index 6a9c8ae..5c07193 100644
--- a/src/com/mirantis/mk/Aws.groovy
+++ b/src/com/mirantis/mk/Aws.groovy
@@ -123,14 +123,14 @@
 
                 // check for desired state
                 if (stack_info['StackStatus'] == state) {
-                    common.successMsg("Stack ${stack_name} in in state ${state}")
+                    common.successMsg("Stack ${stack_name} is in state ${state}")
                     common.prettyPrint(stack_info)
                     break
                 }
 
                 // check for failed state
                 if (state_failed.contains(stack_info['StackStatus'])) {
-                    throw new Exception("Stack ${stack_name} in in failed state")
+                    throw new Exception("Stack ${stack_name} is in failed state")
                 }
 
                 // print stack resources
diff --git a/src/com/mirantis/mk/Debian.groovy b/src/com/mirantis/mk/Debian.groovy
index 94b0598..4d7b1ee 100644
--- a/src/com/mirantis/mk/Debian.groovy
+++ b/src/com/mirantis/mk/Debian.groovy
@@ -29,7 +29,7 @@
     def imageArray = image.split(":")
     def os = imageArray[0]
     def dist = imageArray[1]
-    def img = dockerLib.getImage("tcpcloud/debian-build-${os}-${dist}:latest", image)
+    def img = dockerLib.getImage("mirantis/debian-build-${os}-${dist}:latest", image)
     def workspace = common.getWorkspace()
     def debug = env.getEnvironment().containsKey("DEBUG") && env["DEBUG"].toBoolean() ? "true" : ""
 
@@ -92,7 +92,7 @@
     def imageArray = image.split(":")
     def os = imageArray[0]
     def dist = imageArray[1]
-    def img = dockerLib.getImage("tcpcloud/debian-build-${os}-${dist}:latest", image)
+    def img = dockerLib.getImage("mirantis/debian-build-${os}-${dist}:latest", image)
     def workspace = common.getWorkspace()
 
     img.inside("-u root:root" ) {
@@ -123,7 +123,7 @@
     def imageArray = image.split(":")
     def os = imageArray[0]
     def dist = imageArray[1]
-    def img = dockerLib.getImage("tcpcloud/debian-build-${os}-${dist}:latest", image)
+    def img = dockerLib.getImage("mirantis/debian-build-${os}-${dist}:latest", image)
 
     img.inside("-u root:root") {
 
@@ -186,7 +186,7 @@
     def imageArray = image.split(":")
     def os = imageArray[0]
     def dist = imageArray[1]
-    def img = dockerLib.getImage("tcpcloud/debian-build-${os}-${dist}:latest", image)
+    def img = dockerLib.getImage("mirantis/debian-build-${os}-${dist}:latest", image)
     img.inside("-u root:root") {
         sh("""cd ${workspace} && apt-get update && apt-get install -y lintian &&
             lintian -Ii -E --pedantic --profile=${profile} ${changes}""")
diff --git a/src/com/mirantis/mk/Docker.groovy b/src/com/mirantis/mk/Docker.groovy
index 7b57e5b..796cc3c 100644
--- a/src/com/mirantis/mk/Docker.groovy
+++ b/src/com/mirantis/mk/Docker.groovy
@@ -35,7 +35,7 @@
 /**
  * Build step to build docker image.
  *
- * @param dockerHubImg     Name of image on dockerhub (ie: tcpcloud/salt-models-testing)
+ * @param dockerHubImg     Name of image on dockerhub (ie: mirantis/salt-models-testing)
  * @param defaultImg       Image to use if dockerHubImg is not found
  * @return img             Docker image
  */
diff --git a/src/com/mirantis/mk/Orchestrate.groovy b/src/com/mirantis/mk/Orchestrate.groovy
index 4c18224..b7c8b16 100644
--- a/src/com/mirantis/mk/Orchestrate.groovy
+++ b/src/com/mirantis/mk/Orchestrate.groovy
@@ -42,6 +42,7 @@
         salt.runSaltProcessStep(master, '*', 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
     }
     salt.enforceState(master, 'I@linux:network:interface', ['linux.network.interface'])
+    sleep(5)
     salt.enforceState(master, 'I@linux:system', ['linux', 'openssh', 'ntp', 'rsyslog'])
     salt.enforceState(master, '*', ['salt.minion'], true, false, null, false, 60, 2)
     sleep(5)
@@ -81,6 +82,7 @@
     salt.enforceState(master, target, ['salt.minion'], true, false, null, false, 60, 2)
     salt.enforceState(master, target, ['salt.minion'])
     salt.enforceState(master, target, ['linux.network.interface'])
+    sleep(5)
     salt.enforceState(master, target, ['linux', 'openssh', 'ntp', 'rsyslog'])
     sleep(5)
 
diff --git a/src/com/mirantis/mk/SaltModelTesting.groovy b/src/com/mirantis/mk/SaltModelTesting.groovy
index 77959db..f0921c4 100644
--- a/src/com/mirantis/mk/SaltModelTesting.groovy
+++ b/src/com/mirantis/mk/SaltModelTesting.groovy
@@ -24,7 +24,7 @@
   def saltOpts = "--retcode-passthrough --force-color"
   def common = new com.mirantis.mk.Common()
   def workspace = common.getWorkspace()
-  def img = docker.image("tcpcloud/salt-models-testing:latest")
+  def img = docker.image("mirantis/salt:saltstack-ubuntu-xenial-salt-2017.7")
   img.pull()
 
   if (!extraFormulas || extraFormulas == "") {
@@ -41,8 +41,8 @@
             "DEBUG=1", "MASTER_HOSTNAME=${masterName}", "CLUSTER_NAME=${clusterName}", "MINION_ID=${masterName}",
             "RECLASS_VERSION=${reclassVersion}", "RECLASS_IGNORE_CLASS_NOTFOUND=${ignoreClassNotfound}", "APT_REPOSITORY=${aptRepoUrl}",
             "APT_REPOSITORY_GPG=${aptRepoGPG}"]){
-
-        sh("""cp -r ${testDir}/* /srv/salt/reclass && echo '127.0.1.2  salt' >> /etc/hosts
+        sh("git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts")
+        sh("""rsync -ah ${testDir}/* /srv/salt/reclass && echo '127.0.1.2  salt' >> /etc/hosts
               cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt-mk.mirantis.com/apt.mirantis.net:8085/g' {} \\;
               cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt.mirantis.com/apt.mirantis.net:8085/g' {} \\;""")
         sh("""for s in \$(python -c \"import site; print(' '.join(site.getsitepackages()))\"); do
@@ -51,15 +51,14 @@
                 done""")
         sh("""timeout ${testTimeout} bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && configure_salt_master && configure_salt_minion && install_salt_formula_pkg'
               bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && saltservice_restart'""")
-
         sh("timeout ${testTimeout} bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && source_local_envs && saltmaster_init'")
 
-        if (!legacyTestingMode) {
+        if (!legacyTestingMode.toBoolean()) {
            sh("bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts && verify_salt_minions'")
         }
     }
 
-    if (legacyTestingMode) {
+    if (legacyTestingMode.toBoolean()) {
       common.infoMsg("Running legacy mode test for master hostname ${masterName}")
       def nodes = sh script: "find /srv/salt/reclass/nodes -name '*.yml' | grep -v 'cfg*.yml'", returnStdout: true
       for (minion in nodes.tokenize()) {