Merge "Fix condition for haproxy opencontrail tagdrop"
diff --git a/_modules/contrail_health.py b/_modules/contrail_health.py
index 59530e6..750cd8c 100644
--- a/_modules/contrail_health.py
+++ b/_modules/contrail_health.py
@@ -12,17 +12,22 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+import logging
 import os
 import subprocess
 
 
+MODULE_NAME = 'contrail_health'
+LOG = logging.getLogger(__name__)
+
+
 def __virtual__():
     '''
     Only load this module if contrail-status or doctrail utility
     (in case of containerized contrail version) is available.
     '''
     if _is_cmd_available('contrail-status') or _is_cmd_available('doctrail'):
-        return 'contrail_health'
+        return MODULE_NAME
     return False
 
 
@@ -39,19 +44,37 @@
 
 
 def get_services_status():
+    cs_out = None
 
     if _is_cmd_available('contrail-status'):
-        status_cmd_list = ['contrail-status']
-    else:
-        status_cmd_list = ['doctrail', 'all', 'contrail-status']
+        LOG.info('Trying to get status of contrail services '
+                 'using contrail-status utility on host ...')
+        try:
+            cs_out = str(subprocess.check_output(['contrail-status']))
+        except subprocess.CalledProcessError as e:
+            LOG.warn('Status of contrail services cannot be checked '
+                     'by contrail-status utility from host')
+    if cs_out is None and _is_cmd_available('doctrail'):
+        LOG.info('Trying to get status of contrail services inside containers '
+                 'using doctrail utility ...')
+        try:
+            cs_out = str(subprocess.check_output(
+                ['doctrail', 'all', 'contrail-status'])
+            )
+        except subprocess.CalledProcessError as e:
+            LOG.warn('Status of contrail services inside containers cannot '
+                     'be checked by contrail-status utility via doctrail cmd')
 
-    cs_out = str(subprocess.check_output(status_cmd_list))
     status_map = {}
 
-    for line in cs_out.split('\n'):
-        line_list = line.split()
-        if (not line.startswith("==") and "FOR NODE" not in line and
-                len(line_list) >= 2):
-            status_map[line_list[0].split(":")[0]] = line_list[1]
+    if cs_out:
+        for line in cs_out.split('\n'):
+            line_list = line.split()
+            if (not line.startswith("==") and "FOR NODE" not in line and
+                    len(line_list) >= 2):
+                status_map[line_list[0].split(":")[0]] = line_list[1]
+    else:
+        LOG.error('Status of contrail services cannot be checked '
+                  'by {0} module.'.format(MODULE_NAME))
 
     return status_map
diff --git a/_states/contrail_health.py b/_states/contrail_health.py
index fdd1f48..c6c4202 100644
--- a/_states/contrail_health.py
+++ b/_states/contrail_health.py
@@ -49,7 +49,7 @@
             result = True
 
     else:
-        comment = ("Contrail services were not found.\n"
+        comment = ("Contrail services states could not be verified.\n"
                    "If contrail services are working inside container(s) "
                    "(starting from version 4.0), please check "
                    "that related container(s) is (are) started.")
diff --git a/metadata/service/control/cluster.yml b/metadata/service/control/cluster.yml
index dedcc1f..aae62cf 100644
--- a/metadata/service/control/cluster.yml
+++ b/metadata/service/control/cluster.yml
@@ -68,6 +68,13 @@
         id: 2
       - host: ${_param:cluster_node03_address}
         id: 3
+      services_extra_states:
+        contrail-schema:
+        - backup
+        contrail-svc-monitor:
+        - backup
+        contrail-device-manager:
+        - backup
     control:
       version: ${_param:opencontrail_version}
       enabled: true