示例#1
0
    def _getRmakeConfig(self, rmakeCfgFn=None):
        # Get default pluginDirs from the rmake cfg object, setup the plugin
        # manager, then create a new rmake config object so that rmakeUser
        # will be parsed correctly.
        rmakeCfg = buildcfg.BuildConfiguration(readConfigFiles=False)
        disabledPlugins = [ x[0] for x in rmakeCfg.usePlugin.items()
                            if not x[1] ]
        disabledPlugins.append('monitor')
        pluginMgr = plugins.PluginManager(rmakeCfg.pluginDirs, disabledPlugins)
        pluginMgr.loadPlugins()
        pluginMgr.callClientHook('client_preInit', self, [])

        rmakerc = 'rmakerc'
        if rmakeCfgFn:
            rmakeCfgPath = util.join(self._cfg.configPath, rmakeCfgFn)
            if os.path.exists(rmakeCfgPath):
                rmakerc = rmakeCfgFn
                # FIXME: This is a hack to work around having two conaryrc
                #        files, one for building groups and one for building
                #        packages.
                self._ccfg.autoLoadRecipes = []
            else:
                log.warn('%s not found, falling back to rmakerc' % rmakeCfgFn)

        rmakeCfg = buildcfg.BuildConfiguration(readConfigFiles=False)
        rmakeCfg.read(util.join(self._cfg.configPath, rmakerc))
        rmakeCfg.useConaryConfig(self._ccfg)
        rmakeCfg.copyInConfig = False
        rmakeCfg.strictMode = True

        # Use default tmpDir when building with rMake since the specified
        # tmpDir may not exist in the build root.
        rmakeCfg.resetToDefault('tmpDir')

        return rmakeCfg
示例#2
0
def initializePlugins(pluginDirs, disabledPlugins=None):
    global pluginManager
    from rmake import plugins
    pluginManager = plugins.PluginManager(pluginDirs=pluginDirs,
                                          disabledPlugins=disabledPlugins)
    pluginManager.loadPlugins()
    pluginManager.callLibraryHook('library_preInit')
示例#3
0
 def testPlugin(self):
     pluginDir = self.workDir + '/plugins'
     util.mkdirChain(pluginDir)
     self.writeFile(pluginDir + '/test.py', pluginTxt)
     mgr = plugins.PluginManager([pluginDir])
     mgr.loadPlugins()
     mainHandler = Main(mgr, self.buildCfg, self.cfg)
     mgr.callClientHook('client_preInit', mainHandler, ['rmake'])
     rc, txt = self.captureOutput(mainHandler.main, ['rmake', '--skip-default-config'])
     assert('test         Test Command' in txt)
     rc, txt = self.captureOutput(mainHandler.main, ['rmake', 'test', '--skip-default-config'])
     assert("TEST!\n" == txt)
     mgr.unloadPlugin('test')
     rc, txt = self.captureOutput(mainHandler.main, ['rmake', '--skip-default-config'])
     assert("test              Test Command" not in txt)
示例#4
0
    def __init__(self,
                 uri,
                 cfg,
                 repositoryPid=None,
                 proxyPid=None,
                 pluginMgr=None,
                 quiet=False):
        util.mkdirChain(cfg.logDir)
        logPath = cfg.logDir + '/rmake.log'
        rpcPath = cfg.logDir + '/xmlrpc.log'
        serverLogger = ServerLogger()
        serverLogger.disableRPCConsole()
        serverLogger.logToFile(logPath)
        serverLogger.logRPCToFile(rpcPath)
        if quiet:
            serverLogger.setQuietMode()
        else:
            if cfg.verbose:
                logLevel = logging.DEBUG
            else:
                logLevel = logging.INFO
            serverLogger.enableConsole(logLevel)
        serverLogger.info(
            '*** Started rMake Server at pid %s (serving at %s)' %
            (os.getpid(), uri))
        try:
            self._initialized = False
            self.db = None

            # forked jobs that are currently active
            self._buildPids = {}

            self.uri = uri
            self.cfg = cfg
            self.repositoryPid = repositoryPid
            self.proxyPid = proxyPid
            apirpc.XMLApiServer.__init__(
                self,
                uri,
                logger=serverLogger,
                forkByDefault=True,
                sslCertificate=cfg.getSslCertificatePath(),
                caCertificate=cfg.getCACertificatePath())
            self._setUpInternalUser()
            self.db = database.Database(cfg.getDbPath(),
                                        cfg.getDbContentsPath())
            self.auth = auth.AuthenticationManager(cfg.getAuthUrl(), self.db)

            if pluginMgr is None:
                pluginMgr = plugins.PluginManager([])
            self.plugins = pluginMgr

            # any jobs that were running before are not running now
            subscriberLog = logger.Logger('susbscriber',
                                          self.cfg.getSubscriberLogPath())
            self._publisher = publish._RmakeServerPublisher(
                subscriberLog, self.db, self._fork)
            self.worker = worker.Worker(self.cfg, self._logger)
            dbLogger = subscriber._JobDbLogger(self.db)
            # note - it's important that the db logger
            # comes first, before the general publisher,
            # so that whatever published is actually
            # recorded in the DB.
            self._subscribers = [dbLogger]
            if self.uri:
                s = subscriber._RmakeServerPublisherProxy(self.uri)
            else:
                # testsuite path - external subscribers also go through
                # internal interface when the server is not run as a separate
                # process.
                s = subscriber._RmakeServerPublisherProxy(ShimAddress(self))
            self._subscribers.append(s)

            self._internalSubscribers = [dbLogger]
            s = subscriber._RmakeServerPublisherProxy(ShimAddress(self))
            self._internalSubscribers.append(s)
            self.plugins.callServerHook('server_postInit', self)
        except errors.uncatchableExceptions:
            raise
        except Exception, err:
            self.error('Error initializing rMake Server:\n  %s\n%s', err,
                       traceback.format_exc())
            self._try('halt', self._shutDown)
            raise
示例#5
0
    def _getRmakeConfig(self, useCache=True, includeContext=True):
        """
        Returns an rmake configuration file that matches the product associated
        with the current handle.
        @param useCache: if True (default), uses a cached version of the
        rmake configuration file if available, and caches the results
        for future invocations.
        @type useCache: bool
        @param includeContext: include context-specific information, as
        required when building an rmake configuration for use in a
        specific rMake job (default: True).  Setting this to False
        also disables caching.
        @type includeContext: bool
        @return: rMake configuration file suitable for use with the current
        product.
        """
        if not includeContext:
            # context-free config must not be cached
            useCache = False

        if self._rmakeConfig and useCache:
            return self._rmakeConfig

        conaryFacade = self._handle.facade.conary
        rbuildConfig = self._handle.getConfig()
        if not self._plugins:
            p = plugins.PluginManager(rbuildConfig.rmakePluginDirs, ['test'])
            p.loadPlugins()
            p.callLibraryHook('library_preInit')
            self._plugins = p

        if includeContext:
            stageName = self._handle.productStore.getActiveStageName()
            stageLabel = conaryFacade._getLabel(
                self._handle.product.getLabelForStage(stageName))
            baseFlavor = conaryFacade._getFlavor(
                self._handle.product.getBaseFlavor())

        # BuildConfiguration must be created after loading rMake plugins
        cfg = buildcfg.BuildConfiguration(False)
        cfg.rbuilderUrl = rbuildConfig.serverUrl
        cfg.rmakeUser = rbuildConfig.user
        cfg.user.extend(rbuildConfig.repositoryUser)
        cfg.resolveTrovesOnly = True
        cfg.shortenGroupFlavors = True
        cfg.ignoreExternalRebuildDeps = True
        # strictMode settings
        cfg.strictMode = True
        cfg.enforceManagedPolicy = True
        cfg.copyInConary = False
        cfg.copyInConfig = False

        if rbuildConfig.rmakePluginDirs:
            cfg.pluginDirs = rbuildConfig.rmakePluginDirs

        if includeContext:
            cfg.buildLabel = stageLabel
            cfg.installLabelPath = [stageLabel]
            cfg.flavor = [baseFlavor]
            cfg.buildFlavor = baseFlavor
            searchPaths = self._handle.product.getResolveTroves()
            searchPaths = [x.getTroveTup() for x in searchPaths]
            # Search paths with no trove name go at the end of installLabelPath
            # Everything else becomes a resolveTrove
            cfg.resolveTroves = [[x] for x in searchPaths if x[0] is not None]
            cfg.installLabelPath.extend(
                conaryFacade._getLabel(x[1]) for x in searchPaths if x[1])

            cfg.autoLoadRecipes = \
                self._handle.productStore.getPlatformAutoLoadRecipes()
            cfg.bootstrapTroves = \
                    self._handle.productStore.getBootstrapTroves()
            cfg.rpmRequirements = \
                    self._handle.productStore.getRPMRequirements()

            #E1101: 'BuildConfiguration' has no 'user' member - untrue
            #pylint: disable-msg=E1101
            cfg.user.append((stageLabel.getHost(), ) + rbuildConfig.user)

        cfg.repositoryMap = rbuildConfig.repositoryMap
        if rbuildConfig.rmakeUrl:
            cfg.rmakeUrl = rbuildConfig.rmakeUrl
        if rbuildConfig.rmakeUser:
            cfg.rmakeUser = rbuildConfig.rmakeUser
        cfg.signatureKey = rbuildConfig.signatureKey
        cfg.signatureKeyMap = rbuildConfig.signatureKeyMap
        cfg.name = rbuildConfig.name
        cfg.contact = rbuildConfig.contact
        self._handle.facade.conary._parseRBuilderConfigFile(cfg)

        # Only try to get platform information if this command is
        # associated with a product.
        if self._handle.product:
            platformInformation = self._handle.product.getPlatformInformation()
            if (platformInformation
                    and hasattr(platformInformation, 'platformClassifier')
                    and platformInformation.platformClassifier and 'windows'
                    in platformInformation.platformClassifier.get_tags()):

                rbuilder = self._handle.facade.rbuilder

                if not cfg.windowsBuildService:
                    cfg.windowsBuildService = rbuilder.getWindowsBuildService()

        if self._handle.productStore:
            rmakeConfigPath = self._handle.productStore.getRmakeConfigPath()
            if os.path.exists(rmakeConfigPath):
                cfg.includeConfigFile(rmakeConfigPath)

        if useCache:
            self._rmakeConfig = cfg

        return cfg