Merge "Fixing finalize step for infrastructure nodes with glusterfs."
diff --git a/cloud-deploy-pipeline.groovy b/cloud-deploy-pipeline.groovy
index a37a655..c2f9351 100644
--- a/cloud-deploy-pipeline.groovy
+++ b/cloud-deploy-pipeline.groovy
@@ -579,7 +579,17 @@
 
             stage('Finalize') {
                 if (common.checkContains('STACK_INSTALL', 'finalize')) {
-                    salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
+                    def gluster_compound = 'I@glusterfs:server'
+                    // Enforce highstate asynchronous only on the nodes which are not glusterfs servers
+                    salt.enforceHighstate(venvPepper, '* and not ' + gluster_compound)
+                    // Iterate over nonempty set of gluster servers and apply highstates one by one
+                    // TODO: switch to batch once salt 2017.7+ would be used
+                    def glusterMinions = salt.getMinionsSorted(venvPepper, gluster_compound)
+                    if ( !glusterMinions.isEmpty() ) {
+                        for ( target in glusterMinions ) {
+                            salt.enforceHighstate(venvPepper, target)
+                        }
+                    }
                 }
 
                 outputsPretty = common.prettify(outputs)