def trial(num_bins=1, size_bin=500, after_rm=None, max_delta=0.05): from sh import imgbase, rm, ls def img_free(): return float(imgbase("layout", "--free-space")) imgbase = imgbase.bake("--debug") a = img_free() [dd(B, size_bin) for B in iter(range(0, num_bins))] print("Files which were created") print(ls("-shal", *glob.glob("/var/tmp/*.bin"))) b = img_free() print("Files are getting removed") rm("-f", *glob.glob("/var/tmp/*.bin")) after_rm() c = img_free() ratio = a / c print(a, b, c, ratio) delta = 1 - ratio assert delta < max_delta, \ "Delta %s is larger than %s" % (delta, max_delta)
def test_basic(self): from sh import imgbase, touch # All subsequent imgbase calls include the debug arg imgbase = imgbase.bake("--debug") assert "Image-0.0" in imgbase.layout() assert "Image-0.1" in imgbase.layout() log(imgbase.layer("--add")) assert "Image-0.2" in imgbase.layer("--latest") touch("/root/marker") touch("/var/tmp/marker") diff = imgbase("--debug", "diff", "Image-0.1", "Image-0.2") print(diff) assert "/root/marker" in diff assert "/var/tmp/marker" not in diff
def test_imgbase(self): from sh import imgbase, lvm # All subsequent imgbase calls include the debug arg imgbase = imgbase.bake("--debug") log("Using %s" % imgbase) log(imgbase("--version")) log("Existing LVM layout") log(lvm.pvs()) log(lvm.vgs()) log(lvm.lvs()) assert "HostVG" in lvm.vgs() assert "Image-0.0" in imgbase.layout() # Check that a current layer exists imgbase.layer("--current")
def trial(num_bins=1, size_bin=500, after_rm=None, max_delta=0.05): from sh import imgbase, rm, ls imgbase = imgbase.bake("--debug") img_free = lambda: float(imgbase("layout", "--free-space")) a = img_free() [dd(B, size_bin) for B in iter(range(0, num_bins))] print("Files which were created") print(ls("-shal", *glob.glob("/var/tmp/*.bin"))) b = img_free() print("Files are getting removed") rm("-f", *glob.glob("/var/tmp/*.bin")) after_rm() c = img_free() ratio = a / c print(a, b, c, ratio) delta = 1 - ratio assert delta < max_delta, \ "Delta %s is larger than %s" % (delta, max_delta)