Ejemplo n.º 1
0
    def test_processes(self) -> None:

        assert not find_process("this-should-not-exist")
        assert find_process("restapi")
        assert find_process("dumb-init")
        # current process is not retrieved by find_process
        current_pid = os.getpid()
        process = psutil.Process(current_pid)
        assert not find_process(process.name())

        start_timeout(15)
        try:
            wait_socket("invalid", 123, service_name="test")
            pytest.fail("wait_socket should be blocking!")  # pragma: no cover
        except Timeout:
            pass

        start_timeout(15)
        try:
            wait_socket("invalid", 123, service_name="test", retries=2)
            pytest.fail("No exception raised")  # pragma: no cover
        except ServiceUnavailable:
            pass
        except Timeout:  # pragma: no cover
            pytest.fail("Reached Timeout, max retries not worked?")
Ejemplo n.º 2
0
    def test_processes(self) -> None:

        assert not find_process("this-should-not-exist")
        assert find_process("restapi")
        assert find_process("dumb-init")
        # current process is not retrieved by find_process
        current_pid = os.getpid()
        process = psutil.Process(current_pid)
        assert not find_process(process.name())

        start_timeout(15)
        with pytest.raises(Timeout):
            wait_socket("invalid", 123, service_name="test")

        start_timeout(15)
        with pytest.raises(ServiceUnavailable):
            wait_socket("invalid", 123, service_name="test", retries=2)
Ejemplo n.º 3
0
def verify(services):
    """Verify connected service"""

    if len(services) == 0:
        log.warning("Empty list of services, nothing to be verified.")
        log.info("Provide list of services by using --services option")

    for service in services:

        if not Connector.check_availability(service):
            print_and_exit("Service {} not detected", service)

        log.info("Verifying service: {}", service)
        variables = Connector.services.get(service, {})
        host, port = get_service_address(variables, "host", "port", service)
        wait_socket(host, port, service)

    log.info("Completed successfully")
Ejemplo n.º 4
0
def verify(service: str) -> None:
    """Verify if a service is connected"""

    if not Connector.check_availability(service):
        print_and_exit("Service {} not detected", service)

    log.info("Verifying service: {}", service)
    variables = Connector.services.get(service, {})
    host, port = get_service_address(variables, "host", "port", service)
    if host != "nohost":
        wait_socket(host, port, service)

    connector_module = Connector.get_module(service, BACKEND_PACKAGE)
    if not connector_module:  # pragma: no cover
        print_and_exit("Connector {} not detected", service)

    c = connector_module.get_instance()
    log.info("{} successfully authenticated on {}", service,
             c.variables.get("host", service))
Ejemplo n.º 5
0
def mywait() -> None:
    """
    Wait for a service on his host:port configuration
    This check is merely based on a socket connection
    """
    for name, variables in Connector.services.items():

        if name == "smtp" or name == "ftp":
            log.info("Service {} is enabled but not tested at startup time",
                     name)
            continue

        if name == "celery":

            broker = variables.get("broker_service", "N/A")

            if broker == "RABBIT":
                service_vars = Env.load_variables_group(prefix="rabbitmq")
            elif broker == "REDIS":
                service_vars = Env.load_variables_group(prefix="redis")
            else:
                print_and_exit("Invalid celery broker: {}",
                               broker)  # pragma: no cover

            label = f"{broker.lower()} as celery broker"
            host, port = get_service_address(service_vars, "host", "port",
                                             label)

            wait_socket(host, port, label)

            backend = variables.get("backend_service", "N/a")
            if backend == "RABBIT":
                service_vars = Env.load_variables_group(prefix="rabbitmq")
            elif backend == "REDIS":
                service_vars = Env.load_variables_group(prefix="redis")
            else:
                print_and_exit("Invalid celery backend: {}",
                               backend)  # pragma: no cover

            label = f"{backend.lower()} as celery backend"
            host, port = get_service_address(service_vars, "host", "port",
                                             label)

            wait_socket(host, port, label)

        else:
            host, port = get_service_address(variables, "host", "port", name)

            if host != "nohost":
                wait_socket(host, port, name)
Ejemplo n.º 6
0
def mywait():
    """
    Wait for a service on his host:port configuration
    basing the check on a socket connection.
    """
    for name, variables in Connector.services.items():

        if name == "smtp":
            continue

        if name == "celery":

            broker = variables.get("broker", "N/A")

            if broker == "RABBIT":
                service_vars = Env.load_variables_group(prefix="rabbitmq")
            elif broker == "REDIS":
                service_vars = Env.load_variables_group(prefix="redis")
            else:
                print_and_exit("Invalid celery broker: {}", broker)  # pragma: no cover

            label = f"{broker.lower()} as celery broker"
            host, port = get_service_address(service_vars, "host", "port", label)

            wait_socket(host, port, label)

            backend = variables.get("backend", "N/a")
            # Rabbit is no longer used as backend due to the strong limitations
            if backend == "RABBIT":  # pragma: no cover
                service_vars = Env.load_variables_group(prefix="rabbitmq")
            elif backend == "REDIS":
                service_vars = Env.load_variables_group(prefix="redis")
            elif backend == "MONGODB":
                service_vars = Env.load_variables_group(prefix="mongo")
            else:
                print_and_exit(
                    "Invalid celery backend: {}", backend
                )  # pragma: no cover

            label = f"{backend.lower()} as celery backend"
            host, port = get_service_address(service_vars, "host", "port", label)

            wait_socket(host, port, label)

        else:
            host, port = get_service_address(variables, "host", "port", name)

            wait_socket(host, port, name)