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

ini_manage.options_absent: files are rewritten with modified content, when returning no changes #33789

Closed
morganwillcock opened this issue Jun 6, 2016 · 3 comments
Labels
Bug broken, incorrect, or confusing behavior P4 Priority 4 Platform Relates to OS, containers, platform-based utilities like FS, system based apps severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around stale State-Module Windows
Milestone

Comments

@morganwillcock
Copy link
Contributor

ini_manage.options_absent is rewriting the files it's checking and reporting no changes. I would have expected that checking the file would only read it (and I guess there is an argument for re-writing to a consistent format - maybe the ini states need a reformat flag?) but the rewrite results are giving inconsistent line endings on Windows. Here is a test case, where I've already applied the fix for #33590.

{% if grains['os'] == 'Windows' %}
  {% set test_file = 'C:\\test.txt' %}
{% else %}
  {% set test_file = '/test' %}
{% endif %}

write_ini_file:
  file.managed:
    - name: '{{ test_file }}'
    - contents: |
        [Section1]
        a=1
        b=2
        [Section2]
        c=3
        d=4
        [Section3]
        e=5
        f=6

cleanup_ini_file:
  ini.options_absent:
    - name: '{{ test_file }}'
    - sections:
        Section4:
          - g
          - h

this_should_not_do_anything:
  file.managed:
    - name: '{{ test_file }}'
    - contents: |
        [Section1]
        a=1
        b=2
        [Section2]
        c=3
        d=4
        [Section3]
        e=5
        f=6

salt salt-test state.apply

salt-test:
----------
          ID: write_ini_file
    Function: file.managed
        Name: C:\test.txt
      Result: True
     Comment: File C:\test.txt updated
     Started: 10:59:04.475000
    Duration: 43.0 ms
     Changes:   
              ----------
              diff:
                  New file
----------
          ID: cleanup_ini_file
    Function: ini.options_absent
        Name: C:\test.txt
      Result: True
     Comment: No anomaly detected
     Started: 10:59:06.501000
    Duration: 15.0 ms
     Changes:   
----------
          ID: this_should_not_do_anything
    Function: file.managed
        Name: C:\test.txt
      Result: True
     Comment: File C:\test.txt updated
     Started: 10:59:06.518000
    Duration: 28.0 ms
     Changes:   
              ----------
              diff:
                  --- 
                  +++ 
                  @@ -1,12 +1,9 @@
                  -
                  -[Section1]
                  -a = 1
                  -b = 2
                  -
                  -[Section2]
                  -c = 3
                  -d = 4
                  -
                  -[Section3]
                  -e = 5
                  -f = 6
                  +[Section1]
                  +a=1
                  +b=2
                  +[Section2]
                  +c=3
                  +d=4
                  +[Section3]
                  +e=5
                  +f=6

Summary for salt-test
------------
Succeeded: 3 (changed=2)
Failed:    0
------------
Total states run:     3

On Linux, at least the rewrite is consistent:

[Section1]
a = 1
b = 2

[Section2]
c = 3
d = 4

[Section3]
e = 5
f = 6

...but on Windows the line endings have been mixed up:

[Section1]a = 1
b = 2
[Section2]c = 3
d = 4
[Section3]e = 5
f = 6

Tested on 2016.3.0

@Ch3LL
Copy link
Contributor

Ch3LL commented Jun 7, 2016

@morganwillcock i am able to replicate this behavior except for the line endings being mixed up, although I am running off of a clean 2016.3.0 without that patch. If you remove that patch are you still seeing the line endings being mixed up?

Also i'm wondering if the issue is related to #33669 at all because it looks like it is adding whitespace, although it shouldn't be replacing the file. Thanks.

@Ch3LL Ch3LL added Bug broken, incorrect, or confusing behavior P4 Priority 4 State-Module severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around Platform Relates to OS, containers, platform-based utilities like FS, system based apps Windows labels Jun 7, 2016
@Ch3LL Ch3LL added this to the Approved milestone Jun 7, 2016
@morganwillcock
Copy link
Contributor Author

@Ch3LL I've re-tested without the patch and I still get the same result. I'm checking it in Notepad, but doing a hexdump also shows the differences in the line endings:

hexdump -C test.txt

00000000  0a 5b 53 65 63 74 69 6f  6e 31 5d 0a 61 20 3d 20  |.[Section1].a = |
00000010  31 0d 0a 62 20 3d 20 32  0d 0a 0a 5b 53 65 63 74  |1..b = 2...[Sect|
00000020  69 6f 6e 32 5d 0a 63 20  3d 20 33 0d 0a 64 20 3d  |ion2].c = 3..d =|
00000030  20 34 0d 0a 0a 5b 53 65  63 74 69 6f 6e 33 5d 0a  | 4...[Section3].|
00000040  65 20 3d 20 35 0d 0a 66  20 3d 20 36 0d 0a        |e = 5..f = 6..|
0000004e

Sections have been rewritten just using line feeds (0a), whereas the options themselves still have a carriage return and a line feed (0d0a).

@stale
Copy link

stale bot commented May 19, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label May 19, 2018
@stale stale bot closed this as completed May 26, 2018
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 P4 Priority 4 Platform Relates to OS, containers, platform-based utilities like FS, system based apps severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around stale State-Module Windows
Projects
None yet
Development

No branches or pull requests

2 participants