salt icon indicating copy to clipboard operation
salt copied to clipboard

file_tree pillar: fails when data files at root end in '\n'

Open pprince opened this issue 10 years ago • 3 comments

Since 1ba448b (in v2015.8.4)

Using file_tree pillar, if any of the files end with '\n', this exception is thrown:

It looks to me like a bug in the code, and I am submitting a PR momentarily.

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/pillar/__init__.py", line 637, in ext_pillar
    key)
  File "/usr/lib/python2.7/dist-packages/salt/pillar/__init__.py", line 589, in _external_pillar_data
    ext = self.ext_pillars[key](self.opts['id'], pillar, **val)
  File "/usr/lib/python2.7/dist-packages/salt/pillar/file_tree.py", line 307, in ext_pillar
    keep_newline)
  File "/usr/lib/python2.7/dist-packages/salt/pillar/file_tree.py", line 234, in _construct_pillar
    and _check_newline(prefix,
UnboundLocalError: local variable 'prefix' referenced before assignment

For reference, I have the files laid out like this:

/srv/salt
├── file_tree
│   ├── hosts
│   │   ├── m1.nacl.example.com
│   │   │   ├── file.txt
│   │   │   └── m1.nacl.example.com.txt
│   │   ├── m2.nacl.example.com
│   │   │   ├── file.txt
│   │   │   └── m2.nacl.example.com.txt
│   │   └── master.nacl.example.com
│   │       ├── file.txt
│   │       └── master.nacl.example.com.txt
│   └── nodegroups
│       └── all
│           ├── file.txt
│           └── nodegroups_all.txt
├── modules
└── pillar
    ├── default.sls
    └── top.sls

and my /etc/salt/master contains this:

interface: '::'
ipv6: True
extension_modules: /srv/salt/modules
pillar_roots:
    base:
        - /srv/salt/pillar
ext_pillar:
    - file_tree:
        root_dir: /srv/salt/file_tree
        keep_newline: True
nodegroups:
    all: '*'

pprince avatar Feb 15 '16 18:02 pprince

Submitted PR #31225

pprince avatar Feb 15 '16 19:02 pprince

I figured out why I was having this issue, but no one else had yet.

It only occurs when the data files are at the top level of the tree, so this breaks:

/srv/salt/file_tree_pillar/hosts/minion1.example.com/file.txt

but this works:

/srv/salt/file_tree_pillar/hosts/minion1.example.com/some_dir/file.txt

pprince avatar Feb 16 '16 00:02 pprince

@pprince, thanks for fixing this.

jfindlay avatar Feb 16 '16 18:02 jfindlay