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 CS module cs_role_permission #37065

Merged
merged 5 commits into from Apr 27, 2018
Merged

new CS module cs_role_permission #37065

merged 5 commits into from Apr 27, 2018

Conversation

dpassante
Copy link
Contributor

SUMMARY

Add a new CloudStack module to manage role permissions.

ISSUE TYPE

New Module Pull Request

COMPONENT NAME

lib/ansible/modules/cloud/cloudstack/cs_role_permission.py

ANSIBLE VERSION
$ ansible --version
ansible 2.6.0 (devel c3ee2188a9) last updated 2018/03/06 12:05:56 (GMT +200)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/dpassante/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /mnt/filer/Github/ansible/lib/ansible
  executable location = /mnt/filer/Github/ansible/bin/ansible
  python version = 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4]
ADDITIONAL INFORMATION
This module is working with Cloudstack 4.11. Some integration tests have been commented out to be compliant with the Cloudstack 4.9.2 integration environment.
Everything seem's to work with Cloudstack 4.9.2 except the dynamic role permission rules update.

@ansibot
Copy link
Contributor

ansibot commented Mar 6, 2018

@ansibot ansibot added cloud cloudstack core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. labels Mar 6, 2018
@@ -413,6 +413,7 @@ lib/ansible/modules/cloud/cloudstack/cs_project.py E325
lib/ansible/modules/cloud/cloudstack/cs_region.py E324
lib/ansible/modules/cloud/cloudstack/cs_resourcelimit.py E324
lib/ansible/modules/cloud/cloudstack/cs_role.py E324
lib/ansible/modules/cloud/cloudstack/cs_role_permission.py E324
Copy link
Contributor

Choose a reason for hiding this comment

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

this is ok for now, I am working on a fix for E324

@resmo resmo self-assigned this Mar 6, 2018
@resmo
Copy link
Contributor

resmo commented Mar 6, 2018

@dpassante thanks for this new module. would you like to join me in maintaining the cloudstack namespace?

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Mar 6, 2018
@dpassante
Copy link
Contributor Author

@resmo Yes! I would be happy to help maintaining this namespace.

@ansibot
Copy link
Contributor

ansibot commented Mar 7, 2018

@dpassante this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibot ansibot added merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html and removed core_review In order to be merged, this PR must follow the core review workflow. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Mar 7, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Mar 7, 2018
@ansibot
Copy link
Contributor

ansibot commented Mar 7, 2018

@DazWorrall @jeffersongirao @marcaurele @netservers

As a maintainer of a module in the same namespace this new module has been submitted to, your vote counts for shipits. Please review this module and add shipit if you would like to see it merged.

click here for bot help

Copy link
Contributor

@resmo resmo left a comment

Choose a reason for hiding this comment

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

Thanks for this. Looks pretty good. Hadn't had the chance to test it (especially the comp with 4.9 issue), can you explain a bit what and how it fails? Any suggestion to make it "not fail" for 4.9?

super(AnsibleCloudStackRolePermission, self).__init__(module)
self.returns = {
'id': 'id',
'roleid': 'roleid',
Copy link
Contributor

Choose a reason for hiding this comment

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

i would prefer role_id here

Copy link
Contributor

Choose a reason for hiding this comment

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

would you mind change this to the following?

'roleid': 'role_id',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry! Done.

@dpassante
Copy link
Contributor Author

The ability to dynamically update permission of existing rules has been introduced in the 4.11 release by this issue.
Cloudstack 4.9 only supports updating rules order.

Trying to update a permission (e.g. from "allow" to "deny") in 4.9 now returns the following as 'ruleorder' argument is required by the 4.9 'updateRolePermission' API method:

TASK [cs_role_permission : test update role permission] *****************************************************************************************************
fatal: [testhost]: FAILED! => {"api_http_method": "get", "api_key": "ClwInp7F5FC0IFNJGGf5u9QlqecLvsK5vhs6sV9jGtYr8JOy_zxAwEUxJ6y_hW4hVUWSkqlAR9hiJfFG_8T2jw", "api_region": "cloudstack", "api_timeout": "60", "api_url": "http://localhost:8888/client/api", "changed": true, "msg": "CloudStackException: ('HTTP 431 response from CloudStack', <Response [431]>, {'uuidList': [], 'errorcode': 431, 'cserrorcode': 9999, 'errortext': 'Unable to execute API command updaterolepermission due to missing parameter ruleorder'})"}

The 'ruleid' / 'permission' couple and 'ruleorder' are mutually exclusive in Cloudstack 4.11.

The options I have in mind to avoid any issue with 4.9 would be:

  • Catch the Cloudstack response and return an error like ‘Updating rule permission is not supported on cs <= 4.11’ for 4.9.
  • Remove the ability to update rule permission and never do any update except if 'parent' argument is passed

On the first case, the behavior of the module would be different depending on the version of Cloudstack but the new 4.11 feature would be supported.
On the second, we would have the choice to return that nothing has been changed or to return an error when 'permission' argument of the playbook doesn't match the actual rule permission.

@dpassante
Copy link
Contributor Author

Another option is to return a 'skipped' result with an explicit message when the permission update fail.
The task doesn't fail and the user is aware that the permission wasn't updated.
The behavior of the module would be something like this: dpassante@d25484e

Or outright replace the existing rule by a new one with the updated permission for Cloudstack versions that don't natively support it ? :)

name: "createVPC"
permission: "deny"

# Updade rules order. move the rule at the top of list
Copy link
Contributor

Choose a reason for hiding this comment

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

typo


if self._get_role_perm():
for _rule in self._get_role_perm():
if rule == _rule['rule'] or rule in _rule['id']:
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be like the following?

if rule == _rule['rule'] or rule == _rule['id']:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it seems to be a more appropriate syntax

'name',
'permission',
]
self.module.fail_on_missing_params(required_params=required_params)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO this check is not required, because name is always required and permission is defaulted to something (not None). Any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I'll remove this check.

description:
- The rule permission, allow or deny. Defaulted to deny.
choices: [ allow, deny ]
required: false
Copy link
Contributor

Choose a reason for hiding this comment

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

not a blocker but required: false is the default, can be omitted in the docs (was needed in the past)

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 27, 2018
@resmo
Copy link
Contributor

resmo commented Apr 27, 2018

Thanks for the update, waiting for the build to finish before merge

@dpassante
Copy link
Contributor Author

@resmo Thanks for review!

@resmo
Copy link
Contributor

resmo commented Apr 27, 2018

;) btw, I think about to update the cloudstack version for integration testing to 4.11 (once 4.11.1 is released) any concerns? Or other preferences?

@dpassante
Copy link
Contributor Author

I think it's a good idea to base integration testing to the latest LTS major release.
The ideal would be to have the 4.11 as default but keeping the ability to run tests on the 4.9.2 to check backward compatibility. But this can already be done by managing docker images manually...

@resmo
Copy link
Contributor

resmo commented Apr 27, 2018

shipit

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed community_review In order to be merged, this PR must follow the community review workflow. labels Apr 27, 2018
@resmo resmo merged commit 200a0bc into ansible:devel Apr 27, 2018
oolongbrothers pushed a commit to oolongbrothers/ansible that referenced this pull request May 12, 2018
oolongbrothers pushed a commit to oolongbrothers/ansible that referenced this pull request May 14, 2018
oolongbrothers pushed a commit to oolongbrothers/ansible that referenced this pull request May 14, 2018
oolongbrothers pushed a commit to oolongbrothers/ansible that referenced this pull request May 15, 2018
oolongbrothers pushed a commit to oolongbrothers/ansible that referenced this pull request May 15, 2018
ilicmilan pushed a commit to ilicmilan/ansible that referenced this pull request Nov 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cloud cloudstack module This issue/PR relates to a module. new_module This PR includes a new module. new_plugin This PR includes a new plugin. shipit This PR is ready to be merged by Core support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants