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)
Exemple #2
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)
Exemple #3
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)
Exemple #4
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)
    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)
    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)
Exemple #7
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)
Exemple #8
0
                    % 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:
                        rc = cache.lookup(cache_key, l_file.path, link=True)
                    else:
                        rc = cache.lookup(cache_key, l_file.path, link=False)
                    if rc:
                        self.c.log.info(
                            "The file was found in the cache and copied to %s"
                            % (l_file.path))
                        return
                    self.c.log.info("cache miss for %s" % (cache_key))
                except Exception, ex:
                    self.c.log.warn(
                        "an exception occured while performing a cache lookup on %s | %s"
                        % (cache_key, str(ex)))

            for keyword in self.adapters.keys():
                schemestring = keyword + "://"
 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)
Exemple #10
0
                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:
                        self.c.log.info(
                            "The file was found in the cache and copied to %s"
                            % (l_file.path))
                        return
                    self.c.log.info("cache miss for %s" % (cache_key))
                except Exception, ex:
                    self.c.log.warn(
                        "an exception occured while performing a cache lookup on %s | %s"
                        % (cache_key, str(ex)))

            for keyword in self.adapters.keys():
                schemestring = keyword + "://"
                scheme_len = len(schemestring)
                target_scheme = l_file._propagation_source[:scheme_len]
                    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:
                        self.c.log.info("The file was found in the cache and copied to %s" % (l_file.path))
                        return
                    self.c.log.info("cache miss for %s" % (cache_key))
                except Exception, ex:
                    self.c.log.warn("an exception occured while performing a cache lookup on %s | %s" % (cache_key, str(ex)))
                
            for keyword in self.adapters.keys():
                schemestring = keyword + "://"
                scheme_len = len(schemestring)
                target_scheme = l_file._propagation_source[:scheme_len]
                    
                if target_scheme == schemestring:
                    adapter = self.adapters[keyword]
                    
Exemple #12
0
            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:
                        rc = cache.lookup(cache_key, l_file.path, link=True)
                    else:
                        rc = cache.lookup(cache_key, l_file.path, link=False)
                    if rc:
                        self.c.log.info("The file was found in the cache and copied to %s" % (l_file.path))
                        return
                    self.c.log.info("cache miss for %s" % (cache_key))
                except Exception, ex:
                    self.c.log.warn("an exception occured while performing a cache lookup on %s | %s" % (cache_key, str(ex)))
                
            for keyword in self.adapters.keys():
                schemestring = keyword + "://"
                scheme_len = len(schemestring)
                target_scheme = l_file._propagation_source[:scheme_len]
                    
                if target_scheme == schemestring: