コード例 #1
0
def test_get_running2(client):
    """
    Tests getting running containers when some hosts are unavailable
    """

    with client.application.app_context():
        match = re.compile(r"test-.+")
        client_mock = ClientFixture.new([
            ContainerFixture.new(name="fastlane-job-123",
                                 container_id="fastlane-job-123")
        ])
        faulty_client = ClientFixture.new([
            ContainerFixture.new(name="fastlane-job-456",
                                 container_id="fastlane-job-456")
        ])
        faulty_client.containers.list.side_effect = RuntimeError("failed")

        pool_mock = PoolFixture.new(
            clients={
                "host:1234": ("host", 1234, client_mock),
                "host:4567": ("host", 4567, faulty_client),
            },
            clients_per_regex=[(match, [("host", 1234, client_mock),
                                        ("host", 4567, faulty_client)])],
            max_running={match: 2},
        )

        executor = Executor(client.application, pool_mock)
        result = executor.get_running_containers()

        expect(result).to_include("available")
        available = result["available"]
        expect(available).to_be_like([{
            "host": "host",
            "port": 1234,
            "available": True,
            "blacklisted": False,
            "circuit": "closed",
            "error": None,
        }])

        expect(result).to_include("unavailable")
        unavailable = result["unavailable"]

        expect(unavailable).to_be_like([{
            "host": "host",
            "port": 4567,
            "available": False,
            "blacklisted": False,
            "circuit": "closed",
            "error": "failed",
        }])

        expect(result).to_include("running")
        running = result["running"]
        expect(running).to_length(1)
        host, port, container_id = running[0]
        expect(host).to_equal("host")
        expect(port).to_equal(1234)
        expect(container_id).to_equal("fastlane-job-123")
コード例 #2
0
def test_validate_max2(client):
    """
    Tests validating max current executions works even if no hosts match task_id
    """

    app = client.application

    with app.app_context():
        pool_mock = PoolFixture.new()
        executor = Executor(app, pool_mock)

        result = executor.validate_max_running_executions("test123")
        expect(result).to_be_true()
コード例 #3
0
def test_get_running3(client):
    """
    Tests getting running containers when some hosts are blacklisted
    """

    with client.application.app_context():
        match = re.compile(r"test-.+")
        client_mock = ClientFixture.new([
            ContainerFixture.new(name="fastlane-job-123",
                                 container_id="fastlane-job-123")
        ])

        pool_mock = PoolFixture.new(
            clients={"host:1234": ("host", 1234, client_mock)},
            clients_per_regex=[(match, [("host", 1234, client_mock)])],
            max_running={match: 2},
        )

        executor = Executor(client.application, pool_mock)
        result = executor.get_running_containers(
            blacklisted_hosts=set(["host:1234"]))

        expect(result).to_include("available")
        available = result["available"]
        expect(available).to_be_empty()

        expect(result).to_include("unavailable")
        unavailable = result["unavailable"]

        expect(unavailable).to_be_like([{
            "host": "host",
            "port": 1234,
            "available": False,
            "blacklisted": True,
            "circuit": "closed",
            "error": "server is blacklisted",
        }])

        expect(result).to_include("running")
        running = result["running"]
        expect(running).to_length(0)