示例#1
0
文件: __init__.py 项目: sweptr/conary
 def run(*args, **kwargs):
     try:
         __import__('rpm')
         requireChroot()
     except ImportError:
         raise testhelp.SkipTestException('RPM module not present')
     except ChrootError:
         raise testhelp.SkipTestException(
             '"sudo setcap cap_sys_chroot=ep /usr/bin/python" to run RPM module tests'
         )
     else:
         return func(*args, **kwargs)
示例#2
0
    def testSSLxmlrpc(self):
        self.openRepository()
        if self.cfg.proxy:
            raise testhelp.SkipTestException(
                'Cannot test squid proxy when another proxy is being used')
        if not os.path.exists(rephelp.HTTPProxy.proxyBinPath):
            raise testhelp.SkipTestException(
                'testSSLxmlrpc depends on squid being installed')

        h = rephelp.HTTPProxy(os.path.join(self.workDir, "http-cache"))
        proxyUri = h.start()

        try:
            h.updateConfig(self.cfg)
            self.cfg.proxy['http'] = self.cfg.proxy['http'].replace(
                'localhost', '127.0.0.1')
            self.cfg.proxy['https'] = self.cfg.proxy['https'].replace(
                'localhost', '127.0.0.1')
            httputils.LocalHosts.remove('127.0.0.1')
            httputils.LocalHosts.remove('localhost')

            self.stopRepository(1)
            self.openRepository(1, useSSL=True)
            try:

                # We cannot have an HTTP proxy and a Conary proxy chained together.
                # (we can have a client talking to a Conary proxy that talks to a repo
                # via an HTTP proxy)
                self.cfg.conaryProxy = {}
                repos = conaryclient.ConaryClient(self.cfg).getRepos()

                logsz0 = h.getAccessLogSize()
                versions = repos.c['localhost1'].checkVersion()
                logEntry = h.getAccessLogEntry(logsz0)
                self.assertTrue(logEntry)
                self.assertTrue('CONNECT' in logEntry,
                                "CONNECT not in %s" % logEntry)

                logsz1 = h.getAccessLogSize()
                versions = repos.c['localhost1'].checkVersion()
                # Wait for a second, make sure the proxy's log file did increase
                self.sleep(1)
                logsz2 = h.getAccessLogSize()
                self.assertFalse(logsz1 == logsz2)
            finally:
                httputils.LocalHosts.add('127.0.0.1')
                httputils.LocalHosts.add('localhost')
                self.stopRepository(1)

        finally:
            h.stop()
示例#3
0
文件: utiltest.py 项目: sweptr/conary
    def testLZMAFile(self):
        # CNY-3564 - test for short reads
        xzbin = "/usr/bin/xz"
        if not os.path.exists(xzbin):
            raise testhelp.SkipTestException(
                "Skipping test, %s not found" % xzbin)
        fobj = tempfile.TemporaryFile()
        p = subprocess.Popen([xzbin, "-zc"],
            stdin=subprocess.PIPE, stdout=fobj)
        data = "0" * 1024
        for i in range(1024):
            p.stdin.write(data)
        p.stdin.close()
        p.wait()
        fobj.flush()

        # Make sure something did get written
        self.assertTrue(fobj.tell() > 0)
        fobj.seek(0)

        b = util.LZMAFile(fobj)
        # Read a large amount of data, hopefully larger than the pipe buffer
        limit = 128000
        buf = b.read(limit)
        self.assertEqual(len(buf), limit)
        self.assertEqual(list(set(buf)), ["0"])
示例#4
0
文件: webtest.py 项目: tensor5/conary
    def testBrowseDistributedShadow(self):
        raise testhelp.SkipTestException("Fails periodically in automated tests")
        self.openRepository(1)
        v = '/localhost@rpl:1/1.0-1'
        self.addComponent('test:source', v)
        self.mkbranch(v, 'localhost1@rpl:1', 'test:source', shadow = True)

        # use the second repository for the test
        self.useServer(1)
        # first view the troveInfo page for test:source
        page = self.assertContent('/troveInfo?t=test:source', code=[200],
                                  content = '<a href="files?t=test:source')

        # get the "show files' link
        dom = page.getDOM()
        filesLink = None
        for anchor in dom.getByName('a'):
            if 'Show Files' in anchor.getContents():
                filesLink = anchor
                break
        if not filesLink:
            raise RuntimeError('could not find "Show Files" link')
        # get the link to pull down the contents
        page = self.assertContent('/' + filesLink.href, code=[200],
                                  content = '/contents0')
        dom = page.getDOM()
        contentsLink = None
        for anchor in dom.getByName('a'):
            if '/contents0' in anchor.getContents():
                contentsLink = anchor
                break
        # pull down the contents
        page = self.assertContent('/' + contentsLink.href, code=[200],
                                  content = 'hello, world!')
示例#5
0
文件: webtest.py 项目: tensor5/conary
    def testTroveInfo(self):
        raise testhelp.SkipTestException("Fails periodically in automated tests")
        self.addQuickTestComponent('test:runtime', '3.0-1-1', filePrimer=3,
                                   buildTime=None)

        page = self.assertContent('/troveInfo?t=test:runtime', code=[200],
                                  content = 'trove: test:runtime')

        # check to make sure that buildtime is represented properly when
        # no buildtime is set in troveinfo (CNY-990)
        self.assertTrue('<td>Build time:</td><td>(unknown)' in page.body,
                        'Expected build time to be (unknown)')

        dom = page.getDOM()
        filesLink = None
        for anchor in dom.getByName('a'):
            contents = anchor.getContents()
            if len(contents) and 'Show Files' in contents[0]:
                filesLink = anchor
                break

        page = self.assertContent('/' + filesLink.getattr('href'), code=[200],
            content = '-rw-r--r--')

        # test non-frozen version request
        page = self.assertContent(
            '/troveInfo?t=test:runtime;v=/localhost/3.0-1-1',
            code=[200], content = 'Invalid version')
示例#6
0
 def testGetDaemon(self):
     raise testhelp.SkipTestException('Fails in bamboo')
     daemonClass = self.generateDaemonClass()
     util.mkdirChain(self.workDir + '/var/log')
     util.mkdirChain(self.workDir + '/var/lock')
     d = daemonClass()
     rv, txt = self.captureOutput(d.main, ['./daemontest', 'start'])
     assert (not rv)
     err, txt = self.captureOutput(d.main, ['./daemontest', 'start'],
                                   _returnException=True)
     assert (isinstance(err, SystemExit))
     assert (err.code == 1)
     assert (re.match(
         '[0-9:]+ - \[foobar\] - error: Daemon already running as pid [0-9]+',
         txt))
     pid = d.getPidFromLockFile()
     rv, txt = self.captureOutput(d.main, ['./daemontest', 'stop'])
     err, txt = self.captureOutput(d.main, ['./daemontest', 'stop'],
                                   _returnException=True)
     txt = open(self.workDir + '/var/log/foobar.log').read()
     assert (re.search(
         "[0-9/]+ [0-9:]+ [A-Z]* - \[foobar\] - warning: unable to open lockfile for reading: %s/var/lock/foobar.pid \(\[Errno 2\] No such file or directory: '%s/var/lock/foobar.pid'\)\n"
         "[0-9/]+ [0-9:]+ [A-Z]* - \[foobar\] - error: could not kill foobar: no pid found.\n"
         % (self.workDir, self.workDir), txt))
     assert (isinstance(err, SystemExit))
     assert (err.code == 1)
示例#7
0
    def testRdiff8(self):
        # CNY-1753
        # Different files living on different branches
        raise testhelp.SkipTestException(
            "Unable to reproduce CNY-1753 in a test case")
        # Manifested in running conary rdiff
        # mkinitrd=conary.rpath.com@rpl:1--usplash.rb.rpath.com@rpl:1

        rf1 = rephelp.RegularFile(
            contents='\000\001\002\003',
            perms=0644,
            mtime=1176921017,
        )
        rf2 = rephelp.RegularFile(
            contents='\000\001\003\005',
            perms=0644,
            mtime=1176921317,
        )

        v1 = versions.ThawVersion('/localhost@rpl:1/1:1-1-1')
        v2 = versions.ThawVersion('/localhost1@rpl:2/2:2-2-2')

        self.openRepository()
        self.openRepository(1)

        self.addComponent('foo:run', v1, [('/bin/foo', rf1)])
        self.addCollection('foo', v1, [':run'])

        self.addComponent('foo:run', v2, [('/bin/foo', rf2)])
        self.addCollection('foo', v2, [':run'])

        troveSpec = cmdline.parseChangeList('foo=%s--%s' % (v1, v2))[0]
        ret, outs = self.captureOutput(queryrep.diffTroves, self.cfg,
                                       troveSpec)
        self.assertEqual(outs, '')
示例#8
0
    def testAuthenticatedHTTPProxy(self):
        # CNY-1687
        self.openRepository()
        if not os.path.exists(rephelp.HTTPProxy.proxyBinPath):
            raise testhelp.SkipTestException(
                'testHTTPProxy depends on squid being installed')

        h = rephelp.HTTPProxy(os.path.join(self.workDir, "http-cache"))
        proxyUri = h.start()
        try:
            sock_utils.tryConnect("localhost", h.port)

            # We cannot have an HTTP proxy and a Conary proxy chained together.
            # (we can have a client talking to a Conary proxy that talks to a repo
            # via an HTTP proxy)
            self.cfg.conaryProxy = {}

            # Unauthenticated, should fail
            self.cfg.configLine("proxy http://localhost:%s" % h.authPort)
            client = conaryclient.ConaryClient(self.cfg)
            repos = client.getRepos()
            try:
                versions = repos.c['localhost'].checkVersion()
            except errors.OpenError, e:
                self.assertTrue('407 Proxy Authentication Required' in str(e),
                                str(e))
            else:
示例#9
0
    def testIncomplete(self):
        raise testhelp.SkipTestException('Broken in hg rev 0efa49c1bcab')
        built, info = self.setup()
        OLD_TROVE_VERSION = trove.TROVE_VERSION
        OLD_TROVE_VERSION_1_1 = trove.TROVE_VERSION_1_1
        d = {}
        if use.Arch.x86:
            d = { 'flavor': 'is: x86' }
        elif use.Arch.x86_64:
            d = { 'flavor': 'is: x86_64' }
        else:
            raise NotImplementedError, 'edit test for this arch'
        try:
            trove.TROVE_VERSION = 1
            trove.TROVE_VERSION_1_1 = 2
            self.logFilter.add()
            try:
                path = self._testBasic1(built, info)
            except errors.ConaryError, err:
                assert(str(err) == '''\
Cannot create a local changeset using an incomplete troves:  Please ensure 
you have the latest conary and then reinstall these troves:
     testcase=/localhost@rpl:linux/1.0-1-1[%(flavor)s]
    testcase:runtime=/localhost@rpl:linux/1.0-1-1[%(flavor)s]
''' %d)
            else:
示例#10
0
    def testBatchCheck(self):
        if sqlite3.sqlite_version_info() < (3,7,0):
            raise testhelp.SkipTestException("buggy sqlite; use embedded sqlite")
        self.openRepository()
        db = self._setupDB()
        na = netauth.NetworkAuthorization(db, "localhost")

        db.transaction()

        self._addUserRole(na, "ro", "ro")
        na.addAcl("ro", "foo:.*", label=None, write=False)
        ro = ("ro", "ro", [ (None, None) ], None )

        self._addUserRole(na, "rw", "rw")
        na.addAcl("rw", "foo:.*", label=None, write=True)
        rw = ("rw", "rw", [ (None, None) ], None )
        
        self._addUserRole(na, "mixed", "mixed")
        na.addAcl("mixed", "foo:.*", label=None, write=False)
        na.addAcl("mixed", "foo:runtime", label=None, write=True)
        mixed = ("mixed", "mixed", [ (None, None) ], None )

        db.commit()
        
        fr = self.addComponent("foo:runtime")
        fd = self.addComponent("foo:devel")
        troveList = [ (fr.getName(), fr.getVersion().asString(), fr.getFlavor().freeze()),
                      (fd.getName(), fd.getVersion().asString(), fd.getFlavor().freeze())]
        self.assertEqual(na.batchCheck(ro, troveList), [True,True])
        self.assertEqual(na.batchCheck(ro, troveList, write=True), [False,False])
        self.assertEqual(na.batchCheck(rw, troveList), [True,True])
        self.assertEqual(na.batchCheck(rw, troveList, write=True), [True,True])
        self.assertEqual(na.batchCheck(mixed, troveList), [True,True])
        self.assertEqual(na.batchCheck(mixed, troveList, write=True), [True,False])
示例#11
0
    def testMissingFiles(self):
        self.openRepository(1)
        self.addComponent('test:source', '1.0-1')
        self.mkbranch(['test:source=1.0'],
                      'localhost1@rpl:shadow',
                      shadow=True)
        self.stopRepository(0)
        os.chdir(self.workDir)
        raise testhelp.SkipTestException(
            'CNY-462 Temporarily disabling until we figure out how to pass the OpenError exception'
        )
        self.assertRaises(repository.errors.OpenError, self.checkout, "test",
                          'localhost1@rpl:shadow')

        # this open resets repository 0, which means that files from the
        # shadow are missing
        self.openRepository(0)
        try:
            self.checkout("test", 'localhost1@rpl:shadow')
        except repository.errors.FileStreamMissing, e:
            j = """File Stream Missing
    The following file stream was not found on the server:
    fileId: 1602c79ea7aeb2cc64c6f11b45bc1be141f610d2
    This could be due to an incomplete mirror, insufficient permissions,
    or the troves using this filestream having been removed from the server."""
            assert (str(e) == j)
示例#12
0
    def testBuildImagesWithBuildName(self):
        raise testhelp.SkipTestException()
        rbuildServer = self.startMockRbuilder()
        oldSleep = time.sleep
        self.mock(time, 'sleep', lambda x: oldSleep(.1))
        self.addComponent('foo:run')
        trv = self.addCollection('group-foo', ['foo:run'])
        rmakeClient = self.startRmakeServer(multinode=True)
        self.startNode()
        helper = self.getRmakeHelper(rmakeClient.uri)
        job = helper.createImageJob('project', [
            ('group-foo', 'imageType', {}, 'Image Name'),
            ('group-foo', 'imageType', {}, 'Image Name'),
            ('group-foo', 'imageType', {}),
            ('group-foo', 'imageType', {})
        ])
        self.assertEquals(
            [x[3] for x in job.troves.keys()],
            ['Image_3', 'Image_2', 'Image_Name_(1)', 'Image_Name'])

        jobId = helper.buildJob(job)
        helper.waitForJob(jobId)
        db = self.openRmakeDatabase()
        expectedLog = '''\
0: Working: 51
0: Working: 101
0: Working: 151
0: Finished.
'''
        for trove in job.troves.values():
            nvfc = list(trove.getNameVersionFlavor()) + [trove.getContext()]
            log = db.getTroveBuildLog(1, nvfc, 0)[1]
            assert(expectedLog in log)
示例#13
0
    def testIncludeConfigFileFails(self):
        class TestCfgFile(ConfigFile):
            bam = CfgBool

        dir = tempfile.mkdtemp()
        try:
            open('%s/foo' % dir, 'w').write('inCLUDEconFIGFile http://nonesuchrediculoushostexists//bar\n')
            cfg = TestCfgFile()
            assert(not cfg.bam)
            try:
                cfg.read('%s/foo' % dir)
                assert(0)
            except Exception, e:
                if 'failure in name resolution' in str(e):
                    raise testhelp.SkipTestException('requires default route')
                self.assertEqual(str(e), "%s/foo:1: when processing "
                        "inCLUDEconFIGFile: Error reading config file "
                        "http://nonesuchrediculoushostexists//bar: "
                        "Name or service not known" % dir)

            cfg = TestCfgFile()
            cfg.ignoreUrlIncludes()
            cfg.read('%s/foo' % dir)
            cfg = TestCfgFile()
            cfg.ignoreUrlIncludes()
            cfg.ignoreUrlIncludes(False)
            self.assertRaises(Exception, cfg.read,'%s/foo' % dir)
            cfg = TestCfgFile()
            cfg.setIgnoreErrors()
            cfg.read('%s/foo' % dir)
示例#14
0
        def dorunproxy(obj, *args, **kwargs):
            if 'CONARY_PROXY' in os.environ:
                raise testhelp.SkipTestException(
                    "testInjectedEntitlements doesn't run with a proxy already running"
                )

            memcache = None
            if params.pop('memcache', False):
                memcache = memcache_server.MemcacheServer()
                memcache.start()
                params['cacheLocation'] = memcache.getHostPort()

            proxy = obj.getConaryProxy(**params)

            obj.stopRepository(1)
            obj.openRepository(1, useSSL=True, forceSSL=True)

            cfg = copy.deepcopy(obj.cfg)
            proxy.addToConfig(cfg)
            client = conaryclient.ConaryClient(cfg)
            repos = client.getRepos()

            proxy.start()

            try:
                fn(obj, repos, *args, **kwargs)
            finally:
                proxy.stop()
                if memcache:
                    memcache.stop()
                server = obj.servers.getServer(1)
                if server is not None:
                    server.reset()
                    obj.stopRepository(1)
示例#15
0
    def testLoadedTrovesWithAutoLoad(self):
        self.logFilter.add()
        repos = self.openRepository()
        if 'x86_64' not in str(self.cfg.buildFlavor):
            raise testhelp.SkipTestException('Skip test on x86 arch')

        self.cfg.autoLoadRecipes.append('other')

        self.overrideBuildFlavor('is: x86 x86_64')

        header = '''
    if Arch.x86: pass
'''
        self.addComponent(
            'other:recipe=2.0[is:x86 x86_64]',
            [('simplesuper.recipe', simpleSuperRecipe.replace('1.0', '2.0'))])
        self.addCollection('other=2.0[is:x86 x86_64]', [':recipe'])
        self.addTestPkg(1, version='1.0', header=header)
        self.addTestPkg(2, header='loadRecipe("test1")')

        use.track()
        rldep = deps.parseFlavor('readline')
        ssldep = deps.parseFlavor('ssl')
        nobsdep = deps.parseFlavor('~!bootstrap')
        emptydep = deps.Flavor()
        x64dep = deps.parseFlavor('is:x86_64')
        v1 = versions.VersionFromString('/localhost@rpl:linux/1.0-1')

        loader = self._testSubload(repos, "loadInstalled('test2')")
        FooLoaded = loader.getLoadedSpecs()
        assertEq = self.assertEqual
        assertEq(FooLoaded['test2'][0], ('test2:source', v1, emptydep))

        Test2Loaded = FooLoaded['test2'][1]
        assertEq(Test2Loaded['test1'][0], ('test1:source', v1, x64dep))

        Test1Loaded = Test2Loaded['test1'][1]
        assertEq(Test1Loaded, {})

        loadedTroves = loader.getLoadedTroves()
        assertEq(len(loadedTroves), 2)
        assertEq(loadedTroves[0], ('test1:source', v1, x64dep))
        assertEq(loadedTroves[1], ('test2:source', v1, emptydep))

        # Now reset and load again w/ overrides specified
        branch = versions.VersionFromString('/localhost@rpl:foo/')
        oldLoadedSpecs = loader.getLoadedSpecs()
        # move ILP and buildLabel over to another branch, and use overrides
        # to load exactly what we want anyway.
        cfg = copy.copy(self.cfg)
        self.overrideBuildFlavor('!readline, !ssl')
        overrides = oldLoadedSpecs
        loader = self._testSubload(repos,
                                   "loadInstalled('test2')",
                                   cfg=cfg,
                                   overrides=overrides)
        assert (loadedTroves[0] == ('test1:source', v1, x64dep))
        assert (loadedTroves[1] == ('test2:source', v1, emptydep))
示例#16
0
    def testStart(self):
        raise testhelp.SkipTestException('Failing test in bamboo')
        startFile = self.workDir + '/startFile'
        if os.path.exists(startFile):
            os.remove(startFile)
        stopFile = self.workDir + '/stopFile'
        #sys.argv[0] = 'python ./testsuite.py'
        #sys.argv[0] = 'daemontest.py'
        self.rmakeCfg.pluginDirs = resources.get_plugin_dirs()
        self.rmakeCfg.usePlugins = False
        self.rmakeCfg.usePlugin['multinode'] = False
        reposPort, proxyPort = sock_utils.findPorts(2)
        self.rmakeCfg.reposUrl = 'http://LOCAL:%s' % reposPort
        self.rmakeCfg.proxyUrl = 'http://LOCAL:%s' % proxyPort

        util.mkdirChain(self.rmakeCfg.lockDir)
        util.mkdirChain(self.rmakeCfg.buildDir)
        pid = os.fork()
        if not pid:
            self.rmakeCfg.writeToFile(self.workDir + '/rmakecfg')
            daemon.rMakeDaemon.configClass.getSocketPath = lambda x: self.rootDir + '/socket'
            daemon.rMakeDaemon.configClass.getServerUri = lambda x: 'unix://' + self.rootDir + '/socket'

            logFile = logfile.LogFile(startFile)
            logFile.redirectOutput()
            try:
                try:
                    daemon.main([
                        'rmake-server', 'start', '-n', '--skip-default-config',
                        '--config-file', self.workDir + '/rmakecfg'
                    ])
                except SystemExit, err:
                    if err.code == 0:
                        os._exit(0)
            finally:
                os._exit(1)
        timeSlept = 0
        while timeSlept < 5:
            if os.path.exists(startFile):
                log = open(startFile).read()
                if 'Started rMake Server at pid %s' % pid in log:
                    break
            time.sleep(.1)
            timeSlept += .1
        assert (timeSlept < 5)
        # wait for fail current jobs process to stop.
        time.sleep(1)
        try:
            logFile = logfile.LogFile(stopFile)
            logFile.redirectOutput()
            daemon.main([
                'rmake-server', 'stop', '--skip-default-config',
                '--config-file', self.workDir + '/rmakecfg'
            ])
        except SystemExit, err:
            if err.code:
                raise
示例#17
0
 def testRepairGhostFile(self):
     if sys.version_info < (2, 6):
         raise testhelp.SkipTestException(
                 'RPM repair requires python 2.6 or later')
     self.addRPMComponent("ghost:rpm=1.0", 'ghost-1.0-1.i386.rpm')
     self.updatePkg('ghost:rpm', raiseError=True)
     rc, s = self.captureOutput(self.repairTroves, [ 'ghost:rpm' ])
     self.assertEquals(s, '')
     self.verifyFile(self.rootDir + '/foo/ghost', '')
示例#18
0
    def testSecureHTTPServer(self):
        # Checks that the secure SSL server works
        if not server.SSL:
            raise testhelp.SkipTestException("m2crypto not installed")

        cfg = server.ServerConfig()
        cfg.port = testhelp.findPorts(1)[0]
        cfg.tmpdir = os.path.join(self.workDir, 'proxyTmpDir')
        cfg.changesetCacheDir = os.path.join(self.workDir, 'changesetCacheDir')
        cfg.proxyContentsDir = os.path.join(self.workDir, 'proxyContentsDir')
        cfg.traceLog = (10, os.path.join(self.workDir, "proxy.debug"))

        cfg.useSSL = True
        cfg.sslCert = os.path.join(resources.get_archive(), 'ssl-cert.crt')
        cfg.sslKey = os.path.join(resources.get_archive(), 'ssl-cert.key')

        cfgfile = os.path.join(self.workDir, "proxy.conf")
        serverrc = open(cfgfile, "w+")
        cfg.store(serverrc, includeDocs=False)
        serverrc.close()
        util.mkdirChain(cfg.tmpdir)
        util.mkdirChain(cfg.changesetCacheDir)
        util.mkdirChain(cfg.proxyContentsDir)

        pid = os.fork()
        if pid == 0:
            # In the child
            try:
                errfd = os.open(os.path.join(self.workDir, "proxy.log"),
                    os.O_RDWR | os.O_CREAT)
                os.dup2(errfd, sys.stderr.fileno())
                os.close(errfd)
                srvpy = os.path.abspath(server.__file__).replace('.pyc', '.py')
                os.execv(srvpy, [ srvpy, '--config-file', cfgfile ])
                os._exit(0)
            except:
                os._exit(70)

        self.openRepository(2, useSSL=True)
        # In the parent
        try:
            # Set conary proxy
            self.cfg.configLine("conaryProxy https://localhost:%s" % cfg.port)

            client = conaryclient.ConaryClient(self.cfg)

            sock_utils.tryConnect("127.0.0.1", cfg.port)

            srvVers = client.repos.c['localhost2'].checkVersion()
            self.assertTrue(srvVers)
        finally:
            self.servers.stopServer(2)
            os.kill(pid, signal.SIGTERM)
            os.waitpid(pid, 0)
示例#19
0
    def testFetchFreshmeat(self):
        """Tests metadata.fetchFreshmeat"""
        filename = os.path.join(resources.get_archive(), 'tora.xml')
        f = open(filename)

        try:
            m = metadata_mod.fetchFreshmeat('tora', xmlDocStream=f)
        except socket.gaierror:
            raise testhelp.SkipTestException('requires network access')
        self.assertEqual(
            m.getShortDesc(),
            "A tool for administrating or developing for Oracle databases.")
示例#20
0
    def testProxyBypass(self):
        if not os.path.exists(rephelp.HTTPProxy.proxyBinPath):
            raise testhelp.SkipTestException(
                'testProxyBypass depends on squid being installed')

        class Controller(ServerController):
            class XMLRPCHandler:
                def ping(self):
                    return [True]

            def handlerFactory(self):
                return self.XMLRPCHandler()

        sc = Controller()
        h = None
        oldLocalHosts = httputils.LocalHosts
        try:
            h = rephelp.HTTPProxy(os.path.join(self.workDir, "http-cache"))
            proxyUri = h.start()

            proxyMap = proxy_map.ProxyMap()
            proxyMap.addStrategy('*', ['http://' + proxyUri])

            tsp = transport.Transport(proxyMap=proxyMap)
            sp = util.ServerProxy(url=sc.url(), transport=tsp)

            # Make sure we're proxying
            logsz0 = h.getAccessLogSize()
            self.assertEqual(sp.ping(), ([True], ))
            logEntry = h.getAccessLogEntry(logsz0)
            self.assertTrue(logEntry)

            # Now mangle localhosts. Proxy is 127.0.0.1, server is on
            # localhost.
            # Make the proxy appear to be remote

            localhosts = set(httputils.LocalHosts)
            localhosts.remove('127.0.0.1')
            httputils.LocalHosts = localhosts

            logsz0 = h.getAccessLogSize()
            sp.ping()
            self.sleep(1)
            logsz1 = h.getAccessLogSize()

            self.assertEqual(logsz1, logsz0)
        finally:
            httputils.LocalHosts = oldLocalHosts
            sc.kill()
            if h:
                h.stop()
示例#21
0
    def testGroupRecipe(self):
        if compat.ConaryVersion().conaryVersion[0:2] == [1,2]:
            raise testhelp.SkipTestException('test fails on 1.2')
        repos = self.openRmakeRepository()
        db = self.openRmakeDatabase()

        self.buildCfg.shortenGroupFlavors = True
        self.buildCfg.setSection('foo') # add context foo
        self.buildCfg.configLine('buildFlavor desktop is:x86')
        self.buildCfg.setSection('bar') 
        self.buildCfg.configLine('buildFlavor !desktop is:x86')

        simple = self.addComponent('simple:runtime', '1.0-1-1', '')
        other1 = self.addComponent('other:runtime', '1.0-1-1', '!desktop',
                filePrimer=1)
        other2 = self.addComponent('other:runtime', '1.0-1-1', 'desktop',
                filePrimer=1)

        # Prevent the desktop flag from being pre-filtered out
        recipe = groupRecipe + '\n        if Use.desktop: pass\n'
        trv = self.addComponent('group-foo:source', 
                     '/localhost@rpl:linux//rmakehost@local:linux/1:1.0-1',
                     [('group-foo.recipe', recipe)])
        troveList = [
                trv.getNameVersionFlavor() + ('foo',),
                trv.getNameVersionFlavor() + ('bar',),
                ]
        job = self.newJob(*troveList)
        b = builder.Builder(self.rmakeCfg, job)

        logFile = logfile.LogFile(self.workDir + '/buildlog')
        logFile.redirectOutput()
        b.build()
        logFile.restoreOutput()
        assert b.job.isBuilt(), str(b.job.getFailureReason())
        assert len(b.job.getBuiltTroveList()) == 2, b.job.getBuiltTroveList()

        for tup in b.job.getBuiltTroveList():
            groupTrove = repos.getTrove(*tup)
            # this is just a very basic test of builder -> group build.
            # tests of the group cook code's ability to include the right 
            # version in particular cases should be in cooktest.py
            if '!desktop' in str(groupTrove.getFlavor()):
                other = other1
            else:
                other = other2
            self.assertEqual(sorted(groupTrove.iterTroveList(strongRefs=True)),
                    [other.getNameVersionFlavor(),
                        simple.getNameVersionFlavor()])
示例#22
0
    def testHTTPProxy(self):
        '''Make sure that the lookaside cache can fetch through an http proxy'''
        if not os.path.exists(rephelp.HTTPProxy.proxyBinPath):
            raise testhelp.SkipTestException(
                'testHTTPProxy depends on squid being installed')

        class Always200Handler(SimpleHTTPRequestHandler):
            def log_message(self, *args, **kw):
                pass

            def do_GET(self):
                response = 'Hello, world!'
                self.send_response(200)
                self.send_header("Content-type", "text/unknown")
                self.send_header("Content-Length", len(response))
                self.end_headers()
                self.wfile.write(response)

        # create the file server
        server = rephelp.HTTPServerController(Always200Handler)

        proxy = rephelp.HTTPProxy(os.path.join(self.workDir, "http-cache"))
        proxyUri = proxy.start()

        repos = self.openRepository()

        try:
            self.cfg.proxy = {'http': 'http://*****:*****@localhost:%d/' % proxy.authPort
            }
            url2 = 'http://localhost:%d/authProxy.txt' \
                % (server.port)
            path = lookaside.fetchURL(self.cfg, url2, 'recipename')
            self.assertTrue(path)

            proxy.stop()
            l = open(proxy.accessLog).read()
            self.assertTrue(url1 in l)
            self.assertTrue(url2 in l)

        finally:
            proxy.stop()
            server.stop()
示例#23
0
文件: webtest.py 项目: tensor5/conary
    def setUp(self):
        if not webunitPresent:
            raise testhelp.SkipTestException('this test requires webunit')
        WebTestCase.setUp(self)
        rephelp.RepositoryHelper.setUp(self)

        try:
            # this *may* be required for some versions of webunit but it seems
            # to break things in other cases
            HTTPResponse._TestCase__testMethodName = \
                self._TestCase__testMethodName
        except:
            pass

        self.useServer(0)
        self.registerErrorContent("Traceback (most recent call last)")
示例#24
0
    def testRpmMissingFiles(self):
        if sys.version_info < (2, 6):
            raise testhelp.SkipTestException(
                    'RPM repair requires python 2.6 or later')

        cmp = self.addRPMComponent("simple:rpm=1.0", 'simple-1.0-1.i386.rpm')
        self.updatePkg('simple:rpm')
        os.unlink(self.rootDir + '/config')
        os.unlink(self.rootDir + '/normal')
        os.rmdir(self.rootDir + '/dir')

        rc, s = self.captureOutput(self.repairTroves, [ 'simple:rpm' ])
        self.assertEquals(s, '')

        self.verifyFile(self.rootDir + '/config', "config\n")
        self.verifyFile(self.rootDir + '/normal', "normal\n")
        assert(os.path.isdir(self.rootDir + '/dir'))
示例#25
0
 def testStopDaemon(self):
     raise testhelp.SkipTestException('Fails in bamboo')
     daemonClass = self.generateDaemonClass()
     util.mkdirChain(self.workDir + '/var/log')
     util.mkdirChain(self.workDir + '/var/lock')
     d = daemonClass()
     rv, txt = self.captureOutput(d.main, ['./daemontest', 'start'])
     assert (not rv)
     mock.mock(os, 'kill')
     mock.mock(time, 'sleep')
     mock.mockMethod(d.error)
     err, txt = self.captureOutput(d.main, ['./daemontest', 'stop'],
                                   _returnException=True)
     msg = d.error._mock.popCall()[0][0]
     assert ('Failed to kill foobar (pid ' in msg)
     mock.unmockAll()
     self.captureOutput(d.main, ['./daemontest', 'stop'])
示例#26
0
    def testRpmDocSharing(self):
        'test for CNY-3420'
        if os.uname()[4] != 'x86_64':
            raise testhelp.SkipTestException(
                'this test only works on x86_64 platforms')
        recipestr = r'''
class docConflict(CapsuleRecipe):
    name = 'doc-conflict'
    version = '1.0'
    clearBuildReqs()
    def setup(r):
        r.addCapsule('doc-conflict-1.0-1.%s.rpm', use=Arch.%s)
'''
        groupRecipe = r'''
class GroupShare(GroupRecipe):
    name = 'group-dist'
    version = '1.0'
    clearBuildRequires()
    autoResolve = False

    def setup(r):
        r.add('doc-conflict', flavor ='is:x86')
        r.add('doc-conflict', flavor ='is:x86_64')
'''

        c0, d = self.buildRecipe(recipestr % ('x86_64', 'x86_64'),
                                 'docConflict')
        self.overrideBuildFlavor('is: x86')
        c1, d = self.buildRecipe(recipestr % ('i386', 'x86'), 'docConflict')
        g, d = self.buildRecipe(groupRecipe, 'GroupShare')
        self.assertEquals(g[0][0], 'group-dist')
        self._installPkgs(['group-dist'], output='^$')
        self.resetRoot()
        self._installPkgs(['doc-conflict[is:x86]'], output='^$')
        self._installPkgs(['doc-conflict[is:x86_64]'],
                          output='^$',
                          keepExisting=True)
        self.resetRoot()
        self._installPkgs(['doc-conflict[is:x86]', 'doc-conflict[is:x86_64]'],
                          output='^$',
                          keepExisting=True)
        self.resetRoot()
        self._installPkgs(['doc-conflict[is:x86]', 'doc-conflict[is:x86_64]'],
                          output='^$',
                          keepExisting=True,
                          justDatabase=True)
示例#27
0
    def test_checkReplaceManagedFiles(self):
        if rpmcapsule is None:
            raise testhelp.SkipTestException('rpm not installed')
        # CNY-3662 - code defensively

        class OldFlags(object):
            def __init__(self):
                # Make sure we convert to bool
                self.replaceManagedFiles = 'adfad'

        class NewFlags(object):
            def replaceManagedFiles(self, path):
                return (path == "managed")

        meth = rpmcapsule.RpmCapsuleOperation._checkReplaceManagedFiles
        self.assertEqual(meth(OldFlags(), 'aaa'), True)
        self.assertEqual(meth(NewFlags(), 'managed'), True)
        self.assertEqual(meth(NewFlags(), 'unmanaged'), False)
示例#28
0
    def testProxyUsedForGettingIncludeConfigFile(self):
        # CNY-2363
        if not os.path.exists(rephelp.HTTPProxy.proxyBinPath):
            raise testhelp.SkipTestException(
                'testHTTPProxy depends on squid being installed')

        h = rephelp.HTTPProxy(os.path.join(self.workDir, "http-cache"))
        proxyUri = h.start()

        #NOTE: this web server only serves one time - if we try to access
        # it twice, it won't work, so that's another test.
        srvThread, port, queue = startServer()
        val = queue.get(block=True)
        self.assertEqual(val, "started")
        serverUrl = "http://127.0.0.1:%s/" % port

        configFile = self.workDir + '/foo'
        self.writeFile(
            configFile, '''
includeConfigFile %s
proxy http http://%s
''' % (serverUrl, proxyUri))

        calls = [0]

        def readFiles(self):
            calls[0] += 1
            if calls[0] == 1:
                assert (not self.proxy)
            elif calls[0] == 2:
                # the proxy is there when we read the files the second time
                assert (self.proxy == {'http': 'http://%s' % proxyUri})
            self.read(configFile)

        # replace readfiles so that we only read our file.
        oldReadFiles = conarycfg.ConaryConfiguration.readFiles
        try:
            logsz0 = h.getAccessLogSize()
            conarycfg.ConaryConfiguration.readFiles = readFiles
            cfg = conarycfg.ConaryConfiguration(readConfigFiles=True)
            logEntry = h.getAccessLogEntry(logsz0)
            self.assertEqual(logEntry[5:7], ['GET', serverUrl])
        finally:
            conarycfg.ConaryConfiguration.readFiles = oldReadFiles
示例#29
0
 def testChangingSharedUpdateRPM(self):
     'CNY-3620'
     if 'x86_64' not in str(self.cfg.buildFlavor):
         raise testhelp.SkipTestException('Skip test on x86 arch')
     # avoid needing to flavor using names
     su1032 = self.addRPMComponent('shared-update-32:rpm=1.0',
                                   'shared-update-1.0-1.i386.rpm')
     su1064 = self.addRPMComponent('shared-update-64:rpm=1.0',
                                   'shared-update-1.0-1.x86_64.rpm')
     su1132 = self.addRPMComponent('shared-update-32:rpm=1.1',
                                   'shared-update-1.1-1.i386.rpm',
                                   versus=su1032)
     su1164 = self.addRPMComponent('shared-update-64:rpm=1.1',
                                   'shared-update-1.1-1.x86_64.rpm',
                                   versus=su1064)
     self.updatePkg(['shared-update-32:rpm=1.0', 'shared-update-64:rpm=1.0'])
     self.verifyFile(self.rootDir + '/usr/share/test', 'contents1.0\n')
     self.updatePkg(['shared-update-32:rpm=1.1', 'shared-update-64:rpm=1.1'])
     self.verifyFile(self.rootDir + '/usr/share/test', 'contents1.1\n')
示例#30
0
 def testKillPidSignal(self):
     raise testhelp.SkipTestException("Test is unreliable")
     s = server.Server()
     pid = os.fork()
     signal.signal(signal.SIGTERM, self._signalHandlerKill)
     if pid:
         time.sleep(.1)
         signal.signal(signal.SIGTERM, signal.SIG_DFL)
         rc, txt = self.captureOutput(s._killPid,
                                      pid,
                                      'Frobnicator',
                                      timeout=2)
         assert (re.match(
             '[0-9:]+ - \[root\] - warning: pid [0-9]+ \(Frobnicator\) killed with signal 9',
             txt))
     else:
         try:
             time.sleep(10000)
         finally:
             os._exit(1)