Skip to content

Commit

Permalink
vdk-core: comments
Browse files Browse the repository at this point in the history
Signed-off-by: mrMoZ1 <mzhivkov@vmware.com>
  • Loading branch information
mrMoZ1 committed Oct 6, 2022
1 parent a88c225 commit 9683600
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ def invoke_run_function(func: Callable, job_input: IJobInput, step_name: str):
try:
func(**actual_arguments)
except SkipRemainingStepsException as e:
log.info(e)
# Catch and rethrow exception here since it is handled at
# the run_step() hook level. We also don't want to use the
# errors.log_and_rethrow() method since it will log a
# confusing message to the users.
log.debug(e)
raise e
except BaseException as e:
from vdk.internal.builtin_plugins.run.job_input_error_classifier import (
Expand Down
66 changes: 37 additions & 29 deletions projects/vdk-core/tests/functional/run/test_run_job_cancel.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
import logging
import unittest.mock
from unittest.mock import MagicMock
from unittest.mock import patch

from click.testing import Result
from functional.run import util
from vdk.internal.core import errors
from vdk.plugin.test_utils.util_funcs import cli_assert_equal
from vdk.plugin.test_utils.util_funcs import CliEntryBasedTestRunner
from vdk.plugin.test_utils.util_funcs import TestingCliEntryPlugin


@patch(
"vdk.internal.builtin_plugins.termination_message.writer.TerminationMessageWriterPlugin.write_termination_message"
)
def test_run(patched_writer: MagicMock):
"""
Test that runs a sample data job consisting of 3 steps.
Each step logs <Step 1,2> etc. However after the second step's log call
the cancel_job_execution method is invoked which should cancel
the job execution. Test checks:
execution is canceled and final step isn't executed.
proper exit code is set.
proper message is logged confirming job was cancelled from cancel_job_execution() method.
:return:
"""
test_runner = CliEntryBasedTestRunner()
class TestCancellation(unittest.TestCase):
@patch(
"vdk.internal.builtin_plugins.termination_message.writer.TerminationMessageWriterPlugin"
+ ".write_termination_message"
)
def test_run(self, patched_writer: MagicMock):
"""
Test that runs a sample data job consisting of 3 steps.
Each step logs <Step 1,2> etc. However after the second step's log call
the cancel_job_execution method is invoked which should cancel
the job execution. Test checks:
execution is canceled and final step isn't executed.
proper exit code is set.
proper message is logged confirming job was cancelled from cancel_job_execution() method.
:return:
"""
test_runner = CliEntryBasedTestRunner()

result: Result = test_runner.invoke(["run", util.job_path("cancel-job")])
# clear recorded errors before invoking run since other tests might leave a dirty state
errors.clear_intermediate_errors()

# Check the writer plugin wasn't called with user or platform errors.
# 1st param is overall blamee, should be None.
# 2nd parm is overall user error in this case it's empty string which is a falsy value.
# 3rd param is context.configuration and can be ignored for this test.
patched_writer.assert_called_once_with(None, "", unittest.mock.ANY)
assert "Step Cancel 1." in result.output
assert "Step Cancel 2." in result.output
assert "Step Cancel 3." not in result.output
assert (
"Job/template execution was skipped from job/template step code."
in result.output
)
cli_assert_equal(0, result)
result: Result = test_runner.invoke(["run", util.job_path("cancel-job")])

# Check the writer plugin wasn't called with user or platform errors.
# 1st param is overall blamee, should be None.
# 2nd parm is overall user error in this case it's empty string which is a falsy value.
# 3rd param is context.configuration and can be ignored for this test.
patched_writer.assert_called_once_with(None, "", unittest.mock.ANY)
assert "Step Cancel 1." in result.output
assert "Step Cancel 2." in result.output
assert "Step Cancel 3." not in result.output
assert (
"Job/template execution was skipped from job/template step code."
in result.output
)
cli_assert_equal(0, result)

0 comments on commit 9683600

Please sign in to comment.