Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vdk-core: Add flag to JobConfig in case config file is required #2521

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,29 @@ class JobConfig:
For more see the user wiki
"""

def __init__(self, data_job_path: Union[pathlib.Path, str]):
def __init__(
self, data_job_path: Union[pathlib.Path, str], should_fail_missing_config=False
):
self._config_ini = configparser.ConfigParser()
self._config_file = os.path.join(data_job_path, "config.ini")
self._should_fail_missing_config = should_fail_missing_config

if not os.path.isfile(self._config_file):
# TODO: Figure out a way to properly handle cases where there is no config.ini present
log.info("Missing config.ini file.")
# raise VdkConfigurationError(
# ErrorMessage(
# summary="Error while loading config.ini file",
# what="Cannot extract job Configuration",
# why=f"Configuration file config.ini is missing in data job path: {data_job_path}",
# consequences="Cannot deploy and configure the data job without config.ini file.",
# countermeasures="config.ini must be in the root of the data job folder. "
# "Make sure the file is created "
# "or double check the data job path is passed correctly.",
# )
# )
if should_fail_missing_config:
raise VdkConfigurationError(
ErrorMessage(
summary="Error while loading config.ini file",
what="Cannot extract job Configuration",
why=f"Configuration file config.ini is missing in data job path: {data_job_path}",
consequences="Cannot deploy and configure the data job without config.ini file.",
countermeasures="config.ini must be in the root of the data job folder. "
"Make sure the file is created "
"or double check the data job path is passed correctly.",
)
)
else:
log.info("Missing config.ini file.")

self._read_config_ini_file(
config_parser=self._config_ini, configuration_file_path=self._config_file
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ def test_defaults(self, tmpdir):
self.assertEqual(False, cfg.get_enable_attempt_notifications())
# this is the only important default no need to verify the others.

def test_error_raised_missing_config(self, tmpdir):
empty_job_dir = tmpdir.mkdir("foo-job")

with pytest.raises(VdkConfigurationError) as exc:
JobConfig(pathlib.Path(empty_job_dir), should_fail_missing_config=True)

assert "Error while loading config.ini file" in exc.value.args[0]

def test_vdk_options_empty(self):
self.assertEqual({}, self._cfg.get_vdk_options())

Expand All @@ -97,15 +105,14 @@ def test_vdk_options(self):
cfg = JobConfig(self._test_dir)
self.assertEqual({"a": "b"}, cfg.get_vdk_options())

# TODO: Enable when JobConfig issues resolved, tests still present in https://github.com/vmware/versatile-data-kit/blob/main/projects/vdk-control-cli/tests/vdk/internal/control/command_groups/job/test_datajob_config.py
# def test_set_team(self):
# self._perform_set_team_test("my_unique_team_name")
#
# def test_set_empty_team(self):
# self._perform_set_team_test("")
#
# def test_set_team_with_spaces(self):
# self._perform_set_team_test("my unique team name")
def test_set_team(self):
self._perform_set_team_test("my_unique_team_name")

def test_set_empty_team(self):
self._perform_set_team_test("")

def test_set_team_with_spaces(self):
self._perform_set_team_test("my unique team name")

def test_set_team_with_no_team_in_config_ini(self):
# remove all contents of config.ini (including team option)
Expand Down