Exemple #1
0
def test__get_jobs__get_job_summary(client):
    # Verify no jobs are returned before jobs are created.
    res = client.get_job_summary("")
    assert len(res.summaries) == 0

    res = client.get_jobs("")
    assert len(res.configs) == 0

    # Create two jobs under same role.
    test_dc_labrat_key = start_job_update(client, "test_dc_labrat_read.yaml",
                                          "start job update test/dc/labrat")
    test_dc_labrat_0_key = start_job_update(
        client, "test_dc_labrat0.yaml", "start job update test/dc/labrat0")

    # Different role should not show up.
    start_job_update(client, "test2_dc2_labrat2.yaml",
                     "start job update test2/dc2/labrat2")

    # Add some wait time for lucene index to build
    time.sleep(10)

    # reduce instance count by 1 for test/dc/labrat0
    client.kill_tasks(
        test_dc_labrat_0_key,
        {0},
        "killing instance 0 for task test/dc/labrat0",
    )
    wait_for_killed(client, test_dc_labrat_0_key, {0})

    # Ensure get_job_summary returns both jobs under role=test.
    res = client.get_job_summary(test_dc_labrat_key.role)
    assert len(res.summaries) == 2, "{jobs}".format(
        jobs=[s.job.key for s in res.summaries])

    assert_keys_equal(
        [s.job.key for s in res.summaries],
        [test_dc_labrat_key, test_dc_labrat_0_key],
    )

    for s in res.summaries:
        if s.job.key == test_dc_labrat_0_key:
            assert s.stats.activeTaskCount == 1
        else:
            assert s.stats.activeTaskCount == 2
        assert s.job.instanceCount == 2

    # Ensure get_jobs returns both jobs under role=test.
    res = client.get_jobs(test_dc_labrat_key.role)
    assert len(res.configs) == 2

    assert_keys_equal(
        [c.taskConfig.job for c in res.configs],
        [test_dc_labrat_key, test_dc_labrat_0_key],
    )

    for c in res.configs:
        if c.key == test_dc_labrat_0_key:
            assert c.instanceCount == 1
        else:
            assert c.instanceCount == 2
Exemple #2
0
def test__start_job_update_with_get_jobs(client, aurorabridge):
    """
    Check GetJobs returns the correct results when queried by role, and after
    a new job is created. This is used to verify that StartJobUpdate would
    correctly invalidate role to job id cache.
    Meanwhile, the test will restart aurorabridge container at the end, and
    verify the cache will be populated correctly as well.
    """

    labrat0 = start_job_update(
        client,
        "test_dc_labrat0.yaml",
        "start job update test/dc/labrat0",
    )

    res = client.get_jobs(labrat0.role)
    assert len(res.configs) == 1
    assert list(res.configs)[0].taskConfig.job == labrat0

    # Verify that start a new job invalidates the job role to id cache,
    # and returns the correct result.
    labrat1 = start_job_update(
        client,
        "test_dc_labrat1.yaml",
        "start job update test/dc/labrat1",
    )

    res = client.get_jobs(labrat1.role)
    assert len(res.configs) == 2
    assert_keys_equal(
        [c.taskConfig.job for c in res.configs],
        [labrat0, labrat1],
    )

    # Verify that after aurorabridge container restart, the cache will still
    # be populated correctly and return the correct result.
    aurorabridge.restart()
    time.sleep(10)

    res = client.get_jobs(labrat1.role)
    assert len(res.configs) == 2
    assert_keys_equal(
        [c.taskConfig.job for c in res.configs],
        [labrat0, labrat1],
    )
Exemple #3
0
def test__get_jobs__get_job_summary(client):
    # Verify no jobs are returned before jobs are created.
    res = client.get_job_summary('')
    assert len(res.summaries) == 0

    res = client.get_jobs('')
    assert len(res.configs) == 0

    # Create two jobs under same role.
    test_dc_labrat_key = start_job_update(client, 'test_dc_labrat_read.yaml',
                                          'start job update test/dc/labrat')
    test_dc_labrat_0_key = start_job_update(
        client, 'test_dc_labrat0.yaml', 'start job update test/dc/labrat0')

    # Different role should not show up.
    start_job_update(client, 'test2_dc2_labrat2.yaml',
                     'start job update test2/dc2/labrat2')

    # Ensure get_job_summary returns both jobs under role=test.
    res = client.get_job_summary(test_dc_labrat_key.role)
    assert len(res.summaries) == 2

    assert_keys_equal([s.job.key for s in res.summaries],
                      [test_dc_labrat_key, test_dc_labrat_0_key])

    for s in res.summaries:
        assert s.stats.activeTaskCount == 2
        assert s.job.instanceCount == 2

    # Ensure get_jobs returns both jobs under role=test.
    res = client.get_jobs(test_dc_labrat_key.role)
    assert len(res.configs) == 2

    assert_keys_equal([c.taskConfig.job for c in res.configs],
                      [test_dc_labrat_key, test_dc_labrat_0_key])

    for c in res.configs:
        assert c.instanceCount == 2
Exemple #4
0
def test__get_tasks_without_configs_task_queries(client):
    # Verify no tasks are returned before creating.
    res = client.get_tasks_without_configs(api.TaskQuery())
    assert len(res.tasks) == 0

    # Create jobs.
    test_dc_labrat_key = start_job_update(client, "test_dc_labrat_read.yaml",
                                          "start job update test/dc/labrat")
    test_dc_labrat_0_key = start_job_update(
        client, "test_dc_labrat0.yaml", "start job update test/dc/labrat0")
    test_dc_0_labrat_1_key = start_job_update(
        client, "test_dc0_labrat1.yaml", "start job update test/dc0/labrat1")
    test_dc_labrat_1_key = start_job_update(
        client, "test_dc_labrat1.yaml", "start job update test/dc/labrat1")
    test2_dc2_labrat2_key = start_job_update(
        client, "test2_dc2_labrat2.yaml", "start job update test2/dc2/labrat2")

    # Add some wait time for lucene index to build
    time.sleep(10)

    # Kill one of the jobs.
    client.kill_tasks(test_dc_labrat_1_key, None,
                      "killing all tasks test/dc/labrat1")
    wait_for_killed(client, test_dc_labrat_1_key)

    for message, query, expected_job_keys in [
        (
            "query job keys",
            api.TaskQuery(jobKeys={
                test_dc_labrat_key,
                test_dc_labrat_0_key,
                test2_dc2_labrat2_key,
            }),
            [test_dc_labrat_key, test_dc_labrat_0_key, test2_dc2_labrat2_key],
        ),
        (
            "query role + env + name",
            api.TaskQuery(
                role=test_dc_labrat_key.role,
                environment=test_dc_labrat_key.environment,
                jobName=test_dc_labrat_key.name,
            ),
            [test_dc_labrat_key],
        ),
        (
            "query role + env",
            api.TaskQuery(
                role=test_dc_labrat_key.role,
                environment=test_dc_labrat_key.environment,
            ),
            [test_dc_labrat_key, test_dc_labrat_0_key, test_dc_labrat_1_key],
        ),
        (
            "query role",
            api.TaskQuery(role=test_dc_labrat_key.role),
            [
                test_dc_labrat_key,
                test_dc_labrat_0_key,
                test_dc_labrat_1_key,
                test_dc_0_labrat_1_key,
            ],
        ),
        (
            "query role + statuses",
            api.TaskQuery(
                role=test_dc_labrat_key.role,
                statuses={api.ScheduleStatus.RUNNING},
            ),
            [test_dc_labrat_key, test_dc_labrat_0_key, test_dc_0_labrat_1_key],
        ),
    ]:
        res = client.get_tasks_without_configs(query)
        # Expect 3 tasks per job key.
        assert len(res.tasks) == len(expected_job_keys) * 2, message
        assert_keys_equal(
            remove_duplicate_keys(t.assignedTask.task.job for t in res.tasks),
            expected_job_keys,
            message=message,
        )
Exemple #5
0
def test__get_tasks_without_configs_task_queries(client):
    # Verify no tasks are returned before creating.
    res = client.get_tasks_without_configs(api.TaskQuery())
    assert len(res.tasks) == 0

    # Create jobs.
    test_dc_labrat_key = start_job_update(client, 'test_dc_labrat_read.yaml',
                                          'start job update test/dc/labrat')
    test_dc_labrat_0_key = start_job_update(
        client, 'test_dc_labrat0.yaml', 'start job update test/dc/labrat0')
    test_dc_0_labrat_1_key = start_job_update(
        client, 'test_dc0_labrat1.yaml', 'start job update test/dc0/labrat1')
    test_dc_labrat_1_key = start_job_update(
        client, 'test_dc_labrat1.yaml', 'start job update test/dc/labrat1')
    test2_dc2_labrat2_key = start_job_update(
        client, 'test2_dc2_labrat2.yaml', 'start job update test2/dc2/labrat2')

    # Kill one of the jobs.
    client.kill_tasks(test_dc_labrat_1_key, {0, 1},
                      'killing all tasks test/dc/labrat1')
    wait_for_killed(client, test_dc_labrat_1_key)

    for message, query, expected_job_keys in [
        (
            'query job keys',
            api.TaskQuery(jobKeys={
                test_dc_labrat_key,
                test_dc_labrat_0_key,
                test2_dc2_labrat2_key,
            }),
            [
                test_dc_labrat_key,
                test_dc_labrat_0_key,
                test2_dc2_labrat2_key,
            ],
        ),
        (
            'query role + env + name',
            api.TaskQuery(
                role=test_dc_labrat_key.role,
                environment=test_dc_labrat_key.environment,
                jobName=test_dc_labrat_key.name,
            ),
            [test_dc_labrat_key],
        ),
        (
            'query role + env',
            api.TaskQuery(
                role=test_dc_labrat_key.role,
                environment=test_dc_labrat_key.environment,
            ),
            [
                test_dc_labrat_key,
                test_dc_labrat_0_key,
                test_dc_labrat_1_key,
            ],
        ),
        (
            'query role',
            api.TaskQuery(role=test_dc_labrat_key.role),
            [
                test_dc_labrat_key,
                test_dc_labrat_0_key,
                test_dc_labrat_1_key,
                test_dc_0_labrat_1_key,
            ],
        ),
        (
            'query role + statuses',
            api.TaskQuery(
                role=test_dc_labrat_key.role,
                statuses={api.ScheduleStatus.RUNNING},
            ),
            [
                test_dc_labrat_key,
                test_dc_labrat_0_key,
                test_dc_0_labrat_1_key,
            ],
        )
    ]:
        res = client.get_tasks_without_configs(query)
        # Expect 3 tasks per job key.
        assert len(res.tasks) == len(expected_job_keys) * 2, message
        assert_keys_equal(remove_duplicate_keys(t.assignedTask.task.job
                                                for t in res.tasks),
                          expected_job_keys,
                          message=message)