diff --git a/swift/common/middleware/recon.py b/swift/common/middleware/recon.py index 9e15269121..2fa8db804c 100644 --- a/swift/common/middleware/recon.py +++ b/swift/common/middleware/recon.py @@ -16,6 +16,7 @@ import errno import os +from swift import __version__ as swiftver from swift.common.swob import Request, Response from swift.common.utils import get_logger, config_true_value, json from swift.common.constraints import check_mount @@ -77,6 +78,11 @@ class ReconMiddleware(object): self.logger.exception(_('Error retrieving recon data')) return dict((key, None) for key in cache_keys) + def get_version(self): + """get swift version""" + verinfo = {'version': swiftver} + return verinfo + def get_mounted(self, openr=open): """get ALL mounted fs from /proc/mounts""" mounts = [] @@ -305,6 +311,8 @@ class ReconMiddleware(object): content = self.get_quarantine_count() elif rcheck == "sockstat": content = self.get_socket_info() + elif rcheck == "version": + content = self.get_version() else: content = "Invalid path: %s" % req.path return Response(request=req, status="404 Not Found", diff --git a/test/unit/common/middleware/test_recon.py b/test/unit/common/middleware/test_recon.py index 6c3e5474ae..8cfd8c1535 100644 --- a/test/unit/common/middleware/test_recon.py +++ b/test/unit/common/middleware/test_recon.py @@ -20,8 +20,10 @@ from posix import stat_result, statvfs_result import os import swift.common.constraints +from swift import __version__ as swiftver from swift.common.swob import Request from swift.common.middleware import recon +from swift.common.utils import json class FakeApp(object): @@ -652,6 +654,11 @@ class TestReconMiddleware(unittest.TestCase): resp = self.app(req.environ, start_response) self.assertEquals(resp, get_mem_resp) + def test_recon_get_version(self): + req = Request.blank('/recon/version', environ={'REQUEST_METHOD': 'GET'}) + resp = self.app(req.environ, start_response) + self.assertEquals(resp, [json.dumps({'version': swiftver})]) + def test_recon_get_load(self): get_load_resp = ['{"loadtest": "1"}'] req = Request.blank('/recon/load', environ={'REQUEST_METHOD': 'GET'})