Пример #1
0
def test_disable_schedule():
    """ Confirms that a schedule runs when enabled but then stops firing
        when the schedule is disabled.
    """
    client = metronome.create_client()
    job_id = 'schedule-disabled-{}'.format(uuid.uuid4().hex)
    job_json = job_no_schedule(job_id)
    with job(job_json):
        # indent
        job_schedule = schedule()
        job_schedule['cron'] = '* * * * *'  # every minute
        client.add_schedule(job_id, job_schedule)

        # sleep until we run
        time.sleep(timedelta(minutes=1.1).total_seconds())
        runs = client.get_runs(job_id)
        run_count = len(runs)
        # there is a race condition where this could be 1 or 2
        # both are ok... what matters is that after disabled, that there are
        # no more
        assert run_count > 0

        # update enabled = False
        job_schedule['enabled'] = False
        client.update_schedule(job_id, 'nightly', job_schedule)

        # wait for the next run
        time.sleep(timedelta(minutes=1.5).total_seconds())
        runs = client.get_runs(job_id)
        # make sure there are no more than the original count
        assert len(runs) == run_count
Пример #2
0
def test_disable_schedule():
    """ Confirms that a schedule runs when enabled but then stops firing
        when the schedule is disabled.
    """
    client = metronome.create_client()
    job_id = 'schedule-disabled-{}'.format(uuid.uuid4().hex)
    job_json = job_no_schedule(job_id)
    with job(job_json):
        # indent
        job_schedule = schedule()
        job_schedule['cron'] = '* * * * *'  # every minute
        client.add_schedule(job_id, job_schedule)

        # sleep until we run
        time.sleep(timedelta(minutes=1.1).total_seconds())
        runs = client.get_runs(job_id)
        run_count = len(runs)
        # there is a race condition where this could be 1 or 2
        # both are ok... what matters is that after disabled, that there are
        # no more
        assert run_count > 0

        # update enabled = False
        job_schedule['enabled'] = False
        client.update_schedule(job_id, 'nightly', job_schedule)

        # wait for the next run
        time.sleep(timedelta(minutes=1.5).total_seconds())
        runs = client.get_runs(job_id)
        # make sure there are no more than the original count
        assert len(runs) == run_count
Пример #3
0
def test_docker_job():
    client = metronome.create_client()
    job_id = uuid.uuid4().hex
    job_def = job_no_schedule(job_id)
    common.add_docker_image(job_def)
    with job(job_def):
        client.run_job(job_id)
        time.sleep(2)
        assert len(client.get_runs(job_id)) == 1
Пример #4
0
def test_update_schedule():
    client = metronome.create_client()
    with job(job_no_schedule('schedule')):
        client.add_schedule('schedule', schedule())
        assert client.get_schedule('schedule', 'nightly')['cron'] == '20 0 * * *'
        schedule_json = schedule()
        schedule_json['cron'] = '10 0 * * *'
        client.update_schedule('schedule', 'nightly', schedule_json)
        assert client.get_schedule('schedule', 'nightly')['cron'] == '10 0 * * *'
Пример #5
0
def test_update_schedule():
    client = metronome.create_client()
    with job(job_no_schedule('schedule')):
        client.add_schedule('schedule', schedule())
        assert client.get_schedule('schedule', 'nightly')['cron'] == '20 0 * * *'
        schedule_json = schedule()
        schedule_json['cron'] = '10 0 * * *'
        client.update_schedule('schedule', 'nightly', schedule_json)
        assert client.get_schedule('schedule', 'nightly')['cron'] == '10 0 * * *'
Пример #6
0
def test_update_job():
    client = metronome.create_client()
    job_json = job_no_schedule('update-job')
    with job(job_json):
        assert client.get_job('update-job')['description'] == 'electrifying rodent'

        job_json['description'] = 'updated description'
        client.update_job('update-job', job_json)
        assert client.get_job('update-job')['description'] == 'updated description'
Пример #7
0
def test_docker_job():
    client = metronome.create_client()
    job_id = uuid.uuid4().hex
    job_def = job_no_schedule(job_id)
    common.add_docker_image(job_def)
    with job(job_def):
        client.run_job(job_id)
        time.sleep(2)
        assert len(client.get_runs(job_id)) == 1
Пример #8
0
def test_update_job():
    client = metronome.create_client()
    job_json = job_no_schedule('update-job')
    with job(job_json):
        assert client.get_job('update-job')['description'] == 'electrifying rodent'

        job_json['description'] = 'updated description'
        client.update_job('update-job', job_json)
        assert client.get_job('update-job')['description'] == 'updated description'
Пример #9
0
def test_get_job_run():
    client = metronome.create_client()
    job_id = uuid.uuid4().hex
    with job(job_no_schedule(job_id)):
        client.run_job(job_id)
        time.sleep(2)
        run_id = client.get_runs(job_id)[0]['id']
        run = client.get_run(job_id, run_id)
        assert run['id'] == run_id
        assert run['status'] in ['ACTIVE', 'INITIAL']
Пример #10
0
def test_run_job():
    client = metronome.create_client()
    job_id = uuid.uuid4().hex
    with job(job_no_schedule(job_id)):
        runs = client.get_runs(job_id)
        assert len(runs) == 0

        client.run_job(job_id)
        time.sleep(2)
        assert len(client.get_runs(job_id)) == 1
Пример #11
0
def test_run_job():
    client = metronome.create_client()
    job_id = uuid.uuid4().hex
    with job(job_no_schedule(job_id)):
        runs = client.get_runs(job_id)
        assert len(runs) == 0

        client.run_job(job_id)
        time.sleep(2)
        assert len(client.get_runs(job_id)) == 1
Пример #12
0
def test_get_job_run():
    client = metronome.create_client()
    job_id = uuid.uuid4().hex
    with job(job_no_schedule(job_id)):
        client.run_job(job_id)
        time.sleep(2)
        run_id = client.get_runs(job_id)[0]['id']
        run = client.get_run(job_id, run_id)
        assert run['id'] == run_id
        assert run['status'] in ['ACTIVE', 'INITIAL']
Пример #13
0
def test_stop_job_run():
    client = metronome.create_client()
    job_id = uuid.uuid4().hex
    with job(job_no_schedule(job_id)):
        client.run_job(job_id)
        time.sleep(2)
        assert len(client.get_runs(job_id)) == 1
        run_id = client.get_runs(job_id)[0]['id']
        client.kill_run(job_id, run_id)

        assert len(client.get_runs(job_id)) == 0
Пример #14
0
def test_stop_job_run():
    client = metronome.create_client()
    job_id = uuid.uuid4().hex
    with job(job_no_schedule(job_id)):
        client.run_job(job_id)
        time.sleep(2)
        assert len(client.get_runs(job_id)) == 1
        run_id = client.get_runs(job_id)[0]['id']
        client.kill_run(job_id, run_id)

        assert len(client.get_runs(job_id)) == 0
Пример #15
0
def test_remove_job():
    client = metronome.create_client()
    client.add_job(job_no_schedule('remove-job'))
    assert client.remove_job('remove-job') is None
    job_exists = False
    try:
        client.get_job('remove-job')
        job_exists = True
    except:
        pass
    assert not job_exists, "Job exists"
Пример #16
0
def test_remove_job():
    client = metronome.create_client()
    client.add_job(job_no_schedule('remove-job'))
    assert client.remove_job('remove-job') is None
    job_exists = False
    try:
        client.get_job('remove-job')
        job_exists = True
    except Exception:
        pass
    assert not job_exists, "Job exists"
Пример #17
0
def test_remove_schedule():
    client = metronome.create_client()
    with job(job_no_schedule('schedule')):
        client.add_schedule('schedule', schedule())
        assert client.get_schedule('schedule', 'nightly')['cron'] == '20 0 * * *'
        client.remove_schedule('schedule', 'nightly')
        schedule_exists = False
        try:
            client.get_schedule('schedule', 'nightly')
            schedule_exists = True
        except Exception:
            pass
        assert not schedule_exists, "Schedule exists"
Пример #18
0
def test_remove_schedule():
    client = metronome.create_client()
    with job(job_no_schedule('schedule')):
        client.add_schedule('schedule', schedule())
        assert client.get_schedule('schedule', 'nightly')['cron'] == '20 0 * * *'
        client.remove_schedule('schedule', 'nightly')
        schedule_exists = False
        try:
            client.get_schedule('schedule', 'nightly')
            schedule_exists = True
        except:
            pass
        assert not schedule_exists, "Schedule exists"
Пример #19
0
def test_metronome_shutdown_with_no_extra_tasks():
    """ Test for METRONOME-100 regression
        When Metronome is restarted it incorrectly started another task for already running job run task.
    """
    client = metronome.create_client()
    job_id = "metronome-shutdown-{}".format(uuid.uuid4().hex)
    with job(job_no_schedule(job_id)):
        # run a job before we shutdown Metronome
        run_id = client.run_job(job_id)["id"]
        common.wait_for_job_started(job_id, run_id)
        common.assert_job_run(client, job_id)

        # restart metronome process
        common.run_command_on_metronome_leader('sudo systemctl restart dcos-metronome')
        common.wait_for_metronome()

        # verify that no extra job runs were started when Metronome was restarted
        common.assert_wait_for_no_additional_tasks(tasks_count=1, client=client, job_id=job_id)
Пример #20
0
def test_metronome_shutdown_with_no_extra_tasks():
    """ Test for METRONOME-100 regression
        When Metronome is restarted it incorrectly started another task for already running job run task.
    """
    client = metronome.create_client()
    job_id = "metronome-shutdown-{}".format(uuid.uuid4().hex)
    with job(job_no_schedule(job_id)):
        # run a job before we shutdown Metronome
        run_id = client.run_job(job_id)["id"]
        common.wait_for_job_started(job_id, run_id)
        common.assert_job_run(client, job_id)

        # restart metronome process
        common.run_command_on_metronome_leader(
            'sudo systemctl restart dcos-metronome')
        common.wait_for_metronome()

        # verify that no extra job runs were started when Metronome was restarted
        common.assert_wait_for_no_additional_tasks(tasks_count=1,
                                                   client=client,
                                                   job_id=job_id)
Пример #21
0
def test_metronome_shutdown_with_no_extra_tasks():
    """ Test for METRONOME-100 regression
        When Metronome is restarted it incorrectly started another task for already running job run task.
    """
    client = metronome.create_client()
    job_id = "metronome-shutdown-{}".format(uuid.uuid4().hex)
    with job(job_no_schedule(job_id)):
        # run a job before we shutdown Metronome
        run_id = client.run_job(job_id)["id"]
        common.wait_for_job_started(job_id, run_id)
        common.assert_job_run(client, job_id)

        # restart metronome process
        # this won't work in multi-master setup if the mesos leader is not the same as metronome leader
        # we can improve this one there is a good way how to get metronome leader from the system (e.g. info endpoint)
        metronome_leader = shakedown.master_leader_ip()
        shakedown.run_command_on_agent(metronome_leader, 'sudo systemctl restart dcos-metronome')
        common.wait_for_metronome()

        # verify that no extra job runs were started when Metronome was restarted
        common.assert_wait_for_no_additional_tasks(tasks_count=1, client=client, job_id=job_id)
Пример #22
0
def test_job_constraints():
    client = metronome.create_client()
    host = common.get_private_ip()
    job_id = uuid.uuid4().hex
    job_def = job_no_schedule(job_id)
    common.pin_to_host(job_def, host)
    with job(job_def):
        # on the same node 3x
        for i in range(3):
            client.run_job(job_id)
            time.sleep(2)
            assert len(client.get_runs(job_id)) == 1
            run_id = client.get_runs(job_id)[0]['id']

            @retry(wait_fixed=1000, stop_max_delay=5000)
            def check_tasks():
                task = get_job_tasks(job_id, run_id)[0]
                task_ip = task['statuses'][0]['container_status']['network_infos'][0]['ip_addresses'][0]['ip_address']
                assert task_ip == host

            client.kill_run(job_id, run_id)

        assert len(client.get_runs(job_id)) == 0
Пример #23
0
def test_job_constraints():
    client = metronome.create_client()
    host = common.get_private_ip()
    job_id = uuid.uuid4().hex
    job_def = job_no_schedule(job_id)
    common.pin_to_host(job_def, host)
    with job(job_def):
        # on the same node 3x
        for i in range(3):
            client.run_job(job_id)
            time.sleep(2)
            assert len(client.get_runs(job_id)) == 1
            run_id = client.get_runs(job_id)[0]['id']

            @retry(wait_fixed=1000, stop_max_delay=5000)
            def check_tasks():
                task = common.get_job_tasks(job_id, run_id)[0]
                task_ip = task['statuses'][0]['container_status']['network_infos'][0]['ip_addresses'][0]['ip_address']
                assert task_ip == host

            client.kill_run(job_id, run_id)

        assert len(client.get_runs(job_id)) == 0
Пример #24
0
def test_list_jobs():
    client = metronome.create_client()
    with job(job_no_schedule('job1')):
        with job(job_no_schedule('job2')):
            jobs = client.get_jobs()
            assert len(jobs) == 2
Пример #25
0
def test_add_schedule():
    client = metronome.create_client()
    with job(job_no_schedule('schedule')):
        client.add_schedule('schedule', schedule())
        assert client.get_schedule('schedule',
                                   'nightly')['cron'] == '20 0 * * *'
Пример #26
0
def test_list_jobs():
    client = metronome.create_client()
    with job(job_no_schedule('job1')):
        with job(job_no_schedule('job2')):
            jobs = client.get_jobs()
            assert len(jobs) == 2
Пример #27
0
def test_add_job():
    client = metronome.create_client()
    with job(job_no_schedule()):
        job_id = job_no_schedule()['id']
        response = client.get_job(job_id)
        assert response.get('id') == job_id
Пример #28
0
def test_add_schedule():
    client = metronome.create_client()
    with job(job_no_schedule('schedule')):
        client.add_schedule('schedule', schedule())
        assert client.get_schedule('schedule', 'nightly')['cron'] == '20 0 * * *'
Пример #29
0
def test_add_job():
    client = metronome.create_client()
    with job(job_no_schedule()):
        job_id = job_no_schedule()['id']
        response = client.get_job(job_id)
        assert response.get('id') == job_id