示例#1
0
 def writeConaryProxies(self, remotes):
     """
     Management nodes should already be written as conaryProxies by the cim
     interface, but add an extra check here to be sure.
     """
     proxies = set()
     for remote in remotes:
         if not remote.strip():
             continue
         # Strip off port in a way that works for IPv4 and IPv6
         # 1.2.3.4:8443 -> conarys://1.2.3.4
         # [fd00::1234]:8443 -> conarys://[fd00::1234]
         try:
             host = networking.HostPort(remote).host
         except ValueError:
             continue
         hostport = networking.HostPort(host, None)
         url = request.URL(
                 scheme='conarys',
                 userpass=(None, None),
                 hostport=hostport,
                 path='',
                 )
         proxies.add(str(url))
     if not proxies:
         return
     with open(self.cfg.conaryProxyFilePath, 'w') as f:
         print >> f, 'proxyMap *', ' '.join(sorted(proxies))
示例#2
0
 def testGetProxyMap(self):
     cfg = conarycfg.ConaryConfiguration(readConfigFiles=False)
     cfg.configLine("conaryproxy http http://localhost:123")
     cfg.configLine("conaryproxy https http://localhost:123")
     pm = cfg.getProxyMap()
     # getProxyMap() does not return proxyMap in this case - it's a new
     # proxyMap object
     self.assertFalse(pm is cfg.proxyMap)
     got = dict((x[0].protocol, (x[0].address, x[1])) for x in pm.filterList)
     self.assertEquals(got, {
         'http': (networking.HostPort('*'),
             [request.URL('conary://localhost:123')]),
         'https': (networking.HostPort('*'),
             [request.URL('conary://localhost:123')]),
         })
示例#3
0
 def testPickling(self):
     things = [
         'foo.bar',
         '*.bar',
         'foo.bar:1234',
         '*.bar:1234',
         '192.168.4.5',
         '192.168.4.5:1234',
         '192.168.4.5/24',
         '192.168.4.5/24:1234',
         '[::1]',
         '[::1]:1234',
         '[::1/48]:1234',
     ]
     for name, mangler in [
         ('copy', copy.copy),
         ('deepcopy', copy.deepcopy),
         ('pickle v0', lambda x: pickle.loads(pickle.dumps(x, 0))),
         ('pickle v2', lambda x: pickle.loads(pickle.dumps(x, 2))),
         ('cPickle v0', lambda x: cPickle.loads(cPickle.dumps(x, 0))),
         ('cPickle v2', lambda x: cPickle.loads(cPickle.dumps(x, 2))),
     ]:
         try:
             mangled = [
                 str(mangler(networking.HostPort(x))) for x in things
             ]
             self.assertEqual(mangled, things)
         except:
             print 'Error testing pickling using %r' % (name, )
             raise
示例#4
0
 def setConaryProxy(self, managementNodes):
     proxies = set()
     for remote in managementNodes:
         if not remote.strip():
             continue
         # Strip off port in a way that works for IPv4 and IPv6
         # 1.2.3.4:8443 -> conarys://1.2.3.4
         # [fd00::1234]:8443 -> conarys://[fd00::1234]
         try:
             host = networking.HostPort(remote).host
         except ValueError:
             continue
         hostport = networking.HostPort(host, None)
         url = request.URL(
                 scheme='conarys',
                 userpass=(None, None),
                 hostport=hostport,
                 path='',
                 )
         proxies.add(str(url))
     if not proxies:
         return
     with open(self.cfg.conaryProxyFilePath, 'w') as f:
         print >> f, 'proxyMap *', ' '.join(sorted(proxies))
示例#5
0
 def parse(cls, url, defaultScheme='http'):
     if '://' not in url and defaultScheme:
         url = '%s://%s' % (defaultScheme, url)
     (
         scheme,
         username,
         password,
         host,
         port,
         path,
         query,
         fragment,
     ) = util.urlSplit(url)
     if not port and port != 0:
         if scheme[-1] == 's':
             port = 443
         else:
             port = 80
     hostport = networking.HostPort(host, port)
     path = urlparse.urlunsplit(('', '', path, query, fragment))
     return cls(scheme, (username, password), hostport, path)
示例#6
0
 def _assertProxy(self, via, cProxy):
     via = networking.HostPort(via.strip().split(' ')[1])
     # Not all app servers can report their local port, and not all app
     # servers will even have one (UNIX socket, etc.)
     self.assertIn(via.port, [cProxy.appServer.port, 0])
示例#7
0
    def testConaryCfgOptions(self):
        configfile = """
repositoryMap host.somewhere.com http://someotherhost.com:port/loc
proxyMap host.somewhere.com http://someotherhost.com:123/loc
installLabelPath conary.rpath.com@rpl:1 contrib.rpath.org@rpl:1
macros a  a
macros b  b b
macros c
flavor use:ssl,krb,readline,\
       bootstrap is: x86(i486,i586,i686,mmx) 
"""
        dir = tempfile.mkdtemp()
        cwd = os.getcwd()
        os.chdir(dir)
        f = open('foo', 'w')
        f.write(configfile)
        f.close()
        cfg = conarycfg.ConaryConfiguration(readConfigFiles=False)
        cfg.read(dir + '/foo')
        assert (cfg.buildPath)  # make sure defaults are working
        assert (cfg['macros']['a'] == 'a')
        assert (cfg['macros']['b'] == 'b b')
        assert (cfg['macros']['c'] == '')
        assert (cfg['repositoryMap']['host.somewhere.com'] ==
                'http://someotherhost.com:port/loc')

        filter, targets = cfg.proxyMap.filterList[0]
        self.assertEqual(filter.address,
                         networking.HostPort('host.somewhere.com'))
        self.assertEqual(targets,
                         [request.URL('http://someotherhost.com:123/loc')])

        ilp = cfg['installLabelPath']
        l0 = versions.Label('conary.rpath.com@rpl:1')
        l1 = versions.Label('contrib.rpath.org@rpl:1')
        lOther = versions.Label('contrib.rpath.org@rpl:devel')
        assert (ilp == [l0, l1])

        assert (ilp.priority(l0, l1) == -1)
        assert (ilp.priority(l0, l0) == 0)
        assert (ilp.priority(l1, l0) == 1)
        assert (ilp.priority(lOther, l0) is None)
        assert (ilp.priority(lOther, lOther) is None)
        assert (ilp.priority(l0, lOther) is None)

        v0 = versions.VersionFromString('/conary.rpath.com@rpl:1/1.0-1-1')
        v1 = versions.VersionFromString('/contrib.rpath.org@rpl:1/1.0-1-1')
        assert (ilp.versionPriority(v0, v1) == -1)
        assert (ilp.versionPriority(v0, v0) == 0)
        assert (ilp.versionPriority(v1, v0) == 1)

        assert (str(cfg.flavor[0]) ==
                'bootstrap,krb,readline,ssl is: x86(i486,i586,i686,mmx)')
        out = StringIO()
        cfg.displayKey('flavor', out)
        assert (
            out.getvalue().split(None, 1)[1] ==
            'bootstrap, krb, readline, ssl is: x86(i486, i586, i686, mmx)\n')
        out.close()
        out = StringIO()
        cfg.setDisplayOptions(prettyPrint=True)
        cfg.displayKey('flavor', out)
        assert (
            out.getvalue().split(None, 1)[1] ==
            'bootstrap, krb, readline, ssl is: x86(i486,\n                          i586, i686, mmx)\n'
        )
        out.close()
        out = StringIO()
        cfg.displayKey('repositoryMap', out)
        assert (
            out.getvalue() ==
            'repositoryMap             host.somewhere.com        http://someotherhost.com:port/loc\n'
        )
        out.close()
        out = StringIO()
        cfg.displayKey('proxyMap', out)
        self.assertEqual(
            out.getvalue(), "proxyMap                  host.somewhere.com "
            "http://someotherhost.com:123/loc\n")
        out.close()
        cfg.setDisplayOptions(hidePasswords=True)
        out = StringIO()
        cfg.displayKey('repositoryMap', out)
        assert (
            out.getvalue() ==
            'repositoryMap             host.somewhere.com        http://someotherhost.com:port/loc\n'
        )
        out.close()

        keys = cfg.macros.keys()
        keys.sort()
        assert (keys == ['a', 'b', 'c'])
        os.remove('foo')
        foo = open('foo', 'w')
        cfg.display(foo)
        foo.close()
        lines = [x.split() for x in open('foo', 'r')]
        assert (['macros', 'a', 'a'] in lines)
        assert (['macros', 'c'] in lines)
        os.remove('foo')
        os.chdir(cwd)
        os.rmdir(dir)