Upgrade OS files before Openstack

Currently applyOpenstackAppsStates and runOpenStackUpgradePhase functions
will be executed even if OS_UPGRADE and OS_DIST_UPGRADE variables are
set to 'false', althoug it is the task of previouse step.

PROD-25392 (PROD:25392)

Change-Id: I794a5e1cf1fcb65f61db8a64392595c52f2511c1
diff --git a/openstack-control-upgrade.groovy b/openstack-control-upgrade.groovy
index 2f4b2a6..f2dd78c 100644
--- a/openstack-control-upgrade.groovy
+++ b/openstack-control-upgrade.groovy
@@ -49,6 +49,21 @@
  * Stop OpenStack python services''',
     'State result': 'OpenStack python services are stopped',
   ])
+upgradeStageMap.put('Upgrade OS',
+  [
+    'Description': 'Optional step. OS packages will be upgraded during this phase, depending on the job parameters dist-upgrade might be called. And reboot of node executed.',
+    'Status': 'NOT_LAUNCHED',
+    'Expected behaviors': '''
+ * OpenStack services might flap
+ * No workload downtime
+ * The nodes might be rebooted''',
+    'Launched actions': '''
+ * Install new version of system packages
+ * If doing dist-upgrade new kernel might be installed and node rebooted
+ * System packages are updated
+ * Node might be rebooted
+'''
+  ])
 upgradeStageMap.put('Upgrade OpenStack',
    [
     'Description': 'OpenStack python code will be upgraded during this stage. No workload downtime is expected.',
@@ -70,27 +85,6 @@
  * Verified that agents/services on data plane nodes are connected to new control plane
 '''
   ])
-upgradeStageMap.put('Upgrade OS',
-  [
-    'Description': 'Optional step. OS packages will be upgraded during this phase, depending on the job parameters dist-upgrade might be called. And reboot of node executed.',
-    'Status': 'NOT_LAUNCHED',
-    'Expected behaviors': '''
- * OpenStack services might flap
- * No workload downtime
- * The nodes might be rebooted''',
-    'Launched actions': '''
- * Install new version of system packages
- * If doing dist-upgrade new kernel might be installed and node rebooted
- * Verify agents are alive/connected
- * Run basic API validation''',
-    'State result': '''
- * System packages are updated
- * Services are running
- * Basic checks around services API are passed
- * Verified that agents/services on data plane nodes are connected
- * Node might be rebooted
-'''
-  ])
 
 def stopOpenStackServices(env, target) {
     def salt = new com.mirantis.mk.Salt()
@@ -170,12 +164,6 @@
     }
 
     for (target in upgradeTargets) {
-      common.stageWrapper(upgradeStageMap, "Upgrade OpenStack", target, interactive) {
-        openstack.runOpenStackUpgradePhase(env, target, 'upgrade')
-        openstack.applyOpenstackAppsStates(env, target)
-        openstack.runOpenStackUpgradePhase(env, target, 'verify')
-      }
-
       common.stageWrapper(upgradeStageMap, "Upgrade OS", target, interactive) {
         if (OS_DIST_UPGRADE.toBoolean() == true){
           upgrade_mode = 'dist-upgrade'
@@ -184,10 +172,14 @@
         }
         if (OS_DIST_UPGRADE.toBoolean() == true || OS_UPGRADE.toBoolean() == true) {
           debian.osUpgradeNode(env, target, upgrade_mode, false)
-          openstack.applyOpenstackAppsStates(env, target)
-          openstack.runOpenStackUpgradePhase(env, target, 'verify')
         }
       }
+
+      common.stageWrapper(upgradeStageMap, "Upgrade OpenStack", target, interactive) {
+        openstack.runOpenStackUpgradePhase(env, target, 'upgrade')
+        openstack.applyOpenstackAppsStates(env, target)
+        openstack.runOpenStackUpgradePhase(env, target, 'verify')
+      }
     }
   }
 }