Skip to content

Commit

Permalink
Merge pull request #5384 from MetRonnie/set-verbosity
Browse files Browse the repository at this point in the history
Fix set-verbosity GraphQL bug
  • Loading branch information
hjoliver authored Feb 28, 2023
2 parents 74056a9 + 1f038a8 commit 37e7d22
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ creating a new release entry be sure to copy & paste the span tag with the
`actions:bind` attribute, which is used by a regex to find the text to be
updated. Only the first match gets replaced, so it's fine to leave the old
ones in. -->
-------------------------------------------------------------------------------
## __cylc-8.1.3 (<span actions:bind='release-date'>Upcoming</span>)__

### Fixes

[#5384](https://github.com/cylc/cylc-flow/pull/5384) -
Fixes `cylc set-verbosity`.

-------------------------------------------------------------------------------
## __cylc-8.1.2 (<span actions:bind='release-date'>Released 2023-02-20</span>)__
Expand Down
2 changes: 1 addition & 1 deletion cylc/flow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
LOG.addHandler(logging.NullHandler())

LOG_LEVELS = {
"DEBUG": logging.DEBUG,
"INFO": logging.INFO,
"NORMAL": logging.INFO,
"WARNING": logging.WARNING,
"ERROR": logging.ERROR,
"CRITICAL": logging.CRITICAL,
"DEBUG": logging.DEBUG,
}


Expand Down
16 changes: 9 additions & 7 deletions cylc/flow/network/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from copy import deepcopy
from functools import partial
import json
import logging
from operator import attrgetter
from textwrap import dedent
from typing import (
Expand All @@ -38,6 +37,7 @@
from graphene.types.generic import GenericScalar
from graphene.utils.str_converters import to_snake_case

from cylc.flow import LOG_LEVELS
from cylc.flow.broadcast_mgr import ALL_CYCLE_POINTS_STRS, addict
from cylc.flow.flow_mgr import FLOW_ALL, FLOW_NEW, FLOW_NONE
from cylc.flow.id import Tokens
Expand Down Expand Up @@ -1426,9 +1426,11 @@ class TimePoint(String):

LogLevels = graphene.Enum(
'LogLevels',
list(logging._nameToLevel.items()),
description=lambda x: f'Python logging level: {x.name} = {x.value}.'
if x else ''
list(LOG_LEVELS.items()),
description=lambda x: (
f'Logging level: {x.name} = {x.value}.'
if x else ''
)
)


Expand Down Expand Up @@ -1667,9 +1669,9 @@ class Meta:
description = sstrip('''
Change the logging severity level of a running workflow.
Only messages at or above the chosen severity level will be logged;
for example, if you choose `WARNING`, only warnings and critical
messages will be logged.
Only messages at or above the chosen severity level will be logged.
For example, if you choose `WARNING`, only warning, error and
critical level messages will be logged.
''')
resolver = mutator

Expand Down
10 changes: 4 additions & 6 deletions cylc/flow/scripts/set_verbosity.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_option_parser() -> COP:
return parser


async def run(options: 'Values', severity, workflow_id) -> None:
async def run(options: 'Values', severity: str, workflow_id: str) -> None:
pclient = get_client(workflow_id, timeout=options.comms_timeout)

mutation_kwargs = {
Expand All @@ -81,11 +81,9 @@ async def run(options: 'Values', severity, workflow_id) -> None:


@cli_function(get_option_parser)
def main(parser: COP, options: 'Values', severity_str: str, *ids) -> None:
try:
severity = LOG_LEVELS[severity_str]
except KeyError:
raise InputError("Illegal logging level, %s" % severity_str)
def main(parser: COP, options: 'Values', severity: str, *ids: str) -> None:
if severity not in LOG_LEVELS:
raise InputError(f"Illegal logging level, {severity}")
call_multi(
partial(run, options, severity),
*ids,
Expand Down
32 changes: 27 additions & 5 deletions tests/functional/cli/03-set-verbosity.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,31 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
# Test "cylc set-verbosity" with a bad verbosity level.
# Test "cylc set-verbosity"
. "$(dirname "$0")/test_header"
set_test_number 2
run_fail "${TEST_NAME_BASE}" cylc set-verbosity duck quack
grep_ok 'InputError: Illegal logging level, duck' "${TEST_NAME_BASE}.stderr"
exit
set_test_number 6

# Test illegal log level
TEST_NAME="${TEST_NAME_BASE}-bad"
run_fail "$TEST_NAME" cylc set-verbosity duck quack
grep_ok 'InputError: Illegal logging level, duck' "${TEST_NAME}.stderr"

# Test good log level
TEST_NAME="${TEST_NAME_BASE}-good"
init_workflow "${TEST_NAME_BASE}" << '__FLOW__'
[scheduler]
allow implicit tasks = True
[scheduling]
[[graph]]
R1 = andor
__FLOW__

run_ok "${TEST_NAME}-validate" cylc validate "$WORKFLOW_NAME"
workflow_run_ok "${TEST_NAME}-run" cylc play --pause "$WORKFLOW_NAME"

run_ok "$TEST_NAME" cylc set-verbosity DEBUG "$WORKFLOW_NAME"
log_scan "${TEST_NAME}-grep" "${WORKFLOW_RUN_DIR}/log/scheduler/log" 5 1 \
'Command succeeded: set_verbosity'

cylc stop "$WORKFLOW_NAME"
purge

0 comments on commit 37e7d22

Please sign in to comment.