def testStrictOptionaParamsThroughArgDef(self): flags, args = options._processArgs( {'coverage' : options.STRICT_OPT_PARAM}, {}, conarycfg.ConaryConfiguration(False), '', argv=['foo', '--coverage', 'bar'])[0:2] assert(flags['coverage'] == True) assert(args == ['foo', 'bar']) flags, args = options._processArgs( {'coverage' : options.STRICT_OPT_PARAM}, {}, conarycfg.ConaryConfiguration(False), '', argv=['foo', '--coverage=bar'])[0:2] assert(flags['coverage'] == 'bar') assert(args == ['foo'])
def testIncludeConfigFileInContext(self): configfile1 = """ [foo] buildLabel foo.rpath.org@rpl:devel includeConfigFile bar threaded False """ configfile2 = """ installLabelPath foo.rpath.org@rpl:ilp [bam] buildLabel bam.rpath.org@rpl:devel """ tdir = tempfile.mkdtemp() cwd = os.getcwd() os.chdir(tdir) try: f = open('foo', 'w').write(configfile1) f = open('bar', 'w').write(configfile2) cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.read(tdir + '/foo') cfg.setContext('foo') assert(str(cfg.buildLabel) == 'foo.rpath.org@rpl:devel') assert(str(cfg.installLabelPath[0]) == 'foo.rpath.org@rpl:ilp') assert(len(cfg.installLabelPath) == 1) rc, txt = self.captureOutput(cfg.displayContext) self.assertEqual(txt, '''\ [foo] buildLabel foo.rpath.org@rpl:devel installLabelPath foo.rpath.org@rpl:ilp threaded False ''') finally: os.chdir(cwd) shutil.rmtree(tdir)
def main(args, fingerprints): if len(args) != 3: return usage(args) cfg = conarycfg.ConaryConfiguration(True) keyringfn = args[2] sync = KeySync(cfg, keyringfn=keyringfn) if args[1] == 'get': msg = 'getting' method = sync.getKey elif args[1] == 'set': msg = 'setting' method = sync.setKey for server_name, fps in fingerprints.iteritems(): for fp in fps.split(): fp = fp.strip() if not fp: continue try: print >> sys.stdout, '%s: %s %s' % (server_name, msg, fp) method(server_name, fp) except Exception, e: print >> sys.stderr, str(e) return 1 time.sleep(1)
def testSetEntitlementWithClass(self): cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.configLine("entitlement a b c") sio = StringIO() cfg.storeKey('entitlement', sio) line = ' '.join(x for x in sio.getvalue().strip().split() if x) self.assertEqual(line, 'entitlement a b c')
def getClient(context=None, environ=None, searchCurrentDir=False, cfg=None): """ Returns a ConaryClient object that has the context set as it would be if the conary command line were used. This means it checks for the explicit "context" variable passed in manually. It follows by checking the eviron dict (defaults to os.environ) for the CONARY_CONTEXT variable. It then falls back to the CONARY file and looks for a context set there. Finally, if these checks fail to find a context, it will look at the context specified in the cfg variable. @param context: a context override string or None @param environ: a dict representing the current environment or None to use os.environ @param searchCurrentDir: if True, look in the current directory for a CONARY file and set the context from there if needed. Otherwise, do not look for a CONARY file. (Default False) @param cfg: ConaryConfiguration to use. If None, read the configuration as conary would, from /etc/conaryrc, ~/.conaryrc, and ./conaryrc. """ if cfg is None: cfg = conarycfg.ConaryConfiguration(True) cmdline.setContext(cfg, context, environ, searchCurrentDir) return ConaryClient(cfg)
def testServerGlob(self): # CNY-2083 cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) l = [] for i in range(10000): l.append(("server-%05d" % i, ('name-%05d' % i, 'pass'))) cfg.user.addServerGlobs(l) cfg.user.clear() l = [ ('*-commits', ('c', 'pass')), ('c*', ('c', 'pass')), ('conary-commits', ('conary-commits', 'pass')), ('conary-commits', ('conary-commits2', 'pass')), ('conary-*', ('conary-', 'pass')), ('conary-commits', ('conary-commits3', 'pass')), ] cfg.user.addServerGlobs(l) target = [ ('conary-commits', 'conary-commits', 'pass'), ('conary-*', 'conary-', 'pass'), ('c*', 'c', 'pass'), ('*-commits', 'c', 'pass'), ] self.assertEqual(list(cfg.user), target) # Now verify that addServerGlob does the same thing cfg.user.clear() # extend reverses the list, so to achieve the same effect we have to # process l in reverse order too for item in reversed(l): cfg.user.addServerGlob(*item) self.assertEqual(list(cfg.user), target)
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 testFingerprintMap(self): cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.configLine('signatureKeyMap local@rpl:devel 00000') out = StringIO() cfg.displayKey('signatureKeyMap', out) assert (out.getvalue() == 'signatureKeyMap local@rpl:devel 00000\n')
def testShimClient(self): t = self.addQuickTestComponent('test:runtime', '1.0-1-1') shim, cfg = self._setupShim() label = t.getVersion().branch().label() self.assertEqual(shim.troveNames(label), ['test:runtime']) n, v, f = t.getName(), t.getVersion(), t.getFlavor() trove = shim.getTroves([(n, v, f)])[0] self.assertEqual(trove.getName(), n) # test 3-member auth token server = shimclient.NetworkRepositoryServer(cfg, self.cfg.repositoryMap['localhost']) empty = conarycfg.ConaryConfiguration(False) shim = shimclient.ShimNetClient(server, 'http', 80, ('anonymous', 'anonymous', []), cfg=empty) trove = shim.getTroves([(n, v, f)])[0] self.assertEqual(trove.getName(), n) # test exceptions self.assertRaises(errors.InsufficientPermission, shim.updateRoleMembers, 'localhost', 'unknown_group', [])
def testIncludeUnreachableNetworkConfigFile(self): configUrl = "http://10.1.1.1/conaryrc" fobj = tempfile.NamedTemporaryFile() print >> fobj, "includeConfigFile", configUrl fobj.flush() cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) def _getOpener(): opener = type(cfg)._getOpener(cfg) opener.connectAttempts = 1 return opener cfg._getOpener = _getOpener def connectSocket(self): raise socket.timeout('timed out') oldfn = connection.Connection.connectSocket oldStderr = sys.stderr connection.Connection.connectSocket = connectSocket try: sys.stderr = StringIO() try: cfg.read(fobj.name) except conarycfg.ParseError, e: assert 'timed out' in str(e) or 'timeout' in str(e) else:
def testUserInfo(self): cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.user.addServerGlob('name*', 'user', 'passwd') cfg.configLine('user foobar a') self.assertEqual(cfg.user.find('namefoo'), ('user', 'passwd')) self.assertEqual(cfg.user.find('foobar'), ('a', None)) out = StringIO() cfg.setDisplayOptions(hidePasswords=True) cfg.displayKey('user', out) assert (out.getvalue() == """\ user foobar a user name* user <password> """) out = StringIO() cfg.setDisplayOptions(hidePasswords=False) cfg.displayKey('user', out) assert (out.getvalue() == """\ user foobar a user name* user passwd """) assert (cfg.user.find('nameone') == ('user', 'passwd')) cfg.user.addServerGlob('nameone', 'user1', 'passwd1') assert (cfg.user.find('nameone') == ('user1', 'passwd1')) # CNY-1267 try: cfg.configLine('user conary.rpath.com "Michael Jordon" a') except conarycfg.ParseError, e: self.assertEqual( str(e), "override:<No line>: expected <hostglob> <user> [<password>] for configuration item 'user'" )
def testIncludeConfigFileStableOrder(self): # CNY-2483 cfgdir = os.path.join(self.workDir, "cfgdir") os.mkdir(cfgdir) cfg = os.path.join(self.workDir, "cfg") cfg1 = os.path.join(cfgdir, "cfg1") cfg2 = os.path.join(cfgdir, "cfg2") # Make sure we create cfg1 after cfg2 - we have higher chances of glob # sorting them by creation time self.writeFile(cfg2, "installLabelPath A@B:C\n") self.writeFile(cfg1, "installLabelPath a@b:c\n") self.writeFile(cfg, "includeConfigFile %s/*\n" % cfgdir) c = conarycfg.ConaryConfiguration(readConfigFiles=False) obc = util.braceGlob def mockBraceGlob(val): return reversed(obc(val)) self.mock(util, 'braceGlob', mockBraceGlob) c.read(cfg) self.assertEqual(len(c.installLabelPath), 1) self.assertEqual(str(c.installLabelPath[0]), "A@B:C")
def getConaryConfig(self, useCache=True): """ Fetches a (possibly cached) B{opaque} conary config object with all appropriate data inherited from the associated rbuild config object. @param useCache: if True (default), uses a cached version of the conary configuration file if available. @type useCache: bool @return: C{conarycfg.ConaryConfiguration} B{opaque} object """ if self._conaryCfg and useCache: return self._conaryCfg cfg = conarycfg.ConaryConfiguration(False) rbuildCfg = self._handle.getConfig() self._parseRBuilderConfigFile(cfg) #pylint: disable-msg=E1101 # pylint does not understand config objects very well cfg.repositoryMap.update(rbuildCfg.repositoryMap) cfg.user.append(('*', ) + rbuildCfg.user) cfg.name = rbuildCfg.name cfg.contact = rbuildCfg.contact cfg.signatureKey = rbuildCfg.signatureKey cfg.signatureKeyMap = rbuildCfg.signatureKeyMap if useCache: self._conaryCfg = cfg return cfg
def testSignatureKeyOptions(self): cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.configLine("signatureKey") if (cfg.signatureKey is not None): self.fail( "signatureKey line with nothing following didn't return None") cfg.configLine("signatureKey A_FINGERPRINT #item") if (cfg.signatureKey is None): self.fail("signatureKey line illegally returned None") assert (cfg.signatureKey == 'A_FINGERPRINT') cfg.configLine("signatureKey None") if (cfg.signatureKey is not None): self.fail( "signatureKey line didn't return None when explicitly specified" ) cfg.configLine("signatureKeyMap label_1") cfg.configLine("signatureKeyMap label_2 None") for label, fingerprint in cfg.signatureKeyMap: if (fingerprint is not None): self.fail("signatureKeyMap for label %s didn't return None" % label) out = StringIO() cfg.displayKey('signatureKeyMap', out) assert ( out.getvalue() == 'signatureKeyMap label_1 None\nsignatureKeyMap label_2 None\n' ) cfg.configLine("signatureKeyMap label_2 A_FINGERPRINT") cfg.configLine("signatureKey") if (cfg.signatureKeyMap): self.fail("assigning a signatureKey did not reset signatureKeyMap")
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 __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 __init__(self): # get configs from /etc/conary cfg = conarycfg.ConaryConfiguration( readConfigFiles = True) # get if the machine its x86 or x86_64 cfg.initializeFlavors() self.cfg = cfg # Don't use threaded mode self.cfg.configLine('threaded False') cli = ConaryClient(cfg) # labels enable on /etc/conary/config.d/ self.default_label = self.cfg.installLabelPath # get if x86 or x86_64 self.flavors = self.cfg.flavor self.flavor = self.cfg.flavor[0] # for client self.cli = cli # for query on system (database) self.db = cli.db # for request query on repository (repos) self.repos = cli.repos self.job_cache = UpdateJobCache()
def testPrintEntitlement(self): cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.configLine("entitlement a b") sio = StringIO() cfg.storeKey('entitlement', sio) # Drop extra white spaces line = ' '.join(x for x in sio.getvalue().strip().split() if x) self.assertEqual(line, 'entitlement a b')
def testProxyMapEquality(self): proxySpecs = [ ('1.1.1.1', 'proxy1.example.com proxy2.example.com'), ('1.2.3.4', 'direct'), ] cfg1 = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg2 = conarycfg.ConaryConfiguration(readConfigFiles=False) for cfg in [cfg1, cfg2]: cfg.configLine("proxyMap []") for host, proxy in proxySpecs: cfg.configLine("proxyMap %s %s" % (host, proxy)) pm1 = cfg1.getProxyMap() pm2 = cfg2.getProxyMap() self.assertEqual(pm1, pm2) del pm1.filterList[0] self.assertFalse(pm1 == pm2)
def _getMirrorClient(mirrorCfg, section): section = mirrorCfg.getSection(section) cfg = conarycfg.ConaryConfiguration(False) for name in ['repositoryMap', 'user', 'entitlement']: cfg[name] = section[name] for name in ['uploadRateLimit', 'downloadRateLimit', 'entitlementDirectory']: cfg[name] = mirrorCfg[name] return netclient.NetworkRepositoryClient(cfg=cfg)
def testProxyMapDirect(self): cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.configLine("proxyMap []") cfg.configLine("proxyMap 1.1.1.1 direct") pm = cfg.getProxyMap() from conary.lib.http import proxy_map self.assertEquals([x for x in pm.getProxyIter('1.1.1.1')], [proxy_map.DirectConnection])
class ConaryCfgTest(rephelp.RepositoryHelper): cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) argDef = {} cfgMap = {} cfgMap["cfgmap"] = "root" (NO_PARAM, ONE_PARAM) = (options.NO_PARAM, options.ONE_PARAM) (OPT_PARAM, MULT_PARAM) = (options.OPT_PARAM, options.MULT_PARAM) STRICT_OPT_PARAM = options.STRICT_OPT_PARAM argDef['no'] = NO_PARAM argDef['one'] = ONE_PARAM argDef['opt'] = OPT_PARAM argDef['mult'] = MULT_PARAM argDef['strict'] = STRICT_OPT_PARAM def usage(rc=1): return rc def testOptions(self): argv = [ 'conary', '--no', 'other1', '--one=onev', 'other2', '--opt=opt', '--mult', 'multv1', 'other3', '--mult', '--multv2', 'other4' ] argSet, otherArgs = options.processArgs(self.argDef, self.cfgMap, self.cfg, self.usage, argv=argv) assert (otherArgs == [ 'conary', 'other1', 'other2', 'other3', 'other4' ]) assert (argSet['no'] is True) assert (argSet['one'] == 'onev') assert (argSet['opt'] == 'opt') assert (argSet['mult'] == ['multv1', '--multv2']) def testBadParams(self): argv = ['conary', '--unknown'] try: options.processArgs(self.argDef, self.cfgMap, self.cfg, self.usage, argv=argv) raise RuntimeError except options.OptionError, msg: assert (msg[0] == 'no such option: --unknown') argv = ['conary', '--one'] try: options.processArgs(self.argDef, self.cfgMap, self.cfg, self.usage, argv=argv) raise RuntimeError except options.OptionError, msg: assert (msg[0] == '--one option requires an argument')
def testIncludeConfigFileNoLoop(self): # CNY-914: including the same file in two contexts fd, configfile = tempfile.mkstemp() fd1, configfile1 = tempfile.mkstemp() fd2, configfile2 = tempfile.mkstemp() fd3, configfile3 = tempfile.mkstemp() f = os.fdopen(fd, "w+") f1 = os.fdopen(fd1, "w+") f2 = os.fdopen(fd2, "w+") f3 = os.fdopen(fd3, "w+") f.write("includeConfigFile %s\n" % configfile1) f.write("includeConfigFile %s\n" % configfile2) f1.write("[sect1]\n") f1.write("buildLabel c.example.com@foo:1\n") f1.write("includeConfigFile %s\n" % configfile3) f2.write("[sect2]\n") f2.write("buildLabel c.example.com@foo:2\n") f2.write("includeConfigFile %s\n" % configfile3) f3.write("lookaside /tmp/foobar\n") for fobj in (f, f1, f2, f3): fobj.close() cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.read(configfile) expected = { 'sect1': { 'buildLabel': versions.Label('c.example.com@foo:1'), 'lookaside': '/tmp/foobar', }, 'sect2': { 'buildLabel': versions.Label('c.example.com@foo:2'), 'lookaside': '/tmp/foobar', } } for sectName in cfg.iterSectionNames(): self.assertTrue(sectName in expected) sect = cfg.getSection(sectName) expSect = expected[sectName] for k in ['buildLabel', 'lookaside']: self.assertEqual(sect[k], expSect[k]) del expected[sectName] # More sections? self.assertFalse(expected) for cf in [configfile, configfile1, configfile2, configfile3]: os.unlink(cf)
def testRepositoryMap(self): cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.configLine('repositorymap a.b.c http://a.b.c:8000/conary/') self.assertRaises(conarycfg.ParseError, cfg.configLine, 'repositorymap a.b.c http://u:[email protected]:8000/conary/') self.assertRaises(conarycfg.ParseError, cfg.configLine, 'repositorymap a.b.c http://u:[email protected]/conary/') cfg.configLine('repositorymap * http://other/conary/') assert (cfg.repositoryMap['a.b.c'] == 'http://a.b.c:8000/conary/') assert (cfg.repositoryMap['foo.org'] == 'http://other/conary/')
def testDependencyClassList(self): cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.configLine('ignoreDependencies perl php') self.assertEquals(set(cfg.ignoreDependencies), set((deps.PerlDependencies, deps.PhpDependencies)) ) try: cfg.configLine('ignoreDependencies foo') assert(0) except conarycfg.ParseError, e: self.assertEquals(str(e), "override:<No line>: unknown dependency " "class: foo for configuration item 'ignoreDependencies'")
def getConfigFile(self, argv): pluginManager = self.initializePlugins(argv) if '--skip-default-config' in argv: argv.remove('--skip-default-config') read = False else: read = True buildConfig = buildcfg.BuildConfiguration(readConfigFiles=read) conaryConfig = conarycfg.ConaryConfiguration(readConfigFiles=read) return buildConfig, conaryConfig, pluginManager
def testSelectLocalKey(self): fingerprint = 'F7440D78FE813C882212C2BF8AC2828190B1E477' cfg = conarycfg.ConaryConfiguration() cfg.configLine("signatureKey None") cfg.configLine("signatureKeyMap foo.example.com %s" % fingerprint) cfg.configLine("buildLabel foo.example.com@rpl:devel") self.assertFalse( not signtrove.selectSignatureKey(cfg, 'local@local'), "selectSignatureKey didn't convert local to buildLabel")
def _getBaseConaryConfig(self, readConfigFiles=True): """ Fetches an B{opaque} conary config object with no rBuild configuration data included. @param readConfigFiles: initialize contents of config object from normal configuration files (default: True) @type readConfigFiles: bool @return: C{conarycfg.ConaryConfiguration} B{opaque} object """ return conarycfg.ConaryConfiguration(readConfigFiles=readConfigFiles, ignoreErrors=True, readProxyValuesFirst=True)
def loadRecipeClass(repos, name, version, flavor, trv=None, ignoreInstalled=True, root=None, loadInstalledSource=None, overrides=None, buildLabel=None, cfg=None): if trv is None: trv = repos.getTrove(name, version, deps.parseFlavor(''), withFiles=True) if cfg is None: cfg = conarycfg.ConaryConfiguration(False) else: cfg = copy.deepcopy(cfg) cfg.initializeFlavors() if root: cfg.root = root branch = version.branch() label = version.branch().label() cfg.buildLabel = label cfg.buildFlavor = flavor name = name.split(':')[0] use.LocalFlags._clear() use.setBuildFlagsFromFlavor(name, flavor, error=False) use.resetUsed() use.track(True) loader = RecipeLoaderFromSourceTrove(trv, repos, cfg, name + ':source', branch, ignoreInstalled=ignoreInstalled, db=loadInstalledSource, overrides=overrides, buildFlavor=flavor) recipeClass = loader.getRecipe() recipeClass._trove = trv use.track(False) localFlags = flavorutil.getLocalFlags() usedFlags = use.getUsed() use.LocalFlags._clear() return loader, recipeClass, localFlags, usedFlags
def testProxyOverrides(self): cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.configLine('proxy http http://foo:123') proxy = conarycfg.getProxyFromConfig(cfg) self.assertEqual(proxy, {'http': 'http://foo:123'}) cfg.configLine('conaryProxy https https://bar') proxy = conarycfg.getProxyFromConfig(cfg) self.assertEqual(proxy, {'https': 'conarys://bar'}) cfg.configLine('proxy https https://foo:123') proxy = conarycfg.getProxyFromConfig(cfg) self.assertEqual(proxy, {'https': 'conarys://bar'})