From: david-sarah Date: Tue, 9 Aug 2011 19:07:22 +0000 (-0700) Subject: test_storage.py: test that we are using the filesystem of storage/shares/, rather... X-Git-Url: https://git.rkrishnan.org/about.html?a=commitdiff_plain;h=4c592f15054c5a533b1a099702bb5aa85efa8c44;p=tahoe-lafs%2Ftahoe-lafs.git test_storage.py: test that we are using the filesystem of storage/shares/, rather than storage/, to calculate remaining space, and that the HTML status output reflects the values returned by fileutil.get_disk_stats. This version works with older versions of the mock library. refs #1384 --- diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 5952eeca..81a889ed 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -2546,6 +2546,44 @@ class WebStatus(unittest.TestCase, pollmixin.PollMixin, WebRenderingMixin): self.failUnlessIn("Space Available to Tahoe: ?", s) self.failUnlessEqual(ss.get_available_space(), 0) + @mock.patch('allmydata.util.fileutil.get_disk_stats') + def test_status_right_disk_stats(self, mock_get_disk_stats): + GB = 1000000000 + total = 5*GB + free_for_root = 4*GB + free_for_nonroot = 3*GB + reserved_space = 1*GB + used = total - free_for_root + avail = max(free_for_nonroot - reserved_space, 0) + mock_get_disk_stats.return_value = { + 'total': total, + 'free_for_root': free_for_root, + 'free_for_nonroot': free_for_nonroot, + 'used': used, + 'avail': avail, + } + + basedir = "storage/WebStatus/status_right_disk_stats" + fileutil.make_dirs(basedir) + ss = StorageServer(basedir, "\x00" * 20, reserved_space=reserved_space) + expecteddir = ss.sharedir + ss.setServiceParent(self.s) + w = StorageStatus(ss) + html = w.renderSynchronously() + + self.failIf([True for args in mock_get_disk_stats.call_args_list if args != ((expecteddir, reserved_space), {})], + mock_get_disk_stats.call_args_list) + + self.failUnlessIn("

Storage Server Status

", html) + s = remove_tags(html) + self.failUnlessIn("Total disk space: 5.00 GB", s) + self.failUnlessIn("Disk space used: - 1.00 GB", s) + self.failUnlessIn("Disk space free (root): 4.00 GB", s) + self.failUnlessIn("Disk space free (non-root): 3.00 GB", s) + self.failUnlessIn("Reserved space: - 1.00 GB", s) + self.failUnlessIn("Space Available to Tahoe: 2.00 GB", s) + self.failUnlessEqual(ss.get_available_space(), 2*GB) + def test_readonly(self): basedir = "storage/WebStatus/readonly" fileutil.make_dirs(basedir)