-
Notifications
You must be signed in to change notification settings - Fork 37
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
Added keyword for role create and delete #97
Open
rohini-nubolab
wants to merge
50
commits into
devopsspiral:master
Choose a base branch
from
rohini-nubolab:master
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
50 commits
Select commit
Hold shift + click to select a range
419d410
Added keyword for create and delete role
rohini-nubolab 8a336d3
Added index.html
rohini-nubolab e6af6c2
Added role binding
rohini-nubolab 60f27dd
Update role_kw.robot
rohini-nubolab e7cb010
Update .coveragerc
rohini-nubolab fde6cc0
Update role_kw.robot
rohini-nubolab b50a0d9
Merge branch 'master' into master
rohini-nubolab 5f1a50a
Added keywords
rohini-nubolab 289031e
Update KubeLibrary.py
rohini-nubolab 1103cc0
Update KubeLibrary.py
rohini-nubolab bc10f48
Update KubeLibrary.py
rohini-nubolab e95df5a
Update KubeLibrary.py
rohini-nubolab 5cc49d7
Update configmap.robot
rohini-nubolab 4f0e2fc
Update cronjob.robot
rohini-nubolab 8398a0d
Update daemonsets.robot
rohini-nubolab 066dd58
Update configmap_kw.robot
rohini-nubolab dee5c0a
Update cronjob_kw.robot
rohini-nubolab 6de8dc3
Update daemonsets_kw.robot
rohini-nubolab 09f9a53
Update deployment_kw.robot
rohini-nubolab 0e95f7d
Update ingress.robot
rohini-nubolab 659f022
Update ingress_kw.robot
rohini-nubolab 7066d87
Update ingress_kw.robot
rohini-nubolab 50c75f9
Update pod.robot
rohini-nubolab 3738af8
Update pod_kw.robot
rohini-nubolab af4511e
Update pvc.robot
rohini-nubolab 6e22d3b
Update pvc_kw.robot
rohini-nubolab 00fc6e3
Update replicaset.robot
rohini-nubolab cbd3868
Update replicaset_kw.robot
rohini-nubolab ee9b1bd
Update role.robot
rohini-nubolab 1d18007
Update role.robot
rohini-nubolab b4e9f2c
Update role_kw.robot
rohini-nubolab d67af0d
Update secret.robot
rohini-nubolab bbdc9ea
Update secret_kw.robot
rohini-nubolab 5861191
Update service.robot
rohini-nubolab 820a84e
Update service_kw.robot
rohini-nubolab 391dd35
Update service_account.robot
rohini-nubolab 3ae1bc4
Update service_account_kw.robot
rohini-nubolab 561459c
Update deployment.robot
rohini-nubolab 3dfee0a
added unittest for role create and delete
rohini-nubolab faa2e13
Update test_KubeLibrary.py
rohini-nubolab c3af1d6
Update test_KubeLibrary.py
rohini-nubolab f1e358f
Update test_KubeLibrary.py
rohini-nubolab babe32c
Update test_KubeLibrary.py
rohini-nubolab 607a82e
Update test_KubeLibrary.py
rohini-nubolab 208da09
Update test_KubeLibrary.py
rohini-nubolab c040059
Update test_KubeLibrary.py
rohini-nubolab a69b83c
Update test_KubeLibrary.py
rohini-nubolab 4545100
Update .coveragerc
rohini-nubolab bfc588b
Update role_kw.robot
rohini-nubolab 1c07727
Update KubeLibrary.py
rohini-nubolab 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
|
@@ -233,6 +233,22 @@ def mock_list_namespaced_role_bindings(namespace, watch=False): | |
return list_of_role_bind | ||
|
||
|
||
def mock_delete_role_in_namespace(name, namespace): | ||
if namespace == 'default': | ||
with open('test/resources/role.json') as json_file: | ||
role_details_content = json.load(json_file) | ||
role_details = AttributeDict({'items': role_details_content}) | ||
return role_details | ||
|
||
|
||
def mock_create_role_in_namespace(namespace, body): | ||
if namespace == 'default': | ||
with open('test/resources/role.json') as json_file: | ||
role_details_content = json.load(json_file) | ||
read_role_details = AttributeDict({'items': role_details_content}) | ||
return read_role_details | ||
|
||
|
||
bearer_token = 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjdXVWJMOUdTaDB1TjcyNmF0Sjk4RWlzQ05RaWdSUFoyN004TmlGT1pSX28ifQ.' \ | ||
'eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1' \ | ||
'lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6Im15c2EtdG' \ | ||
|
@@ -678,3 +694,53 @@ def test_get_cron_job_details_in_namespace(self, mock_lnp): | |
kl = KubeLibrary(kube_config='test/resources/k3d') | ||
cron_job_details = kl.get_cron_job_details_in_namespace('hello', 'default') | ||
self.assertEqual('mytestlabel', cron_job_details.items.metadata.labels.TestLabel) | ||
|
||
@mock.patch('kubernetes.client.RbacAuthorizationV1Api.delete_namespaced_role') | ||
def test_delete_role_in_namespace(self, mock_lnp): | ||
mock_lnp.side_effect = mock_delete_role_in_namespace | ||
kl = KubeLibrary(kube_config='test/resources/k3d') | ||
role_list = kl.delete_role_in_namespace('pod-reader', 'default') | ||
self.assertEqual(['pod-reader'], [item.metadata.name for item in role_list.items]) | ||
|
||
@mock.patch('kubernetes.client.RbacAuthorizationV1Api.create_namespaced_role') | ||
def test_create_role_in_namespace(self, mock_lnp): | ||
mock_lnp.side_effect = mock_create_role_in_namespace | ||
kl = KubeLibrary(kube_config='test/resources/k3d') | ||
name = 'pod-reader' | ||
role_manifest = { | ||
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. I believe this test has no value, we are not testing anything as everything is mocked. One thing that might be useful is testing handling situation when role is already created with some meaningful output. |
||
"apiVersion": "rbac.authorization.k8s.io/v1", | ||
"kind": "Role", | ||
"metadata": { | ||
"creationTimestamp": "2021-03-10T04:54:29Z", | ||
"managedFields": [ | ||
{ | ||
"apiVersion": "rbac.authorization.k8s.io/v1", | ||
"fieldsType": "FieldsV1", | ||
"fieldsV1": { | ||
"f:rules": {} | ||
}, | ||
"manager": "kubectl", | ||
"operation": "Update", | ||
"time": "2021-03-10T04:54:29Z" | ||
} | ||
], | ||
"name": name | ||
}, | ||
"rules": [ | ||
{ | ||
"apiGroups": [ | ||
"" | ||
], | ||
"resources": [ | ||
"pods" | ||
], | ||
"verbs": [ | ||
"get", | ||
"watch", | ||
"list" | ||
] | ||
} | ||
] | ||
} | ||
role_details = kl.create_role_in_namespace('default', role_manifest) | ||
self.assertEqual(['pod-reader'], [item.metadata.name for item in role_details.items]) |
This file contains 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 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 |
---|---|---|
|
@@ -30,5 +30,3 @@ Log key value pairs | |
FOR ${key} ${value} IN &{configmap_data} | ||
Log ${key} = ${value} console=True | ||
END | ||
|
||
|
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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.
You could test handling situation when there is no role to remove. Other than that the mocked response is wrong because as I understand it will return V1 status.