From 769f9d3cd76c343fda337f60a293659af607d582 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 27 Mar 2017 15:42:03 -0400 Subject: [PATCH] Add version string to status string Sometimes debugging puppet deployment issues is difficult without knowing exactly which version of the code is actually running. To help debug automated deployment issues being able to query the exact version running is useful. This commit does this by adding the version string to the /status response so we can easily tell which version is running. Change-Id: I4a26cf097cd1efc9962911e7b5824eb6b8b2f5d9 --- openstack_health/api.py | 13 +++++++---- openstack_health/tests/test_api.py | 37 ++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/openstack_health/api.py b/openstack_health/api.py index 80e4f172..277933f7 100644 --- a/openstack_health/api.py +++ b/openstack_health/api.py @@ -32,6 +32,7 @@ from flask import make_response from flask import request from flask_jsonpify import jsonify from operator import itemgetter +from pbr import version import pyelasticsearch import pytz from sqlalchemy import create_engine @@ -651,10 +652,14 @@ def get_status(): is_db_available = _check_db_availability() is_er_available = _check_er_availability() - status = {'status': {'availability': { - 'database': is_db_available, - 'elastic-recheck': is_er_available - }}} + status = {'status': { + 'availability': { + 'database': is_db_available, + 'elastic-recheck': is_er_available, + }, + 'version': version.VersionInfo( + 'openstack_health').version_string_with_vcs() + }} response = jsonify(status) if not is_db_available: diff --git a/openstack_health/tests/test_api.py b/openstack_health/tests/test_api.py index 47457406..c0fa668a 100644 --- a/openstack_health/tests/test_api.py +++ b/openstack_health/tests/test_api.py @@ -21,6 +21,7 @@ from dateutil import parser as date_parser import feedparser import mock import numpy +from pbr import version import six from subunit2sql.db import models @@ -686,10 +687,14 @@ class TestRestAPI(base.TestCase): return_value='NotInstalled') def test_get_status_failure_er_not_installed(self, status_check_mock, er_mock): - expected_response = {'status': {'availability': { - 'database': False, - 'elastic-recheck': 'NotInstalled' - }}} + expected_response = {'status': { + 'availability': { + 'database': False, + 'elastic-recheck': 'NotInstalled' + }, + 'version': version.VersionInfo( + 'openstack_health').version_string_with_vcs() + }} response = self.app.get('/status') self.assertEqual(response.status_code, 500) self.assertEqual(json.loads(response.data.decode('utf-8')), @@ -701,10 +706,14 @@ class TestRestAPI(base.TestCase): return_value='NotConfigured') def test_get_db_status_success_er_not_configured(self, status_check_mock, er_mock): - expected_response = {'status': {'availability': { - 'database': True, - 'elastic-recheck': 'NotConfigured' - }}} + expected_response = {'status': { + 'availability': { + 'database': True, + 'elastic-recheck': 'NotConfigured' + }, + 'version': version.VersionInfo( + 'openstack_health').version_string_with_vcs() + }} response = self.app.get('/status') self.assertEqual(response.status_code, 200) output = json.loads(response.data.decode('utf-8')) @@ -715,10 +724,14 @@ class TestRestAPI(base.TestCase): @mock.patch('openstack_health.api._check_er_availability', return_value={'Configured': {'elastic-search': 'green'}}) def test_get_db_status_success_er_green(self, status_check_mock, er_mock): - expected_response = {'status': {'availability': { - 'database': True, - 'elastic-recheck': {'Configured': {'elastic-search': 'green'}} - }}} + expected_response = {'status': { + 'availability': { + 'database': True, + 'elastic-recheck': {'Configured': {'elastic-search': 'green'}} + }, + 'version': version.VersionInfo( + 'openstack_health').version_string_with_vcs() + }} response = self.app.get('/status') self.assertEqual(response.status_code, 200) output = json.loads(response.data.decode('utf-8'))