saltstack / saltstack/salt

Prepend with header not working in test=True

Open
#51,320 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description of Issue/Question
Setup

Ubuntu 18.04, Salt 2018.3.3

Steps to Reproduce Issue
  • Write a state prepending some text to a file with the header parameter set to true.
  • Apply the state once
  • Try to reapply in test=True => it shows changes
  • remove test=True => it doesn't change anything

Example state :

Create file:
  file.exists:
    - name: /etc/testing-prepend

Add nice header:
  file.prepend:
    - name: /etc/testing-prepend
    - header: True
    - text: |
          ################################
          ##### THIS IS A NICE HEADER ####
          ################################
    - require:
      - file: Create file

Example output :

# salt-call state.apply test-prepend-header --state-output=changes
local:
----------
          ID: Create file
    Function: file.exist
        Name: /etc/testing-prepend
      Result: True
     Comment: Created empty file /etc/testing-prepend
     Started: 22:05:48.401595
    Duration: 5.676 ms
     Changes:   
              ----------
              new:
                  /etc/testing-prepend
----------
          ID: Add nice header
    Function: file.prepend
        Name: /etc/testing-prepend
      Result: True
     Comment: Prepended 3 lines
     Started: 22:05:48.407609
    Duration: 1.909 ms
     Changes:   
              ----------
              diff:
                  --- 
                  +++ 
                  @@ -0,0 +1,3 @@
                  +################################
                  +##### THIS IS A NICE HEADER ####
                  +################################

Summary for local
------------
Succeeded: 2 (changed=2)
Failed:    0
------------
Total states run:     2
Total run time:   7.585 ms
# cat /etc/testing-prepend 
################################
##### THIS IS A NICE HEADER ####
################################
# salt-call state.apply test-prepend-header --state-output=changes test=True
local:
  Name: /etc/testing-prepend - Function: file.exists - Result: Clean Started: - 22:12:03.129254 Duration: 0.43 ms
----------
          ID: Add nice header
    Function: file.prepend
        Name: /etc/testing-prepend
      Result: None
     Comment: File /etc/testing-prepend is set to be updated
     Started: 22:12:03.130029
    Duration: 1.858 ms
     Changes:   
              ----------
              diff:
                  --- 
                  +++ 
                  @@ -1,3 +1,6 @@
                   ################################
                   ##### THIS IS A NICE HEADER ####
                   ################################
                  +################################
                  +##### THIS IS A NICE HEADER ####
                  +################################

Summary for local
------------
Succeeded: 2 (unchanged=1, changed=1)
Failed:    0
------------
Total states run:     2
Total run time:   2.288 ms
# salt-call state.apply test-prepend-header --state-output=changes
local:
  Name: /etc/testing-prepend - Function: file.exists - Result: Clean Started: - 22:10:44.662027 Duration: 0.447 ms
  Name: /etc/testing-prepend - Function: file.prepend - Result: Clean Started: - 22:10:44.662811 Duration: 0.745 ms

Summary for local
------------
Succeeded: 2
Failed:    0
------------
Total states run:     2
Total run time:   1.192 ms
# cat /etc/testing-prepend 
################################
##### THIS IS A NICE HEADER ####
################################
Versions Report
# salt-call --versions-report
Salt Version:
           Salt: 2018.3.3
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.6.1
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.7
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
   python-gnupg: 0.4.1
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.2.5
 
System Versions:
           dist: Ubuntu 18.04 bionic
         locale: UTF-8
        machine: x86_64
        release: 4.15.0-34-generic
         system: Linux
        version: Ubuntu 18.04 bionic

We use test=True a lot, and it looks like an actual bug. We also don't have a documentation for the header parameter.

Any ideas ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the file.prepend state entry point and reproduce the supplied state on Salt 2018.3.3, first applying it normally and then with test=True. Compare the reported diff with the resulting file contents; done means test mode no longer reports the header as being prepended again, while the issue’s missing header documentation is addressed if included in scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.