Exemple #1
0
def test_undeploy_custom_deploy_params_check(subprocess_mock, os_environ_mock):
    job_name = 'test-job-name'
    namespace = 'test-namespace'
    user_env = dict(os_environ_mock,
                    JOB_NAME=job_name,
                    NAMESPACE=namespace,
                    USER='******')
    UndeployCommand._custom_undeploy(job_name, namespace)
    subprocess_mock.check_output.\
        assert_called_with(["make", "undeploy"],
                           env=user_env,
                           stderr=subprocess_mock.STDOUT)
Exemple #2
0
def test_undeploy_by_job_name(proc_helpers, remove_job_dir_mock,
                              get_deployed_jobs_mock):
    """tests `mlt undeploy --job-name` to undeploy a job."""
    remove_job_dir_mock.input_value = 'k8s/job1'
    get_deployed_jobs_mock.return_value = {"job1"}
    UndeployCommand({'undeploy': True, '--job-name': 'job1'}).action()
    proc_helpers.run.assert_called_once()
Exemple #3
0
def test_undeploy(load_config_mock, proc_helpers, remove_job_dir_mock,
                  get_deployed_jobs_mock):
    """simple undeploy"""
    remove_job_dir_mock.input_value = 'k8s/job1'
    get_deployed_jobs_mock.return_value = {"job1"}
    UndeployCommand({'undeploy': True}).action()
    proc_helpers.run.assert_called_once()
Exemple #4
0
def test_undeploy_by_bad_job_name(remove_job_dir_mock, get_deployed_jobs_mock):
    """tests `mlt undeploy --job-name` with a non existing job name."""
    remove_job_dir_mock.input_value = 'k8s/job1'
    get_deployed_jobs_mock.return_value = ["job1"]
    command = {'undeploy': True, '--job-name': 'job2'}
    with catch_stdout() as output:
        with pytest.raises(SystemExit):
            UndeployCommand(command).action()
        assert "Job name job2 not found" in output.getvalue()
Exemple #5
0
def test_undeploy_custom_delete_job_dir(
        open_mock, get_deployed_jobs_mock, get_sync_spec_mock,
        is_custom_mock, subprocess_mock, os_path_exists_mock):
    """test removing job dir while undeploying it."""
    get_sync_spec_mock.return_value = None
    is_custom_mock.return_value = True
    subprocess_mock.return_value = b"No such file or directory: 'k8s/job1'"
    get_deployed_jobs_mock.return_value = {"job1"}
    os_path_exists_mock.return_value = True
    with catch_stdout() as output:
        with pytest.raises(OSError):
            UndeployCommand({'undeploy': True}).action()
        assert"No such file or directory: 'k8s/job1'" in output.getvalue()
Exemple #6
0
def test_undeploy_custom_by_job_name(
        open_mock, get_deployed_jobs_mock, remove_job_dir_mock,
        get_sync_spec_mock, is_custom_mock, subprocess_mock,
        os_path_exists_mock):
    """test `mlt undeploy --job-name` with custom undeploy."""
    get_sync_spec_mock.return_value = None
    is_custom_mock.return_value = True
    subprocess_mock.return_value = b"Successful Custom Undeploy"
    get_deployed_jobs_mock.return_value = {"job1", "job2"}
    os_path_exists_mock.return_value = True
    remove_job_dir_mock.input_value = 'k8s/job1'
    with catch_stdout() as output:
        UndeployCommand({'undeploy': True, '--job-name': 'job1'}).action()
        assert output.getvalue().strip() == "Successful Custom Undeploy"
Exemple #7
0
def test_undeploy_custom_all(open_mock, get_deployed_jobs_mock,
                             remove_job_dir_mock, get_sync_spec_mock,
                             is_custom_mock, subprocess_mock,
                             os_path_exists_mock):
    """test `mlt undeploy --all."""
    get_sync_spec_mock.return_value = None
    is_custom_mock.return_value = True
    subprocess_mock.check_output.return_value = b"Successful Custom Undeploy"
    get_deployed_jobs_mock.return_value = ["job1", "job2"]
    os_path_exists_mock.return_value = True
    remove_job_dir_mock.input_value = 'k8s/job1'
    with catch_stdout() as output:
        UndeployCommand({'undeploy': True, '--all': True}).action()
        assert output.getvalue().strip() == 'Successful Custom Undeploy' \
                                            '\nSuccessful Custom Undeploy'
Exemple #8
0
def test_undeploy_custom(get_sync_spec_mock, is_custom_mock, open_mock,
                         os_path_exists_mock, subprocess_mock,
                         remove_job_dir_mock, get_deployed_jobs_mock):
    """
    Tests successful call to the undeploy command with a custom deploy
    """
    get_sync_spec_mock.return_value = None
    is_custom_mock.return_value = True
    os_path_exists_mock.return_value = True
    subprocess_mock.return_value = b"Successful Custom Undeploy"
    remove_job_dir_mock.input_value = 'k8s/job1'
    get_deployed_jobs_mock.return_value = {"job1"}

    with catch_stdout() as output:
        UndeployCommand({'undeploy': True}).action()
        assert output.getvalue().strip() == "Successful Custom Undeploy"
Exemple #9
0
def undeploy_fail(fail_text, command):
    """asserts we get some output along with a SystemExit"""
    with catch_stdout() as output:
        with pytest.raises(SystemExit):
            UndeployCommand(command).action()
        assert output.getvalue().strip() == fail_text
Exemple #10
0
def test_undeploy(proc_helpers, load_config):
    undeploy = UndeployCommand({'undeploy': True})
    undeploy.config = {'namespace': 'foo'}
    undeploy.action()
    proc_helpers.run.assert_called_once()