Merge "mirror-image updates"
diff --git a/mirror-image/run.example.sh b/mirror-image/run.example.sh
index f1161ac..cab6393 100644
--- a/mirror-image/run.example.sh
+++ b/mirror-image/run.example.sh
@@ -23,9 +23,9 @@
 
 BINARY_MCP_VERSION="nightly"
 export UBUNTU_BASEURL="http://mirror.mirantis.com/${BINARY_MCP_VERSION}/ubuntu/"
-export SALTSTACK_REPO="http://apt.mirantis.com/xenial/salt/2016.3/ ${BINARY_MCP_VERSION} main"
+export SALTSTACK_REPO="http://mirror.mirantis.com/${BINARY_MCP_VERSION}/saltstack-2017.7/xenial xenial main"
+export SALTSTACK_GPG="http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2017.7/SALTSTACK-GPG-KEY.pub"
 export APT_MIRANTIS_GPG="http://apt.mirantis.com/public.gpg"
-export SALTSTACK_GPG="${APT_MIRANTIS_GPG}"
 export APT_MIRANTIS_SALT_REPO="http://apt.mirantis.com/xenial/ ${BINARY_MCP_VERSION} salt "
 #
 export GIT_SALT_FORMULAS_SCRIPTS="https://github.com/salt-formulas/salt-formulas-scripts.git"
diff --git a/mirror-image/scripts/mirrors.sh b/mirror-image/scripts/mirrors.sh
index fe7101f..764597a 100644
--- a/mirror-image/scripts/mirrors.sh
+++ b/mirror-image/scripts/mirrors.sh
@@ -1,19 +1,22 @@
 #!/bin/bash -xe
 
+SALT_OPTS="-l debug -t 10 --retcode-passthrough --no-color"
+
 #aptly
-salt-call -t 5 --no-color state.sls aptly.server
-salt-call -t 5 --no-color state.sls aptly.publisher
-salt-call -t 5 --no-color state.sls aptly
-salt-call -t 5 --retcode-passthrough --no-color state.sls aptly
+# FIXME: remove duplicate run after fix: PROD-21387
+# RC: aptly may fail to import gpg key's randomly(most probably,nw issue), so lets run it twice
+salt-call ${SALT_OPTS} state.sls aptly.server || salt-call ${SALT_OPTS} state.sls aptly.server
+salt-call ${SALT_OPTS} state.sls aptly.publisher
+salt-call ${SALT_OPTS} state.sls aptly || salt-call ${SALT_OPTS} state.sls aptly
 aptly_mirror_update.sh -sv
 aptly-publisher --url http://10.99.0.1:18084 --timeout=1200 publish -v -d -c /etc/aptly-publisher.yaml --architectures amd64 --recreate --force-overwrite
 
 #docker registry
-salt-call -t 5 --retcode-passthrough state.sls docker.client.registry
-docker system prune --all --force
+salt-call ${SALT_OPTS} state.sls docker.client.registry
+docker system prune --all --force || true
 
 #debmirror
-salt-call -t 5 --no-color state.sls debmirror
+salt-call ${SALT_OPTS} state.sls debmirror
 
 #git
-salt-call -t 5 --retcode-passthrough --no-color state.sls git.server
+salt-call ${SALT_OPTS} state.sls git.server
diff --git a/mirror-image/scripts/salt.sh b/mirror-image/scripts/salt.sh
index 613352a..9655ec0 100644
--- a/mirror-image/scripts/salt.sh
+++ b/mirror-image/scripts/salt.sh
@@ -1,16 +1,19 @@
 #!/bin/bash -xe
 
+SALT_OPTS="-l debug -t 10 --retcode-passthrough --no-color"
+
 echo "deb [arch=amd64] ${APT_MIRANTIS_SALT_REPO}" > /etc/apt/sources.list.d/mcp_salt.list
 apt-get update
 apt-get install salt-formula* -y
 salt-call saltutil.refresh_pillar
 salt-call saltutil.sync_all
-salt-call -t 5 --retcode-passthrough --no-color state.sls salt
-salt-call -t 5 --retcode-passthrough --no-color state.sls linux.system.repo,linux.system.directory,linux.system.package
-salt-call -t 5 --retcode-passthrough --no-color state.sls linux.system.file
-salt-call -t 5 --retcode-passthrough --no-color state.sls docker.host
-salt-call -t 5 --retcode-passthrough --no-color state.sls docker exclude=docker.client.registry
+
+salt-call ${SALT_OPTS} state.sls salt
+salt-call ${SALT_OPTS} state.sls linux.system.repo,linux.system.directory,linux.system.package
+salt-call ${SALT_OPTS} state.sls linux.system.file
+salt-call ${SALT_OPTS} state.sls docker.host
+salt-call ${SALT_OPTS} state.sls docker exclude=docker.client.registry
 sleep 120
-salt-call -t 5 --retcode-passthrough --no-color state.sls linux.network
-salt-call -t 5 --retcode-passthrough --no-color state.sls nginx
-salt-call -t 5 --retcode-passthrough --no-color state.sls maas.mirror
+salt-call ${SALT_OPTS} state.sls linux.network
+salt-call ${SALT_OPTS} state.sls nginx
+salt-call ${SALT_OPTS} state.sls maas.mirror
diff --git a/mirror-image/template.json b/mirror-image/template.json
index 48045c1..5b942d0 100644
--- a/mirror-image/template.json
+++ b/mirror-image/template.json
@@ -161,7 +161,7 @@
       "headless": true,
       "ssh_username": "{{user `user`}}",
       "ssh_password": "{{user `password`}}",
-      "shutdown_command": "sync; shutdown -P now",
+      "shutdown_command": "sync ; shutdown -P now",
       "vnc_bind_address": "0.0.0.0",
       "vnc_port_max": "5956",
       "vnc_port_min": "5956",