Exemple #1
0
    def action(self):
        args = sys.argv[1:]
        if not args:
            self.usage()
        
        if args[0].startswith('--xyzzy='):
            self.cfgPath = args.pop(0).split('=')[1]
            print "Test mode using configuration from %s" % self.cfgPath
        elif os.getuid():
            sys.exit("This script must be run as root")

        # make sure they want to do it
        if '--force' in args:
            args.remove('--force')
        else:
            self.confirm(args)
        
        mintConfig = config.getConfig(self.cfgPath)
        self.setConfig(mintConfig)

        mintClient = shimclient.ShimMintClient(mintConfig,
                (mintConfig.authUser, mintConfig.authPass))

        for projectName in args:
            print "Deleting '" + projectName + "'..."
            mintClient.deleteProjectByName(projectName)
        return 0
def handler(req):
    """
    The presence of this function in the module allows it to be added directly
    into apache as a mod_python handler.

    The function is for testing purposes only.
    """
    coveragehook.install()
    mintCfgPath = os.path.join(req.document_root(), '..', '..', 'mint.conf')
    mintcfg = config.getConfig(mintCfgPath)
    mintdb = Database(mintcfg)
    restdb = RestDatabase(mintcfg, mintdb)

    topLevel = os.path.join(mintcfg.basePath)

    _handler = ApacheRESTHandler(topLevel, restdb)
    return _handler.handle(req)
def handler(req):
    """
    The presence of this function in the module allows it to be added directly
    into apache as a mod_python handler.

    The function is for testing purposes only.
    """
    coveragehook.install()
    mintCfgPath = os.path.join(req.document_root(), "..", "..", "mint.conf")
    mintcfg = config.getConfig(mintCfgPath)
    mintdb = Database(mintcfg)
    restdb = RestDatabase(mintcfg, mintdb)

    topLevel = os.path.join(mintcfg.basePath)

    _handler = ApacheRESTHandler(topLevel, restdb)
    return _handler.handle(req)
Exemple #4
0
 def cfg(self):
     # NOTE: this path should only be used in the testsuite. Normally
     # mint.web.wsgi_hook should be the only place MintConfig is ever
     # instantiated.
     cfgPath = config.RBUILDER_CONFIG
     return config.getConfig(cfgPath)
Exemple #5
0
 def loadConfig(self, cfgPath=config.RBUILDER_CONFIG):
     self.setConfig(config.getConfig(cfgPath))
Exemple #6
0
    def setUp(self):
        testcase.TestCaseWithWorkDir.setUp(self)
        helpDir = os.path.join(os.path.dirname(handler.__file__), 'rest')

        buildData = BuildData.buildData.copy()
        buildData.update(self.BUILD_DATA)
        # Fix up imageType
        for imageType, images in buildData.items():
            for img in images:
                img.setdefault('imageType', imageType)

        dbpath = os.path.join(self.workDir, "db.sqlite")
        # Stub mint config file
        mintCfgPath = self.mintCfgPath = os.path.join(self.workDir,
                                                      'mint.conf')
        mintCfgDict = dict(self.MINT_CFG)
        mintCfgDict['dataPath'] = self.storagePath = os.path.join(
            self.workDir, "data")
        mintCfgDict['dbPath'] = dbpath
        mintCfgDict['basePath'] = self._basePath
        file(mintCfgPath,
             "w").write('\n'.join(' '.join(x) for x in mintCfgDict.items()))
        mintcfg = self.mintcfg = config.getConfig(mintCfgPath)

        mintdb = Database(mintcfg)

        restdb = self.restdb = RestDatabase(mintcfg, mintdb)
        setupbase.createSchema(mintdb.db)
        mintdb.db._buildData = buildData

        for targetType, targetName, targetData in self.TARGETS:
            restdb.targetMgr.addTarget(targetType, targetName, targetData)
        for username, password, fullName in self.USERS:
            restdb.db.users.registerNewUser(username, password, fullName,
                                            '*****@*****.**', 'Y', 'blurb',
                                            1)
        for username, targetType, targetName, credentials in self.USER_TARGETS:
            restdb.targetMgr.setTargetCredentialsForUser(
                targetType, targetName, username, credentials)
        self.setUpJobs()
        restdb.commit()

        if os.path.isdir(helpDir):
            handler.Request._helpDir = helpDir
            handler.Request._driverHelpDir = "drivers/%(driverName)s/help"
        self.services = []
        self.inventoryManager = rbuildermanager.RbuilderManager(
            self.mintcfg, 1)
        self.systemMgr = self.inventoryManager.sysMgr

        RESTHandler.updateHandler(restdb)

        from rpath_job import api1 as rpath_job

        # We need to slow down addHistoryEntry a bit
        origAddHistoryEntry = rpath_job.HistoryBaseJob.addHistoryEntry

        def fakeAddHistoryEntry(slf, *args, **kwargs):
            time.sleep(0.002)
            return origAddHistoryEntry(slf, *args, **kwargs)

        self.mock(rpath_job.HistoryBaseJob, 'addHistoryEntry',
                  fakeAddHistoryEntry)

        # Mock postFork, we don't want to reopen the db, or we lose the mock
        # data
        def mockPostFork(slf):
            slf.zoneAddresses = ['1.2.3.4:5678', '2.3.4.5:6789']

        self.mock(baseDriver.BaseDriver, 'postFork', mockPostFork)

        self.setUpSystemManager()
        self.setUpSchemaDir()
    def setUp(self):
        testcase.TestCaseWithWorkDir.setUp(self)
        helpDir = os.path.join(
            os.path.dirname(handler.__file__),
            'rest')

        buildData = BuildData.buildData.copy()
        buildData.update(self.BUILD_DATA)
        # Fix up imageType
        for imageType, images in buildData.items():
            for img in images:
                img.setdefault('imageType', imageType)

        dbpath = os.path.join(self.workDir, "db.sqlite")
        # Stub mint config file
        mintCfgPath = self.mintCfgPath = os.path.join(self.workDir, 'mint.conf')
        mintCfgDict = dict(self.MINT_CFG)
        mintCfgDict['dataPath'] = self.storagePath = os.path.join(self.workDir, "data")
        mintCfgDict['dbPath'] = dbpath
        mintCfgDict['basePath'] = self._basePath
        file(mintCfgPath, "w").write('\n'.join(' '.join(x)
            for x in mintCfgDict.items()))
        mintcfg = self.mintcfg = config.getConfig(mintCfgPath)

        mintdb = Database(mintcfg)

        restdb = self.restdb = RestDatabase(mintcfg, mintdb)
        setupbase.createSchema(mintdb.db)
        mintdb.db._buildData = buildData

        for targetType, targetName, targetData in self.TARGETS:
            restdb.targetMgr.addTarget(targetType, targetName, targetData)
        for username, password, fullName in self.USERS:
            restdb.db.users.registerNewUser(username, password, fullName,
                '*****@*****.**', 'Y', 'blurb', 1)
        for username, targetType, targetName, credentials in self.USER_TARGETS:
            restdb.targetMgr.setTargetCredentialsForUser(targetType,
                targetName, username, credentials)
        self.setUpJobs()
        restdb.commit()

        if os.path.isdir(helpDir):
            handler.Request._helpDir = helpDir
            handler.Request._driverHelpDir = "drivers/%(driverName)s/help"
        self.services = []
        self.inventoryManager = rbuildermanager.RbuilderManager(self.mintcfg, 1)
        self.systemMgr = self.inventoryManager.sysMgr

        RESTHandler.updateHandler(restdb)

        from rpath_job import api1 as rpath_job

        # We need to slow down addHistoryEntry a bit
        origAddHistoryEntry = rpath_job.HistoryBaseJob.addHistoryEntry
        def fakeAddHistoryEntry(slf, *args, **kwargs):
            time.sleep(0.002)
            return origAddHistoryEntry(slf, *args, **kwargs)
        self.mock(rpath_job.HistoryBaseJob, 'addHistoryEntry', fakeAddHistoryEntry)

        # Mock postFork, we don't want to reopen the db, or we lose the mock
        # data
        def mockPostFork(slf):
            slf.zoneAddresses = [ '1.2.3.4:5678', '2.3.4.5:6789' ]
        self.mock(baseDriver.BaseDriver, 'postFork', mockPostFork)

        self.setUpSystemManager()
        self.setUpSchemaDir()