fix quoting in list representation of commands#1510
Conversation
Removed redundant quotes included due to incorrect handling of command conversion to string representation in leapp framework's reporting module. The reporting module is fixed by RHEL-156521 and this patch is a followup that fixes usage of the module so that the commands are propagated to the leapp-report.txt correctly. Jira: RHEL-155517, RHEL-155515
Thank you for contributing to the Leapp project!Please note that every PR needs to comply with the leapp-repository contribution and development guidelines and must pass all tests in order to be mergeable.
Packit will automatically schedule regression tests for this PR's build and latest upstream leapp build.
Note that first time contributors cannot run tests automatically - they need to be started by a reviewer. It is possible to schedule specific on-demand tests as well. Currently 2 test sets are supported,
See other labels for particular jobs defined in the Please open ticket in case you experience technical problem with the CI. (RH internal only) Note: In case there are problems with tests not being triggered automatically on new PR/commit or pending for a long time, please contact leapp-infra. |
| command = ' '.join(['ln', | ||
| '-snf', | ||
| os.path.relpath(item.target, '/'), | ||
| os.path.join('/', item.name)]) | ||
| f"'{os.path.relpath(item.target, '/')}'", | ||
| f"'{os.path.join('/', item.name)}'"]) | ||
| commands.append(command) | ||
| rem_commands = [['sh', '-c', '"{}"'.format(' && '.join(commands))]] | ||
| rem_commands = [['bash', '-c', '{}'.format(' && '.join(commands))]] |
There was a problem hiding this comment.
This is a problematic place, the quoting in the leapp framework will only reach the top level. The commands in the subshell are on the developer to handle. Here, I've wrapped the paths in ', this works in most of the cases but as soon sa the path contains a ' the command won't work.
This could be handled by simply calling shlex.quote, but that reaches the same problem with ugly quoting as described in the framework PR - there is also a custom quoting function proposed in the PR. So after we decide what we want to use, I'll replace the ' here with shlex or the custom function.
There was a problem hiding this comment.
@PeterMocary actually, this one will be broken in the current state for several possible symlinks. see this:
Remediation: [command] bash -c "ln -snf 'usr/sbin' '/sbin' && ln -snf 'usr/lib' '/lib' && ln -snf 'usr/lib64' '/lib64' && ln -snf 'usr/sbin' '/mi'amiga' && ln -snf 'usr/sbin' '/miqu\"oloool' && ln -snf 'usr/sbin' '/mark \!mark'"
(the one with single quote ' and !)
But as I merged already the leapp framework PR, we are now anyway in broken state even if we do not merge this change. Merging the PR will fix more issues actually and we will focus on corner-cases in a follow up.
|
I searched for the places that might be affected by the changes in leapp framework, hopefully catching everything. After we decide what to use in framework, I'll update the changes that depend on the decision. |
| remediation_commands = [ | ||
| f"sed -i 's/^plugins=0/plugins=1/' '{dnf_conf_path}'" | ||
| f"sed -i 's/^enabled=0/enabled=1/' '{rhsm_plugin_conf}'" | ||
| f"sed -i 's/^enabled=0/enabled=1/' '{product_id_plugin_conf}'" | ||
| ] | ||
|
|
||
| reporting.create_report([ | ||
| reporting.Title('Required DNF plugins are not being loaded.'), | ||
| reporting.Summary( | ||
| 'The following DNF plugins are not being loaded: {}'.format(missing_required_plugins_text) | ||
| ), | ||
| reporting.Remediation( | ||
| hint=( | ||
| 'If you have DNF plugins globally disabled, please enable them by editing the {0}. ' | ||
| 'Individually, the DNF plugins can be enabled in their corresponding configurations found at: {1}' | ||
| .format(dnf_conf_path, plugin_configs_dir) | ||
| ), | ||
| # Provide all commands as one due to problems with satellites | ||
| commands=[['bash', '-c', '"{0}"'.format('; '.join(remediation_commands))]] | ||
| commands=[['bash', '-c', '{0}'.format('; '.join(remediation_commands))]] |
There was a problem hiding this comment.
Here is a mention of satellite problems, not sure what is meant by it. The command could be split, but works ok as is. However, it has to be changed if we decide to use shlex.quote only without the custom change that handles ' escaping in a pretty way. See the framework PR.
Update: since we are moving forward with the double quoting when there is ' in the string, this will work as is namely thanks to the known paths and no special characters in the sed commands.
pirat89
left a comment
There was a problem hiding this comment.
missing updated spec file. without the update framework the solution is broken.
d74b5aa to
5d99386
Compare
|
Fixed unit tests and updated spec file to require the updated leapp framework. |
5d99386 to
9a5e0ef
Compare
|
/packit copr-build |
|
/packit copr-build |
pirat89
left a comment
There was a problem hiding this comment.
there are actually still some broken commands (at least one) but merging this PR will fix more problems at this moment than causing if we do not merge it. So merging and we will track the corner cases in a followup PR.
| command = ' '.join(['ln', | ||
| '-snf', | ||
| os.path.relpath(item.target, '/'), | ||
| os.path.join('/', item.name)]) | ||
| f"'{os.path.relpath(item.target, '/')}'", | ||
| f"'{os.path.join('/', item.name)}'"]) | ||
| commands.append(command) | ||
| rem_commands = [['sh', '-c', '"{}"'.format(' && '.join(commands))]] | ||
| rem_commands = [['bash', '-c', '{}'.format(' && '.join(commands))]] |
There was a problem hiding this comment.
@PeterMocary actually, this one will be broken in the current state for several possible symlinks. see this:
Remediation: [command] bash -c "ln -snf 'usr/sbin' '/sbin' && ln -snf 'usr/lib' '/lib' && ln -snf 'usr/lib64' '/lib64' && ln -snf 'usr/sbin' '/mi'amiga' && ln -snf 'usr/sbin' '/miqu\"oloool' && ln -snf 'usr/sbin' '/mark \!mark'"
(the one with single quote ' and !)
But as I merged already the leapp framework PR, we are now anyway in broken state even if we do not merge this change. Merging the PR will fix more issues actually and we will focus on corner-cases in a follow up.
Removed redundant quotes included due to incorrect handling of command conversion to string representation in leapp framework's reporting module. The reporting module is fixed by RHEL-156521 and this patch is a followup that fixes usage of the module so that the commands are propagated to the leapp-report.txt correctly.
Note: This depends on the reporting module change in the leapp framework: oamg/leapp#919. For a better description of the problem see the RHEL-156521 and the framework PR description.
Example with both leapp and leapp-repository PRs
leapp-report.txt
leapp-report.json
Both have correct equivalent representation of the command.
Jira: RHEL-155517, RHEL-155515