Skip to content

Commit fd0a0f0

Browse files
Jenkinsopenstack-gerrit
Jenkins
authored andcommitted
Merge "Ensure empty results are returned" into milestone-proposed
2 parents 9cb0c84 + 82590da commit fd0a0f0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

swift/common/middleware/recon.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def GET(self, req):
310310
content = "Invalid path: %s" % req.path
311311
return Response(request=req, status="404 Not Found",
312312
body=content, content_type="text/plain")
313-
if content:
313+
if content is not None:
314314
return Response(request=req, body=json.dumps(content),
315315
content_type="application/json")
316316
else:

test/unit/common/middleware/test_recon.py

+27
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ def fake_mounted(self):
145145
def fake_unmounted(self):
146146
return {'unmountedtest': "1"}
147147

148+
def fake_no_unmounted(self):
149+
return []
150+
148151
def fake_diskusage(self):
149152
return {'diskusagetest': "1"}
150153

@@ -547,6 +550,21 @@ def fake_checkmount_true(*args):
547550
self.assertEquals(self.mockos.listdir_calls, [(('/srv/node/',), {})])
548551
self.assertEquals(rv, unmounted_resp)
549552

553+
def test_no_get_unmounted(self):
554+
555+
def fake_checkmount_true(*args):
556+
return True
557+
558+
unmounted_resp = []
559+
self.mockos.ls_output=[]
560+
self.mockos.path_exists_output=False
561+
real_checkmount = swift.common.constraints.check_mount
562+
swift.common.constraints.check_mount = fake_checkmount_true
563+
rv = self.app.get_unmounted()
564+
swift.common.constraints.check_mount = real_checkmount
565+
self.assertEquals(self.mockos.listdir_calls, [(('/srv/node/',), {})])
566+
self.assertEquals(rv, unmounted_resp)
567+
550568
def test_get_diskusage(self):
551569
#posix.statvfs_result(f_bsize=4096, f_frsize=4096, f_blocks=1963185,
552570
# f_bfree=1113075, f_bavail=1013351, f_files=498736,
@@ -778,10 +796,19 @@ def test_recon_get_mounted(self):
778796

779797
def test_recon_get_unmounted(self):
780798
get_unmounted_resp = ['{"unmountedtest": "1"}']
799+
self.app.get_unmounted = self.frecon.fake_unmounted
781800
req = Request.blank('/recon/unmounted',
782801
environ={'REQUEST_METHOD': 'GET'})
783802
resp = self.app(req.environ, start_response)
784803
self.assertEquals(resp, get_unmounted_resp)
804+
805+
def test_recon_no_get_unmounted(self):
806+
get_unmounted_resp = '[]'
807+
self.app.get_unmounted = self.frecon.fake_no_unmounted
808+
req = Request.blank('/recon/unmounted',
809+
environ={'REQUEST_METHOD': 'GET'})
810+
resp = ''.join(self.app(req.environ, start_response))
811+
self.assertEquals(resp, get_unmounted_resp)
785812

786813
def test_recon_get_diskusage(self):
787814
get_diskusage_resp = ['{"diskusagetest": "1"}']

0 commit comments

Comments
 (0)