-
Notifications
You must be signed in to change notification settings - Fork 875
traffic_ctl: emit JSON null instead of YAML tilde #13609
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
Open
brbzull0
wants to merge
12
commits into
apache:master
Choose a base branch
from
brbzull0:fix/traffic-ctl-json-null
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fd6c024
traffic_ctl: emit JSON null instead of YAML tilde
81a52a9
traffic_ctl: route JSON emitters through one helper
f6ee3fb
traffic_ctl: address review on the JSON emitter helper
86119e6
traffic_ctl: add a regression test for JSON null output
ae3d943
traffic_ctl: check JSON output with a tester, not a shell pipeline
45ec4b1
traffic_ctl: make the test helper's frame lookup and file reads deter…
e22b3bd
traffic_ctl: compare JSON field expectations as strings
842d240
traffic_ctl: correct the boolean note on the JSON field check
7f8131e
traffic_ctl: import autest's testers instead of walking the stack
1252891
traffic_ctl: fail the field check on a key the output lacks
734f43a
traffic_ctl: assert the plugin list shape, not just that it parses
2d9dfd6
traffic_ctl: compare JSON field values, not their str()
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
tests/gold_tests/traffic_ctl/traffic_ctl_json_null.test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import sys | ||
|
|
||
| # To include util classes | ||
| sys.path.insert(0, f'{Test.TestDirectory}') | ||
|
|
||
| from traffic_ctl_test_utils import Make_traffic_ctl | ||
|
|
||
| Test.Summary = ''' | ||
| traffic_ctl JSON output must be parseable JSON, including when a node is null. | ||
|
|
||
| yaml-cpp emits null as `~`, which is valid YAML but rejected by every JSON | ||
| parser. Emitters that produce JSON must set YAML::LowerNull, and container | ||
| nodes that may stay empty must be constructed as sequences so they emit `[]` | ||
| rather than null. | ||
|
|
||
| The trigger for both regressions is the *empty* case, so this test | ||
| deliberately runs against a freshly started server with an empty HostDB and no | ||
| plugins loaded. A test that populates either one first would pass against the | ||
| bug. | ||
| ''' | ||
|
|
||
| Test.ContinueOnFail = True | ||
|
|
||
| records_yaml = ''' | ||
| exec_thread: | ||
| autoconfig: | ||
| enabled: 0 | ||
| limit: 4 | ||
| ''' | ||
|
|
||
| traffic_ctl = Make_traffic_ctl(Test, records_yaml) | ||
|
|
||
| ###### | ||
| # hostdb status -- `partitions` is empty on a fresh server. | ||
| # | ||
| # Flagless output goes through BasePrinter::write_output_json (the client | ||
| # printer). Before the fix this emitted `"partitions": ~`. | ||
| traffic_ctl.hostdb().status().validate_is_valid_json() | ||
|
|
||
| # ... and it must be an empty array, not null. hostdb_status_schema.json | ||
| # declares partitions as "type": "array". | ||
| traffic_ctl.hostdb().status().validate_json_contains(partitions=[]) | ||
|
|
||
| # -f json goes through the full envelope. Same emitter, different entry point. | ||
| traffic_ctl.hostdb().status().as_json().validate_is_valid_json() | ||
|
|
||
| # The server-side encoder (yamlcpp_json_encoder) is a third, independent | ||
| # emitter. rpc invoke exercises it directly. | ||
| # | ||
| # The params are required: get_hostdb_status without them fails with "invalid | ||
| # node; this may result from using a map iterator as a sequence iterator", and | ||
| # an error envelope is valid JSON no matter what the emitter does -- the | ||
| # assertion would pass against the bug. | ||
| traffic_ctl.rpc().invoke(handler="get_hostdb_status", params='"hostname: \\"\\""').validate_is_valid_json() | ||
|
brbzull0 marked this conversation as resolved.
brbzull0 marked this conversation as resolved.
|
||
|
|
||
| ###### | ||
| # plugin list -- `plugins` is empty when plugin.config loads nothing. | ||
| # | ||
| # plugin list ignores the format flag today and prints a human table, so only | ||
| # the RPC path is assertable. Once plugin list honours -f json, add: | ||
| # traffic_ctl.plugin().list().as_json().validate_is_valid_json() | ||
| # | ||
| # Assert the shape rather than mere parseability: `plugins` has to be `[]`, | ||
| # matching what the hostdb case above asserts for `partitions`. The field sits | ||
| # at result.data.plugins, which validate_json_contains cannot reach, so this | ||
| # compares the whole result, as the connection tracker cases in | ||
| # traffic_ctl_server_output.test.py do. Before the fix the field emitted `~`, | ||
| # which fails this comparison as surely as it fails a JSON parser. Nothing | ||
| # forces plugin.config to be empty here, and nothing needs to: should a | ||
| # default ever load a plugin, this assertion fails rather than going quiet. | ||
| traffic_ctl.rpc().invoke( | ||
| handler="admin_plugin_get_list").validate_result_with_text('{"data": {"source": "plugin.config", "plugins": []}}') | ||
|
|
||
| ###### | ||
| # Commands that were already valid JSON -- guard against the shared emitter | ||
| # change regressing them. | ||
| traffic_ctl.server().status().validate_is_valid_json() | ||
| traffic_ctl.rpc().invoke(handler="show_registered_handlers").validate_is_valid_json() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.