Skip to content

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

Closed

Description

@pprince

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: '*'

Activity

  1. added a commit that references this issue on Feb 15, 2016
    d592d86
  2. pprince commented on Feb 15, 2016

    @pprince
    ContributorAuthor

    Submitted PR #31225

  3. changed the title [-]file_tree pillar regression: UnboundLocalError exception when any of the files end in '\n'[/-] [+]file_tree pillar: fails when data files at root end in '\n'[/+] on Feb 16, 2016
  4. pprince commented on Feb 16, 2016

    @pprince
    ContributorAuthor

    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

  5. added
    bug
    severity-medium
    P3
    Platform
    on Feb 16, 2016
  6. added this to the Approved milestone on Feb 16, 2016
  7. jfindlay commented on Feb 16, 2016

    @jfindlay
    Contributor

    @pprince, thanks for fixing this.

  8. added a commit that references this issue on Feb 18, 2016
    c58f654
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3PillarPlatformbugseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions