-
Notifications
You must be signed in to change notification settings - Fork 44
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 a sudo
argument to cli.Client.run
to avoid boilerplate.
#1132
Conversation
592a0d6
to
a5dcf46
Compare
pulp_smash/cli.py
Outdated
which prior to execution checks if user is root and if not | ||
adds ``sudo`` as the first argument of the command. | ||
""" | ||
if args[0] != 'sudo' and not is_root(self.cfg): |
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.
@rochacbruno, thanks for this PR.
I have seen this idiom being used.
sudo = '' if cli.is_root(cls.cfg) else 'sudo '
I have not looked into details your PR, but about the space after sudo like the example above. Did you cover this case as well?
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.
@kersommoura The space there is because the use of .split()
on a string. As run
will accept only a list/tuple it is not a problem, we can replace those calls with just client.sudo
.
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.
@rochacbruno, great.
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.
What if the run
method accepted an optional sudo
flag instead? To me, client.run()
is very intuitive, and so is client.sudo()
but since they both do the same action but with different "permissions", we could have the same result if we were to change the existing method to something like:
client.run(('ls', '-l'), sudo=True)
Thoughts?
As part of our `less boilerplate` effort I added a new method `sudo` argument to `cli.Client.run`. In a lot of test cases there are code like: ```python sudo = () if cli.is_root(cfg) else ('sudo',) ... client.run(sudo + ('command_name', 'argument1', ...)) ``` The idea is to replace the above boilerplate with ```python client.run(('command_name', 'argument1', ...), sudo=True) ``` With this change we will be able to remove the `sudo = () if cli.is_root(cfg) else ('sudo',)` boilerplate in those Pulp-2-tests referenced: ```bash pulp_2_tests/tests/docker/utils.py: sudo = '' if cli.is_root(cfg) else 'sudo' pulp_2_tests/tests/puppet/api_v2/test_install_distributor.py: sudo = () if cli.is_root(self.cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_content_sources.py: sudo = () if cli.is_root(cls.cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_content_sources.py: sudo = () if cli.is_root(cls.cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_content_sources.py: sudo = '' if cli.is_root(cfg) else 'sudo' pulp_2_tests/tests/rpm/api_v2/test_crud.py: sudo = () if cli.is_root(self.cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_download_policies.py: sudo = '' if cli.is_root(cls.cfg) else 'sudo ' pulp_2_tests/tests/rpm/api_v2/test_errata.py: # sudo = () if cli.is_root(cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_errata.py: sudo = () if cli.is_root(cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_export.py: self.__sudo = None pulp_2_tests/tests/rpm/api_v2/test_export.py: self.__sudo = '' if cli.is_root(self.cfg) else 'sudo ' pulp_2_tests/tests/rpm/api_v2/test_iso_sync_publish.py: sudo = () if cli.is_root(self.cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_modularity.py: sudo = () if cli.is_root(cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_republish.py: sudo = () if cli.is_root(self.cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_rich_weak_dependencies.py: sudo = () if cli.is_root(cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_rsync_distributor.py: sudo = () if cli.is_root(cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_rsync_distributor.py: sudo = () if cli.is_root(cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/test_rsync_distributor.py: sudo = '' if cli.is_root(cfg) else 'sudo ' pulp_2_tests/tests/rpm/api_v2/test_service_resiliency.py: sudo = '' if cli.is_root(self.cfg) else 'sudo' pulp_2_tests/tests/rpm/api_v2/test_service_resiliency.py: sudo = () if cli.is_root(self.cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/utils.py: sudo = '' if cli.is_root(cfg) else 'sudo ' pulp_2_tests/tests/rpm/api_v2/utils.py: sudo = '' if cli.is_root(cfg) else 'sudo ' pulp_2_tests/tests/rpm/api_v2/utils.py: sudo = () if cli.is_root(cfg) else ('sudo',) pulp_2_tests/tests/rpm/api_v2/utils.py: sudo = '' if cli.is_root(cfg) else 'sudo ' pulp_2_tests/tests/rpm/api_v2/utils.py: sudo = () if cli.is_root(cfg) else ('sudo',) pulp_2_tests/tests/rpm/cli/test_copy_units.py: sudo = () if cli.is_root(cfg) else ('sudo',) pulp_2_tests/tests/rpm/cli/test_process_recycling.py: sudo = () if cli.is_root(cfg) else ('sudo',) pulp_2_tests/tests/rpm/cli/test_process_recycling.py: sudo = () if cli.is_root(cfg) else ('sudo',) ```
a5dcf46
to
f8a21c3
Compare
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.
ACK
sudo
method to cli.Client
to avoid boilerplate.sudo
argument to cli.Client.run
to avoid boilerplate.
Fix #1037
As part of our
less boilerplate
effort I added a new methodsudo
argumentto
cli.Client.run
.In a lot of test cases there are code like:
The idea is to replace the above boilerplate with
With this change we will be able to remove the
sudo = () if cli.is_root(cfg) else ('sudo',)
boilerplate in 28 Pulp-2-tests references: