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

file.uncomment does not work as expected and documented #2875

Closed
rhertzog opened this issue Dec 12, 2012 · 8 comments
Closed

file.uncomment does not work as expected and documented #2875

rhertzog opened this issue Dec 12, 2012 · 8 comments
Milestone

Comments

@rhertzog
Copy link
Contributor

I have a file /etc/apache2/conf.d/charset which contains:

#AddDefaultCharset UTF-8

I have setup a state to uncomment this:

/etc/apache2/conf.d/charset:
  file.uncomment:
    - regex: AddDefaultCharset UTF-8
    - watch_in:
      - service: apache2
    - require:
      - pkg: apache2

But when run, the state returns back that the file already contains the uncommented line while this is clearly not the case:

    State: - file
    Name:      /etc/apache2/conf.d/charset
    Function:  uncomment
        Result:    True
        Comment:   Pattern already uncommented
        Changes:   

The code only checks that the provided regex matches apparently which doesn't make sense. It should use a more elaborated regex that ensures that the first (non-white) character is not a comment marker.

Then I thought that maybe we were supposed to include a leading ^ that is supposed to get stripped (as documented) but then it's not stripped and the regex fails to find a line to uncomment...

Something is really fishy in the whole logic of this function.

@thatch45
Copy link
Contributor

comment and uncomment have been problem children, we will of course work on this, but I am going to suggest using file.managed

@s0undt3ch
Copy link
Collaborator

@rhertzog could you please provide the output of salt --versions-report?

@rhertzog
Copy link
Contributor Author

@s0undt3ch sure:

$ salt --versions-report
           Salt: 0.10.5
         Python: 2.7.3rc2 (default, Apr 22 2012, 22:30:17)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: not installed
       pycrypto: 2.6
         PyYAML: 3.10
          PyZMQ: 2.2.0

@inthecloud247
Copy link
Contributor

Also experiencing a similar issue:

$ salt --versions-report
           Salt: 0.12.1
         Python: 2.7.3 (default, Aug  1 2012, 05:14:39)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: not installed
       pycrypto: 2.4.1
         PyYAML: 3.10
          PyZMQ: 2.2.0.1

here's the state I created that doesn't work correctly:

cron-logging:
  file.uncomment:
    - name: /etc/rsyslog.d/50-default.conf
    - regex: 'cron\.\*'
    - char: '#'

the beginning of my /etc/rsyslog.d/50-default.conf file:

#  Default rules for rsyslog.
#
#                       For more information see rsyslog.conf(5) and /etc/rsyslog.conf

#
# First some standard log files.  Log by facility.
#
auth,authpriv.*                 /var/log/auth.log
*.*;auth,authpriv.none          -/var/log/syslog
#cron.*                                /var/log/cron.log
#daemon.*                       -/var/log/daemon.log
kern.*                          -/var/log/kern.log
#lpr.*                          -/var/log/lpr.log
mail.*                          -/var/log/mail.log
#user.*                         -/var/log/user.log

result:

    State: - file
    Name:      /etc/rsyslog.d/50-default.conf
    Function:  uncomment
        Result:    True
        Comment:   Pattern already uncommented
        Changes:  

But when I switch to use file.comment, it adds another '#' to the correct line. So it does seem to be identifying the correct line here. It's just not removing the comment marker properly.

@basepi
Copy link
Contributor

basepi commented Mar 11, 2013

This should be fixed by #4015. Can anyone verify? (once it gets merged, of course)

@inthecloud247
Copy link
Contributor

hm are there any functionality tests for the module that could also help verify if it's working as expected?

@basepi
Copy link
Contributor

basepi commented Mar 13, 2013

Yes, there are state tests in place for it. Plus I did my own engineering tests.

@inthecloud247
Copy link
Contributor

cool :-)

On Wed, Mar 13, 2013 at 9:25 AM, Colton Myers notifications@github.comwrote:

Yes, there are state tests in place for it. Plus I did my own engineering
tests.


Reply to this email directly or view it on GitHubhttps://github.com//issues/2875#issuecomment-14851811
.

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

No branches or pull requests

5 participants