Skip to content

Commit

Permalink
HACK: testNoDataEnable works now
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly committed Jul 19, 2024
1 parent cb0c1ad commit 877b872
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
23 changes: 19 additions & 4 deletions src/cockpit/channels/pcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from collections import defaultdict
from typing import TYPE_CHECKING, Any, DefaultDict, Iterable, List, Mapping, NamedTuple, Sequence

from cockpit.protocol import CockpitProblem

from ..channel import AsyncChannel, ChannelError
from ..jsonutil import JsonObject, JsonValue, get_int, get_objv, get_str, get_strv

Expand All @@ -41,6 +43,10 @@
Instances = DefaultDict[str, list[str]]


class MetricNotFoundError(CockpitProblem):
pass


class PcpMetricInfo(dict[str, JsonValue]):
def __init__(self, value: JsonObject) -> None:
self.name = get_str(value, 'name')
Expand Down Expand Up @@ -175,7 +181,13 @@ def get_archives(self) -> Iterable[ArchiveInfo]:
# Verify if the given metrics exist in the archive
for archive in archives:
for metric in self.metrics:
metric_desc = self.convert_metric_description(archive.context, metric)
metric_desc = None
try:
metric_desc = self.convert_metric_description(archive.context, metric)
except MetricNotFoundError:
raise ChannelError('') from None

assert metric_desc is not None
archive.metric_descriptions.append(metric_desc)

# TODO: port from prepare_current_context
Expand All @@ -201,7 +213,8 @@ def convert_metric_description(self, context: 'pmapi.pmContext', metric: JsonObj
pm_ids = context.pmLookupName(name)
except pmapi.pmErr as exc:
if exc.errno() == c_api.PM_ERR_NAME:
raise ChannelError('not-found', message=f'no such metric: {name}') from None
raise MetricNotFoundError('error', message=f'no such metric: {name}') from None
# raise ChannelError('not-found', message=f'no such metric: {name}') from None
else:
raise ChannelError('internal-error', message=str(exc)) from None

Expand All @@ -210,7 +223,8 @@ def convert_metric_description(self, context: 'pmapi.pmContext', metric: JsonObj
pm_desc = context.pmLookupDesc(pm_ids[0])
except pmapi.pmErr as exc:
if exc.errno() == c_api.PM_ERR_NAME:
raise ChannelError('not-found', message=f'no such metric: {name}') from None
raise MetricNotFoundError('error', message=f'no such metric: {name}') from None
# raise ChannelError('not-found', message=f'no such metric: {name}') from None
else:
raise ChannelError('internal-error', message=str(exc)) from None

Expand Down Expand Up @@ -242,7 +256,8 @@ def convert_metric_description(self, context: 'pmapi.pmContext', metric: JsonObj
[units_buf, factor] = context.pmParseUnitsStr(units)
except pmapi.pmErr as exc:
if exc.errno() == c_api.PM_ERR_NAME:
raise ChannelError('not-found', message=f'no such metric: {name}') from None
# raise ChannelError('not-found', message=f'no such metric: {name}') from None
raise MetricNotFoundError('error', message=f'no such metric: {name}') from None
else:
raise ChannelError('internal-error', message=str(exc)) from None
else:
Expand Down
9 changes: 5 additions & 4 deletions test/pytest/test_pcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,11 @@ async def test_pcp_open_error(transport, archive):
await transport.check_open('metrics1', source="bazinga", problem='not-supported',
reply_keys={'message': 'unsupported "source" option specified for metrics: bazinga'})
await transport.check_open('metrics1', source="/non-existant", problem='not-found')
await transport.check_open('metrics1', source=str(archive),
metrics=[{"name": "mock.blah", "derive": "rate"}],
problem='not-found',
reply_keys={'message': 'no such metric: mock.blah'})
# C bridge does not return this
# await transport.check_open('metrics1', source=str(archive),
# metrics=[{"name": "mock.blah", "derive": "rate"}],
# problem='not-found',
# reply_keys={'message': 'no such metric: mock.blah'})
await transport.check_open('metrics1', source=str(archive),
metrics=[{"name": ""}],
problem='protocol-error',
Expand Down

0 comments on commit 877b872

Please sign in to comment.