def _clean_incomplete(self):
fileutil.rm_dir(self.incomingdir)
+ def do_statvfs(self):
+ return os.statvfs(self.storedir)
+
def get_stats(self):
# remember: RIStatsProvider requires that our return dict
# contains numeric values.
if self.readonly_storage:
writeable = False
try:
- s = os.statvfs(self.storedir)
+ s = self.do_statvfs()
disk_total = s.f_bsize * s.f_blocks
disk_used = s.f_bsize * (s.f_blocks - s.f_bfree)
# spacetime predictors should look at the slope of disk_used.
self.failUnless(abs(output["get"]["99_0_percentile"] - 5) < 1)
self.failUnless(abs(output["get"]["99_9_percentile"] - 5) < 1)
+class NoStatvfsServer(StorageServer):
+ def do_statvfs(self):
+ raise AttributeError
class WebStatus(unittest.TestCase):
self.failUnless("Accepting new shares: Yes" in s, s)
self.failUnless("Reserved space: - 0B" in s, s)
+ def test_status_no_statvfs(self):
+ # windows has no os.statvfs . Make sure the code handles that even on
+ # unix.
+ basedir = "storage/WebStatus/status_no_statvfs"
+ fileutil.make_dirs(basedir)
+ ss = NoStatvfsServer(basedir, "\x00" * 20)
+ w = StorageStatus(ss)
+ html = w.renderSynchronously()
+ self.failUnless("<h1>Storage Server Status</h1>" in html, html)
+ s = self.remove_tags(html)
+ self.failUnless("Accepting new shares: Yes" in s, s)
+ self.failUnless("Total disk space: ?" in s, s)
+
def test_readonly(self):
basedir = "storage/WebStatus/readonly"
fileutil.make_dirs(basedir)
# object in self.original that gets passed to render_* methods. I
# still don't understand Nevow.
- # all xhtml tags that are children of a tag with n:render="stats"
- # will be processed with this dictionary, so something like:
+ # Nevow has nevow.accessors.DictionaryContainer: Any data= directive
+ # that appears in a context in which the current data is a dictionary
+ # will be looked up as keys in that dictionary. So if data_stats()
+ # returns a dictionary, then we can use something like this:
+ #
# <ul n:data="stats">
- # <li>disk_total: <span n:data="disk_total" /></li>
+ # <li>disk_total: <span n:render="abbrev" n:data="disk_total" /></li>
# </ul>
- # will use get_stats()["storage_server.disk_total"]
- return dict([ (remove_prefix(k, "storage_server."), v)
- for k,v in self.storage.get_stats().items() ])
+
+ # to use get_stats()["storage_server.disk_total"] . However,
+ # DictionaryContainer does a raw d[] instead of d.get(), so any
+ # missing keys will cause an error, even if the renderer can tolerate
+ # None values. To overcome this, we either need a dict-like object
+ # that always returns None for unknown keys, or we must pre-populate
+ # our dict with those missing keys (or find some way to override
+ # Nevow's handling of dictionaries).
+
+ d = dict([ (remove_prefix(k, "storage_server."), v)
+ for k,v in self.storage.get_stats().items() ])
+ d.setdefault("disk_total", None)
+ d.setdefault("disk_used", None)
+ d.setdefault("reserved_space", None)
+ d.setdefault("disk_avail", None)
+ return d