mirror-image updates

  * Check exit code from salt states

EME-372

Change-Id: Ie92f0487d2ee353488925f5129479492895118e0
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