def test_proxy_config(self): # The proxy file goes in a brkt-file part, # so the brkt config should be empty ic = InstanceConfig({}) p = Proxy(host=proxy_host, port=proxy_port) proxy_config = proxy.generate_proxy_config(p) ic.add_brkt_file('proxy.yaml', proxy_config) _verify_proxy_config_in_userdata(self, ic.make_userdata())
def test_generate_proxy_config(self): """ Test generating proxy.yaml from Proxy objects. """ p1 = Proxy(host='proxy1.example.com', port=8001) p2 = Proxy(host='proxy2.example.com', port=8002) proxy_yaml = proxy.generate_proxy_config(p1, p2) proxy.validate_proxy_config(proxy_yaml) d = yaml.load(proxy_yaml) self.assertEquals('proxy1.example.com', d['proxies'][0]['host']) self.assertEquals(8001, d['proxies'][0]['port']) self.assertEqual('https', d['proxies'][0]['protocol']) self.assertEqual('encryptor', d['proxies'][0]['usage']) self.assertEquals('proxy2.example.com', d['proxies'][1]['host']) self.assertEquals(8002, d['proxies'][1]['port'])
def get_proxy_config(values): """ Read proxy config specified by either the --proxy or --proxy-config-file option. :return the contents of the proxy.yaml file, or None if not specified :raise ValidationError if the file cannot be read or is malformed """ proxy_config = None if values.proxy_config_file: path = values.proxy_config_file log.debug('Loading proxy config from %s', path) try: with open(path) as f: proxy_config = f.read() except IOError as e: log.debug('Unable to read %s: %s', path, e) raise ValidationError('Unable to read %s' % path) validate_proxy_config(proxy_config) elif values.proxies: proxies = _parse_proxies(*values.proxies) proxy_config = generate_proxy_config(*proxies) log.debug('Using proxy configuration:\n%s', proxy_config) return proxy_config