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

Use run_command instead of run_get_output for OSUtil functions #1858

Merged
merged 9 commits into from
Apr 24, 2020

Conversation

larohra
Copy link
Contributor

@larohra larohra commented Apr 18, 2020

Description

Changed the internals of certain OSUtil functions to use shellutil.run_command instead of run_get_output or run() because the former is securer as it doesn't create a new shell during Popen. i.e. shell=False in Popen

Issue #


PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • Except for special cases involving multiple contributors, the PR is started from a fork of the main repository, not a branch.
  • If applicable, the PR references the bug/issue that it fixes in the description.
  • New Unit tests were added for the changes made and Travis.CI is passing.

Quality of Code and Contribution Guidelines

@@ -211,8 +199,8 @@ def del_account(self, username):
:param username:
:return:
"""
shellutil.run("> /var/run/utmp")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This command was just using redirection to create empty files, replaced it with touch command

@codecov
Copy link

codecov bot commented Apr 18, 2020

Codecov Report

Merging #1858 into develop will decrease coverage by 0.02%.
The diff coverage is 24.74%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1858      +/-   ##
===========================================
- Coverage    69.45%   69.43%   -0.03%     
===========================================
  Files           82       82              
  Lines        11469    11481      +12     
  Branches      1619     1610       -9     
===========================================
+ Hits          7966     7972       +6     
- Misses        3166     3171       +5     
- Partials       337      338       +1     
Impacted Files Coverage Δ
azurelinuxagent/common/osutil/freebsd.py 43.35% <0.00%> (+0.67%) ⬆️
azurelinuxagent/common/osutil/nsbsd.py 41.66% <0.00%> (+0.96%) ⬆️
azurelinuxagent/common/osutil/openbsd.py 22.70% <0.00%> (+0.57%) ⬆️
azurelinuxagent/common/osutil/openwrt.py 37.80% <0.00%> (+0.45%) ⬆️
azurelinuxagent/common/osutil/redhat.py 58.44% <0.00%> (ø)
azurelinuxagent/common/osutil/suse.py 65.67% <0.00%> (ø)
azurelinuxagent/common/osutil/gaia.py 27.14% <7.69%> (-2.09%) ⬇️
azurelinuxagent/common/osutil/iosxe.py 42.10% <28.57%> (+0.92%) ⬆️
azurelinuxagent/common/osutil/default.py 59.70% <32.25%> (-0.09%) ⬇️
azurelinuxagent/common/osutil/bigip.py 85.34% <75.00%> (-0.95%) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11d0881...0bd76cf. Read the comment docs.

"/bin/clish -s -c '" + cmd + "'", log_cmd=log_cmd)
if not ret:
try:
final_command = ["/bin/clish", "-s", "-c", "'{0}'".format(cmd)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this command is opening a new shell, we dont need to tokenise the cmd variable.

Eg:

shlex.split("/bin/clish -s -c 'set user admin password-hash *LOCK*'")
['/bin/clish', '-s', '-c', 'set user admin password-hash *LOCK*']

@@ -106,7 +106,7 @@ def chpasswd(self, username, password, crypt_id=6, salt_len=10):
if self.is_sys_user(username):
raise OSUtilError(("User {0} is a system user. "
"Will not set passwd.").format(username))
output = self._run_command_raising_OSUtilError(['echo', '-n', '{0}|encrypt'.format(password)],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

echo -n basically just does not append \n at the end of the string. They were using echo to redirect password to the encrypt command. Passing it through Popen now

pgombar
pgombar previously approved these changes Apr 23, 2020
Copy link
Contributor

@pgombar pgombar left a comment

Choose a reason for hiding this comment

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

LGTM

narrieta
narrieta previously approved these changes Apr 23, 2020
@larohra larohra dismissed stale reviews from narrieta and pgombar via 0bd76cf April 24, 2020 17:38
@anhvoms
Copy link
Collaborator

anhvoms commented Apr 24, 2020

LGTM

@larohra larohra merged commit db86ac4 into Azure:develop Apr 24, 2020
@larohra larohra deleted the remove-partial-run-usage branch September 14, 2020 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants