Add handling special case for contrail_health module
This patch covers special case for contrail_health module, when
we have contrail-status and doctrail utilities both available on host.
This case happens during contrail upgrade procedure (3.2 -> 4.0), when
new version of contrail services have already started inside containers and
old packages with contrail-status util are still present on host.
Change-Id: Ic6ef73259544c72890913083822347d5dbd57497
Related-Prod: PROD-23325
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