Skip to content

Commit

Permalink
Delete Mesos related exit codes and docker files - TRON-2187 (#959)
Browse files Browse the repository at this point in the history
* Delete Mesos related exit codes and docker files

* Adding a try/except for validating extra keys

* Testing deleted extra keys
  • Loading branch information
EmanElsaban committed May 16, 2024
1 parent 7178ded commit 33ad2a1
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 105 deletions.
67 changes: 38 additions & 29 deletions tests/config/config_parse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def test_invalid_action_node_with_master_context(self):
assert_in(expected_message, str(exception))


class TestJobConfig(TestCase):
class TestJobConfig:
def test_no_actions(self):
test_config = dict(
jobs=[
Expand Down Expand Up @@ -856,7 +856,7 @@ def test_config_cleanup_action_name(self):
)
assert_in(expected_msg, str(exception))

def test_config_cleanup_requires(self):
def test_config_cleanup_requires(self, capfd):
test_config = dict(
jobs=[
dict(
Expand All @@ -872,13 +872,12 @@ def test_config_cleanup_requires(self):
**BASE_CONFIG,
)

expected_msg = "Unknown keys in CleanupAction : requires"
exception = assert_raises(
ConfigError,
valid_config,
test_config,
)
expected_msg = "Unknown keys in CleanupAction : requires: removing them.\n"
output_config = valid_config(test_config)
exception, err = capfd.readouterr()
assert_equal(expected_msg, str(exception))
# assert that "requires" key doesn't exist in the dictionary
assert "requires" not in output_config.jobs.get("MASTER.test_job0").cleanup_action

def test_validate_job_no_actions(self):
job_config = dict(
Expand All @@ -903,7 +902,7 @@ def test_validate_job_no_actions(self):
assert_in(expected_msg, str(exception))


class TestValidSecretSource(TestCase):
class TestValidSecretSource:
def test_missing_secret_name(self):
secret_env = dict(key="no_secret_name")

Expand All @@ -912,16 +911,17 @@ def test_missing_secret_name(self):

assert "missing options: secret" in str(missing_exc.value)

def test_validate_job_extra_secret_env(self):
def test_validate_job_extra_secret_env(self, capfd):
secret_env = dict(
secret_name="tron-secret-k8s-name-no--secret--name",
key="no_secret_name",
extra_key="unknown",
)
with pytest.raises(ConfigError) as missing_exc:
config_parse.valid_secret_source(secret_env, NullConfigContext)

assert "Unknown keys in SecretSource : extra_key" in str(missing_exc.value)
output_config = config_parse.valid_secret_source(secret_env, NullConfigContext)
expected_msg = "Unknown keys in SecretSource : extra_key: removing them.\n"
exception, err = capfd.readouterr()
assert_equal(expected_msg, str(exception))
assert not hasattr(output_config, "extra_key")

def test_valid_job_secret_env_success(self):
secret_env = dict(
Expand All @@ -935,7 +935,7 @@ def test_valid_job_secret_env_success(self):
assert built_env == expected_env


class TestNodeConfig(TestCase):
class TestNodeConfig:
def test_validate_node_pool(self):
config_node_pool = valid_node_pool(
dict(name="theName", nodes=["node1", "node2"]),
Expand Down Expand Up @@ -1033,16 +1033,13 @@ def test_invalid_node_pool_config(self):
)
assert_in(expected_msg, str(exception))

def test_invalid_named_update(self):
def test_invalid_named_update(self, capfd):
test_config = dict(bozray=None)
expected_message = "Unknown keys in NamedConfigFragment : bozray"
exception = assert_raises(
ConfigError,
validate_fragment,
"foo",
test_config,
)
assert_in(expected_message, str(exception))
output_config = validate_fragment("foo", test_config)
expected_msg = "Unknown keys in NamedConfigFragment : bozray: removing them.\n"
exception, err = capfd.readouterr()
assert_equal(expected_msg, str(exception))
assert not hasattr(output_config, "bozray")


class TestValidateJobs(TestCase):
Expand Down Expand Up @@ -1565,19 +1562,31 @@ class TestValidSecretVolumeItem:
@pytest.mark.parametrize(
"config",
[
{"path": "abc"},
{
"key": "abc",
},
{
"key": "abc",
"path": "abc",
"extra_key": None,
},
],
)
def test_extra_keys(self, config, capfd):
output_config = config_parse.valid_secret_volume_item(config, NullConfigContext)
expected_msg = "Unknown keys in SecretVolumeItem : extra_key: removing them.\n"
exception, err = capfd.readouterr()
assert_equal(expected_msg, str(exception))
assert not hasattr(output_config, "extra_key")

@pytest.mark.parametrize(
"config",
[
{"path": "abc"},
{"key": "abc", "path": "abc", "mode": "a"},
{
"key": "abc",
},
],
)
def test_invalid(self, config):
def test_invalid_missing_required(self, config):
with pytest.raises(ConfigError):
config_parse.valid_secret_volume_item(config, NullConfigContext)

Expand Down
17 changes: 0 additions & 17 deletions tests/core/actionrun_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1596,23 +1596,6 @@ def test_submit_command(self, mock_cluster_repo, mock_filehandler):
self.action_run.output_path,
)

@mock.patch("tron.core.actionrun.filehandler", autospec=True)
@mock.patch("tron.core.actionrun.MesosClusterRepository", autospec=True)
def test_submit_command_task_none(
self,
mock_cluster_repo,
mock_filehandler,
):
# Task is None if Mesos is disabled
mock_get_cluster = mock_cluster_repo.get_cluster
mock_get_cluster.return_value.create_task.return_value = None
new_attempt = self.action_run.create_attempt()
self.action_run.submit_command(new_attempt)

mock_get_cluster.assert_called_once_with()
assert mock_get_cluster.return_value.submit.call_count == 0
assert self.action_run.is_failed

@mock.patch("tron.core.actionrun.filehandler", autospec=True)
@mock.patch("tron.core.actionrun.MesosClusterRepository", autospec=True)
def test_recover(self, mock_cluster_repo, mock_filehandler):
Expand Down
6 changes: 5 additions & 1 deletion tron/config/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ def validate(self, in_dict, config_context):
config_context = self.build_context(in_dict, config_context)
in_dict = self.cast(in_dict, config_context)
self.validate_required_keys(in_dict)
self.validate_extra_keys(in_dict)
try:
self.validate_extra_keys(in_dict)
except ConfigError as e:
print(f"{e}: removing them.")
in_dict = {k: v for k, v in in_dict.items() if k in self.all_keys}
return self.build_config(in_dict, config_context)

def __call__(self, in_dict, config_context=NullConfigContext):
Expand Down
2 changes: 0 additions & 2 deletions tron/utils/exitcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
EXIT_NODE_ERROR = -2
EXIT_STOP_KILL = -3
EXIT_TRIGGER_TIMEOUT = -4
EXIT_MESOS_DISABLED = -5
EXIT_KUBERNETES_DISABLED = -6
EXIT_KUBERNETES_NOT_CONFIGURED = -7
EXIT_KUBERNETES_TASK_INVALID = -8
Expand All @@ -16,7 +15,6 @@
EXIT_NODE_ERROR: "Node error",
EXIT_STOP_KILL: "Stopped or killed",
EXIT_TRIGGER_TIMEOUT: "Timed out waiting for trigger",
EXIT_MESOS_DISABLED: "Mesos disabled",
EXIT_KUBERNETES_DISABLED: "Kubernetes disabled",
EXIT_KUBERNETES_NOT_CONFIGURED: "Kubernetes enabled, but not configured",
EXIT_KUBERNETES_TASK_INVALID: "Kubernetes task was not valid",
Expand Down
40 changes: 0 additions & 40 deletions yelp_package/itest_dockerfiles/mesos/Dockerfile

This file was deleted.

12 changes: 0 additions & 12 deletions yelp_package/itest_dockerfiles/mesos/mesos-secrets

This file was deleted.

4 changes: 0 additions & 4 deletions yelp_package/itest_dockerfiles/mesos/mesos-slave-secret

This file was deleted.

0 comments on commit 33ad2a1

Please sign in to comment.