Ejemplo n.º 1
0
def get_endpoint_or_skip_container(name, default_port):
    """Find a test server of the given type or raise SkipTest.

    This is useful for running tests in environments where we can't launch
    servers.

    If an environment variable like BASEPLATE_MEMCACHED_ADDR is present, that will
    override the default of localhost:{default_port}.

    """

    address = os.environ.get("BASEPLATE_%s_ADDR" % name.upper(),
                             "localhost:%d" % default_port)
    endpoint = Endpoint(address)

    try:
        sock = socket.socket(endpoint.family, socket.SOCK_STREAM)
        sock.settimeout(0.1)
        sock.connect(endpoint.address)
    except socket.error:
        raise unittest.SkipTest(
            "could not find %s server for integration tests" % name)
    else:
        sock.close()

    return endpoint
Ejemplo n.º 2
0
def _parse(watched_file: IO) -> _Inventory:
    backends = []
    for d in json.load(watched_file):
        endpoint = Endpoint("%s:%d" % (d["host"], d["port"]))
        weight = d["weight"] if d["weight"] is not None else 1
        backend = Backend(d["id"], d["name"], endpoint, weight)
        backends.append(backend)

    lottery = None
    if backends:
        lottery = WeightedLottery(backends, weight_key=lambda b: b.weight)

    return _Inventory(backends, lottery)
Ejemplo n.º 3
0
def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__)

    parser.add_argument(
        "type",
        choices=CHECKERS.keys(),
        default="thrift",
        help="The protocol of the service to check.",
    )
    parser.add_argument(
        "endpoint",
        type=Endpoint,
        default=Endpoint("localhost:9090"),
        help="The endpoint to find the service on.",
    )

    return parser.parse_args()
Ejemplo n.º 4
0
def parse_args(args: Sequence[str]) -> argparse.Namespace:
    parser = argparse.ArgumentParser(
        description=sys.modules[__name__].__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )

    parser.add_argument("--debug",
                        action="store_true",
                        default=False,
                        help="enable extra-verbose debug logging")
    parser.add_argument(
        "--reload",
        action="store_true",
        default=False,
        help="restart the server when code changes (development only)",
    )
    parser.add_argument(
        "--app-name",
        default="main",
        metavar="NAME",
        help="name of app to load from config_file (default: main)",
    )
    parser.add_argument(
        "--server-name",
        default="main",
        metavar="NAME",
        help="name of server to load from config_file (default: main)",
    )
    parser.add_argument(
        "--bind",
        type=Endpoint,
        default=Endpoint("localhost:9090"),
        metavar="ENDPOINT",
        help="endpoint to bind to (ignored if under Einhorn)",
    )
    parser.add_argument("config_file",
                        type=argparse.FileType("r"),
                        help="path to a configuration file")

    return parser.parse_args(args)
Ejemplo n.º 5
0
def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__)

    parser.add_argument(
        "type",
        choices=CHECKERS.keys(),
        default="thrift",
        help="The protocol of the service to check.",
    )
    parser.add_argument(
        "endpoint",
        type=Endpoint,
        default=Endpoint("localhost:9090"),
        help="The endpoint to find the service on.",
    )
    parser.add_argument(
        "--probe",
        choices=[probe.lower() for probe in IsHealthyProbe._NAMES_TO_VALUES],
        default="readiness",
        help="The probe to check.",
    )

    return parser.parse_args()
Ejemplo n.º 6
0
 def test_remote_recorder_setup(self):
     client = make_client("test-service",
                          tracing_endpoint=Endpoint("test:1111"))
     baseplate_observer = TraceBaseplateObserver(client)
     self.assertTrue(isinstance(baseplate_observer.recorder,
                                RemoteRecorder))