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

[BUG] state file.patch pretend to apply malformed patch #59805

Closed
msciciel opened this issue Mar 15, 2021 · 2 comments · Fixed by #59806
Closed

[BUG] state file.patch pretend to apply malformed patch #59805

msciciel opened this issue Mar 15, 2021 · 2 comments · Fixed by #59806
Labels
Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@msciciel
Copy link
Contributor

Description
If patch file provided for file.patch state is malformed then state returns Patch was already applied but patch is not applied.

          ID: patch_example
    Function: file.patch
        Name: /tmp/example
      Result: True
     Comment: Patch was already applied
     Started: 12:20:50.953163
    Duration: 61.558 ms
     Changes:

Setup
/srv/salt/example.sls:

patch_example:
  file.patch:
    - name: /tmp/example
    - source: salt://example.patch

/srv/salt/example.patch:

--- /tmp/example        2021-03-15 12:20:20.698463273 +0000
+++ /tmp/example.new    2021-03-15 12:01:26.620433384 +0000
@@ -172,6 +172,7 @@ malformed patch
+EXAMPLE PATCH
+EXAMPLE PATCH
+EXAMPLE PATCH
+EXAMPLE PATCH
[root@1566f989189e ~]# cat /tmp/example
EXAMPLE FILE TO PATCH

/tmp/example

EXAMPLE FILE TO PATCH

Steps to Reproduce the behavior

yum install -y patch
salt-call --local state.sls example -l debug

[DEBUG   ] file.managed: {'changes': {'diff': '--- \n+++ \n@@ -0,0 +1,4 @@\n+--- /tmp/example\t2021-03-15 12:20:20.698463273 +0000\n++++ /tmp/example.new\t2021-03-15 12:01:26.620433384 +0000\n+@@ -172,6 +172,19 @@ malformed patch\n++EXAMPLE PATCH\n'}, 'comment': 'File /tmp/__salt.tmp.vkktza9o updated', 'name': '/tmp/__salt.tmp.vkktza9o', 'result': True}
[DEBUG   ] LazyLoaded cmd.run_all
[INFO    ] Executing command /usr/bin/patch in directory '/root'
[ERROR   ] Command '/usr/bin/patch' failed with return code: 2
[ERROR   ] stdout: patching file /tmp/__salt.tmp.pj5ysvms (read from /tmp/example)
[ERROR   ] stderr: /usr/bin/patch: **** unexpected end of file in patch
[ERROR   ] retcode: 2
[INFO    ] Executing command /usr/bin/patch in directory '/root'
[INFO    ] Patch was already applied

Expected behavior
It would be nice to return error when patch is malformed and can not be applied:

          ID: patch_example
    Function: file.patch
        Name: /tmp/example
      Result: False
     Comment: /usr/bin/patch: **** malformed patch at line 7:
     Started: 12:33:44.915605
    Duration: 59.202 ms
     Changes:

Versions Report

salt --versions-report
Salt Version:
          Salt: 3002.5

Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.6.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: 0.35.2
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: Not Installed
        pygit2: Not Installed
        Python: 3.6.8 (default, Aug 24 2020, 17:57:11)
  python-gnupg: Not Installed
        PyYAML: 3.12
         PyZMQ: 19.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: centos 8
        locale: UTF-8
       machine: x86_64
       release: 3.10.0-1160.15.2.el7.x86_64
        system: Linux
       version: CentOS Linux 8

Additional context
Add any other context about the problem here.

@msciciel
Copy link
Contributor Author

If proposed solution is acceptable I will fulfill requirements for the pull request.

@danielrobbins
Copy link

@msciciel Thank your for your PR. I have reviewed it, and added a comment with suggested minor changes. If these changes look good to you, please submit an updated PR and I will then support having this fix added to salt.

@danielrobbins danielrobbins assigned danielrobbins and unassigned dwoz Apr 19, 2021
@sagetherage sagetherage added this to the Approved milestone Apr 20, 2021
@sagetherage sagetherage added the severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around label Apr 20, 2021
@sagetherage sagetherage removed their assignment Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants