Ejemplo n.º 1
0
 def createSchema(self):
     if self.verbose:
         print "CREATE SCHEMA", self.driver, self.path
     db = self.connect()
     from conary.server.schema import loadSchema
     loadSchema(db)
     db.commit()
Ejemplo n.º 2
0
def startRepository(cfg, logger=None):
    reposDir = cfg.getReposDir()
    util.mkdirChain(reposDir)

    # Generate and store a random password for the rmake user if not configured
    # with one.
    if not cfg.reposUser:
        passwordFile = reposDir + '/password'
        if os.path.exists(passwordFile):
            password = open(passwordFile).readline().strip()
        else:
            password = ''.join([ chr(random.randrange(ord('a'), ord('z'))) 
                               for x in range(10)])
            open(passwordFile, 'w').write(password + '\n')
            os.chmod(reposDir + '/password', 0700)
        cfg.reposUser.addServerGlob(cfg.reposName, 'rmake', password)

    serverCfg = cny_server.ServerConfig()
    serverCfg.repositoryDB = ('sqlite', cfg.getReposDbPath())
    serverCfg.contentsDir = cfg.getContentsPath()
    serverCfg.port = cfg.getReposInfo()[1]
    serverCfg.configKey('serverName', cfg.reposName)

    # Transfer SSL settings from rMake config object
    if getattr(cny_server, 'SSL', None):
        # The server supports starting in SSL mode
        serverCfg.useSSL = cfg.reposRequiresSsl()
        serverCfg.sslCert = cfg.sslCertPath
        serverCfg.sslKey = cfg.sslCertPath
    elif cfg.reposRequiresSsl():
        raise errors.RmakeError("Tried to start repository at %s, but missing "
                "ssl server library: Please install m2crypto." %
                (cfg.getRepositoryUrl(),))

    (driver, database) = serverCfg.repositoryDB
    db = dbstore.connect(database, driver)

    # Note - this will automatically migrate this repository! 
    # Since this is a throwaway repos anyway, I think that's
    # acceptable.
    cny_schema.loadSchema(db, doMigrate=True)
    db.commit()
    db.close()

    user, password = cfg.reposUser.find(cfg.reposName)
    addUser(serverCfg, user, password, write=True)
    if not serverCfg.useSSL:
        # allow anonymous access if we're not securing this repos
        # by using SSL - no use securing access if it's all going to be
        # viewable via tcpdump.
        addUser(serverCfg, 'anonymous', 'anonymous')

    return _startServer(serverCfg, cfg.getReposLogPath(),
            cfg.getReposConfigPath(), 'repository')
Ejemplo n.º 3
0
def getDb(path):
    if os.path.exists(path):
        print "Deleting database"
        os.remove(path)
    if os.listdir("/srv/rmake-repos/contents/"):
        print "Deleting contents..."
        os.system("rm -rf /srv/rmake-repos/contents/*")
    open(path, 'w')
    os.chown(path, pwd.getpwnam('apache').pw_uid,
                   pwd.getpwnam('apache').pw_gid)

    db = dbstore.connect(path, driver='sqlite')
    schema.loadSchema(db, True)
    schema.setupTempTables(db)
    return db
Ejemplo n.º 4
0
def getDb(path):
    if os.path.exists(path):
        print "Deleting database"
        os.remove(path)
    if os.listdir("/srv/rmake-repos/contents/"):
        print "Deleting contents..."
        os.system("rm -rf /srv/rmake-repos/contents/*")
    open(path, 'w')
    os.chown(path,
             pwd.getpwnam('apache').pw_uid,
             pwd.getpwnam('apache').pw_gid)

    db = dbstore.connect(path, driver='sqlite')
    schema.loadSchema(db, True)
    schema.setupTempTables(db)
    return db
Ejemplo n.º 5
0
 def fix(self):
     db = self.getDB()
     dbVersion = db.getVersion()
     try:
         log.info("performing a schema migration...")
         newVersion = schema.loadSchema(db, doMigrate=True)
     except sqlerrors.SchemaVersionError, e:
         log.error(e.msg)
         return False
Ejemplo n.º 6
0
 def fix(self):
     db = self.getDB()
     dbVersion = db.getVersion()
     try:
         log.info("performing a schema migration...")
         newVersion = schema.loadSchema(db, doMigrate=True)
     except sqlerrors.SchemaVersionError, e:
         log.error(e.msg)
         return False
Ejemplo n.º 7
0
        dbVersion = db.getVersion()
        # a more recent major is not compatible
        if dbVersion.major > schema.VERSION.major:
            print "ERROR: code base too old for this repository database"
            print "ERROR: repo=", dbVersion, "code=", schema.VERSION
            sys.exit(-1)
        # determine is we need to call the schema migration
        loadSchema = False
        if dbVersion == 0:  # no schema initialized
            loadSchema = True
        elif dbVersion.major < schema.VERSION.major:  # schema too old
            loadSchema = True
        elif 'migrate' in argSet:  # a migration was asked for
            loadSchema = True
        if loadSchema:
            dbVersion = schema.loadSchema(db, 'migrate' in argSet)
        if dbVersion < schema.VERSION:  # migration failed...
            print "ERROR: schema migration has failed from %s to %s" % (
                dbVersion, schema.VERSION)
        if 'migrate' in argSet:
            logMe(1, "Schema migration complete", dbVersion)
            sys.exit(0)

        netRepos = NetworkRepositoryServer(cfg, baseUrl)
        reqClass.netRepos = proxy.SimpleRepositoryFilter(
            cfg, baseUrl, netRepos)
        reqClass.restHandler = None
        if cfg.baseUri:
            global cresthooks
            if cresthooks is None:
                # we haven't tried to import cresthooks yet - let's give
Ejemplo n.º 8
0
        dbVersion = db.getVersion()
        # a more recent major is not compatible
        if dbVersion.major > schema.VERSION.major:
            print "ERROR: code base too old for this repository database"
            print "ERROR: repo=", dbVersion, "code=", schema.VERSION
            sys.exit(-1)
        # determine is we need to call the schema migration
        loadSchema = False
        if dbVersion == 0: # no schema initialized
            loadSchema = True
        elif dbVersion.major < schema.VERSION.major: # schema too old
            loadSchema = True
        elif 'migrate' in argSet: # a migration was asked for
            loadSchema = True
        if loadSchema:
            dbVersion = schema.loadSchema(db, 'migrate' in argSet)
        if dbVersion < schema.VERSION: # migration failed...
            print "ERROR: schema migration has failed from %s to %s" %(
                dbVersion, schema.VERSION)
        if 'migrate' in argSet:
            logMe(1, "Schema migration complete", dbVersion)
            sys.exit(0)

        netRepos = NetworkRepositoryServer(cfg, baseUrl)
        reqClass.netRepos = proxy.SimpleRepositoryFilter(cfg, baseUrl, netRepos)
        reqClass.restHandler = None
        if cfg.baseUri:
            global cresthooks
            if cresthooks is None:
                # we haven't tried to import cresthooks yet - let's give
                # it a try
Ejemplo n.º 9
0
 def loadServerSchema(self, db):
     from conary.server import schema
     if self.checkVersion(minVer='1.2.6'):
         schema.loadSchema(db, doMigrate=True)
     else:
         schema.loadSchema(db, migrate=True)
Ejemplo n.º 10
0
    def _testSlowActionWithStandalone(self, useSSL = False):
        # Test to make sure that slow commits still work even with the
        # proxy keepalive code added (CNY-1341)
        cfg = server.ServerConfig()
        cfg.port = testhelp.findPorts(1)[0]
        cfg.contentsDir = ('legacy', [self.workDir + '/contents'])
        cfg.repositoryDB = ('sqlite', self.workDir + '/serverdb')
        cfg.logFile = self.workDir + '/serverlog'
        cfg.tmpDir = self.workDir + '/tmp'
        cfg.serverName = 'localhost'
        util.mkdirChain(cfg.tmpDir)
        util.mkdirChain(cfg.contentsDir[1][0])
        if useSSL:
            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')

        (driver, database) = cfg.repositoryDB
        db = dbstore.connect(database, driver)
        schema.loadSchema(db)
        schema.setupTempTables(db)
        auth = netauth.NetworkAuthorization(db, 'localhost')
        auth.addRole('foo')
        auth.addUser('foo', 'foo')
        auth.addRoleMember('foo', 'foo')
        auth.addAcl('foo', None, None, write = True)


        if useSSL:
            proto = "https"
        else:
            proto = "http"
        baseUrl = '%s://localhost:%s/' % (proto, cfg.port)

        pid = os.fork()
        if not pid:
            try:
                netServer = netserver.NetworkRepositoryServer(cfg, baseUrl)

                oldGetChangeSet = netServer.getChangeSet
                @netserver.accessReadOnly
                def getChangeSet(*args, **kw):
                    rv = oldGetChangeSet(*args, **kw)
                    # make sure the client sends its message
                    self.sleep(7)
                    return rv
                getChangeSet.im_func = getChangeSet
                netServer.getChangeSet = getChangeSet

                class HttpRequestsSubclass(server.HttpRequests):
                    tmpDir = cfg.tmpDir
                    netRepos = proxy.SimpleRepositoryFilter(cfg, baseUrl, netServer)
                    restHandler = None

                HttpRequestsSubclass.cfg = cfg

                if useSSL:
                    ctx = server.createSSLContext(cfg)
                    httpServer = server.SecureHTTPServer(("", cfg.port),
                                                         HttpRequestsSubclass, ctx)
                else:
                    httpServer = server.HTTPServer(("", cfg.port),
                                                   HttpRequestsSubclass)
                self.captureOutput(server.serve, httpServer)
            finally:
                os._exit(0)
        try:
            sock_utils.tryConnect("127.0.0.1", cfg.port)
            cfg = conarycfg.ConaryConfiguration(False)
            cfg.repositoryMap  = {'localhost' : baseUrl }
            cfg.user.addServerGlob('localhost', 'foo', 'foo')
            client = conaryclient.ConaryClient(cfg)
            repos = client.getRepos()

            trv, cs = self.Component('foo:run', '1')
            repos.commitChangeSet(cs)
            # getTrove will fail because it takes more than 5 seconds
            assert(repos.getTrove(*trv.getNameVersionFlavor()))
        finally:
            os.kill(pid, signal.SIGTERM)
            os.waitpid(pid, 0)
Ejemplo n.º 11
0
def getIndexes(driver = "sqlite"):
    pd = PrintDatabase(False, driver)
    schema.loadSchema(pd)
    return pd.statements
Ejemplo n.º 12
0
def getTables(driver = "sqlite"):
    pd = PrintDatabase(True, driver)
    schema.loadSchema(pd)
    return pd.statements