Пример #1
0
    def testDuplicateBasenames(self):
        self.resetCache()
        self.resetWork()
        self.resetRepository()
        repos = self.openRepository()
        cfg = self.cfg
        repCache = lookaside.RepositoryCache(repos, cfg=cfg)

        try:
            contentServer = rephelp.HTTPServerController(getRequester())
            contentURL = contentServer.url()

            origDir = os.getcwd()
            os.chdir(self.workDir)
            self.newpkg('test')
            os.chdir('test')
            testdir = '/'.join((self.workDir, 'test'))

            log.setVerbosity(log.INFO)
            self.logFilter.add()

            # first, look for a file that does not exist
            assert lookaside.findAll(self.cfg,
                                     repCache,
                                     contentURL + '/404/foo',
                                     'test', (testdir, ),
                                     allowNone=True) is None
            # make sure that we got a negative cache entry
            assert os.stat(self.cacheDir + '/NEGATIVE/test/404/foo')

            # now look for a file that does exist
            assert lookaside.findAll(self.cfg,
                                     repCache,
                                     contentURL + '/200/foo',
                                     'test', (testdir, ),
                                     allowNone=True) is not None
            # make sure that we got a the cache entry
            assert os.stat(self.cacheDir + '/test/200/foo')

            # put two different files with the same name name in the cache
            fooDir = os.path.join(self.cacheDir, 'test/foo.conary.com/foo/')
            os.makedirs(fooDir)
            self.writeFile(os.path.join(fooDir, 'theFile'),
                           'Foo version of the file\n')
            barDir = os.path.join(self.cacheDir, 'test/bar.conary.com/bar/')
            os.makedirs(barDir)
            self.writeFile(os.path.join(barDir, 'theFile'),
                           'Bar version of the file\n')

            # this file shouldn't be found
            path = lookaside.findAll(self.cfg,
                                     repCache,
                                     'http://baz.conary.com/foo/theFile',
                                     'test', (testdir, ),
                                     allowNone=True)
            self.assertEqual(path, None)
            # this file should be found and have the right contents
            path = lookaside.findAll(self.cfg,
                                     repCache,
                                     'http://foo.conary.com/foo/theFile',
                                     'test', (testdir, ),
                                     allowNone=True)
            f = open(path)
            self.assertEqual(f.readline()[0:3], 'Foo')
            f.close()
            # so should this one
            path = lookaside.findAll(self.cfg,
                                     repCache,
                                     'http://bar.conary.com/bar/theFile',
                                     'test', (testdir, ),
                                     allowNone=True)
            f = open(path)
            self.assertEqual(f.readline()[0:3], 'Bar')
            f.close()
        finally:
            contentServer.kill()
Пример #2
0
    def testDuplicateBasenames(self):
        self.resetCache()
        self.resetWork()
        self.resetRepository()
        repos = self.openRepository()
        cfg = self.cfg
        repCache = lookaside.RepositoryCache(repos, cfg=cfg)

        try:
            contentServer = rephelp.HTTPServerController(getRequester())
            contentURL = contentServer.url()

            origDir = os.getcwd()
            os.chdir(self.workDir)
            self.newpkg('test')
            os.chdir('test')
            testdir = '/'.join((self.workDir, 'test'))

            log.setVerbosity(log.INFO)
            self.logFilter.add()

            # first, look for a file that does not exist
            assert lookaside.findAll(self.cfg, repCache,
                    contentURL + '/404/foo', 'test', (testdir,), allowNone=True
                ) is None
            # make sure that we got a negative cache entry
            assert os.stat(self.cacheDir + '/NEGATIVE/test/404/foo')

            # now look for a file that does exist
            assert lookaside.findAll(self.cfg, repCache,
                    contentURL + '/200/foo', 'test', (testdir,), allowNone=True
                ) is not None
            # make sure that we got a the cache entry
            assert os.stat(self.cacheDir + '/test/200/foo')

            # put two different files with the same name name in the cache 
            fooDir = os.path.join(self.cacheDir,'test/foo.conary.com/foo/')
            os.makedirs(fooDir)
            self.writeFile(os.path.join(fooDir,'theFile'),
                           'Foo version of the file\n')
            barDir = os.path.join(self.cacheDir,'test/bar.conary.com/bar/')
            os.makedirs(barDir)
            self.writeFile(os.path.join(barDir,'theFile'),
                           'Bar version of the file\n')

            # this file shouldn't be found
            path = lookaside.findAll(self.cfg, repCache,
                                     'http://baz.conary.com/foo/theFile', 'test', (testdir,),
                                     allowNone=True)
            self.assertEqual(path,None)
            # this file should be found and have the right contents
            path = lookaside.findAll(self.cfg, repCache,
                                     'http://foo.conary.com/foo/theFile', 'test', (testdir,),
                                     allowNone=True)
            f = open(path)
            self.assertEqual(f.readline()[0:3],'Foo')
            f.close()
            # so should this one
            path = lookaside.findAll(self.cfg, repCache,
                                     'http://bar.conary.com/bar/theFile', 'test', (testdir,),
                                     allowNone=True)
            f = open(path)
            self.assertEqual(f.readline()[0:3],'Bar')
            f.close()
        finally:
            contentServer.kill()
Пример #3
0
    def testLookAsideTest1(self):
        raise testhelp.SkipTestException(
            "tests shouldn't talk to the internet")
        self.resetCache()
        self.resetWork()
        self.resetRepository()
        repos = self.openRepository()
        cfg = self.cfg
        repCache = lookaside.RepositoryCache(repos, cfg=cfg)

        origDir = os.getcwd()
        os.chdir(self.workDir)
        self.newpkg('test')
        os.chdir('test')
        testdir = '/'.join((self.workDir, 'test'))

        log.setVerbosity(log.INFO)
        self.logFilter.add()
        # first, look for a file that does not exist
        assert (lookaside.findAll(self.cfg,
                                  repCache,
                                  'http://example.conary.com/foo',
                                  'test', (testdir, ),
                                  allowNone=True) is None)
        # make sure that we got a negative cache entry
        assert (os.stat('/'.join(
            (self.cacheDir, 'NEGATIVE/test/example.conary.com/foo'))))

        # now make sure that this works for ftp as well (urllib workaround)
        #    XXX WORKAROUND until FTP works in eng lab
        #assert(lookaside.findAll(self.cfg, repCache,
        #    'ftp://download.rpath.com/blah', 'test', (testdir,),
        #     allowNone=True) is None)
        # make sure that we got a negative cache entry
        #assert(os.stat('/'.join((self.cacheDir,
        #                         'NEGATIVE/test/download.rpath.com/blah'))))

        # now we put a file in place
        f = file(os.sep.join((testdir, 'bar')), 'w')
        f.write('this is a test')
        f.close()
        c = lookaside.findAll(self.cfg, repCache, 'bar', 'test', (testdir, ))
        # it does not need to cache it; it is known to exist
        assert (c == os.sep.join((testdir, 'bar')))

        # Test httpHeaders:
        c = util.normpath(
            lookaside.findAll(self.cfg,
                              repCache,
                              'http://www.google.com/preferences',
                              'test', (testdir, ),
                              httpHeaders={'Accept-Language': 'es-es'}))
        assert (c == '/'.join(
            (self.cacheDir, 'test/www.google.com/preferences')))
        #open the page and check to see if it's in spanish
        f = open(c)
        contents = f.read()
        f.close()
        assert 'Preferencias globales' in contents

        # we need a web page to actually test the cache in operation
        # we do it a second time to make sure that the cache works
        for i in (0, 1):
            c = util.normpath(
                lookaside.findAll(self.cfg, repCache,
                                  'http://wiki.rpath.com/wiki/Main_Page',
                                  'test', (testdir, )))
            assert (c == '/'.join(
                (self.cacheDir, 'test/wiki.rpath.com/wiki/Main_Page')))
        self.logFilter.remove()
        self.logFilter.compare((
            '+ Trying http://example.conary.com/foo...',
            # XXX WORKAROUND until FTP works in eng lab
            #'+ Trying ftp://download.rpath.com/blah...',
            #'+ Downloading ftp://download.rpath.com/blah...',
            '+ Trying http://www.google.com/preferences...',
            '+ Downloading http://www.google.com/preferences...',
            '+ Trying http://wiki.rpath.com/wiki/Main_Page...',
            '+ Downloading http://wiki.rpath.com/wiki/Main_Page...'))

        recipestr = """
class TestLookaside(PackageRecipe):
    name = 'test'
    version = '1'
    clearBuildReqs()

    def setup(r):
        r.addSource('bar', dest='/')
"""
        self.writeFile('test.recipe', recipestr)
        self.addfile('test.recipe')
        self.addfile('bar', binary=True)
        self.commit()
        os.chdir(origDir)

        # ensure that a localOnly=True lookup in the repository works;
        # for this, we need a prepped recipeObj for its RepositoryCache
        # object
        recipeObj = self.getRecipeObjFromRepos('test', repos)
        self.logFilter.add()
        c = lookaside.findAll(self.cfg,
                              recipeObj.laReposCache,
                              'bar',
                              'test', (),
                              localOnly=True)
        self.logFilter.remove()
        self.logFilter.compare('+ found bar in repository', )
        assert (c == os.sep.join((self.cacheDir, 'test', 'bar')))
Пример #4
0
    def testLookAsideTest1(self):
        raise testhelp.SkipTestException("tests shouldn't talk to the internet")
        self.resetCache()
        self.resetWork()
        self.resetRepository()
        repos = self.openRepository()
        cfg = self.cfg
        repCache = lookaside.RepositoryCache(repos, cfg=cfg)

        origDir = os.getcwd()
        os.chdir(self.workDir)
        self.newpkg('test')
        os.chdir('test')
        testdir = '/'.join((self.workDir, 'test'))

        log.setVerbosity(log.INFO)
        self.logFilter.add()
        # first, look for a file that does not exist
        assert(lookaside.findAll(self.cfg, repCache,
            'http://example.conary.com/foo', 'test', (testdir,),
            allowNone=True) is None)
        # make sure that we got a negative cache entry
        assert(os.stat('/'.join((self.cacheDir, 'NEGATIVE/test/example.conary.com/foo'))))

        # now make sure that this works for ftp as well (urllib workaround)
        #    XXX WORKAROUND until FTP works in eng lab
        #assert(lookaside.findAll(self.cfg, repCache,
        #    'ftp://download.rpath.com/blah', 'test', (testdir,),
        #     allowNone=True) is None)
        # make sure that we got a negative cache entry
        #assert(os.stat('/'.join((self.cacheDir,
        #                         'NEGATIVE/test/download.rpath.com/blah'))))

        # now we put a file in place
        f = file(os.sep.join((testdir, 'bar')), 'w')
        f.write('this is a test')
        f.close()
        c = lookaside.findAll(self.cfg, repCache, 'bar', 'test', (testdir,))
        # it does not need to cache it; it is known to exist
        assert(c == os.sep.join((testdir, 'bar')))
        
        # Test httpHeaders:
        c = util.normpath(lookaside.findAll(self.cfg, repCache,
            'http://www.google.com/preferences', 'test', (testdir,),
            httpHeaders={'Accept-Language': 'es-es'}))
        assert(c == '/'.join((self.cacheDir, 'test/www.google.com/preferences')))
        #open the page and check to see if it's in spanish
        f = open(c)
        contents = f.read()
        f.close()
        assert 'Preferencias globales' in contents

        # we need a web page to actually test the cache in operation
        # we do it a second time to make sure that the cache works
        for i in (0, 1):
            c = util.normpath(lookaside.findAll(self.cfg, repCache,
                'http://wiki.rpath.com/wiki/Main_Page', 'test', (testdir,)))
            assert(c == '/'.join((self.cacheDir, 'test/wiki.rpath.com/wiki/Main_Page')))
        self.logFilter.remove()
        self.logFilter.compare(
            ('+ Trying http://example.conary.com/foo...',
        # XXX WORKAROUND until FTP works in eng lab
             #'+ Trying ftp://download.rpath.com/blah...',
             #'+ Downloading ftp://download.rpath.com/blah...',
             '+ Trying http://www.google.com/preferences...',
             '+ Downloading http://www.google.com/preferences...',
             '+ Trying http://wiki.rpath.com/wiki/Main_Page...',
             '+ Downloading http://wiki.rpath.com/wiki/Main_Page...'))

        recipestr = """
class TestLookaside(PackageRecipe):
    name = 'test'
    version = '1'
    clearBuildReqs()

    def setup(r):
        r.addSource('bar', dest='/')
"""
        self.writeFile('test.recipe', recipestr)
        self.addfile('test.recipe')
        self.addfile('bar', binary = True)
        self.commit()
        os.chdir(origDir)

        # ensure that a localOnly=True lookup in the repository works;
        # for this, we need a prepped recipeObj for its RepositoryCache
        # object
        recipeObj = self.getRecipeObjFromRepos('test', repos)
        self.logFilter.add()
        c = lookaside.findAll(self.cfg, recipeObj.laReposCache,
                              'bar', 'test', (), localOnly=True)
        self.logFilter.remove()
        self.logFilter.compare(
            '+ found bar in repository',
        )
        assert(c == os.sep.join((self.cacheDir, 'test', 'bar')))