Example #1
0
    def test_touch_expulsion(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums) - 1):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            time.sleep(1.1)
            self.assertEqual(rc, True)
        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        print cache.list_cache()
        rc = cache.lookup(work_sums[0], newfile)
        self.assertEqual(rc, True)
        print cache.list_cache()
        sum = work_sums[i]
        rc = cache.add(self._work_file, work_sums[len(work_sums) - 1])
        self.assertEqual(rc, True)

        list = cache.list_cache()
        self.assertEqual(len(list), 3)
        print list
        print work_sums
        self.assertTrue(work_sums[0] in list)
        self.assertTrue(work_sums[1] not in list)
Example #2
0
 def test_noroom(self):
     sz1 = os.path.getsize(self._work_file)
     max = sz1 - 1
     cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
     try:
         cache.add(self._work_file, self._work_sum)
         passes = False
     except:
         passes = True
     self.assertTrue(passes)
Example #3
0
 def test_noroom(self):
     sz1 = os.path.getsize(self._work_file)
     max = sz1 - 1
     cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
     try:
         cache.add(self._work_file, self._work_sum)
         passes = False
     except:
         passes = True
     self.assertTrue(passes)
Example #4
0
    def test_exceedsize(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
Example #5
0
    def test_exceedsize(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
Example #6
0
    def test_touch_expulsion(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums) - 1):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            time.sleep(1.1)
            self.assertEqual(rc, True)
        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        print cache.list_cache()
        rc = cache.lookup(work_sums[0], newfile)
        self.assertEqual(rc, True)
        print cache.list_cache()
        sum = work_sums[i]
        rc = cache.add(self._work_file, work_sums[len(work_sums) - 1])
        self.assertEqual(rc, True)

        list = cache.list_cache()
        self.assertEqual(len(list), 3)
        print list
        print work_sums
        self.assertTrue(work_sums[0] in list)
        self.assertTrue(work_sums[1] not in list)
Example #7
0
    def test_flush_cache(self):
        work_sums = ["1", "XX", "III", "four"]

        cache = WSCCacheObj(self._dir, self.lockfilepath)
        for sum in work_sums:
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
        cache.flush_cache()

        list = cache.list_cache()
        self.assertEqual(len(list), 0)
Example #8
0
    def test_correct_expulsion(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            time.sleep(1.1)
            self.assertEqual(rc, True)

        list = cache.list_cache()
        self.assertEqual(len(list), 3)
        self.assertTrue(work_sums[0] not in list)
Example #9
0
    def test_correct_expulsion(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            rc = cache.add(self._work_file, sum)
            time.sleep(1.1)
            self.assertEqual(rc, True)

        list = cache.list_cache()
        self.assertEqual(len(list), 3)
        self.assertTrue(work_sums[0] not in list)
Example #10
0
    def test_basic_sequence(self):
        cache = WSCCacheObj(self._dir, self.lockfilepath)
        rc = cache.add(self._work_file, self._work_sum)
        self.assertEqual(rc, True)

        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        rc = cache.lookup(self._work_sum, newfile)
        self.assertEqual(rc, True)

        rc = filecmp.cmp(newfile, self._work_file)
        self.assertEqual(rc, 1)

        rc = cache.remove(self._work_sum)
        self.assertEqual(rc, True)
Example #11
0
    def test_lookupmiss(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            time.sleep(1.1)
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        rc = cache.lookup(work_sums[0], newfile)
        self.assertEqual(rc, False)
Example #12
0
    def test_basic_sequence(self):
        cache = WSCCacheObj(self._dir, self.lockfilepath)
        rc = cache.add(self._work_file, self._work_sum)
        self.assertEqual(rc, True)

        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        rc = cache.lookup(self._work_sum, newfile)
        self.assertEqual(rc, True)

        rc = filecmp.cmp(newfile, self._work_file)
        self.assertEqual(rc, 1)

        rc = cache.remove(self._work_sum)
        self.assertEqual(rc, True)
Example #13
0
    def test_lookupmiss(self):
        sz1 = os.path.getsize(self._work_file)
        work_sums = ["1", "XX", "III", "four"]
        max = sz1 * (len(work_sums) - 1)

        cache = WSCCacheObj(self._dir, self.lockfilepath, max_size=max)
        for i in range(0, len(work_sums)):
            sum = work_sums[i]
            time.sleep(1.1)
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
        (osf, newfile) = tempfile.mkstemp()
        os.close(osf)
        rc = cache.lookup(work_sums[0], newfile)
        self.assertEqual(rc, False)
Example #14
0
    def test_list_cache(self):
        work_sums = ["1", "XX", "III", "four"]

        cache = WSCCacheObj(self._dir, self.lockfilepath)
        for sum in work_sums:
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)

        count = 0
        first_len = len(work_sums)
        list = cache.list_cache()
        for l in list:
            work_sums.remove(l)
            count = count + 1

        self.assertEqual(len(work_sums), 0)
        self.assertEqual(count, first_len)
Example #15
0
    def test_list_cache(self):
        work_sums = ["1", "XX", "III", "four"]

        cache = WSCCacheObj(self._dir, self.lockfilepath)
        for sum in work_sums:
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)

        count = 0
        first_len = len(work_sums)
        list = cache.list_cache()
        for l in list:
            work_sums.remove(l)
            count = count + 1

        self.assertEqual(len(work_sums), 0)
        self.assertEqual(count, first_len)
Example #16
0
    def test_flush_cache(self):
        work_sums = ["1", "XX", "III", "four"]

        cache = WSCCacheObj(self._dir, self.lockfilepath)
        for sum in work_sums:
            rc = cache.add(self._work_file, sum)
            self.assertEqual(rc, True)
        cache.flush_cache()

        list = cache.list_cache()
        self.assertEqual(len(list), 0)
Example #17
0
        cache_key = self.p.get_arg_or_none(wc_args.CACHECKSUM)
        try:
            cache_path = self._validate_securelocaldir("cachedir")
        except Exception, ex:
            self.c.log.warn("failure validating cache path | %s" % (str(ex)))
            cache_path = None
        cache = None
        if cache_key and cache_path:
            try:
                max_size = self.p.get_conf_or_none("images", "cache_size")
                if max_size is not None:
                    max_size = int(max_size)
                lockfile = self.p.get_conf_or_none("images", "cachelockfile")
                if lockfile is None:
                    lockfile = os.path.join(cache_path, "lock")
                cache = WSCCacheObj(cache_path, lockfile, max_size=max_size, log=self.c.log)
            except ValueError:
                raise InvalidConfig("The images->cache_size configuration is not an integer: '%s'" % max_size)
            except Exception, ex:
                self.c.log.warn("failed to create the cache at %s | %s" % (cache_path, str(ex)))
                
        for l_file in l_files:
            
            if not l_file._propagate_needed:
                continue

            if cache:
                cow = self.p.get_conf_or_none("cow", "qemu_img")
                try:
                    self.c.log.debug("cache lookup %s" % (cache_key))
                    if cow is not None:
Example #18
0
 def test_add_twice(self):
     cache = WSCCacheObj(self._dir, self.lockfilepath)
     rc = cache.add(self._work_file, self._work_sum)
     self.assertEqual(rc, True)
     rc = cache.add(self._work_file, self._work_sum)
     self.assertEqual(rc, False)
Example #19
0
 def test_lookup_fail(self):
     cache = WSCCacheObj(self._dir, self.lockfilepath)
     (osf, newfile) = tempfile.mkstemp()
     os.close(osf)
     rc = cache.lookup(self._work_sum, newfile)
     self.assertEqual(rc, False)
Example #20
0
 def test_remove_fail(self):
     cache = WSCCacheObj(self._dir, self.lockfilepath)
     rc = cache.remove(self._work_sum)
     self.assertEqual(rc, False)
Example #21
0
 def test_lookup_fail(self):
     cache = WSCCacheObj(self._dir, self.lockfilepath)
     (osf, newfile) = tempfile.mkstemp()
     os.close(osf)
     rc = cache.lookup(self._work_sum, newfile)
     self.assertEqual(rc, False)
Example #22
0
 def test_add_twice(self):
     cache = WSCCacheObj(self._dir, self.lockfilepath)
     rc = cache.add(self._work_file, self._work_sum)
     self.assertEqual(rc, True)
     rc = cache.add(self._work_file, self._work_sum)
     self.assertEqual(rc, False)
Example #23
0
 def test_remove_fail(self):
     cache = WSCCacheObj(self._dir, self.lockfilepath)
     rc = cache.remove(self._work_sum)
     self.assertEqual(rc, False)
Example #24
0
        cache_key = self.p.get_arg_or_none(wc_args.CACHECKSUM)
        try:
            cache_path = self._validate_securelocaldir("cachedir")
        except Exception, ex:
            self.c.log.warn("failure validating cache path | %s" % (str(ex)))
            cache_path = None
        cache = None
        if cache_key and cache_path:
            try:
                max_size = self.p.get_conf_or_none("images", "cache_size")
                if max_size is not None:
                    max_size = int(max_size)
                lockfile = self.p.get_conf_or_none("images", "cachelockfile")
                if lockfile is None:
                    lockfile = os.path.join(cache_path, "lock")
                cache = WSCCacheObj(cache_path, lockfile, max_size=max_size, log=self.c.log)
            except ValueError:
                raise InvalidConfig("The images->cache_size configuration is not an integer: '%s'" % max_size)
            except Exception, ex:
                self.c.log.warn("failed to create the cache at %s | %s" % (cache_path, str(ex)))
                
        for l_file in l_files:
            
            if not l_file._propagate_needed:
                continue

            if cache:
                try:
                    self.c.log.debug("cache lookup %s" % (cache_key))
                    rc = cache.lookup(cache_key, l_file.path)
                    if rc:
Example #25
0
        try:
            cache_path = self._validate_securelocaldir("cachedir")
        except Exception, ex:
            self.c.log.warn("failure validating cache path | %s" % (str(ex)))
            cache_path = None
        cache = None
        if cache_key and cache_path:
            try:
                max_size = self.p.get_conf_or_none("images", "cache_size")
                if max_size is not None:
                    max_size = int(max_size)
                lockfile = self.p.get_conf_or_none("images", "cachelockfile")
                if lockfile is None:
                    lockfile = os.path.join(cache_path, "lock")
                cache = WSCCacheObj(cache_path,
                                    lockfile,
                                    max_size=max_size,
                                    log=self.c.log)
            except ValueError:
                raise InvalidConfig(
                    "The images->cache_size configuration is not an integer: '%s'"
                    % max_size)
            except Exception, ex:
                self.c.log.warn("failed to create the cache at %s | %s" %
                                (cache_path, str(ex)))

        for l_file in l_files:

            if not l_file._propagate_needed:
                continue

            if cache: