Beispiel #1
0
 def test_inputs(self):
     for cfg_file_data, expected in valid_config:
         # FIXME: using temptfile has the potential to cause flaky tests,
         # but for now...
         with tempfile.NamedTemporaryFile(prefix='rest_config',
                                          delete=False) as f:
             f.write(cfg_file_data)
             f.close()
             ret = sut.parse_config(f.name)
             self.assertEqual(ret, expected)
             os.unlink(f.name)
Beispiel #2
0
configpath = "/etc/rest.cfg"

try:
    opts, args = getopt.getopt(sys.argv[1:], "hc:", ["config="])
except getopt.GetoptError:
    print("rest.py -c <config_file>")
    sys.exit(2)

for opt, arg in opts:
    if opt == "-h":
        print("rest.py -c <config_file>")
        sys.exit()
    elif opt in ("-c", "--config"):
        configpath = arg

config = parse_config(configpath)

logging.config.dictConfig(get_logger_config(config))

servers = []

app = web.Application(middlewares=[jsonerrorhandler, auth_enforcer])
setup_plat_routes(app, config)

loop = asyncio.get_event_loop()
handler = app.make_handler(access_log=access_logger,
                           access_log_format=ACCESS_LOG_FORMAT)

servers.extend(
    [loop.create_server(handler, "*", port) for port in config["ports"]])