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

Add support for *List kinds #213

Merged
merged 7 commits into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finish updating tests + fixing bugs
  • Loading branch information
fabianvf committed Oct 1, 2018
commit ef98ee7e8755355160f938d2044b06a39f5e5744
7 changes: 3 additions & 4 deletions openshift/dynamic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'DynamicClient',
'ResourceInstance',
'Resource',
'ResourceList',
'Subresource',
'ResourceContainer',
'ResourceField',
Expand Down Expand Up @@ -305,7 +306,6 @@ def __init__(self, prefix=None, group=None, api_version=None, kind=None,
if None in (api_version, kind, prefix):
raise ValueError("At least prefix, kind, and api_version must be provided")

self.list_type = False
self.prefix = prefix
self.group = group
self.api_version = api_version
Expand Down Expand Up @@ -367,15 +367,14 @@ class ResourceList(Resource):

def __init__(self, resource):
self.resource = resource
self.list_type = True
self.kind = '{}List'.format(resource.kind)

def get(self, body=None, **kwargs):
if body is None:
return self.resource.get(**kwargs)
namespace = kwargs.pop('namespace', None)
return [
self.resource.get(name=item['name'], namespace=item.get('namespace', namespace), **kwargs)
self.resource.get(name=item['metadata']['name'], namespace=item['metadata'].get('namespace', namespace), **kwargs)
for item in body['items']
]

Expand Down Expand Up @@ -619,7 +618,7 @@ def main():
key = '{}.{}'.format(resource.group_version, resource.kind)
item = {}
item[key] = {k: v for k, v in resource.__dict__.items() if k not in ('client', 'subresources', 'resource')}
if resource.list_type:
if isinstance(resource, ResourceList):
item[key]["resource"] = '{}.{}'.format(resource.resource.group_version, resource.resource.kind)
else:
item[key]['subresources'] = {}
Expand Down
227 changes: 137 additions & 90 deletions test/functional/dynamic/conftest.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/functional/dynamic/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Create
Given I have edit permissions in <namespace>
And The content of <filename> does not exist in <namespace>
When I create <filename> in <namespace>
Then The contents of <filename> exists in <namespace>
Then The content of <filename> exists in <namespace>

Scenario Outline: Create a resource again
Given I have edit permissions in <namespace>
Expand Down
2 changes: 2 additions & 0 deletions test/functional/dynamic/definitions/v1_Pod_test_patch.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
metadata:
name: test
spec:
containers:
- image: busybox:1
Expand Down
15 changes: 8 additions & 7 deletions test/functional/dynamic/delete.feature
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
Feature: Delete

Examples:
| group_version | kind | namespace | name |
| v1 | Pod | test | test |
| filename | namespace |
| definitions/v1_Pod_test.yaml | test |
| definitions/v1_PodList_test.yaml | test2 |

Scenario Outline: Delete a resource that exists
Given I have edit permissions in <namespace>
And <group_version>.<kind> <name> exists in <namespace>
When I delete <group_version>.<kind> <name> in <namespace>
Then <group_version>.<kind> <name> does not exist in <namespace>
And The content of <filename> exists in <namespace>
When I delete <filename> in <namespace>
Then The content of <filename> does not exist in <namespace>

Scenario Outline: Delete a resource that does not exist
Given I have edit permissions in <namespace>
And <group_version>.<kind> <name> does not exist in <namespace>
When I try to delete <group_version>.<kind> <name> in <namespace>
And The content of <filename> does not exist in <namespace>
When I try to delete <filename> in <namespace>
Then It throws a NotFoundError
14 changes: 7 additions & 7 deletions test/functional/dynamic/patch.feature
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Feature: Patch

Examples:
| group_version | kind | namespace | name | update |
| v1 | Pod | test-patch | test | test_patch |
| filename | namespace | update |
| definitions/v1_Pod_test.yaml | test | definitions/v1_Pod_test_patch.yaml |

Scenario Outline: Patch a resource that does not exist
Given I have edit permissions in <namespace>
And <group_version>.<kind> <name> does not exist in <namespace>
When I try to patch <group_version>.<kind> <name> in <namespace> with <update>
And The content of <filename> does not exist in <namespace>
When I try to patch <filename> with <update> in <namespace>
Then It throws a NotFoundError

Scenario Outline: Patch a resource that exists
Given I have edit permissions in <namespace>
And I have created <group_version>.<kind> <name> in <namespace>
When I patch <group_version>.<kind> <name> in <namespace> with <update>
Then <group_version>.<kind> <name> in <namespace> should match the content of <update>
And I have created <filename> in <namespace>
When I patch <filename> with <update> in <namespace>
Then The resources in <filename> in <namespace> should match the content of <update>
14 changes: 7 additions & 7 deletions test/functional/dynamic/replace.feature
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Feature: Replace

Examples:
| group_version | kind | namespace | name | update |
| route.openshift.io/v1 | Route | test-replace | test | test_replace |
| filename | namespace | update |
| definitions/route.openshift.io_v1_Route_test.yaml | test-replace |definitions/route.openshift.io_v1_Route_test_replace.yaml |

Scenario Outline: Replace a resource that does not exist
Given I have edit permissions in <namespace>
And <group_version>.<kind> <name> does not exist in <namespace>
When I try to replace <group_version>.<kind> <name> in <namespace> with <update>
And The content of <filename> does not exist in <namespace>
When I try to replace <filename> with <update> in <namespace>
Then It throws a NotFoundError

Scenario Outline: Replace a resource that exists
Given I have edit permissions in <namespace>
And I have created <group_version>.<kind> <name> in <namespace>
When I replace <group_version>.<kind> <name> in <namespace> with <update>
Then <group_version>.<kind> <name> in <namespace> should match the content of <update>
And I have created <filename> in <namespace>
When I replace <filename> with <update> in <namespace>
Then The resources in <filename> in <namespace> should match the content of <update>