def runCommand(self, thisCommand, cfg, argSet, args, debugAll=False): client = conaryclient.ConaryClient(cfg) repos = client.getRepos() callback = commit.CheckinCallback(cfg) if not cfg.buildLabel and cfg.installLabelPath: cfg.buildLabel = cfg.installLabelPath[0] sys.excepthook = util.genExcepthook(debug=cfg.debugExceptions, debugCtrlC=debugAll) if cfg.installLabelPath: cfg.installLabel = cfg.installLabelPath[0] else: cfg.installLabel = None cfg.initializeFlavors() log.setMinVerbosity(log.INFO) log.resetErrorOccurred() # set the build flavor here, just to set architecture information # which is used when initializing a recipe class use.setBuildFlagsFromFlavor(None, cfg.buildFlavor, error=False) profile = False if argSet.has_key('lsprof'): import cProfile prof = cProfile.Profile() prof.enable() profile = 'lsprof' del argSet['lsprof'] keyCache = openpgpkey.getKeyCache() keyCache.setPublicPath(cfg.pubRing) repos = conaryclient.ConaryClient(cfg).getRepos() keyCacheCallback = openpgpkey.KeyCacheCallback(repos, cfg) keyCache.setCallback(keyCacheCallback) try: rv = options.MainHandler.runCommand(self, thisCommand, cfg, argSet, args, callback=callback, repos=client.getRepos(), profile=profile) finally: if profile == 'lsprof': prof.disable() prof.dump_stats('cvc.lsprof') prof.print_stats() elif profile: prof.stop() if log.errorOccurred(): sys.exit(2) return rv
def testBasic(self): fooRun = self.addComponent('foo:runtime', '1') barRun = self.addComponent('bar:runtime', '1', '', ['/foobar']) foo = self.addCollection('foo', '1', [':runtime']) bar = self.addCollection('bar', '1', [':runtime']) cacheDir = self.workDir + '/cache' util.mkdirChain(cacheDir) client = conaryclient.ConaryClient(self.cfg) repos = self.openRepository() store = repocache.RepositoryCache(cacheDir) foocs, barruncs = store.getChangeSetsForTroves( repos, [foo.getNameVersionFlavor(), barRun.getNameVersionFlavor()], withFiles=True, withFileContents=True) assert (len(list(foocs.iterNewTroveList())) == 1) jobList = [(x[0], (None, None), (x[1], x[2]), False) for x in [foo.getNameVersionFlavor(), barRun.getNameVersionFlavor()]] updJob, suggMap = client.updateChangeSet( jobList, fromChangesets=[foocs, barruncs], resolveDeps=False, recurse=False) client.applyUpdate(updJob, replaceFiles=False) assert (os.path.exists(self.rootDir + '/foobar')) foocs2, barruncs2 = store.getChangeSetsForTroves( None, [foo.getNameVersionFlavor(), barRun.getNameVersionFlavor()], withFileContents=True) foo2, barrun2 = store.getTroves( None, [foo.getNameVersionFlavor(), barRun.getNameVersionFlavor()], withFileContents=True) assert (foo2.verifyDigests()) assert (barrun2.verifyDigests()) assert (len(list(foocs2.iterNewTroveList())) == 1) self.resetRoot() client = conaryclient.ConaryClient(self.cfg) updJob, suggMap = client.updateChangeSet( jobList, fromChangesets=[foocs2, barruncs2], resolveDeps=False, recurse=False) self.resetRepository() # make sure we're using just the changesets client.applyUpdate(updJob, replaceFiles=False) assert (os.path.exists(self.rootDir + '/foobar'))
def _getNevras(self, NEVRA, label): cfg = conarycfg.ConaryConfiguration(True) client = conaryclient.ConaryClient(cfg) tvers = client.repos.getTroveVersionsByLabel({None: {label: None}}) specs = [] #for n, vs in tvers.iteritems(): for n, vs in iter(sorted(tvers.iteritems())): if not n.endswith(':rpm'): continue for v, fs in vs.iteritems(): for f in fs: specs.append((n, v, f)) capsuleInfo = client.repos.getTroveInfo(trove._TROVEINFO_TAG_CAPSULE, specs) #sort by name, version and commit date specs.sort() for spec, info in itertools.izip(specs, capsuleInfo): r = info.rpm nevra = NEVRA(r.name(), r.epoch(), r.version(), r.release(), r.arch()) yield spec, nevra
def displayUpdateInfo(updJob, cfg, noRestart=False): jobLists = updJob.getJobs() db = conaryclient.ConaryClient(cfg).db formatter = display.JobTupFormatter(affinityDb=db) formatter.dcfg.setTroveDisplay(fullVersions=cfg.fullVersions, fullFlavors=cfg.fullFlavors, showLabels=cfg.showLabels, baseFlavors=cfg.flavor, showComponents=cfg.showComponents) formatter.dcfg.setJobDisplay(compressJobs=not cfg.showComponents) formatter.prepareJobLists(jobLists) totalJobs = len(jobLists) for num, job in enumerate(jobLists): if totalJobs > 1: if num in updJob.getCriticalJobs(): print '** ', print 'Job %d of %d:' % (num + 1, totalJobs) for line in formatter.formatJobTups(job, indent=' '): print line if updJob.getCriticalJobs() and not noRestart: criticalJobs = updJob.getCriticalJobs() if len(criticalJobs) > 1: jobPlural = 's' else: jobPlural = '' jobList = ', '.join([str(x + 1) for x in criticalJobs]) print print '** The update will restart itself after job%s %s and continue updating' % (jobPlural, jobList) return
def _install(jobList): self.cfg.flavor = [] openpgpkey.getKeyCache().setPublicPath(self.cfg.root + '/root/.gnupg/pubring.gpg') openpgpkey.getKeyCache().setPrivatePath(self.cfg.root + '/root/.gnupg/secring.gpg') self.cfg.pubRing = [self.cfg.root + '/root/.gnupg/pubring.gpg'] client = conaryclient.ConaryClient(self.cfg) client.setUpdateCallback(self.callback) if self.csCache: changeSetList = self.csCache.getChangeSets( client.getRepos(), jobList, callback=self.callback) else: changeSetList = [] updJob = client.newUpdateJob() try: client.prepareUpdateJob(updJob, jobList, keepExisting=False, resolveDeps=False, recurse=False, checkPathConflicts=False, fromChangesets=changeSetList, migrate=True) except conaryclient.update.NoNewTrovesError: # since we're migrating, this simply means there were no # operations to be performed pass else: util.mkdirChain(self.cfg.root + '/root') client.applyUpdate(updJob, replaceFiles=True, tagScript=self.cfg.root + '/root/tagscripts')
def testLocalRollbackCheck(self): self.addComponent('foo:runtime', '1') self.addComponent('foo:runtime', '2') self.updatePkg('foo:runtime=1') self.updatePkg('foo:runtime=2') self.erasePkg(self.rootDir, 'foo:runtime') self.cfg.localRollbacks = True self.updatePkg('foo:runtime=1') self.updatePkg('foo:runtime=2') self.erasePkg(self.rootDir, 'foo:runtime') try: client = conaryclient.ConaryClient(self.cfg) rbStack = client.getDatabase().getRollbackStack() assert(rbStack.getRollback('r.0').isLocal()) assert(not rbStack.getRollback('r.1').isLocal()) assert(not rbStack.getRollback('r.2').isLocal()) # these operations were done with localRollbacks True assert(rbStack.getRollback('r.3').isLocal()) assert(rbStack.getRollback('r.4').isLocal()) assert(rbStack.getRollback('r.5').isLocal()) finally: self.cfg.localRollbacks = False
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:
def _restoreFromCache(self): if not self.chrootCache: return None, False start = time.time() client = conaryclient.ConaryClient(self.cfg) manifest = self._getManifest(client) stop = time.time() self.logger.info("Spent %.03f seconds fetching fingerprints", stop - start) self.chrootFingerprint = manifest.getFingerprint() if self.chrootCache.hasChroot(self.chrootFingerprint): start = time.time() self.chrootCache.restore(self.chrootFingerprint, self.cfg.root) stop = time.time() self.logger.info("Restored chroot %s in %.03f seconds", self.chrootFingerprint.encode('hex'), stop - start) return manifest, True start = time.time() partial = self.chrootCache.findPartialMatch(manifest) stop = time.time() self.logger.info("Spent %.03f seconds looking for a partial match", stop - start) if partial: start = time.time() self.chrootCache.restore(partial, self.cfg.root) stop = time.time() self.logger.info("Restored chroot %s in %.03f seconds (partial)", partial.encode('hex'), stop - start) # Continue with rest of install return manifest, False
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)
def testConaryProxy(self): self.openRepository() cProxy = self.getConaryProxy(proxies=self.cfg.conaryProxy) if self.cfg.conaryProxy: proxyCount = 2 else: proxyCount = 1 try: cProxy.start() cProxy.addToConfig(self.cfg) repos = conaryclient.ConaryClient(self.cfg).getRepos() pv = repos.c['localhost'].getProtocolVersion() self.assertEqual(pv, netserver.SERVER_VERSIONS[-1]) transport = repos.c['localhost']._transport self.assertTrue('via' in transport.responseHeaders) via = transport.responseHeaders['via'] via = via.split(',') if os.environ.get('CONARY_HTTP_PROXY', None) and \ os.environ.get('CONARY_PROXY', None): proxyCount += 1 self.assertEqual(len(via), proxyCount) self._assertProxy(via[-1], cProxy) finally: cProxy.stop()
def setProductInfo(trvSpec, info): trvSpec = cmdline.parseTroveSpec(trvSpec) cfg = conarycfg.ConaryConfiguration(True) client = conaryclient.ConaryClient(cfg) repos = client.getRepos() nvfs = repos.findTrove(None, trvSpec) if not len(nvfs): print >>sys.stderr, 'did not find any troves matching %s' % trvSpec return 1 nvf = nvfs[0] trv = repos.getTrove(*nvf) md = trv.troveInfo.metadata keyValue = md.get(1).get('keyValue') if not keyValue: mi = trove.MetadataItem() md.addItem(mi) keyValue = mi.keyValue keyValue['product_info'] = json.dumps(info) repos.setTroveInfo([(nvf, trv.troveInfo), ])
def testGetOverlappingPaths(self): # because they are modifying the same file. tst1 = self.addComponent('test:run', '1.0', '', ['/tmp/foo', '/tmp/fooz', '/tmp/bam']) tst2 = self.addComponent('test:run', '2.0', '', ['/tmp/foo2', '/tmp/fooz2']) foo = self.addComponent('foo:run', '1.0', '', ['/tmp/foo', '/tmp/fooz']) bam = self.addComponent('bam:run', '1.0', '', ['/tmp/bam']) bar = self.addComponent('bar:run', '1.0', '', ['/tmp/bar']) baz = self.addComponent('baz:run', '1.0', '', ['/tmp/baz']) baz2 = self.addComponent('baz2:run', '1.0', '', ['/tmp/baz']) baz3 = self.addComponent('baz3:run', '1.0', '', ['/tmp/baz']) baz4 = self.addComponent('baz4:run', '1.0', '', ['/tmp/baz']) self.updatePkg('test:run=1.0') job = [(tst1.getName(), (tst1.getVersion(), tst1.getFlavor()), (tst2.getVersion(), tst2.getFlavor()), False)] for trv in foo, bam, bar, baz, baz2, baz3, baz4: job.append((trv.getName(), (None, None), (trv.getVersion(), trv.getFlavor()), False)) cl = conaryclient.ConaryClient(self.cfg) uJob = database.UpdateJob(cl.db) repos = self.openRepository() cs = repos.createChangeSet(job, withFiles=False) uJob.getTroveSource().addChangeSet(cs) overlapping = cl._findOverlappingJobs(job, uJob.getTroveSource()) overlappingNames = sorted([ sorted([y[0] for y in x]) for x in overlapping]) assert(overlappingNames == [['bam:run', 'foo:run', 'test:run'], ['baz2:run', 'baz3:run', 'baz4:run', 'baz:run']])
def doCommit(cfg, changeSetFile, targetLabel): client = conaryclient.ConaryClient(cfg) repos = client.getRepos() callback = CheckinCallback() try: cs = changeset.ChangeSetFromFile(changeSetFile) except filecontainer.BadContainer: log.error("invalid changeset %s", changeSetFile) return 1 if cs.isLocal(): if not targetLabel: log.error("committing local changesets requires a targetLabel") label = versions.Label(targetLabel) cs.setTargetShadow(repos, label) commitCs = cs.makeAbsolute(repos) (fd, changeSetFile) = tempfile.mkstemp() os.close(fd) commitCs.writeToFile(changeSetFile) try: # hopefully the file hasn't changed underneath us since we # did the check at the top of doCommit(). We should probably # add commitChangeSet method that takes a fd. try: repos.commitChangeSetFile(changeSetFile, callback=callback) except errors.CommitError, e: print e finally: if targetLabel: os.unlink(changeSetFile)
def __init__(self, passwd=None, getPerson=None, host='localhost', user='******', database='jira', verbose=False): self.getPerson = getPerson self.verbose = verbose self.sourceMap = {} self.sourceOwner = {} self.personIdMap = None self.productIdMap = None if not passwd: self.db = dbstore.connect("%s@%s/%s" % (user, host, database), driver='mysql') else: self.db = dbstore.connect("%s:%s@%s/%s" % (user, passwd, host, database), driver='mysql') cfg = conarycfg.ConaryConfiguration() client = conaryclient.ConaryClient(cfg) self.repos = client.getRepos() self.indentWrapper = textwrap.TextWrapper(subsequent_indent=' ', break_long_words=False)
def signTroves(cfg, specStrList, recurse=False, callback=None): troveStr = "" jobList = [] trv = [] client = conaryclient.ConaryClient(cfg) repos = client.getRepos() if callback is None: if cfg.quiet: callback = callbacks.SignatureCallback() else: callback = SignatureCallback() for specStr in specStrList: name, versionStr, flavor = parseTroveSpec(specStr) try: trvList = repos.findTrove([cfg.buildLabel], (name, versionStr, flavor), cfg.flavor) except errors.TroveNotFound, e: log.error(str(e)) return for trvInfo in trvList: troveStr += "%s=%s[%s]\n" % (trvInfo[0], trvInfo[1].asString(), deps.formatFlavor(trvInfo[2])) jobList.append( (trvInfo[0], (None, None), (trvInfo[1], trvInfo[2]), True))
def _setup(): self.resetRoot() self.updatePkg('foo:runtime=1') self.updatePkg('foo:runtime=2') self.updatePkg('foo:runtime=3') client = conaryclient.ConaryClient(self.cfg) return client.getDatabase()
def _getRepos(self, buildCfg, caching=True): repos = conaryclient.ConaryClient(buildCfg).getRepos() if caching: repos = repocache.CachingTroveSource(repos, self.cfg.root + '/tmp/cscache', readOnly=True) return repos
def refreshVersionSnapshots(self): from conary import conaryclient cfg = self.cfg cclient = conaryclient.ConaryClient(cfg) repos = cclient.getRepos() origOps = set() newOps = {} # {TroveSpec: [CMTroveSpec, ...]} for item in self._iterOpTroveItems(): if isinstance(item, CMTroveSpec) and item.snapshot: l = origOps.add(item) newSpec = item.labelSpec() l = newOps.setdefault(newSpec, []) l.append(item) allOpSpecs = list(origOps) + newOps.keys() if not allOpSpecs: return foundTroves = repos.findTroves(cfg.installLabelPath, allOpSpecs, defaultFlavor=cfg.flavor, allowMissing=True) # origOps may be missing, newOps may not missing = set(newOps) - set(foundTroves) if missing: missing = sorted('%s=%s' % x[:2] for x in missing) if len(missing) == 1: raise errors.TroveNotFound("Trove not found: " + missing[0]) else: raise errors.TroveNotFound("%d troves not found:\n%s" % (len(missing), "\n".join(missing))) # Calculate the appropriate replacements from the lookup replaceSpecs = {} # CMTroveSpec: TroveSpec for troveKey in foundTroves: if troveKey in newOps: for oldTroveKey in newOps[troveKey]: if foundTroves[troveKey] != foundTroves.get(oldTroveKey): # found a new version, create replacement troveSpec foundTrove = foundTroves[troveKey][0] newVersion = foundTrove[1] newverstr = '%s/%s' % (newVersion.trailingLabel(), newVersion.trailingRevision()) troveTup = (oldTroveKey[0], newverstr, oldTroveKey[2]) replaceSpecs[oldTroveKey] = troveTup # Apply the replacement specs to the model for op in self.modelOps: if isinstance(op, TroveOperation): newItem = [replaceSpecs.get(x, x) for x in op.item] if newItem != op.item: # at least one spec was replaced; update the line op.update(newItem) elif isinstance(op, (SearchTrove, IncludeOperation)): if op.item in replaceSpecs: op.update(replaceSpecs[op.item])
def _model_apply_update_job(updJob, cfg, modelFile, callback): if not updJob.getJobs(): return client = conaryclient.ConaryClient(cfg, modelFile=modelFile) client.setUpdateCallback(callback) client.checkWriteableRoot() client.applyUpdateJob(updJob, noRestart=True) modelFile.closeSnapshot()
def showKey(cfg, server, fingerprint): client = conaryclient.ConaryClient(cfg) repos = client.getRepos() if server is None: server = cfg.buildLabel.getHost() key = repos.getAsciiOpenPGPKey(server, fingerprint) print key
def _model_build_update_job(cfg, model, modelFile, callback): '''Build an UpdateJob based on the system model ''' # Copied from conary/cmds/updatecmd.py:_updateTroves(), with slight # modification client = conaryclient.ConaryClient(cfg, modelFile=modelFile) client.setUpdateCallback(callback) updJob = client.newUpdateJob() try: tc = modelupdate.CMLTroveCache(client.getDatabase(), client.getRepos(), callback = callback) tcPath = cfg.root + cfg.dbPath + '/modelcache' if os.path.exists(tcPath): callback.loadingModelCache() tc.load(tcPath) ts = client.cmlGraph(model) try: suggMap = client._updateFromTroveSetGraph(updJob, ts, tc, callback = callback) except errors.TroveSpecsNotFound: callback.done() client.close() return updJob, {} finalModel = copy.deepcopy(model) if model.suggestSimplifications(tc, ts.g): ts2 = client.cmlGraph(model) updJob2 = client.newUpdateJob() try: suggMap2 = client._updateFromTroveSetGraph(updJob2, ts2, tc) except errors.TroveNotFound: pass else: if (suggMap == suggMap2 and updJob.getJobs() == updJob2.getJobs()): ts = ts2 finalModel = model updJob = updJob2 suggMap = suggMap2 model = finalModel modelFile.model = finalModel if tc.cacheModified(): callback.savingModelCache() tc.save(tcPath) callback.done() except: callback.done() client.close() raise return updJob, suggMap
def getClient(counter = None, threaded = False): newcfg = copy.deepcopy(self.cfg) newcfg.user = conarycfg.UserInformation() for userInfo in userList: newcfg.user.addServerGlob(*userInfo) newcfg.threaded = threaded cb = getCallback(counter) cl = conaryclient.ConaryClient(cfg = newcfg, passwordPrompter = cb) return (cl, cl.getRepos())
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)
def testDisconnectRepos(self): flv = parseFlavor('is: x86') self.addComponent('foo:run', '1', flv, fileContents='foo 1\n') client = conaryclient.ConaryClient(self.cfg) ver = versions.Version([self.defLabel, versions.Revision('1-1-1')]) troveSpec = [ ('foo:run', (None, None), (ver, flv), True)] cs = client.createChangeSet(troveSpec) client.disconnectRepos() self.assertRaises(conaryclient.errors.RepositoryError, client.createChangeSet, troveSpec)
def __init__(self, cfg, ccfg, inputFormatter, dispatcher): self._cfg = cfg # Since there's no clone method on a cfg object, use the pickle protocol self._ccfg = ccfg.__class__() self._ccfg.__setstate__(ccfg.__getstate__()) self._dispatcher = dispatcher self._formatInput = inputFormatter # Restet dbPath to the default value for local cooking. self._ccfg.resetToDefault('dbPath') self._client = conaryclient.ConaryClient(self._ccfg)
def updateAll(cfg, **kwargs): showItems = kwargs.pop('showItems', False) restartInfo = kwargs.get('restartInfo', None) migrate = kwargs.pop('migrate', False) modelArg = kwargs.pop('model', False) modelFile = kwargs.get('systemModelFile', None) model = kwargs.get('systemModel', None) infoArg = kwargs.get('info', False) if model and modelFile and modelFile.exists() and restartInfo is None: model.refreshVersionSnapshots() if modelArg: model.write(sys.stdout) sys.stdout.flush() return None kwargs['installMissing'] = kwargs['removeNotByDefault'] = migrate if 'callback' not in kwargs or not kwargs.get('callback'): kwargs['callback'] = UpdateCallback(cfg) # load trove cache only if --info provided kwargs['loadTroveCache'] = infoArg client = conaryclient.ConaryClient(cfg) # We want to be careful not to break the old style display, for whoever # might have a parser for that output. withLongDisplay = (cfg.fullFlavors or cfg.fullVersions or cfg.showLabels) formatter = UpdateAllFormatter() if restartInfo or (model and modelFile and modelFile.exists()): updateItems = [] applyList = None else: if showItems and withLongDisplay: updateItems = client.getUpdateItemList() dcfg = display.DisplayConfig() dcfg.setTroveDisplay(fullFlavors = cfg.fullFlavors, fullVersions = cfg.fullVersions, showLabels = cfg.showLabels) formatter = display.TroveTupFormatter(dcfg) else: updateItems = client.fullUpdateItemList() applyList = [ (x[0], (None, None), x[1:], True) for x in updateItems ] if showItems: for (name, version, flavor) in sorted(updateItems, key=lambda x:x[0]): print formatter.formatNVF(name, version, flavor) return _updateTroves(cfg, applyList, **kwargs) # Clean up after ourselves if restartInfo: util.rmtree(restartInfo, ignore_errors=True)
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()
def addKey(cfg, server, user): client = conaryclient.ConaryClient(cfg) repos = client.getRepos() if server is None: server = cfg.buildLabel.getHost() if user is None: user = cfg.user.find(server)[0] asciiKey = sys.stdin.read() binaryKey = openpgpfile.parseAsciiArmorKey(asciiKey) repos.addNewPGPKey(server, user, binaryKey)
def changePins(cfg, troveStrList, pin = True, systemModel = None, systemModelFile = None, callback = None): client = conaryclient.ConaryClient(cfg) client.checkWriteableRoot() troveList = [] for item in troveStrList: name, ver, flv = parseTroveSpec(item) troves = client.db.findTrove(None, (name, ver, flv)) troveList += troves client.pinTroves(troveList, pin = pin) if systemModel and systemModelFile and not pin: doModelUpdate(cfg, systemModel, systemModelFile, [], callback=callback)
def testRollbackTransactionCounter(self): # CNY-1624 client = conaryclient.ConaryClient(self.cfg) # Make sure we get an assertion error if not passing the transaction # counter self.assertRaises(AssertionError, client.db.applyRollbackList, 'junk', 'junk') # Bogus transaction counter try: client.db.applyRollbackList('junk', 'junk', transactionCounter = 1000) except database.RollbackError, e: self.assertEqual(str(e), 'rollback junk cannot be applied:\n' 'Database state has changed, please run the rollback ' 'command again')