Skip to content

Commit

Permalink
Merge "Retrieve the swift version with recon"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed May 25, 2013
2 parents 43bf568 + 7fbb97b commit 1b283d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions swift/common/middleware/recon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,6 +78,11 @@ def _from_recon_cache(self, cache_keys, cache_file, openr=open):
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 = []
Expand Down Expand Up @@ -305,6 +311,8 @@ def GET(self, req):
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",
Expand Down
7 changes: 7 additions & 0 deletions test/unit/common/middleware/test_recon.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
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):
Expand Down Expand Up @@ -652,6 +654,11 @@ def test_recon_get_mem(self):
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'})
Expand Down

0 comments on commit 1b283d4

Please sign in to comment.