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

new: Changes for CLI/TechDocs spec compatibility #624

Merged
merged 11 commits into from
Jul 17, 2024

Conversation

lgarber-akamai
Copy link
Contributor

@lgarber-akamai lgarber-akamai commented Jul 2, 2024

📝 Description

This pull request resolves a few issues in the OpenAPI spec generation/baking logic that prevented it from being compatible with the upcoming new TechDocs OpenAPI spec. The changes in this PR were also made to be backwards compatible to make sure the transition between specs goes smoothly 🙂

Because this PR needed to be all-encompassing, it also includes a bunch of minor fixes that should get previously failing integration tests passing.

Additionally this PR requires a few minor changes to the internal documentation linked in TPT-3016.

✔️ How to Test

NOTE: You will need to opt into Linode Managed for the managed-related tests to pass. If you would like to subsequently opt-out of Linode Managed, see the description of TPT-3016.

The following test steps assume you have pulled down this PR locally.

Building & Installing the CLI

With the TechDocs OpenAPI Spec

  1. Download the (modified) new OpenAPI spec YAML file to openapi-techdocs.yaml (see TPT-3016's description).
  2. Install the local version of the CLI using the new spec file:
make SPEC=$PWD/openapi-techdocs.yaml install

From here you should be able to run and test arbitrary commands using linode-cli.

With the Legacy (linode-api-docs) OpenAPI Spec

  1. Install the local version of the CLI without specifying the SPEC argument:
make install

From here you should be able to run and test arbitrary commands using linode-cli.

Integration Testing

NOTE: This test command should be run for both versions of the CLI installed above.

make testint

NOTE: The following tests are expected to fail when running against the legacy spec due to bug fixes that were only applied to the TechDocs spec:

  • account/test_account.py::test_user_view

Unit Testing

make testunit

@lgarber-akamai lgarber-akamai added bugfix for any bug fixes in the changelog. improvement for improvements in existing functionality in the changelog. and removed bugfix for any bug fixes in the changelog. labels Jul 2, 2024
@lgarber-akamai lgarber-akamai changed the title fix: Resolve issues blocking CLI/TechDocs OpenAPI spec compatibility new: Resolve issues blocking CLI/TechDocs OpenAPI spec compatibility Jul 2, 2024
@lgarber-akamai lgarber-akamai changed the title new: Resolve issues blocking CLI/TechDocs OpenAPI spec compatibility new: Changes for CLI/TechDocs spec compatibility Jul 2, 2024
Comment on lines +247 to +248
# matches the path of this column
if col == attr.name:
Copy link
Contributor Author

@lgarber-akamai lgarber-akamai Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change to resolve the following from giving an unexpected placement_group.id output:

linode-cli linodes ls --format id

I would consider the previous functionality to technically be broken so I'm thinking this change might be for the best in the long run. If we do end up making this change, we should definitely communicate it through our release notes (and maybe add a warning)?

If anyone else has any ideas definitely let me know 🙂

See: https://github.com/linode/linode-cli/pull/624/files#r1664858657

@@ -244,7 +244,7 @@ def get_user_id():
"--delimiter",
",",
"--format",
"id",
"username",
Copy link
Contributor Author

@lgarber-akamai lgarber-akamai Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test passed at some point because a --format string with an invalid field will give all of the results starting with username. This doesn't seem to be the case anymore so I adjusted it accordingly 👍

Comment on lines 24 to 25
"API Documentation: https://www.linode.com/docs/api/linode-instances/#linodes-list",
"API Documentation: https://www.linode.com/docs/api/linode-instances/#list-linodes",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some minor (but valid) changes to the help pages/descriptions for certain endpoint methods. I updated the tests accordingly to ensure everything will be backwards compatible

@lgarber-akamai lgarber-akamai marked this pull request as ready for review July 3, 2024 21:42
@lgarber-akamai lgarber-akamai requested a review from a team as a code owner July 3, 2024 21:42
@lgarber-akamai lgarber-akamai requested review from jriddle-linode and ezilber-akamai and removed request for a team July 3, 2024 21:42
@@ -34,7 +39,9 @@ def exec_test_command(args: List[str]):
return process


def exec_failing_test_command(args: List[str], expected_code: int = 1):
def exec_failing_test_command(
args: List[str], expected_code: int = ExitCodes.REQUEST_FAILED
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inherited from #625

@@ -73,7 +73,7 @@ def test_create_linode_with_backup_disabled(
"list",
"--id",
linode_id,
"--format=id,enabled",
"--format=id,backups.enabled",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the effect of the breaking change mentioned above

@lgarber-akamai lgarber-akamai force-pushed the fix/cli-new-spec-compat branch from 38abfbb to 630e434 Compare July 5, 2024 14:05
ezilber-akamai

This comment was marked as outdated.

Copy link
Contributor

@ezilber-akamai ezilber-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is working as intended. Nice work!

@lgarber-akamai lgarber-akamai requested review from a team, zliang-akamai, ykim-akamai and yec-akamai and removed request for a team July 5, 2024 17:46
Copy link
Member

@zliang-akamai zliang-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests work well! Just a minor typing suggestion, otherwise looks great!

Co-authored-by: Zhiwei Liang <[email protected]>
@lgarber-akamai lgarber-akamai force-pushed the fix/cli-new-spec-compat branch from 2024ba4 to 1677e08 Compare July 17, 2024 14:06
@lgarber-akamai lgarber-akamai force-pushed the fix/cli-new-spec-compat branch from 1677e08 to 621c928 Compare July 17, 2024 14:09
Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested discovered issues work perfectly now. Great work!

# Matches on pattern [link title](https://.../)
REGEX_MARKDOWN_LINK = re.compile(r"\[(?P<text>.*?)]\((?P<link>.*?)\)")

MARKDOWN_RICH_TRANSLATION = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally trying to use the Rich Markdown renderable but there were a bunch of small issues relating to grouping and styles that heavily complicated things. For the time being this should work 🙂

Comment on lines +49 to +57
description_rich, description = process_arg_description(
schema.description or ""
)

#: The description of this argument for Markdown/plaintext display
self.description = description

#: The description of this argument for display on the help page
self.description_rich = description_rich
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're now baking the rendered descriptions directly into the request for re-use and optimization purposes.

NOTE: The description field is preserved here in preparation for potential docs generation down the road.

def _sub_handler(match: re.Match) -> str:
link = match["link"]
if link.startswith("/"):
link = f"https://linode.com{link}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TechDocs spec does not use relative paths so this is necessary to maintain for backwards compatibility purposes

description, links = extract_markdown_links(result)

if len(links) > 0:
description += f" See: {'; '.join(links)}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Links are now extracted and appended to the end of an argument's description:

--region (required): The region where the Linode will be located. See: https://techdocs.akamai.com/linode-api/reference/get-regions

Previously links were embedded inline after the display text, but this made thing super unreadable with TechDocs due to long the new URLs are.

Copy link
Contributor

@ykim-akamai ykim-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, integration tests and reported issues verified locally. Nice work!

@lgarber-akamai lgarber-akamai merged commit 3be330c into linode:dev Jul 17, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement for improvements in existing functionality in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants