Skip to content

Commit

Permalink
PENG-2457 modify the error raised by the *fetch_influx_data* function
Browse files Browse the repository at this point in the history
  • Loading branch information
matheushent committed Dec 19, 2024
1 parent b2fda63 commit b4e605b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions jobbergate-agent/jobbergate_agent/jobbergate/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
InfluxDBPointDict,
)
from jobbergate_agent.settings import SETTINGS
from jobbergate_agent.utils.exception import JobbergateApiError, SbatchError
from jobbergate_agent.utils.exception import JobbergateApiError, SbatchError, JobbergateAgentError
from jobbergate_agent.utils.logging import log_error
from jobbergate_agent.jobbergate.constants import INFLUXDB_MEASUREMENT
from jobbergate_agent.utils.compute import aggregate_influx_measures
Expand Down Expand Up @@ -95,7 +95,7 @@ async def fetch_influx_data(
"""
Fetch data from InfluxDB for a given host, step and task.
"""
with JobbergateApiError.handle_errors("Failed to fetch measures from InfluxDB", do_except=log_error):
with JobbergateAgentError.handle_errors("Failed to fetch measures from InfluxDB", do_except=log_error):
all_none = all(arg is None for arg in [time, host, step, task])
all_set = all(arg is not None for arg in [time, host, step, task])

Expand Down
14 changes: 7 additions & 7 deletions jobbergate-agent/jobbergate_agent/utils/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@
from buzz.tools import DoExceptParams, noop


class ClusterAgentError(Buzz):
class JobbergateAgentError(Buzz):
"""Raise exception when execution command returns an error"""


class ProcessExecutionError(ClusterAgentError):
class ProcessExecutionError(JobbergateAgentError):
"""Raise exception when execution command returns an error"""


class AuthTokenError(ClusterAgentError):
class AuthTokenError(JobbergateAgentError):
"""Raise exception when there are connection issues with the backend"""


class SbatchError(ClusterAgentError):
class SbatchError(JobbergateAgentError):
"""Raise exception when sbatch raises any error"""


class JobbergateApiError(ClusterAgentError):
class JobbergateApiError(JobbergateAgentError):
"""Raise exception when communication with Jobbergate API fails"""


class JobSubmissionError(ClusterAgentError):
class JobSubmissionError(JobbergateAgentError):
"""Raise exception when a job cannot be submitted raises any error"""


class SlurmParameterParserError(ClusterAgentError):
class SlurmParameterParserError(JobbergateAgentError):
"""Raise exception when Slurm mapper or SBATCH parser face any error"""


Expand Down
18 changes: 9 additions & 9 deletions jobbergate-agent/tests/jobbergate/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
from jobbergate_agent.jobbergate.constants import INFLUXDB_MEASUREMENT
from jobbergate_agent.settings import SETTINGS
from jobbergate_agent.utils.exception import JobbergateApiError
from jobbergate_agent.utils.exception import JobbergateApiError, JobbergateAgentError


@pytest.fixture()
Expand Down Expand Up @@ -438,7 +438,7 @@ async def test_fetch_influx_data__success_with_all_None(mocked_influxdb_client:
],
)
@mock.patch("jobbergate_agent.jobbergate.update.influxdb_client")
async def test_fetch_influx_data__raises_JobbergateApiError_if_bad_arguments_are_passed(
async def test_fetch_influx_data__raises_JobbergateAgentError_if_bad_arguments_are_passed(
mocked_influxdb_client: mock.MagicMock,
time: int | None,
host: int | None,
Expand All @@ -449,7 +449,7 @@ async def test_fetch_influx_data__raises_JobbergateApiError_if_bad_arguments_are
measurement = random.choice(get_args(INFLUXDB_MEASUREMENT))

with pytest.raises(
JobbergateApiError, match="Invalid argument combination: all optional arguments must be either set or None."
JobbergateAgentError, match="Invalid argument combination: all optional arguments must be either set or None."
):
await fetch_influx_data(
job,
Expand All @@ -465,9 +465,9 @@ async def test_fetch_influx_data__raises_JobbergateApiError_if_bad_arguments_are

@pytest.mark.asyncio
@mock.patch("jobbergate_agent.jobbergate.update.influxdb_client")
async def test_fetch_influx_data__raises_JobbergateApiError_if_query_fails(mocked_influxdb_client: mock.MagicMock):
async def test_fetch_influx_data__raises_JobbergateAgentError_if_query_fails(mocked_influxdb_client: mock.MagicMock):
"""
Test that the ``fetch_influx_data()`` function will raise a JobbergateApiError
Test that the ``fetch_influx_data()`` function will raise a JobbergateAgentError
if the query to InfluxDB fails.
"""
measurement = random.choice(get_args(INFLUXDB_MEASUREMENT))
Expand All @@ -485,7 +485,7 @@ async def test_fetch_influx_data__raises_JobbergateApiError_if_query_fails(mocke
""")
params = dict(time=time, host=host, step=str(step), task=str(task), job=str(job))

with pytest.raises(JobbergateApiError, match="Failed to fetch measures from InfluxDB -- Exception: BOOM!"):
with pytest.raises(JobbergateAgentError, match="Failed to fetch measures from InfluxDB -- Exception: BOOM!"):
await fetch_influx_data(
job=job,
measurement=measurement,
Expand All @@ -499,14 +499,14 @@ async def test_fetch_influx_data__raises_JobbergateApiError_if_query_fails(mocke


@pytest.mark.asyncio
async def test_fetch_influx_data__raises_JobbergateApiError_if_influxdb_client_is_None():
async def test_fetch_influx_data__raises_JobbergateAgentError_if_influxdb_client_is_None():
"""
Test that the ``fetch_influx_data()`` function will raise a JobbergateApiError
Test that the ``fetch_influx_data()`` function will raise a JobbergateAgentError
if the influxdb_client is None.
"""
measurement = random.choice(get_args(INFLUXDB_MEASUREMENT))
with mock.patch("jobbergate_agent.jobbergate.update.influxdb_client", None):
with pytest.raises(JobbergateApiError, match="Failed to fetch measures from InfluxDB -- AssertionError:"):
with pytest.raises(JobbergateAgentError, match="Failed to fetch measures from InfluxDB -- AssertionError:"):
await fetch_influx_data(
time=random.randint(0, 1000),
host="test-host",
Expand Down

0 comments on commit b4e605b

Please sign in to comment.