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: Support specifying complex list arguments as JSON #578

Merged
merged 9 commits into from
Feb 16, 2024

Conversation

lgarber-akamai
Copy link
Contributor

@lgarber-akamai lgarber-akamai commented Feb 9, 2024

📝 Description

This change adds support for specifying complex lists (e.g. interfaces) as a single JSON string rather than a series of arguments. This should improve the UX when writing scripts that may use these complex structures.

This pull request also makes various changes to generalize parent/child logic rather than explicitly relating it to lists.

This PR originally included improvements to the command help pages but I decided to break it out into a separate PR because of how big this PR was getting 🙂

✔️ How to Test

The following test steps assume you have pulled down this PR and run make install.

Integration Testing

make testint

Unit Testing

make testunit

Manual Testing

Complex Lists as JSON

  1. Attempt to create a Linode with the interfaces argument defined as JSON:
linode-cli linodes create \
  --label test-instance \
  --region us-mia \
  --image linode/alpine3.19 \
  --root_pass 'testp4ssw0rd!!!!!!23123' \
  --type g6-nanode-1 \
  --interfaces '[{"purpose": "public"}, {"purpose": "vlan", "label": "test-vlan"}]' \
  --debug
  1. Ensure the interfaces JSON is properly represented in the debug request body output.
  2. Navigate to the instance in Cloud Manager and ensure it has been configured as expected.

@@ -463,10 +463,54 @@ def _add_args_post_put(self, parser) -> List[Tuple[str, str]]:

return list_items

def _validate_parent_child_conflicts(self, parsed: argparse.Namespace):
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 originally wanted to implement this validation using argparse's mutually exclusive groups but I couldn't get it to play nicely with multiple compatible fields.

Comment on lines +260 to +261
if v is None:
continue
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 isn't specific to this change but should address some weird errors I was running into.

extensions.append("nullable")

if arg.is_parent:
extensions.append("conflicts with children")
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 don't know if I like the wording here, any suggestions would be much appreciated!

@lgarber-akamai lgarber-akamai marked this pull request as ready for review February 9, 2024 20:31
@lgarber-akamai lgarber-akamai requested a review from a team as a code owner February 9, 2024 20:31
@lgarber-akamai lgarber-akamai requested review from zliang-akamai and yec-akamai and removed request for a team February 9, 2024 20:31
@lgarber-akamai lgarber-akamai added enhancement issues that request a enhancement and removed DO NOT MERGE labels Feb 14, 2024
@zliang-akamai
Copy link
Member

I noticed that a VLAN is used in the interfaces of the instance creation command so VPC creation in step 1 is probably not necessary?

@lgarber-akamai
Copy link
Contributor Author

I noticed that a VLAN is used in the interfaces of the instance creation command so VPC creation in step 1 is probably not necessary?

Oops, you're right. I think I copied it from another PR description and forgot to remove it lol

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.

LGTM. Unit test and manual test passed locally!

However, I'm seeing a couple of similar errors when running the integration tests around put operations, i.e.

>       exec_test_command(BASE_CMD + ["put", str(file_path), bucket_name])

This failed when assert the process.retruncode:

>       assert process.returncode == 0

Not sure if it's related to this PR or a interim issue, but as a heads up. I'm looking into it as well.

@lgarber-akamai
Copy link
Contributor Author

LGTM. Unit test and manual test passed locally!

However, I'm seeing a couple of similar errors when running the integration tests around put operations, i.e.

>       exec_test_command(BASE_CMD + ["put", str(file_path), bucket_name])

This failed when assert the process.retruncode:

>       assert process.returncode == 0

Not sure if it's related to this PR or a interim issue, but as a heads up. I'm looking into it as well.

Nice find, I'll look into this as well!

@zliang-akamai zliang-akamai added new-feature for new features in the changelog. and removed enhancement issues that request a enhancement labels Feb 16, 2024
@zliang-akamai
Copy link
Member

zliang-akamai commented Feb 16, 2024

Firewall tests are failing on my end..
image
Are you able to reproduce it?

@lgarber-akamai
Copy link
Contributor Author

@zliang-akamai Looks like they're failing on my end too, I'll take a quick look

@lgarber-akamai
Copy link
Contributor Author

lgarber-akamai commented Feb 16, 2024

So it looks like supporting dicts as JSON introduces some weird multi-parent conflicts with commands that nest complex lists in dicts (e.g. Firewalls). Given the main use-case of this feature is to reduce complexity when specifying complex lists of objects, I'll remove dicts as JSON from the scope of this PR 👍

@lgarber-akamai lgarber-akamai changed the title new: Support specifying nested structures as JSON new: Support specifying complex list arguments as JSON Feb 16, 2024
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.

Integration test passed! Nice work 🎉

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.

Tested locally. Nice work!

@lgarber-akamai lgarber-akamai merged commit cef8240 into linode:dev Feb 16, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature for new features in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants