-
Notifications
You must be signed in to change notification settings - Fork 81
python-sdk: Support regions/vpc-availability endpoints #646
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
mgwoj
wants to merge
7
commits into
linode:dev
Choose a base branch
from
mgwoj:feature/TPT-4109-python-sdk-support-regions-vpc-availability-endpoints
base: dev
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
7 commits
Select commit
Hold shift + click to select a range
fc5d5b0
python-sdk: Support regions/vpc-availability endpoints
mgwoj 37ad44e
python-sdk: Support regions/vpc-availability endpoints
mgwoj eb78f05
Merge branch 'dev' into feature/TPT-4109-python-sdk-support-regions-v…
mgwoj 77b40ce
python-sdk: Support regions/vpc-availability endpoints
mgwoj bf632a6
Merge branch 'dev' into feature/TPT-4109-python-sdk-support-regions-v…
mgwoj 9dbab80
python-sdk: Support regions/vpc-availability endpoints
mgwoj fddd785
Merge branch 'dev' into feature/TPT-4109-python-sdk-support-regions-v…
mgwoj 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "region": "us-east", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [52, 48] | ||
| } |
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,132 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "region": "us-east", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [52, 48] | ||
| }, | ||
| { | ||
| "region": "us-west", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [56, 52, 48] | ||
| }, | ||
| { | ||
| "region": "nl-ams", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "us-ord", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "us-iad", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "fr-par", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "us-sea", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "br-gru", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "se-sto", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "es-mad", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "in-maa", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "jp-osa", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "it-mil", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "us-mia", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "id-cgk", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "us-lax", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "gb-lon", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "au-mel", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "in-bom-2", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "de-fra-2", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "sg-sin-2", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "jp-tyo-3", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "fr-par-2", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "ca-central", | ||
| "available": false, | ||
| "available_ipv6_prefix_lengths": [] | ||
| }, | ||
| { | ||
| "region": "ap-southeast", | ||
| "available": false, | ||
| "available_ipv6_prefix_lengths": [] | ||
| } | ||
| ], | ||
| "page": 1, | ||
| "pages": 2, | ||
| "results": 50 | ||
| } |
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,62 @@ | ||
| import pytest | ||
|
|
||
| from linode_api4.objects import Region | ||
|
|
||
|
|
||
| @pytest.mark.smoke | ||
| def test_list_regions_vpc_availability(test_linode_client): | ||
| """ | ||
| Test listing VPC availability for all regions. | ||
| """ | ||
| client = test_linode_client | ||
|
|
||
| vpc_availability = client.regions.vpc_availability() | ||
|
|
||
| assert len(vpc_availability) > 0 | ||
|
|
||
| for entry in vpc_availability: | ||
| assert entry.region is not None | ||
| assert len(entry.region) > 0 | ||
| assert entry.available is not None | ||
| assert isinstance(entry.available, bool) | ||
| # available_ipv6_prefix_lengths may be empty list but should exist | ||
| assert entry.available_ipv6_prefix_lengths is not None | ||
| assert isinstance(entry.available_ipv6_prefix_lengths, list) | ||
|
|
||
|
|
||
| @pytest.mark.smoke | ||
| def test_get_region_vpc_availability_via_object(test_linode_client): | ||
| """ | ||
| Test getting VPC availability via the Region object property. | ||
| """ | ||
| client = test_linode_client | ||
|
|
||
| # Get the first available region | ||
| regions = client.regions() | ||
| assert len(regions) > 0 | ||
| test_region_id = regions[0].id | ||
|
|
||
| region = Region(client, test_region_id) | ||
| vpc_avail = region.vpc_availability | ||
|
|
||
| assert vpc_avail is not None | ||
| assert vpc_avail.region == test_region_id | ||
| assert vpc_avail.available is not None | ||
| assert isinstance(vpc_avail.available, bool) | ||
| assert vpc_avail.available_ipv6_prefix_lengths is not None | ||
| assert isinstance(vpc_avail.available_ipv6_prefix_lengths, list) | ||
|
|
||
|
|
||
| def test_vpc_availability_available_regions(test_linode_client): | ||
| """ | ||
| Test that some regions have VPC availability enabled. | ||
| """ | ||
| client = test_linode_client | ||
|
|
||
| vpc_availability = client.regions.vpc_availability() | ||
|
|
||
| # Filter for regions where VPC is available | ||
| available_regions = [v for v in vpc_availability if v.available] | ||
|
|
||
| # There should be at least some regions with VPC available | ||
| assert len(available_regions) > 0 |
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 |
|---|---|---|
|
|
@@ -25,10 +25,7 @@ def test_list_availability(self): | |
| for entry in avail_entries: | ||
| assert entry.region is not None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intended to remove not None checks? It looks the fields are Optional
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but it is redundant with next check: |
||
| assert len(entry.region) > 0 | ||
|
|
||
| assert entry.plan is not None | ||
| assert len(entry.plan) > 0 | ||
|
|
||
| assert entry.available is not None | ||
|
|
||
| # Ensure all three pages are read | ||
|
|
@@ -49,3 +46,30 @@ def test_list_availability(self): | |
| assert json.loads(call.get("headers").get("X-Filter")) == { | ||
| "+and": [{"region": "us-east"}, {"plan": "premium4096.7"}] | ||
| } | ||
|
|
||
| def test_list_vpc_availability(self): | ||
| """ | ||
| Tests that region VPC availability can be listed. | ||
| """ | ||
|
|
||
| with self.mock_get("/regions/vpc-availability") as m: | ||
| vpc_entries = self.client.regions.vpc_availability() | ||
|
|
||
| assert len(vpc_entries) > 0 | ||
|
|
||
| for entry in vpc_entries: | ||
| assert len(entry.region) > 0 | ||
| assert entry.available is not None | ||
| # available_ipv6_prefix_lengths may be empty list but should exist | ||
| assert entry.available_ipv6_prefix_lengths is not None | ||
|
|
||
| # Ensure both pages are read | ||
| assert m.call_count == 2 | ||
| assert ( | ||
| m.mock.call_args_list[0].args[0] == "//regions/vpc-availability" | ||
| ) | ||
|
|
||
| assert ( | ||
| m.mock.call_args_list[1].args[0] | ||
| == "//regions/vpc-availability?page=2&page_size=25" | ||
| ) | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: vpc_availabilities. Normally we use plural forms to indicate it's an list endpoints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but then it will be inconsistent with the naming of
availabilitymethod